@extends('documents.procurement._layout', [ 'documentTitle' => 'Statement of Account', 'reference' => $supplier->name, 'documentDate' => $today->format('d M Y'), ]) @section('header-meta')
Period: {{ $from->format('d M Y') }}{{ $until->format('d M Y') }}
@endsection @section('content') @php $totalInvoiced = $invoices->sum(fn($i) => (float) $i->total_amount); $totalPaid = $invoices->sum(fn($i) => (float) $i->amount_paid_base); $totalBalance = $totalInvoiced - $totalPaid; $runningBalance = 0; @endphp {{-- Supplier block --}}
Supplier:
{{ $supplier->name }}
@if($supplier->contact_email) {{ $supplier->contact_email }}
@endif @if($supplier->contact_phone) {{ $supplier->contact_phone }}
@endif @if($supplier->city) {{ $supplier->city }} @endif
{{-- Transactions --}} @foreach($invoices as $inv) @php $runningBalance += (float) $inv->total_amount; $paidSoFar = $inv->payments->sortBy('payment_date'); @endphp @foreach($paidSoFar as $pmt) @php $runningBalance -= (float) $pmt->amount_base; @endphp @endforeach @endforeach
Date Reference Description Invoiced Paid Balance
{{ \Carbon\Carbon::parse($inv->invoice_date)->format('d M Y') }} {{ $inv->invoice_reference }} Invoice — {{ ucwords(str_replace('_', ' ', $inv->invoice_type)) }} {{ number_format((float) $inv->total_amount, 2) }} {{ number_format($runningBalance, 2) }}
{{ \Carbon\Carbon::parse($pmt->payment_date)->format('d M Y') }} {{ $pmt->payment_reference }} Payment — {{ ucwords(str_replace('_', ' ', $pmt->payment_method)) }} ({{ number_format((float) $pmt->amount_base, 2) }}) {{ number_format($runningBalance, 2) }}
{{-- Summary --}}
Total Invoiced {{ number_format($totalInvoiced, 2) }}
Total Paid ({{ number_format($totalPaid, 2) }})
Outstanding Balance {{ number_format($totalBalance, 2) }}
{{-- Age analysis --}} @if(array_sum($ageBuckets) > 0)

Aged Analysis (Outstanding)

Current (Not Due) 1–30 Days 31–60 Days 61–90 Days Over 90 Days Total
{{ number_format($ageBuckets['current'], 2) }} {{ number_format($ageBuckets['1_30'], 2) }} {{ number_format($ageBuckets['31_60'], 2) }} {{ number_format($ageBuckets['61_90'], 2) }} {{ number_format($ageBuckets['over_90'], 2) }} {{ number_format(array_sum($ageBuckets), 2) }}
@endif @endsection