{{-- Probation & Aftercare dashboard panel. Self-contained: include this in resources/views/dashboard/index.blade.php with @include('dashboard._probation') No DashboardController change required (queries are branch-scoped inline). --}} @php $ProbationCase = \App\Models\ProbationCase::class; $NeedsAssessment = \App\Models\NeedsAssessment::class; $CaseReport = \App\Models\CaseReport::class; $SupervisionBreach = \App\Models\SupervisionBreach::class; $pcBase = fn () => $ProbationCase::forCurrentBranch(); $pcIds = $pcBase()->pluck('id'); $pc = [ 'total' => $pcBase()->count(), 'supervised' => $pcBase()->where('status', 'under_supervision')->count(), 'awaiting' => $pcBase()->where('status', 'awaiting_court')->count(), 'breached' => $pcBase()->where('status', 'breached')->count(), 'completed' => $pcBase()->whereIn('status', ['completed', 'closed'])->count(), 'high_risk' => $NeedsAssessment::whereIn('case_id', $pcIds)->where('risk_level', 'High')->count(), ]; $pcByType = $pcBase()->selectRaw('case_type, COUNT(*) c')->groupBy('case_type') ->pluck('c', 'case_type')->toArray(); $pcMax = max(1, count($pcByType) ? max($pcByType) : 1); $pcLabels = [ 'social_inquiry' => 'Social Inquiry', 'probation_order' => 'Probation Order', 'community_service' => 'Community Service', 'aftercare_borstal' => 'Aftercare', 'power_of_mercy' => 'Power of Mercy', 'special_category' => 'Special Category', 'adr' => 'ADR', 'probation_hostel' => 'Hostel', 'halfway_house' => 'Halfway House', ]; $pcPendingReports = $CaseReport::whereIn('case_id', $pcIds) ->whereIn('status', ['Submitted', 'Under Review'])->count(); $pcOpenBreaches = $SupervisionBreach::whereIn('case_id', $pcIds) ->where(fn ($q) => $q->whereNull('action')->orWhere('action', ''))->count(); $pcRecent = $pcBase()->with('prisoner')->latest()->limit(5)->get(); @endphp
No probation cases yet.
@endforelse