{{-- Debtors Analysis Report (aged receivables) in the house PDF style, laid out as the Receivables screen: the heading with the applied filters, the figure cards, the "Debt by age" bar, then the table - every region (landscape), or one region's debtors. Every figure comes from the same service call as the screen, so the paper always agrees with it. Written for mPDF: tables, not flex or grid. --}} @extends('layouts.PdfReportLayout') @php $s = $summary ?? []; $num = fn ($value) => number_format((int) ($value ?? 0)); $total = (float) ($totals['total'] ?? 0); $above365 = (float) ($totals['365+'] ?? 0); /* Youngest debt green, oldest red - the band colours of the screen. */ $bandColors = [ '1-30' => '#a3cf8f', '31-60' => '#7fb069', '61-90' => '#5a9a4a', '91-120' => '#e0b84c', '121-365' => '#d98c3f', '365+' => '#c0443a', ]; /* The screen's icons (lucide), drawn as small SVGs. */ $paths = [ 'coins' => '', 'alert' => '', 'calendar-x' => '', 'pie' => '', 'history' => '', 'hourglass' => '', 'gauge' => '', ]; $icon = function (string $name, string $color = '#f97316') use ($paths) { // mPDF does not pass the root's stroke and fill down, so every shape carries its own. $style = ' fill="none" stroke="'.$color.'" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"'; $shapes = preg_replace('#<(circle|line|path|rect)\b#', '<$1'.$style, $paths[$name]); $svg = ''.$shapes.''; return ''; }; @endphp @section('doc_title', $docTitle) @section('doc_subtitle', $docSubtitle) @section('content') {{-- The heading, as on the screen. --}}
Aged Analysis of Debtors · {{ $scopeLabel }}
{{ $periodLabel }}
Ages measured as at {{ $asAt }}
Financial year {{ $financialYear }} · Prepared by {{ $generatedBy }}, {{ $generatedAt }}
{{-- The applied filters, as the chips under the screen's heading. --}} @foreach($filterLabels as $label => $value) @endforeach
{{ $label }}: {{ $value }}
@if($level === 'regions') {{-- The eight figures above the age bar, as the Receivables screen lays them out. --}}
{!! $icon('coins') !!} Total receivables (Tsh)
{{ $money($s['total'] ?? 0) }}
pending + partially paid on {{ $num($s['bills'] ?? 0) }} bills across {{ $num($s['regions'] ?? 0) }} regions
Pending bills{{ $money($s['pending_amount'] ?? 0) }} ({{ $num($s['pending_bills'] ?? 0) }})
Partially paid{{ $money($s['partial_amount'] ?? 0) }} ({{ $num($s['partial_bills'] ?? 0) }})
{!! $icon('alert', '#e11d48') !!} Overdue (Tsh)
{{ $money($s['overdue_amount'] ?? 0) }}
{{ $num($s['overdue_bills'] ?? 0) }} bills past their due date · {{ $formatPct($pct($s['overdue_amount'] ?? 0, $total)) }} of the debt · longest {{ $num($s['oldest_age'] ?? 0) }} days
{!! $icon('calendar-x') !!} Expired control numbers (Tsh)
{{ $money($s['expired_amount'] ?? 0) }}
{{ $num($s['expired_bills'] ?? 0) }} bills can no longer be paid without renewal · {{ $num($s['expiring_soon'] ?? 0) }} expire within 7 days
{!! $icon('pie') !!} Partially paid (Tsh)
{{ $money($s['partial_amount'] ?? 0) }}
{{ $num($s['partial_bills'] ?? 0) }} bills with a balance
{!! $icon('history') !!} Above 365 days (Tsh)
{{ $money($above365) }}
{{ $formatPct($pct($above365, $total)) }} of the debt is over a year old
{!! $icon('hourglass') !!} Age of debt
{{ $num($s['average_age'] ?? 0) }} days avg
Oldest bill {{ $num($s['oldest_age'] ?? 0) }} days since billing
{!! $icon('gauge') !!} Average per bill (Tsh)
{{ $money(round((float) ($s['average_per_bill'] ?? 0))) }}
per debtor bill · {{ $num($s['partial_bills'] ?? 0) }} partially paid
@else {{-- One region's four figures: outstanding, overdue, partly paid, oldest debt. --}}
{!! $icon('coins') !!} Outstanding debt (Tsh)
{{ $money($s['total'] ?? 0) }}
{{ $num($s['bills'] ?? 0) }} debtor bills
{!! $icon('alert', '#e11d48') !!} Overdue (Tsh)
{{ $money($s['overdue_amount'] ?? 0) }}
{{ $num($s['overdue_bills'] ?? 0) }} bills past due · {{ $num($s['expired_bills'] ?? 0) }} with expired control numbers
{!! $icon('pie') !!} Partially paid (Tsh)
{{ $money($s['partial_amount'] ?? 0) }}
{{ $num($s['partial_bills'] ?? 0) }} bills with a balance
{!! $icon('hourglass') !!} Oldest debt
{{ $num($s['oldest_age'] ?? 0) }} days
longest overdue {{ $num($s['longest_overdue'] ?? 0) }} days past the due date
@endif {{-- "Debt by age": one bar split by band, with each band's amount and share. --}}
Debt by age
How long the outstanding bills have been open, counted from the day each bill was raised.
@if($total > 0) @foreach($bands as $key => $label) @php $share = $pct($totals[$key] ?? 0, $total); @endphp @if($share > 0) @endif @endforeach @else @endif
@foreach(array_chunk($bands, 6, true) as $row) @foreach($row as $key => $label) @endforeach @endforeach
') }}" style="width: 6pt; height: 6pt; vertical-align: middle;" alt=""/> {{ str_replace(' Days', ' days', $label) }} {{ $money($totals[$key] ?? 0) }} ({{ $formatPct($pct($totals[$key] ?? 0, $total)) }})
@if($level === 'regions') {{-- The table starts its own page, its title with it; its column row repeats on each page. --}}
Receivables by region
@foreach($bands as $label) @endforeach @forelse($rows as $index => $row) @foreach($bands as $key => $label) @endforeach @empty @endforelse @if(count($rows) > 0) @foreach($bands as $key => $label) @endforeach @endif
# Collection Center Bills Total Debt{{ $label }}Overdue Share
{{ $index + 1 }} {{ $row['center_name'] }} {{ $num($row['bills']) }} {{ $money($row['total']) }}@if((float) ($row[$key] ?? 0)){{ $money($row[$key]) }}@else0@endif @if((float) $row['overdue_amount']) {{ $money($row['overdue_amount']) }}
{{ $row['overdue_bills'] }} bills{{ $row['expired_bills'] ? ' ยท '.$row['expired_bills'].' expired' : '' }} @else - @endif
{{ (float) $row['share'] ? $formatPct((float) $row['share']) : '-' }}
Nothing is owed as at this date.
Total {{ $num($s['bills'] ?? 0) }} {{ $money($totals['total']) }} {{ $money($totals[$key] ?? 0) }} {{ $money($s['overdue_amount'] ?? 0) }} 100%
@else
Debtors - {{ $regionLabel }} ({{ number_format($debtorCount) }})
{{-- The debtor list is written here by ReportPdf, one page-sized table at a time. --}} {!! \App\Support\Pdf\ReportPdf::LONG_TABLE !!} @endif
Basis: every bill raised on or before {{ $asAt }}, less the money banked against it by that date, aged from the day the bill was created. Cancelled bills are excluded. Amounts are in Tanzanian Shillings.
@endsection