{{-- resources/views/probation/cases/_pr2.blade.php PR 2 — Supervision record ("Order for supervision" sheet). Blank fields are pre-filled from what the case already holds; the officer completes the rest. Name, serial, officer and breaches are always live. --}} @php $pf = $case->supervisionProfile; $order = $case->supervisionOrders->sortBy('start_date')->first(); $latest = $case->supervisionOrders->sortByDesc('created_at')->first(); $from = optional($pf)->order_from ?? optional($order)->start_date; $to = optional($pf)->order_to ?? optional($latest)->extension_to ?? optional($latest)->end_date; $months = ($from && $to) ? \Carbon\Carbon::parse($from)->diffInMonths(\Carbon\Carbon::parse($to)) : null; $autoDuration = $months !== null ? ($months >= 12 && $months % 12 === 0 ? ($months / 12) . ' year(s)' : $months . ' month(s)') : ''; $autoVariation = $case->supervisionOrders->filter(fn ($o) => $o->extension_to) ->map(fn ($o) => 'Extended to ' . $o->extension_to->format('d M Y'))->implode('; '); $v = fn ($k, $auto = '') => old($k, optional($pf)->{$k} ?? $auto); // contacts: saved list, else next of kin $contacts = optional($pf)->contacts ?: collect(optional($case->prisoner)->nextOfKin ?? [])->map(fn ($k) => [ 'name' => $k->name, 'relationship' => $k->relationship, 'phone' => $k->phone, 'address' => '', ])->values()->all() ?: []; while (count($contacts) < 4) $contacts[] = ['name' => '', 'relationship' => '', 'phone' => '', 'address' => '']; $jobs = optional($pf)->employment_record ?: []; while (count($jobs) < 3) $jobs[] = ['record' => '', 'duration_wages' => '', 'reason_for_leaving' => '']; @endphp