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