@include('loan.payments.partials.flash') @include('loan.collections.hub.partials.collections-due-register-tones') @php $tab = $tab ?? 'register'; $insight = $insight ?? ''; $tomorrow = now()->addDay()->toDateString(); $isWeekly = $tab === 'weekly'; $weekEmpty = $isWeekly && (bool) ($week['empty'] ?? false); $tabQuery = fn (array $extra = []) => collect(request()->query()) ->except(['page', 'export', 'insight']) ->merge($extra) ->reject(fn ($value) => $value === null || $value === '') ->all(); $registerTabUrl = route('loan.book.collections.sheet', $tabQuery(['tab' => 'register', 'iso_week' => null, 'iso_year' => null, 'day' => null])); $weeklyTabUrl = route('loan.book.collections.sheet', $tabQuery(['tab' => 'weekly', 'from' => null, 'to' => null, 'date' => null])); $exportQuery = collect(request()->query())->except(['embedded', 'page'])->merge(['export' => 'csv'])->all(); $prepaidRows = $totals['prepaid_rows'] ?? []; $arrearsRows = $totals['arrears_rows'] ?? []; $selectedDay = $selectedDay ?? ($filters['day'] ?? ''); $selectedDayMeta = collect($weekDays ?? [])->firstWhere('date', $selectedDay); $scopeLabel = $selectedDayMeta ? $selectedDayMeta['weekday'].' '.$selectedDayMeta['date_label'] : 'this week'; $insightLabel = match ($insight) { 'arrears' => 'Needs attention · '.$scopeLabel, 'prepaid' => 'Prepayments · '.$scopeLabel, 'expected' => 'Expected to pay · '.$scopeLabel, 'maturing' => 'Last installments · '.$scopeLabel, default => '', }; @endphp @if ($isWeekly) @endif @if ($isWeekly)
@else
@endif
Clear Export

Upcoming dues from tomorrow onwards. Today's worksheet stays on Due Today; money already received is on the Collection Register.

@if ($isWeekly) @php $prevWeek = ($week['week_start'] ?? now())->copy()->subWeek(); $nextWeek = ($week['week_start'] ?? now())->copy()->addWeek(); @endphp
Previous week ISO week {{ $isoWeek }} · {{ ($week['week_start'] ?? now())->format('j M') }} – {{ ($week['week_end'] ?? now())->format('j M Y') }} Next week
@include('loan.collections.hub.partials.upcoming-pays-attention', [ 'totals' => $totals, 'scopeLabel' => $scopeLabel, 'tab' => 'weekly', 'tabQuery' => $tabQuery, ]) @endif
@if ($isWeekly) @if ($weekEmpty)
This ISO week has no upcoming dues from tomorrow onwards. Use Due Today for today's worksheet, or open a future week.
@endif @include('loan.collections.hub.partials.upcoming-pays-week-days', [ 'weekDays' => $weekDays ?? [], 'selectedDay' => $selectedDay, 'tabQuery' => $tabQuery, ])
Expected to pay · {{ $scopeLabel }}

KES {{ number_format($totals['expected'] ?? 0, 0) }} ({{ number_format($totals['client_count'] ?? 0, 0) }} {{ ($totals['client_count'] ?? 0) === 1 ? 'client' : 'clients' }})

@if (($totals['client_count'] ?? 0) > 0) + @endif
Prepayments · {{ $scopeLabel }}

KES {{ number_format($totals['prepaid'] ?? 0, 0) }} ({{ number_format($totals['prepaid_count'] ?? 0, 0) }} {{ ($totals['prepaid_count'] ?? 0) === 1 ? 'client' : 'clients' }})

{{ number_format($totals['fully_paid_count'] ?? 0, 0) }} fully paid · {{ number_format($totals['partially_paid_count'] ?? 0, 0) }} partial

@if (($totals['prepaid_count'] ?? 0) > 0) + @endif
Collection progress · {{ $scopeLabel }}

{{ number_format($totals['collection_pct'] ?? 0, 1) }}%

Remaining KES {{ number_format($totals['remaining'] ?? 0, 0) }}

@else
Expected

KES {{ number_format($totals['expected'] ?? 0, 0) }} ({{ number_format($totals['client_count'] ?? 0, 0) }} {{ ($totals['client_count'] ?? 0) === 1 ? 'client' : 'clients' }})

Collected / prepaid

KES {{ number_format($totals['collected'] ?? 0, 0) }} @if (($totals['collected_count'] ?? 0) > 0) ({{ number_format($totals['collected_count'], 0) }} paid) @endif

{{ number_format($totals['fully_paid_count'] ?? 0, 0) }} fully paid · {{ number_format($totals['partially_paid_count'] ?? 0, 0) }} partial @if (count($prepaidRows) > 0) @endif

Remaining

KES {{ number_format($totals['remaining'] ?? 0, 0) }} @if (($totals['outstanding_count'] ?? 0) > 0) ({{ number_format($totals['outstanding_count'], 0) }} {{ ($totals['outstanding_count'] ?? 0) === 1 ? 'client' : 'clients' }}) @endif

Collection %

{{ number_format($totals['collection_pct'] ?? 0, 1) }}%

@include('loan.collections.hub.partials.upcoming-pays-insight-preview', ['rows' => $prepaidRows, 'panel' => 'prepaid', 'title' => 'Prepaid toward upcoming dues']) @include('loan.collections.hub.partials.upcoming-pays-insight-preview', ['rows' => $arrearsRows, 'panel' => 'arrears', 'title' => 'Upcoming clients already in arrears']) @endif
@if (! $isWeekly) @include('loan.collections.hub.partials.upcoming-pays-attention', [ 'totals' => $totals, 'scopeLabel' => $from->toDateString() === $to->toDateString() ? $from->format('j M') : $from->format('j M').' – '.$to->format('j M'), 'tab' => 'register', 'tabQuery' => $tabQuery, ]) @endif

Paid Partial In arrears

@if ($insight !== '')

{{ $insightLabel }}

Close list
@include('loan.collections.hub.partials.upcoming-pays-register-table', [ 'rows' => $insightRows ?? $installments, 'empty' => 'No clients in this insight.', ]) @if ($insightRows ?? $installments)
@endif @elseif (! $isWeekly) @include('loan.collections.hub.partials.upcoming-pays-register-table', ['rows' => $installments, 'empty' => 'No upcoming installments in this date window.']) @if ($installments)
@endif @endif