{{-- Current compliance of every service at a glance (SM / RM): one compact panel, worst first, opening on the services that need attention. Needs: $glance (homeRows + e_*/f_* splits from ManagementController@dashboard). --}} @if($glance->isNotEmpty()) @php $dashRole = auth()->user()->primaryRole(); $rows = $glance->map(function ($r) { // Never round up to 100% while something is still overdue. $shown = $r['overdue'] > 0 ? min(99, $r['compliance']) : $r['compliance']; // A manager who hasn't chosen face-to-face trainings isn't "on track": that red alert wins over a good %. $noF2f = $r['total'] > 0 && ! $r['f_total']; $status = match (true) { ! $r['total'] => 'none', $shown < 70 => 'risk', $shown < 90 => 'work', $noF2f => 'noset', default => 'ok', }; return $r + ['shown' => $shown, 'status' => $status, 'no_f2f' => $noF2f, 'attention' => $r['total'] && (in_array($status, ['risk', 'work'], true) || $r['overdue'] > 0)]; })->sortBy(fn ($r) => [$r['total'] ? $r['shown'] : 101, -$r['overdue'], $r['service']->name])->values(); $styles = [ 'ok' => ['check_circle', 'text-primary', 'bg-primary'], 'work' => ['warning', 'text-[#8a6d3b]', 'bg-gold'], 'risk' => ['error', 'text-error', 'bg-error'], 'none' => ['radio_button_unchecked', 'text-outline', 'bg-outline'], 'noset' => ['error', 'text-error', 'bg-primary'], ]; $labels = ['ok' => 'On track', 'work' => 'Needs work', 'risk' => 'At risk', 'none' => 'No training yet', 'noset' => 'Face to face not set']; $attention = $rows->where('attention', true)->count(); $counts = $rows->countBy('status'); $noF2f = $rows->where('no_f2f', true)->count(); $manageRoute = \Illuminate\Support\Facades\Route::has($dashRole.'.service-training') ? route($dashRole.'.service-training') : null; // Long lists open on what needs attention; short ones just show everything. $useFilters = $rows->count() > 6; $default = ! $useFilters ? 'all' : ($attention ? 'attention' : ($noF2f ? 'noset' : 'all')); $chips = array_filter([ 'attention' => $attention ? 'Needs attention' : null, 'noset' => $noF2f ? 'Face to face not set' : null, 'risk' => ($counts['risk'] ?? 0) ? 'At risk' : null, 'work' => ($counts['work'] ?? 0) ? 'Needs work' : null, 'ok' => ($counts['ok'] ?? 0) ? 'On track' : null, 'all' => 'All services', ]); $chipCount = ['attention' => $attention, 'noset' => $noF2f, 'risk' => $counts['risk'] ?? 0, 'work' => $counts['work'] ?? 0, 'ok' => $counts['ok'] ?? 0, 'all' => $rows->count()]; @endphp
{{-- Headline --}}
grid_view

Your Services at a Glance

{{ $attention ? $attention.' of '.$rows->count().' services need attention' : 'All '.$rows->count().' services are on track' }}

{{-- Red alert: the manager hasn't chosen face-to-face trainings --}} @if($noF2f) @endif {{-- Filters --}} @if($useFilters)
@foreach($chips as $key => $chipLabel) @endforeach
search
@endif {{-- Services, worst first --}}
@foreach($rows as $r) @php [$icon, $tone, $bar] = $styles[$r['status']]; $sub = $r['workers'].' '.\Illuminate\Support\Str::plural('worker', $r['workers']); if ($r['e_total']) { $sub .= ' · E-learning '.$r['e_pct'].'%'; } if ($r['f_total']) { $sub .= ' · Face to face '.$r['f_pct'].'%'; } $hidden = ($default === 'attention' && ! $r['attention']) || ($default === 'noset' && ! $r['no_f2f']); @endphp {{ $icon }} {{ $r['service']->name }} @if($r['no_f2f'])Face to face not set · @endif{{ $sub }} {{ $r['total'] ? $r['shown'].'%' : '—' }} @if($r['overdue'] > 0) {{ $r['overdue'] }} overdue @else None due @endif @endforeach
Lowest compliance first · on track 90%+, needs work 70–89%, at risk under 70%
@if($useFilters) @endif @endif