Added cost import via web
This commit is contained in:
@@ -31,6 +31,9 @@ class ImportCosts extends Command
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
if (! str_starts_with($this->argument('file'),'storage/app/'))
|
||||
throw new \Exception('Filename must start with storage/app/');
|
||||
|
||||
Job::dispatchSync(
|
||||
Site::findOrFail($this->argument('siteid')),
|
||||
Supplier::where('name',$this->argument('supplier'))->singleOrFail(),
|
||||
|
@@ -2,9 +2,13 @@
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Carbon\Carbon;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Storage;
|
||||
|
||||
use App\Http\Requests\{SupplierAddEdit,SupplierProductAddEdit};
|
||||
use App\Models\{Cost,Supplier,SupplierDetail};
|
||||
use App\Jobs\ImportCosts;
|
||||
|
||||
class SupplierController extends Controller
|
||||
{
|
||||
@@ -69,7 +73,31 @@ class SupplierController extends Controller
|
||||
public function cost(Cost $o)
|
||||
{
|
||||
// @todo Need to add the services that are active that are not on the bill for the supplier.
|
||||
return view('supplier.cost',['o'=>$o]);
|
||||
return view('supplier.cost.view',['o'=>$o]);
|
||||
}
|
||||
|
||||
public function cost_add(Supplier $o)
|
||||
{
|
||||
return view('supplier.cost.add',['o'=>$o]);
|
||||
}
|
||||
|
||||
public function cost_submit(Request $request,Supplier $o)
|
||||
{
|
||||
$request->validate([
|
||||
'file' => 'required|filled',
|
||||
'billed_at' => 'required|date',
|
||||
]);
|
||||
|
||||
$filename = $request->file('file')->store('cost_import');
|
||||
|
||||
ImportCosts::dispatch(
|
||||
config('site'),
|
||||
$o,
|
||||
Carbon::create($request->billed_at),
|
||||
$filename,
|
||||
)->onQueue('low');
|
||||
|
||||
return redirect()->back()->with('success','File uploaded');
|
||||
}
|
||||
|
||||
/**
|
||||
|
@@ -22,6 +22,7 @@ class ImportCosts implements ShouldQueue
|
||||
|
||||
private const LOGKEY = 'JIC';
|
||||
private Cost $co;
|
||||
private Site $site;
|
||||
private string $file;
|
||||
protected Collection $columns;
|
||||
|
||||
@@ -33,7 +34,7 @@ class ImportCosts implements ShouldQueue
|
||||
public function __construct(Site $site,Supplier $so,Carbon $invoice_date,string $file)
|
||||
{
|
||||
$this->file = $file;
|
||||
Config::set('site',$site);
|
||||
$this->site = $site;
|
||||
|
||||
$this->co = Cost::where('site_id',$site->site_id)
|
||||
->where('supplier_id',$so->id)
|
||||
@@ -72,9 +73,10 @@ class ImportCosts implements ShouldQueue
|
||||
*/
|
||||
public function handle()
|
||||
{
|
||||
Config::set('site',$this->site);
|
||||
$skip = 7; // @todo to be stored in supplier config
|
||||
|
||||
$file = fopen($this->file,'r');
|
||||
$file = fopen('storage/app/'.$this->file,'r');
|
||||
$haveHeader = FALSE;
|
||||
|
||||
$c = 0;
|
||||
|
Reference in New Issue
Block a user