| 1234567891011121314151617181920212223242526272829303132333435363738394041 |
- <?php
- namespace App\Console\Commands;
- use App\Services\TbrCalculationService;
- use Carbon\Carbon;
- use Illuminate\Console\Command;
- /**
- * Geração automática do TBR do mês fechado (roda no schedule mensal).
- *
- * Sem opções, gera o TBR do MÊS ANTERIOR (já fechado) — ex.: rodando em 01/ago,
- * gera as contas referentes a julho. Idempotente: pula o que já foi gerado.
- */
- class GenerateMonthlyTbrCommand extends Command
- {
- protected $signature = 'tbr:generate-monthly {--year=} {--month=}';
- protected $description = 'Gera automaticamente as cobranças do TBR do mês fechado';
- public function handle(TbrCalculationService $service): int
- {
- $reference = Carbon::now()->subMonthNoOverflow();
- $year = (int) ($this->option('year') ?: $reference->year);
- $month = (int) ($this->option('month') ?: $reference->month);
- $this->info("Gerando TBR automático para {$month}/{$year}...");
- $result = $service->generateBatch($year, $month, null);
- $this->info(sprintf(
- '%d gerado(s), %d pulado(s), %d erro(s).',
- $result['generated_count'],
- $result['skipped_count'],
- $result['error_count'],
- ));
- return self::SUCCESS;
- }
- }
|