@php $awaitingDisbursement = $loan->isAwaitingDisbursement(); $paid = (float) $loan->payments->sum('amount'); $remaining = $awaitingDisbursement ? 0.0 : max(0, (float) $loan->balance); $principal = (float) $loan->principal; $dpd = $awaitingDisbursement ? 0 : (int) ($loan->dpd ?? 0); $arrearsAmount = $awaitingDisbursement ? 0.0 : (float) ($loan->arrears_amount ?? 0); $contractTotal = (float) ($contractRepayable ?? ($paid + max(0, (float) $loan->balance))); $progressPct = ($awaitingDisbursement || $contractTotal <= 0.00001) ? 0.0 : min(100, max(0, ($paid / $contractTotal) * 100)); $statusLabel = str($loan->effectiveStatus())->headline(); $termDisplay = trim(($loan->term_value ?? '—').' '.str($loan->term_unit ?? 'monthly')->headline()); $interestDisplay = $loan->interest_rate !== null ? number_format((float) $loan->interest_rate, 2).' % · '.str($loan->interest_rate_period ?? 'annual')->headline() : '—'; $canCollect = $loan->acceptsPostedLoanCollections() && $loan->collectibleOutstandingBalance() > 0.01; $profileFields = [ ['label' => 'Loan #', 'value' => $loan->loan_number ?? '—'], ['label' => 'Client', 'value' => $loan->loanClient?->full_name ?? '—'], ['label' => 'Client #', 'value' => $loan->loanClient?->client_number ?? '—'], ['label' => 'Branch', 'value' => $loan->branch ?: ($loan->loanClient?->branch ?? '—')], ['label' => 'Loan officer', 'value' => $loan->loanClient?->assignedEmployee?->full_name ?? '—'], ['label' => 'Collection agent', 'value' => $loan->collectionAgent?->full_name ?? '—'], ]; $financialFields = [ ['label' => 'Product', 'value' => $loan->product_name ?: '—'], [ 'label' => $awaitingDisbursement ? 'Principal approved' : 'Principal disbursed', 'value' => 'KES '.number_format($principal, 2), 'numeric' => true, ], ['label' => 'Interest rate', 'value' => $interestDisplay], ['label' => 'Term', 'value' => $termDisplay], ['label' => 'Contract repayable', 'value' => 'KES '.number_format($contractTotal, 2), 'numeric' => true], ['label' => 'Disbursed on', 'value' => optional($loan->disbursed_at)->format('d M Y') ?: '—'], ['label' => 'Maturity', 'value' => optional($loan->maturity_date)->format('d M Y') ?: '—'], ['label' => 'Check-off', 'value' => ($loan->is_checkoff ?? false) ? ($loan->checkoff_employer ?: 'Yes') : 'No'], ]; if (! $awaitingDisbursement && ((float) ($loan->principal_outstanding ?? 0) > 0 || (float) ($loan->interest_outstanding ?? 0) > 0)) { $financialFields[] = ['label' => 'Principal outstanding', 'value' => 'KES '.number_format((float) ($loan->principal_outstanding ?? 0), 2), 'numeric' => true]; $financialFields[] = ['label' => 'Interest outstanding', 'value' => 'KES '.number_format((float) ($loan->interest_outstanding ?? 0), 2), 'numeric' => true]; } $recentPayments = $loan->payments->take(6); $overviewOpenFinanceRelease = $openFinanceRelease ?? null; $nextAction = match (true) { $awaitingDisbursement && $overviewOpenFinanceRelease && Route::has('loan.book.finance_release.show') => [ 'label' => 'Open finance release', 'href' => route('loan.book.finance_release.show', $overviewOpenFinanceRelease), 'hint' => 'KES '.number_format($principal, 0).' is approved. Complete treasury maker → checker → payout on finance release.', ], $awaitingDisbursement && Route::has('loan.book.finance_release.index') => [ 'label' => 'Open Finance Release Queue', 'href' => route('loan.book.finance_release.index'), 'hint' => 'KES '.number_format($principal, 0).' is approved and booked. Disburse via Finance Release Queue.', ], $awaitingDisbursement => [ 'label' => 'Open disbursement', 'tab' => 'disbursement', 'hint' => 'KES '.number_format($principal, 0).' is approved and booked. Disburse funds before any repayment is due.', ], $canCollect && Route::has('loan.payments.unposted') => [ 'label' => 'Open unposted register', 'href' => route('loan.payments.unposted'), 'hint' => 'KES '.number_format($remaining, 0).' outstanding on this loan.', ], $dpd > 0 => [ 'label' => 'Review collections', 'tab' => 'collections', 'hint' => $dpd.' days past due · KES '.number_format($arrearsAmount, 0).' in arrears.', ], ($hasInstallmentSchedule ?? false) => [ 'label' => 'Open repayment schedule', 'tab' => 'schedule', 'hint' => 'View installment plan and upcoming due dates.', ], default => [ 'label' => 'View loan register', 'href' => route('loan.book.loans.index'), 'hint' => 'Loan is '.$statusLabel.'. No immediate action required.', ], }; @endphp
{{ $loan->notes }}
{{ $awaitingDisbursement ? 'Not started' : number_format($progressPct, 1).'%' }}
This loan is booked from an approved application. Customer outstanding and repayments begin only after disbursement.
@else{{ $nextAction['hint'] }}
@if (! empty($nextAction['tab'])) @elseif (! empty($nextAction['href']))| Date | Amount | Reference |
|---|---|---|
| {{ optional($payment->transaction_at)->format('d M Y') ?? '—' }} | KES {{ number_format((float) $payment->amount, 2) }} | {{ $payment->receiptNumber() ?? '—' }} |
| {{ $awaitingDisbursement ? 'No repayments yet — disburse the loan first.' : 'No repayments posted yet.' }} | ||