option('dry-run'); $limit = max(1, (int) $this->option('limit')); $created = 0; $skipped = 0; $seen = []; while ($created < $limit) { $due = $service->duePaymentOptions(limit: self::PAGE_SIZE, excludeIds: $seen); if ($due->isEmpty()) { break; } foreach ($due as $option) { $seen[] = $option->id; if ($dryRun) { $this->line(sprintf( '[dry-run] Fällig: Vereinbarung #%d (User #%s, Periode bis %s)%s', $option->id, $option->user_id, $option->current_period_end->toDateString(), $option->billing_hold_reason ? ' – gesperrt: '.$option->billing_hold_reason : '', )); continue; } if ($created >= $limit) { break; } $invoice = $service->invoiceFor($option); if ($invoice) { $created++; $this->line(sprintf('Rechnung %s für Vereinbarung #%d erstellt.', $invoice->number, $option->id)); } else { $skipped++; $this->warn(sprintf('Vereinbarung #%d übersprungen: %s.', $option->id, $option->refresh()->billing_hold_reason ?? 'nicht abrechenbar')); } } } if ($seen === []) { $this->info('Keine fälligen Zahlungsvereinbarungen gefunden.'); return self::SUCCESS; } if (! $dryRun) { $this->info(sprintf('%d Rechnung(en) erstellt, %d übersprungen.', $created, $skipped)); } return self::SUCCESS; } }