Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 10
0.00% covered (danger)
0.00%
0 / 2
CRAP
0.00% covered (danger)
0.00%
0 / 1
InvoicesSync
0.00% covered (danger)
0.00%
0 / 10
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 / 8
0.00% covered (danger)
0.00%
0 / 1
20
1<?php
2
3namespace App\Console\Commands;
4
5use App\Services\FacturasService;
6use Illuminate\Console\Command;
7
8class InvoicesSync extends Command
9{
10    /**
11     * The name and signature of the console command.
12     *
13     * @var string
14     */
15    protected $signature = 'invoices:send-reminder {region?}';
16
17    /**
18     * The console command description.
19     *
20     * @var string
21     */
22    protected $description = 'Automatic sending of invoice reminders';
23
24    /**
25     * Create a new command instance.
26     *
27     * @return void
28     */
29    public function __construct(FacturasService $facturasService)
30    {
31        parent::__construct();
32        $this->facturasService = $facturasService;
33    }
34
35    /**
36     * Execute the console command.
37     *
38     * @return int
39     */
40    public function handle()
41    {
42        $regions = $this->argument('region') ? explode(',', $this->argument('region')) : ['Cataluña', 'Comunidad Valenciana', 'Madrid'];
43
44        try {
45            foreach ($regions as $region) {
46                $this->facturasService->getInvoices($region);
47            }
48            return Command::SUCCESS;
49        } catch (\Exception $e) {
50            Log::channel('g3w_invoices')->error("Error al sincronizar facturas: " . $e->getMessage());
51            $this->error("Error: " . $e->getMessage());
52            return Command::FAILURE;
53        }
54    }
55}