Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
18.18% |
2 / 11 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| CofraiQuotationsSync | |
18.18% |
2 / 11 |
|
50.00% |
1 / 2 |
18.69 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
2 / 2 |
|
100.00% |
1 / 1 |
1 | |||
| handle | |
0.00% |
0 / 9 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Console\Commands; |
| 4 | |
| 5 | use App\Services\CofraiQuotationsService; |
| 6 | use Illuminate\Console\Command; |
| 7 | use Illuminate\Support\Facades\Log; |
| 8 | |
| 9 | class CofraiQuotationsSync extends Command |
| 10 | { |
| 11 | /** |
| 12 | * The name and signature of the console command. |
| 13 | * |
| 14 | * @var string |
| 15 | */ |
| 16 | protected $signature = 'cofrai-quotations:sync {date?} {name?} {region?}'; |
| 17 | |
| 18 | /** |
| 19 | * The console command description. |
| 20 | * |
| 21 | * @var string |
| 22 | */ |
| 23 | protected $description = 'Synchronizes cofrai budgets for the specified date'; |
| 24 | |
| 25 | /** |
| 26 | * The PresupuestoService instance. |
| 27 | * |
| 28 | * @var CofraiQuotationsService |
| 29 | */ |
| 30 | protected $cofraiQuotationsService; |
| 31 | |
| 32 | /** |
| 33 | * Create a new command instance. |
| 34 | * |
| 35 | * @return void |
| 36 | */ |
| 37 | public function __construct(CofraiQuotationsService $cofraiQuotationsService) |
| 38 | { |
| 39 | parent::__construct(); |
| 40 | $this->cofraiQuotationsService = $cofraiQuotationsService; |
| 41 | } |
| 42 | |
| 43 | /** |
| 44 | * Execute the console command. |
| 45 | * |
| 46 | * @return int |
| 47 | */ |
| 48 | public function handle() |
| 49 | { |
| 50 | $date = $this->argument('date') ?? date('Y-m-d'); |
| 51 | $name = $this->argument('name') ?? 'System'; |
| 52 | $regions = $this->argument('region') ? explode(',', $this->argument('region')) : ['Cataluña']; |
| 53 | |
| 54 | try { |
| 55 | foreach ($regions as $region) { |
| 56 | $this->cofraiQuotationsService->syncByDate($date, $name, $region); |
| 57 | } |
| 58 | |
| 59 | return Command::SUCCESS; |
| 60 | } catch (\Exception $e) { |
| 61 | Log::channel('g3w')->error("Synchronization failed for date: $date, Error: ".$e->getMessage()); |
| 62 | |
| 63 | return Command::FAILURE; |
| 64 | } |
| 65 | } |
| 66 | } |