@php use App\Models\LoanBookApplication; $nextInstallment = $nextInstallment ?? null; $pipelineApps = ($clientApplications ?? collect())->filter( fn ($app) => (string) $app->stage !== LoanBookApplication::STAGE_DECLINED && ((string) $app->stage !== LoanBookApplication::STAGE_DISBURSED || $app->isAwaitingTreasuryDisbursement()) ); $pipelineCount = $pipelineApps->count(); $latestPipeline = $pipelineCount > 0 ? $pipelineApps->sortByDesc('updated_at')->first() : null; $latestPayment = ($recentPayments ?? collect())->first(); $borrowerCategory = str((string) ($originationSnapshot['category'] ?? ''))->replace('_', ' ')->title()->toString(); @endphp

Next installment

@if ($nextInstallment) @php $dueDate = $nextInstallment->due_date; $isOverdue = $dueDate && $dueDate->isPast() && ! in_array($nextInstallment->status, ['paid', 'settled'], true); $dueAmount = max(0, (float) ($nextInstallment->total_due ?? 0) - (float) ($nextInstallment->total_paid ?? 0)); @endphp

$isOverdue])>{{ optional($dueDate)->format('M j, Y') ?? '—' }}

KES {{ number_format($dueAmount, 0) }}

$isOverdue])> {{ $isOverdue ? 'Overdue — follow up' : 'Due amount remaining' }}

@else

—

No pending installments

@endif

Latest pipeline file

@if ($latestPipeline)

{{ $latestPipeline->reference }}

{{ str((string) $latestPipeline->stage)->headline() }} · KES {{ number_format((float) $latestPipeline->displayPrincipal(), 0) }}

@else

None open

No application in progress

@if (($loan_client->kind ?? null) === \App\Models\LoanClient::KIND_CLIENT) Start application → @endif @endif

Last payment

@if ($latestPayment)

KES {{ number_format((float) ($latestPayment->amount ?? 0), 0) }}

{{ optional($latestPayment->transaction_at ?? $latestPayment->created_at)->format('M j, Y') ?? '—' }} · {{ $latestPayment->loan?->loan_number ?? '—' }}

@else

—

No repayments yet

@endif @if ($borrowerCategory !== '')

Borrower class: {{ $borrowerCategory }}

@endif