@php $org = auth()->user()->organization ?? \App\Models\System\Organization::find(auth()->user()->organization_id); @endphp @extends('documents.procurement._layout', [ 'documentTitle' => 'Aged Creditors Report', 'reference' => null, 'documentDate' => $reportDate, 'noAutoPrint' => true, ]) @section('header-meta')
As of: {{ $asOf->format('d M Y') }}
Currency: {{ $currency }}
@endsection @section('content') @php $totalCurrent = $buckets['current']->sum(fn($i) => (float)$i->total_amount - (float)$i->amount_paid_base); $total1_30 = $buckets['1_30']->sum(fn($i) => (float)$i->total_amount - (float)$i->amount_paid_base); $total31_60 = $buckets['31_60']->sum(fn($i) => (float)$i->total_amount - (float)$i->amount_paid_base); $total61_90 = $buckets['61_90']->sum(fn($i) => (float)$i->total_amount - (float)$i->amount_paid_base); $totalOver90 = $buckets['over_90']->sum(fn($i) => (float)$i->total_amount - (float)$i->amount_paid_base); $grandTotal = $totalCurrent + $total1_30 + $total31_60 + $total61_90 + $totalOver90; @endphp {{-- Age Summary --}}
Current
{{ number_format($totalCurrent, 0) }}
1–30 Days
{{ number_format($total1_30, 0) }}
31–60 Days
{{ number_format($total31_60, 0) }}
61–90 Days
{{ number_format($total61_90, 0) }}
Over 90 Days
{{ number_format($totalOver90, 0) }}
Total Outstanding
{{ number_format($grandTotal, 0) }}
@if($bySupplier->isEmpty())

No outstanding balances as of {{ $asOf->format('d M Y') }}.

@else {{-- By Supplier --}} @foreach($bySupplier as $supplierId => $supplierInvoices) @php $supplierName = $supplierInvoices->first()->supplier?->name ?? '—'; $supplierTotal = $supplierInvoices->sum(fn($i) => (float)$i->total_amount - (float)$i->amount_paid_base); @endphp

{{ $supplierName }} — {{ $currency }} {{ number_format($supplierTotal, 2) }} outstanding

@foreach($supplierInvoices as $inv) @php $balance = (float)$inv->total_amount - (float)$inv->amount_paid_base; if ($balance <= 0) continue; $days = $inv->due_date ? $inv->due_date->diffInDays($asOf, false) : null; $ageLabel = $days === null ? 'No due date' : ($days <= 0 ? 'Current' : $days . ' days'); $rowClass = $days === null || $days <= 0 ? 'bg-green' : ($days <= 30 ? 'bg-amber' : 'bg-red'); @endphp @endforeach
Invoice Ref Invoice Date Due Date Total ({{ $currency }}) Paid Balance Age
{{ $inv->invoice_reference }} {{ \Carbon\Carbon::parse($inv->invoice_date)->format('d M Y') }} {{ $inv->due_date ? $inv->due_date->format('d M Y') : '—' }} {{ number_format((float)$inv->total_amount, 2) }} {{ number_format((float)$inv->amount_paid_base, 2) }} {{ number_format($balance, 2) }} {{ $ageLabel }}
@endforeach @endif @endsection