{{-- 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

Probation & Aftercare

Open Case Register
{{-- KPI tiles --}}
Total Cases

{{ $pc['total'] }}

Under Supervision

{{ $pc['supervised'] }}

Awaiting Court

{{ $pc['awaiting'] }}

In Breach

{{ $pc['breached'] }}

Completed

{{ $pc['completed'] }}

High Risk

{{ $pc['high_risk'] }}

{{-- Cases by work-stream --}}
Cases by Work-stream
@forelse($pcByType as $type => $count)
{{ $pcLabels[$type] ?? ucwords(str_replace('_',' ',$type)) }} {{ $count }}
@empty

No probation cases yet.

@endforelse
{{-- Action queue --}}
Action Queue
Reports awaiting approval {{ $pcPendingReports }}
Breaches needing action {{ $pcOpenBreaches }}
High-risk cases {{ $pc['high_risk'] }}
{{-- Recent cases --}}
Recent Cases
    @forelse($pcRecent as $c)
  • {{ $c->serial_number ?? '#'.$c->id }} {{ $c->prisoner->name ?? '—' }} {{ ucwords(str_replace('_',' ',$c->status)) }}
  • @empty
  • No recent cases.
  • @endforelse