{{-- The printable Statement of Account. What a tenant is handed when they ask "what do I owe?", so every figure on this page comes from CustomerStatement::for(), already computed - do no arithmetic in this view beyond choosing how to display a Money that is already final. A statement balance is a running total and can legitimately be negative (the customer is in credit) at the opening row, at any line, or at closing - Money::format() would render that with a literal minus sign ("AED -1,234.56"), which reads as a mistake on a document a tenant receives. formatBalance() below always shows the absolute figure and spells "in credit" out instead. Each line's amount is split into a Debit column (invoices and reversals - positive amounts) and a Credit column (credit notes and receipts - negative amounts, shown via ->abs()->format()), leaving the other cell empty, so the sign is never lost - only never printed as "-". $statement is CustomerStatement::for()'s return shape (see App\Support\CustomerStatement); $branch is the customer's own branch. App\Filament\Resources\Customers\Pages\ViewCustomerStatement resolves the record through the branch scope and the viewReceivables gate before this view is ever reached. --}} @php /** @var array{customer: \App\Models\Customer, from: \Carbon\CarbonImmutable, to: \Carbon\CarbonImmutable, opening: \App\Support\Money, lines: \Illuminate\Support\Collection, closing: \App\Support\Money, uncleared_cheques: \Illuminate\Support\Collection, deposit_held: ?\App\Support\Money} $statement */ $customer = $statement['customer']; $formatBalance = fn (\App\Support\Money $money): string => $money->isNegative() ? $money->abs()->format().' in credit' : $money->format(); $formatDebit = fn (\App\Support\Money $money): string => $money->isNegative() ? '' : $money->format(); $formatCredit = fn (\App\Support\Money $money): string => $money->isNegative() ? $money->abs()->format() : ''; @endphp
Statement of Account |
Period: {{ $statement['from']->format('j M Y') }} – {{ $statement['to']->format('j M Y') }} |
Branch{{ $branch->name }} {{ $branch->address }} TRN: {{ $branch->trn }} |
Customer{{ $customer->name }} {{ $customer->address }} @if (filled($customer->trn))TRN: {{ $customer->trn }} @endif |
| Date | Reference | Description | Debit | Credit | Balance |
|---|---|---|---|---|---|
| {{ $statement['from']->format('j M Y') }} | Opening balance | {{ $formatBalance($statement['opening']) }} | |||
| {{ $line['date']->format('j M Y') }} | {{ $line['reference'] }} | {{ $line['description'] }} | {{ $formatDebit($line['amount']) }} | {{ $formatCredit($line['amount']) }} | {{ $formatBalance($line['balance']) }} |
| {{ $statement['to']->format('j M Y') }} | Closing balance | {{ $formatBalance($statement['closing']) }} |
| Cheque No. | Bank | Cheque Date | Amount |
|---|---|---|---|
| {{ $cheque->cheque_no }} | {{ $cheque->bank_name }} | {{ $cheque->cheque_date->format('j M Y') }} | {{ $cheque->amount->format() }} |
Security deposit held: {{ $statement['deposit_held']->format() }}
@endif