Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
10.00% covered (danger)
10.00%
1 / 10
50.00% covered (danger)
50.00%
1 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
QuotationsWorkSync
10.00% covered (danger)
10.00%
1 / 10
50.00% covered (danger)
50.00%
1 / 2
32.24
0.00% covered (danger)
0.00%
0 / 1
 __construct
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 handle
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
30
1<?php
2
3namespace App\Console\Commands;
4
5use App\Services\PresupuestosService;
6use Illuminate\Console\Command;
7use Illuminate\Support\Facades\Log;
8
9class 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     * @var PresupuestosService
27     */
28    protected $presupuestoService;
29
30    /**
31     * Create a new command instance.
32     */
33    public function __construct(private readonly PresupuestosService $presupuestosService)
34    {
35        parent::__construct();
36    }
37
38    /**
39     * Execute the console command.
40     */
41    public function handle(): int
42    {
43        $name = $this->argument('name') ?? 'System';
44        $regions = $this->argument('region') ? explode(',', $this->argument('region')) : ['Cataluña', 'Madrid', 'Comunidad Valenciana', 'AndalucĂ­a', 'Baleares'];
45
46        $hasFailure = false;
47
48        foreach ($regions as $region) {
49            try {
50                $this->presupuestosService->syncBudgetsWorks($name, $region);
51            } catch (\Exception $e) {
52                Log::channel('g3w')->error("Synchronization failed for region: $region, Error: ".$e->getMessage());
53                $hasFailure = true;
54            }
55        }
56
57        return $hasFailure ? Command::FAILURE : Command::SUCCESS;
58    }
59}