osb/app/Console/Commands/ImportCosts.php

45 lines
1019 B
PHP

<?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()
{
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(),
Carbon::create($this->argument('date')),
$this->argument('file'),
);
}
}