Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
QuotationsSync
0.00% covered (danger)
0.00%
0 / 11
0.00% covered (danger)
0.00%
0 / 2
30
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 2
0.00% covered (danger)
0.00%
0 / 1
2
 handle
0.00% covered (danger)
0.00%
0 / 9
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace App\Console\Commands;
4
5use App\Services\PresupuestosService;
6use Illuminate\Console\Command;
7use Illuminate\Support\Facades\Log;
8
9class QuotationsSync extends Command
10{
11    /**
12     * The name and signature of the console command.
13     *
14     * @var string
15     */
16    protected $signature = 'quotations:sync {date?} {name?} {region?}';
17
18    /**
19     * The console command description.
20     *
21     * @var string
22     */
23    protected $description = 'Synchronizes budgets for the specified date';
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        $date = $this->argument('date') ?? date('Y-m-d');
56        $name = $this->argument('name') ?? "System";
57        $regions = $this->argument('region') ? explode(',', $this->argument('region')) : ['Cataluña', 'Madrid', 'Comunidad Valenciana'];
58        try {
59            foreach ($regions as $region) {
60                $this->presupuestosService->syncByDate($date, $name, $region);
61            }
62            return Command::SUCCESS;
63        } catch (\Exception $e) {
64            Log::channel('g3w')->error("Synchronization failed for date: $date, Error: " . $e->getMessage());
65            return Command::FAILURE;
66        }
67    }
68}