@php use App\Support\Hr\HrPerformanceLendingRoutes; use App\Support\Navigation\WorkspaceEmbed; $summary = $branchWorkspace['summary'] ?? []; $officerDistribution = $branchWorkspace['officer_distribution'] ?? []; $branchHighlights = $branchWorkspace['branch_highlights'] ?? []; $registerService = app(\App\Services\LoanBook\ClientIntelligenceRegisterService::class); $registerHomeRoute = $registerHomeRoute ?? HrPerformanceLendingRoutes::registerRoute(); $activeState = $branchWorkspace['state'] ?? null; $branchId = (int) ($branchWorkspace['loan_branch_id'] ?? 0); $baseParams = collect(request()->except('page', 'state')) ->merge($registerService->filterQueryParams([ 'type' => 'branch', 'loan_branch_id' => $branchId > 0 ? $branchId : null, ])) ->all(); $fmtBranch = function (?array $row): string { if (! $row) { return '—'; } return ($row['branch_name'] ?? '—').' · '.number_format((float) ($row['metric_value'] ?? 0), ($row['metric_label'] ?? '') === 'PAR30 %' || str_contains((string) ($row['metric_label'] ?? ''), 'PAR30') ? 1 : 0).' '.strtolower((string) ($row['metric_label'] ?? '')); }; $bestOfficer = $summary['best_performing_officer'] ?? null; $riskOfficer = $summary['highest_risk_officer'] ?? null; @endphp
@include('loan.clients.partials.intelligence-workspace-header', [ 'headerTitle' => $summary['branch_name'] ?? 'Branch', 'bulkSmsUrl' => $branchWorkspace['bulk_sms_url'] ?? route('loan.bulksms.compose'), 'showExport' => $registerHomeRoute === 'loan.clients.index', ])
@include('loan.clients.partials.intelligence-scope-switcher', [ 'mode' => 'branch', 'compact' => true, 'selectedBranchId' => $branchId, ])

Total Clients

{{ number_format((int) ($summary['total_clients'] ?? 0)) }}

Active Loans

{{ number_format((int) ($summary['active_loans'] ?? 0)) }}

Active Clients

{{ number_format((int) ($summary['active_clients'] ?? 0)) }}

Dormant

{{ number_format((int) ($summary['dormant_clients'] ?? 0)) }}

Arrears

{{ number_format((int) ($summary['arrears_clients'] ?? 0)) }}

Watch List

{{ number_format((int) ($summary['watchlist_clients'] ?? 0)) }}

VIP

{{ number_format((int) ($summary['vip_clients'] ?? 0)) }}

Portfolio Balance

{{ number_format((float) ($summary['active_portfolio_balance'] ?? 0), 0) }}

Total Arrears

{{ number_format((float) ($summary['total_arrears'] ?? 0), 0) }}

PAR30

{{ number_format((float) ($summary['par30'] ?? 0), 1) }}%

Avg RES

@if (isset($summary['average_res'])) {{ number_format((float) $summary['average_res'], 1) }}% @else — @endif

High-Value Dormant

{{ number_format((int) ($summary['high_value_dormant'] ?? 0)) }}

Needs Follow-up

{{ number_format((int) ($summary['needs_followup'] ?? 0)) }}

Officers Attached

{{ number_format((int) ($summary['officers_attached'] ?? 0)) }}

Best Officer

@if ($bestOfficer) {{ $bestOfficer['officer_name'] ?? '—' }} · {{ number_format((float) ($bestOfficer['par30'] ?? 0), 1) }}% PAR30 @else — @endif

Highest Risk Officer

@if ($riskOfficer) {{ $riskOfficer['officer_name'] ?? '—' }} · {{ number_format((float) ($riskOfficer['par30'] ?? 0), 1) }}% PAR30 @else — @endif

Clients from the client register · PAR30, loans and portfolio from LoanBookPortfolioMetricsService (active book).

Segment: @foreach ([ null => 'All', \App\Services\LoanBook\ClientIntelligenceRegisterService::OFFICER_STATE_ACTIVE => 'Active', \App\Services\LoanBook\ClientIntelligenceRegisterService::OFFICER_STATE_DORMANT => 'Dormant', \App\Services\LoanBook\ClientIntelligenceRegisterService::OFFICER_STATE_ARREARS => 'Arrears', \App\Services\LoanBook\ClientIntelligenceRegisterService::OFFICER_STATE_WATCHLIST => 'Watch List', \App\Services\LoanBook\ClientIntelligenceRegisterService::OFFICER_STATE_VIP => 'VIP', \App\Services\LoanBook\ClientIntelligenceRegisterService::OFFICER_STATE_PERFORMING => 'Performing', \App\Services\LoanBook\ClientIntelligenceRegisterService::OFFICER_STATE_NEEDS_FOLLOWUP => 'Needs Follow-up', ] as $stateKey => $stateLabel) @php $isActive = ($stateKey === null && empty($activeState)) || $activeState === $stateKey; $linkParams = $baseParams; if ($stateKey !== null) { $linkParams['state'] = $stateKey; } @endphp {{ $stateLabel }} @endforeach
@if (! empty($branchHighlights))

Branch comparison (portfolio-wide)

@foreach ([ 'largest' => 'Largest branch', 'highest_par' => 'Highest PAR', 'most_dormant' => 'Most dormant (90+)', 'best_performing' => 'Best performing', ] as $key => $label) @php $row = $branchHighlights[$key] ?? null; @endphp
{{ $label }}
@if ($row && (int) ($row['branch_id'] ?? 0) > 0) {{ $fmtBranch($row) }} @else {{ $fmtBranch($row) }} @endif
@endforeach
@endif
@if (! empty($officerDistribution))

Officer distribution within branch

@foreach ($officerDistribution as $officerRow) @endforeach
Officer Total Active Dormant Arrears Watch List VIP Portfolio PAR30 Suggested Action
{{ $officerRow['officer_name'] ?? '—' }} {{ number_format((int) ($officerRow['total_clients'] ?? 0)) }} {{ number_format((int) ($officerRow['active_clients'] ?? 0)) }} {{ number_format((int) ($officerRow['dormant_clients'] ?? 0)) }} {{ number_format((int) ($officerRow['arrears_clients'] ?? 0)) }} {{ number_format((int) ($officerRow['watchlist_clients'] ?? 0)) }} {{ number_format((int) ($officerRow['vip_clients'] ?? 0)) }} {{ number_format((float) ($officerRow['portfolio_balance'] ?? 0), 0) }} {{ number_format((float) ($officerRow['par30'] ?? 0), 1) }}% {{ $officerRow['suggested_management_action'] ?? '—' }}
@endif @include('loan.clients.partials.intelligence-bulk-actions', [ 'bulkSmsUrl' => $branchWorkspace['bulk_sms_url'] ?? route('loan.bulksms.compose'), 'assignHint' => 'Select clients in the table below, then assign a loans officer or send bulk SMS.', ])