@extends('adminlte::page') @section('title', 'Loan Details - ' . $loan->user->full_name) @section('content_header')

Loan Details

Application #{{ $loan->id }} - {{ $loan->user->full_name }}

@stop @section('content')
{{ ucfirst($loan->status) }} @if($loan->approved_at) {{ $loan->approved_at->format('M j, Y') }} @else {{ $loan->created_at->format('M j, Y') }} @endif
#{{ $loan->id }}
Member Information
{{ strtoupper(substr($loan->user->first_name, 0, 1)) }}{{ strtoupper(substr($loan->user->second_name, 0, 1)) }}
ID: {{ $loan->user->membership->membership_number ?? 'N/A' }}
{{ $loan->user->full_name }}
{{ $loan->user->phone_number }} {{ $loan->user->email }}
{{ $loan->user->id_number }} {{ $loan->user->branch->name ?? 'N/A' }}
Application Date {{ $loan->created_at->format('d M Y') }}
{{ ucfirst($loan->status) }}
Loan Financial Summary
@php $interestAmount = $loan->total_amount - $loan->amount; $principalPercentage = $loan->total_amount > 0 ? ($loan->amount / $loan->total_amount) * 100 : 0; $interestPercentage = $loan->total_amount > 0 ? ($interestAmount / $loan->total_amount) * 100 : 0; $progressPercentage = $loan->total_amount > 0 ? (($loan->total_amount - $loan->balance) / $loan->total_amount) * 100 : 0; $daysRemaining = $loan->status !== 'paid' && $loan->approved_at ? max(0, $loan->approved_at->copy()->addMonths($loan->term_months)->diffInDays(now())) : 0; $nextPaymentDate = $loan->approved_at ? $loan->approved_at->copy()->addMonths(ceil($loan->approved_at->diffInMonths(now(), false))) : null; @endphp
{{ number_format($loan->amount, 0) }}
Principal
{{ number_format($principalPercentage, 1) }}%
{{ $loan->interest_rate }}%
Rate
Annual
{{ $loan->term_months }}
Term
Months
{{ number_format($interestAmount, 0) }}
Interest
{{ number_format($interestPercentage, 1) }}%
Total Amount
{{ number_format($loan->total_amount, 0) }}
Principal: {{ number_format($principalPercentage, 1) }}% | Interest: {{ number_format($interestPercentage, 1) }}%
Monthly Payment
{{ number_format($loan->monthly_payment, 0) }}
Next: {{ $nextPaymentDate ? $nextPaymentDate->format('M j') : 'N/A' }}
Outstanding
{{ number_format($loan->balance, 0) }}
Progress: {{ number_format($progressPercentage, 1) }}% | Days: {{ $daysRemaining }}
@if($loan->status !== 'paid')
Repayment Progress
{{ number_format($progressPercentage, 1) }}%
Paid: {{ number_format($loan->paid_amount, 0) }}
Remaining: {{ number_format($loan->balance, 0) }}
Next Payment: {{ $nextPaymentDate ? $nextPaymentDate->format('M j, Y') : 'N/A' }}
@endif
@if($loan->repayments->count() > 0)
Recent Payments
@foreach($loan->repayments->sortByDesc('created_at')->take(5) as $repayment) @endforeach
Date Amount Method Status
{{ $repayment->created_at->format('d M') }} {{ number_format($repayment->amount, 0) }} @if($repayment->payment_method === 'mpesa_stk') STK @elseif($repayment->payment_method === 'mpesa_manual') Manual @else {{ ucfirst(substr($repayment->payment_method ?? 'cash', 0, 4)) }} @endif {{ $repayment->status === 'completed' ? '✓' : '○' }}
@if($loan->repayments->count() > 5)
... and {{ $loan->repayments->count() - 5 }} more payments
@endif
@endif @if($loan->notes)
Additional Notes
{{ $loan->notes }}
@endif
@if($loan->guarantees->count() > 0)
Loan Security & Guarantees
@foreach($loan->guarantees as $guarantee)
{{ $guarantee->type_label }}
{{ ucfirst($guarantee->status) }}
@if($guarantee->status === 'pending')
@endif
@if($guarantee->guarantee_type === 'guarantor') @foreach($guarantee->guarantors as $guarantor)
{{ $guarantor->guarantor->full_name }}
Guarantor
KSh {{ number_format($guarantor->guarantee_amount, 0) }}
Guarantee Amount
@endforeach @elseif($guarantee->guarantee_type === 'collateral') @foreach($guarantee->collateral as $item)
{{ $item->item_description }}
{{ $item->item_type_label }}
KSh {{ number_format($item->estimated_value, 0) }}
Item Worth
@endforeach @elseif($guarantee->guarantee_type === 'salary') @if($guarantee->salaryGuarantee)
{{ $guarantee->salaryGuarantee->employer_name }}
Employer
KSh {{ number_format($guarantee->salaryGuarantee->monthly_salary, 0) }}/month
Monthly Salary
@endif @endif @if($guarantee->notes)
Notes: {{ $guarantee->notes }}
@endif
@endforeach
@endif
Quick Actions
@if($loan->status === 'pending')
@csrf @method('PATCH')
@csrf @method('PATCH')
@endif @if(in_array($loan->status, ['approved', 'active']))
Process Repayment
@csrf
Outstanding: KSh {{ number_format($loan->balance, 0) }}
@endif
Edit
@csrf @method('DELETE')
Payment Schedule
@php $balance = $loan->amount; $monthlyPayment = $loan->monthly_payment; $totalAmount = $loan->total_amount; $interestAmount = $totalAmount - $loan->amount; $currentDate = $loan->approved_at ?? $loan->created_at; $maxRows = min($loan->term_months, 24); // Show up to 24 months for better visibility @endphp @for($month = 1; $month <= $maxRows; $month++) @php $interestPayment = $balance * ($loan->interest_rate / 100) / 12; $principalPayment = $monthlyPayment - $interestPayment; if($balance + $interestPayment < $monthlyPayment) { $monthlyPayment = $balance + $interestPayment; $principalPayment = $balance; } $balance -= $principalPayment; if($balance < 0.01) $balance = 0; $dueDate = $currentDate->copy()->addMonths($month - 1); @endphp @endfor @if($loan->term_months > $maxRows) @endif
# Due Date Payment Principal Interest Balance
{{ $month }} {{ $dueDate->format('M Y') }} {{ number_format($monthlyPayment, 0) }} {{ number_format($principalPayment, 0) }} {{ number_format($interestPayment, 0) }} {{ number_format($balance, 0) }}
... and {{ $loan->term_months - $maxRows }} more payments
TOTALS: {{ number_format($loan->total_amount, 0) }} {{ number_format($loan->amount, 0) }} {{ number_format($interestAmount, 0) }} 0.00
@stop