2022-06-14 06:55:17 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Console\Commands;
|
|
|
|
|
|
|
|
use Carbon\Carbon;
|
|
|
|
use Illuminate\Console\Command;
|
|
|
|
|
|
|
|
use App\Jobs\ImportCosts as Job;
|
|
|
|
use App\Models\{Site,Supplier};
|
|
|
|
|
|
|
|
class ImportCosts extends Command
|
|
|
|
{
|
|
|
|
/**
|
|
|
|
* The name and signature of the console command.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $signature = 'costs:import {siteid : Site ID} {supplier : Supplier Name} {file : Filename} {date : Date}';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* The console command description.
|
|
|
|
*
|
|
|
|
* @var string
|
|
|
|
*/
|
|
|
|
protected $description = 'Import Costs from file';
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Execute the console command.
|
|
|
|
*
|
|
|
|
* @return void
|
|
|
|
*/
|
|
|
|
public function handle()
|
|
|
|
{
|
2023-06-16 05:10:36 +00:00
|
|
|
if (! str_starts_with($this->argument('file'),'files/'))
|
|
|
|
throw new \Exception('Filename must start with files/');
|
2022-08-19 05:12:56 +00:00
|
|
|
|
2022-06-14 06:55:17 +00:00
|
|
|
Job::dispatchSync(
|
|
|
|
Site::findOrFail($this->argument('siteid')),
|
|
|
|
Supplier::where('name',$this->argument('supplier'))->singleOrFail(),
|
|
|
|
Carbon::create($this->argument('date')),
|
|
|
|
$this->argument('file'),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|