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