{{-- 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
{{ $attention ? $attention.' of '.$rows->count().' services need attention' : 'All '.$rows->count().' services are on track' }}
error {{ $noF2f }} of {{ $rows->count() }} services have no face-to-face trainings set, so their compliance only counts e-learning.
No services match.