@php $money = fn ($value) => number_format((float) $value, 2); $date = fn ($value, $format = 'd M Y') => $value ? \Illuminate\Support\Carbon::parse($value)->format($format) : '-'; $status = \Modules\LegacyDebts\Enums\LegacyDebtStatus::tryFrom((string) $debt->status); $settledAmount = (float) $debt->settled_via_control_number_amount + (float) $debt->manually_settled_amount - (float) $debt->overpaid_amount; $latest = $debt->controlNumbers->sortByDesc('id')->first(fn ($link) => $link->control_number !== null); @endphp {{-- The heading is the rejection note's (resources/views/note.blade.php): coat of arms, the agency's name in small capitals, the WMA mark, the ornamental rules and the widely spaced title. What differs is the contact line, which is the debt's own office rather than a fixed one. Rendered by Chrome through PdfRenderingService, not mPDF - the fonts and SVG ornaments of that heading are ones mPDF cannot draw. --}} Legacy Debt Statement - {{ $debt->debt_number }}
@if ($emblem) Coat of Arms of Tanzania @endif
The United Republic of Tanzania
Ministry of Industry and Trade
Weights and Measures Agency
{{ $office['name'] ? $office['name'].' · ' : '' }}Wakala wa Vipimo
Tel: {{ $office['tel'] }}  ·  {{ $office['address'] }}  ·  {{ $office['email'] }}
@if ($logo) WMA Logo @endif
Legacy Debt Statement
Weights & Measures Agency - Statement of a Historical Debt and Its Collection
{{ $debt->debt_number }} · {{ $status?->label() ?? $debt->status }}
Billed (TZS)
{{ $money($debt->original_billed_amount) }}
Paid (TZS)
{{ $money($debt->paid_amount) }}
Outstanding (TZS)
{{ $money($debt->outstanding_amount) }}
@if ($debt->status === 'SETTLED')
SETTLED - TZS {{ $money($settledAmount) }} on {{ $date($debt->settled_at, 'd M Y H:i') }} @if ($latest) · settled through control number {{ $latest->control_number }}@endif
@endif

Debt information

Debt ID{{ $debt->debt_number }}Date{{ $date($debt->bill_date) }}
Payer{{ $debt->payer_name }}
Description{{ $debt->description }}
Mobile{{ $debt->mobile ?? '-' }}Original control number{{ $debt->original_control_number ?? '-' }}
Region{{ $locations->regionName($debt->region_id) ?? '-' }}District{{ $locations->districtName($debt->district_id) ?? '-' }}
Office{{ $locations->centreName($debt->collection_center) ?? '-' }}Expiry{{ $date($debt->original_expiry_date) }}
Generated by{{ $debt->original_generated_by ?? '-' }}Payment method{{ \Modules\LegacyDebts\Enums\LegacyPaymentMethod::tryFrom((string) $debt->original_payment_method)?->label() ?? '-' }}
As importedBilled {{ $money($debt->original_billed_amount) }} · Paid {{ $money($debt->original_paid_amount) }} · Outstanding {{ $money($debt->original_outstanding_amount) }} · {{ $debt->original_status_label ?? $debt->original_status }}

New control numbers

@if ($debt->controlNumbers->isEmpty())

No new control number has been generated for this debt.

@else @foreach ($debt->controlNumbers->sortBy('id') as $link) @endforeach
Control numberGeneratedByAmountPaidExpiresStatus
{{ $link->control_number ?? 'Awaiting GePG' }} {{ $date($link->generated_at, 'd M Y H:i') }} {{ $link->generated_by_name }} {{ $money($link->amount) }} {{ $money($link->paid_amount) }} {{ $date($link->expires_at) }} {{ $link->statusEnum()->label() }}
@endif

Payments

@if ($debt->payments->isEmpty() && $debt->manualSettlements->where('status', 'APPROVED')->isEmpty())

No payment has been received through this system.

@else @foreach ($debt->payments->sortBy('payment_date') as $payment) @endforeach @foreach ($debt->manualSettlements->where('status', 'APPROVED') as $manual) @endforeach
DateControl numberReferenceReceiptChannelAmount (TZS)
{{ $date($payment->payment_date, 'd M Y H:i') }} {{ $payment->control_number }} {{ $payment->payment_reference }} {{ $payment->receipt_number }} {{ $payment->payment_channel }} {{ $money($payment->amount) }}
{{ $date($manual->settlement_date) }} Manual settlement {{ $manual->settlement_number }} {{ $manual->reference }} Approved by {{ $manual->reviewed_by_name }} {{ $money($manual->amount) }}
@endif

Status history

@foreach ($debt->statusHistories->sortBy('changed_at') as $history) @endforeach
WhenStatusSourceByOutstanding
{{ $date($history->changed_at, 'd M Y H:i') }} {{ \Modules\LegacyDebts\Enums\LegacyDebtStatus::tryFrom((string) $history->new_status)?->label() ?? $history->new_status }} {{ \Modules\LegacyDebts\Enums\HistorySource::tryFrom((string) $history->source)?->label() ?? $history->source }} {{ $history->changed_by_name }} {{ $history->outstanding_amount !== null ? $money($history->outstanding_amount) : '-' }}

Printed {{ now()->format('d M Y H:i') }}{{ $printedBy ? ' by '.$printedBy : '' }}. @if ($debt->import) Imported from {{ $debt->import->file_name }} ({{ $debt->import->import_number }}). @endif