where('user_id', auth()->id())
->withoutHold();
// Neue Rechnungen (STR = Stripe-Spiegelung, MAN = Bestandskreis).
$currentQuery = Invoice::query()->where('user_id', auth()->id());
// Das Altsystem-Archiv erscheint nur, wenn der User dort überhaupt
// Rechnungen hat (QA-Befund 07.07.) — Neukunden sehen es nie.
$invoices = (clone $baseQuery)
->latest('invoice_date')
->paginate(100);
return [
'currentInvoices' => (clone $currentQuery)
->latest('invoice_date')
->latest('id')
->limit(100)
->get(),
'invoices' => $invoices,
'stats' => [
'count' => (clone $baseQuery)->count() + (clone $currentQuery)->count(),
'total_cents' => (int) (clone $baseQuery)->sum('total_cents') + (int) (clone $currentQuery)->sum('total_cents'),
'paid_count' => (clone $baseQuery)->whereNotNull('paid_at')->count()
+ (clone $currentQuery)->where('status', InvoiceStatus::Paid->value)->count(),
'downloadable_count' => (clone $baseQuery)->count()
+ (clone $currentQuery)->count(),
],
];
}
}; ?>
{{-- ============== PAGE HEADER ============== --}}
@if ($notification)
@endif
@if (session('invoice-error'))
{{ session('invoice-error') }}
@endif
{{-- ============== KPI-Reihe ============== --}}
{{ __('neu + Archiv') }}
{{ __('User-spezifisch') }}
{{ __('alle Rechnungen') }}
{{ __('alle Portale') }}
{{ __('vollständig') }}
{{ __('mit Zahlungsdatum') }}
{{ __('PDF / Stripe') }}
{{ __('direkt abrufbar') }}
{{-- ============== AKTUELLE RECHNUNGEN (STR/MAN) ============== --}}
{{ __('Aktuelle Rechnungen') }}
{{ __(':count Einträge', ['count' => $currentInvoices->count()]) }}
{{ __('Rechnungsnr.') }}
{{ __('Netto') }}
{{ __('USt.') }}
{{ __('Gesamt') }}
{{ __('Status') }}
{{ __('Rechnungsdatum') }}
{{ __('Beleg') }}
@forelse ($currentInvoices as $invoice)
{{ $invoice->number }}
{{ number_format($invoice->amount_cents / 100, 2, ',', '.') }} €
{{ number_format($invoice->tax_cents / 100, 2, ',', '.') }} €
{{ number_format($invoice->total_cents / 100, 2, ',', '.') }} €
@if ($invoice->status === \App\Enums\InvoiceStatus::Paid)
{{ $invoice->status->label() }}
@elseif ($invoice->status === \App\Enums\InvoiceStatus::Open)
{{ $invoice->status->label() }}
@if ($invoice->due_date)
{{ __('zahlbar bis :date', ['date' => $invoice->due_date->format('d.m.Y')]) }}
@endif
@else
{{ $invoice->status->label() }}
@endif
{{ $invoice->invoice_date?->format('d.m.Y') ?? '–' }}
@if ($invoice->stripe_invoice_id)
{{-- PDF kommt aus pressekonto; die Stripe-Seite bleibt für den Zahlungsbeleg. --}}
{{ __('PDF öffnen') }}
{{ __('Beleg bei Stripe') }}
@else
{{ __('PDF öffnen') }}
@endif
@empty
{{ __('Noch keine Rechnungen aus neuen Buchungen — sie erscheinen hier automatisch nach der ersten Abrechnung.') }}
@endforelse
{{-- ============== RECHNUNGSARCHIV (ALTSYSTEM) ==============
Nur für Bestandskunden mit importierten Alt-Rechnungen. --}}
@if ($invoices->total() > 0)
{{ __('Rechnungsarchiv (Altsystem)') }}
{{ __(':count Einträge', ['count' => $invoices->count()]) }}
{{ __('Rechnungsnr.') }}
{{ __('Portal') }}
{{ __('Betrag') }}
{{ __('Status') }}
{{ __('Rechnungsdatum') }}
{{ __('Bezahlt am') }}
{{ __('PDF') }}
@foreach ($invoices as $invoice)
{{ $invoice->number ?? ('#'.$invoice->legacy_id) }}
{{ $invoice->legacy_portal?->label() }}
{{ number_format($invoice->total_cents / 100, 2, ',', '.') }} €
@if ($invoice->paid_at)
{{ __('Bezahlt') }}
@elseif ($invoice->status === \App\Models\LegacyInvoice::STATUS_SUPERSEDED)
{{ __('Ersetzt durch :number', ['number' => $invoice->raw_snapshot['superseded_by_invoice_number'] ?? '–']) }}
@elseif ($invoice->status === \App\Models\LegacyInvoice::STATUS_UNCOLLECTIBLE)
{{ __('Erledigt') }}
@else
{{ __('Offen') }}
@endif
{{ $invoice->invoice_date?->format('d.m.Y') ?? '–' }}
{{ $invoice->paid_at?->format('d.m.Y') ?? '–' }}
{{ __('Öffnen') }}
@endforeach
@endif