Code Coverage |
||||||||||
Lines |
Functions and Methods |
Classes and Traits |
||||||||
| Total | |
11.11% |
1 / 9 |
|
50.00% |
1 / 2 |
CRAP | |
0.00% |
0 / 1 |
| InvoicesSync | |
11.11% |
1 / 9 |
|
50.00% |
1 / 2 |
22.56 | |
0.00% |
0 / 1 |
| __construct | |
100.00% |
1 / 1 |
|
100.00% |
1 / 1 |
1 | |||
| handle | |
0.00% |
0 / 8 |
|
0.00% |
0 / 1 |
20 | |||
| 1 | <?php |
| 2 | |
| 3 | namespace App\Console\Commands; |
| 4 | |
| 5 | use App\Services\FacturasService; |
| 6 | use Illuminate\Console\Command; |
| 7 | use Illuminate\Support\Facades\Log; |
| 8 | |
| 9 | class 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 | /** |
| 26 | * Create a new command instance. |
| 27 | */ |
| 28 | public function __construct(protected FacturasService $facturasService) |
| 29 | { |
| 30 | parent::__construct(); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * Execute the console command. |
| 35 | */ |
| 36 | public function handle(): int |
| 37 | { |
| 38 | $regions = $this->argument('region') ? explode(',', $this->argument('region')) : ['Cataluña', 'Comunidad Valenciana', 'Madrid']; |
| 39 | |
| 40 | try { |
| 41 | foreach ($regions as $region) { |
| 42 | $this->facturasService->getInvoices($region); |
| 43 | } |
| 44 | |
| 45 | return Command::SUCCESS; |
| 46 | } catch (\Exception $e) { |
| 47 | Log::channel('g3w_invoices')->error('Error al sincronizar facturas: '.$e->getMessage()); |
| 48 | $this->error('Error: '.$e->getMessage()); |
| 49 | |
| 50 | return Command::FAILURE; |
| 51 | } |
| 52 | } |
| 53 | } |