@php use Carbon\Carbon; use Carbon\CarbonInterface; @endphp
@unless (count($loans) == 0)
{{-- Title --}}

Ongoing Loans

{{-- Live Search Bar --}}
{{-- Placeholder --}}
@forelse ($loans as $loan) @empty @endforelse
Name Amount Loaned @if ($sortField === 'loan_required_amount') @if ($sortDirection === 'asc') @else @endif @endif Amount Paid @if ($sortField === 'amount_paid') @if ($sortDirection === 'asc') @else @endif @endif Amount Remaining @if ($sortField === 'amount_remaining') @if ($sortDirection === 'asc') @else @endif @endif Days Remaining @if ($sortField === 'days_remaining') @if ($sortDirection === 'asc') @else @endif @endif Status More
{{ $loan->applicant_name }} {{ number_format($loan->loan_required_amount) }} Tsh {{ number_format($loan->payments->sum('paid_amount')) }} Tsh {{ number_format($loan->loan_required_amount - $loan->payments->sum('paid_amount')) }} Tsh
@php $now = Carbon::now(); $end = $loan->loan_end_date; $interval = $now->diff($end); $totalMonths = $interval->y * 12 + $interval->m; $weeks = floor($interval->d / 7); $remainingDays = $interval->d % 7; $hours = $interval->h; $minutes = $interval->i; if ($minutes >= 30) { $hours++; } if ($hours >= 24) { $hours -= 24; $remainingDays++; if ($remainingDays >= 7) { $weeks += floor($remainingDays / 7); $remainingDays %= 7; } } $parts = []; if ($totalMonths > 0) { $parts[] = $totalMonths . ' m' . ($totalMonths !== 1 ? 's' : ''); } if ($weeks > 0) { $parts[] = $weeks . ' w' . ($weeks !== 1 ? 's' : ''); } if ($remainingDays > 0) { $parts[] = $remainingDays . ' d' . ($remainingDays !== 1 ? 's' : ''); } if ($hours > 0 || empty($parts)) { $parts[] = $hours . ' h' . ($hours !== 1 ? 's' : ''); } if (empty($parts)) { $parts[] = 'less than an hour'; } echo match (count($parts)) { 1 => $parts[0], 2 => implode(' and ', $parts), default => implode( ', ', array_slice($parts, 0, -1), ) . ' and ' . end($parts), }; @endphp
@php $time_left = $interval; $paid_amount = $loan->payments->sum( 'paid_amount', ); $loan_amount = $loan->loan_required_amount; if ($paid_amount >= $loan_amount) { $status = 'completed'; $color_class = 'text-green-700 bg-green-100 dark:bg-green-700 dark:text-green-100'; } elseif ( $time_left->invert == 0 && $paid_amount < $loan_amount ) { $status = 'ongoing'; $color_class = 'text-yellow-700 bg-yellow-100 dark:bg-yellow-700 dark:text-yellow-100'; } elseif ( $time_left->invert == 1 && $paid_amount < $loan_amount ) { $status = 'overdue'; $color_class = 'text-red-700 bg-red-100 dark:bg-red-700 dark:text-red-100'; } else { $status = 'unknown'; $color_class = 'text-gray-700 bg-gray-100 dark:bg-gray-700 dark:text-gray-100'; } @endphp {{ ucfirst($status) }}
No loans found for "{{ $search }}"
{{ $loans->onEachSide(1)->links('vendor.pagination.tailwind') }}
@endunless
@if ($showPaymentModal)

Add Payment

@error('paymentDate') {{ $message }} @enderror
@if ($paymentMethod === 'mobile_money')
@error('phoneNumber') {{ $message }} @enderror
@error('provider') {{ $message }} @enderror
@endif @if ($paymentMethod === 'bank')
@error('bankName') {{ $message }} @enderror
@error('accountNumber') {{ $message }} @enderror
@endif @if ($paymentMethod === 'cash')
@error('receipt') {{ $message }} @enderror
@endif
@error('paymentAmount') {{ $message }} @enderror
@endif @if (session()->has('message'))
{{ session('message') }}
@endif @if (session()->has('error'))
{{ session('error') }}
@endif