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
InvoicesSync
10.00% covered (danger)
10.00%
1 / 10
50.00% covered (danger)
50.00%
1 / 2
15.66
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
12
1<?php
2
3namespace App\Console\Commands;
4
5use App\Jobs\SyncG3WInvoicesForRegion;
6use App\Services\FacturasService;
7use Illuminate\Console\Command;
8use Illuminate\Support\Facades\Log;
9
10class InvoicesSync extends Command
11{
12    /**
13     * The name and signature of the console command.
14     *
15     * @var string
16     */
17    protected $signature = 'invoices:send-reminder {region?}';
18
19    /**
20     * The console command description.
21     *
22     * @var string
23     */
24    protected $description = 'Automatic sending of invoice reminders';
25
26    /**
27     * Create a new command instance.
28     */
29    public function __construct(protected FacturasService $facturasService)
30    {
31        parent::__construct();
32    }
33
34    /**
35     * Execute the console command.
36     */
37    public function handle(): int
38    {
39        $regions = $this->argument('region') ? explode(',', $this->argument('region')) : ['Cataluña', 'Comunidad Valenciana', 'Madrid'];
40
41        // FIRE-1151: dispatch one job per region (parallel under redis driver,
42        // serial inline under sync driver — see QuotationsSync for details).
43        $cronStart = microtime(true);
44
45        foreach ($regions as $region) {
46            SyncG3WInvoicesForRegion::dispatch($region)->onQueue('g3w');
47        }
48
49        Log::channel('g3w_invoices')->info('invoices:sync dispatched', [
50            'regions' => count($regions),
51            'dispatch_ms' => (int) round((microtime(true) - $cronStart) * 1000),
52        ]);
53
54        return Command::SUCCESS;
55    }
56}