@php
$k = $dash['kpis'];
$tones = ['working' => 'bg-[#22a06b]', 'traveling' => 'bg-[#1673f9]', 'late' => 'bg-[#f59e0b]', 'finished' => 'bg-[#94a3b8]'];
$orderTone = ['submitted' => 'bg-info-soft text-primary', 'accepted' => 'bg-success-soft text-success', 'cancelled' => 'bg-muted text-muted-foreground'];
$deliveryTone = ['not_configured' => 'bg-muted text-muted-foreground', 'pending' => 'bg-info-soft text-primary', 'sending' => 'bg-info-soft text-primary', 'sent' => 'bg-success-soft text-success', 'failed' => 'bg-warning-soft text-warning'];
$stateTone = ['return_travel'=>'bg-info-soft text-primary','on_site'=>'bg-info-soft text-primary','traveling' => 'bg-info-soft text-primary', 'working' => 'bg-success-soft text-success', 'on_break' => 'bg-warning-soft text-warning', 'private_leave' => 'bg-warning-soft text-warning', 'finished' => 'bg-success-soft text-success'];
$order = ['working', 'traveling', 'return_travel', 'on_site', 'on_break', 'private_leave', 'finished'];
$overview = collect($dash['team'])->sortBy(fn ($r) => [$r['state'] ? array_search($r['state']->value, $order) : 99, $r['name']])->take(6)->values();
$card = 'surface';
$max = max(1.0, ...array_map(fn ($b) => $b['hours'], [...$dash['hours']['day'], ...$dash['hours']['week'], ...$dash['hours']['month']]));
@endphp
{{ __('common.dashboardLive') }}
{{ \Carbon\CarbonImmutable::parse($dash['today'])->locale(app()->getLocale())->isoFormat('dddd, D MMMM YYYY') }}
@foreach (['day', 'week', 'month'] as $p)
{{ __('adminDash.period.'.$p) }}
@endforeach
{{-- KPIs: real numbers from saved attendance events, schedules and orders. --}}
@include('dashboard._reference-kpis')
{{-- Team status: map of RECORDED points + list. The map is never re-created by the live refresh (wire:ignore); markers are redrawn by an event. --}}
@include('dashboard._reference-map')
{{-- Orders panel --}}
@foreach ([['ALL', __('ordersPanel.all'), $dash['orderKpis']['total']], ['SUBMITTED', __('ordersPanel.pending'), $dash['orderKpis']['pending']], ['ACCEPTED', __('orders.status.ACCEPTED'), $dash['orderKpis']['accepted']], ['CANCELLED', __('orders.status.CANCELLED'), $dash['orderKpis']['cancelled']]] as [$key, $text, $n])
{{ $text }} {{ $n }}
@endforeach
{{ __('ordersPanel.search') }}
@foreach ($dash['orders'] as $key => $list)
@if ($list->isEmpty())
{{ __('ordersPanel.emptyTitle') }}
{{ __('ordersPanel.emptyBody') }}
@else
{{ __('ordersPanel.col.number') }} {{ __('ordersPanel.col.description') }} {{ __('ordersPanel.col.createdBy') }} {{ __('ordersPanel.col.status') }} {{ __('ordersPanel.col.date') }} {{ __('ordersPanel.col.delivery') }}
@foreach ($list as $o)
@php($search = mb_strtolower($o->reference.' '.\App\Domain\Orders\OrderRules::compactNumber($o->reference).' '.$o->worksite_name.' '.$o->items->first()?->name.' '.$o->requester->name))
id }} })" class="cursor-pointer" x-show="q === '' || @js($search).includes(q.toLowerCase())" class="transition-colors hover:bg-info-soft/40">
id }} })" class="ad-order-number text-foreground hover:text-primary hover:underline" aria-label="{{ __('ordersPanel.open') }} {{ \App\Domain\Orders\OrderRules::compactNumber($o->reference) }}"> {{ \App\Domain\Orders\OrderRules::compactNumber($o->reference) }}
{{ $o->worksite_name ?: __('orders.worksite.notSpecified') }} {{ $o->items->first()?->name }}@if ($o->items_count > 1) +{{ $o->items_count - 1 }}@endif
{{ $o->requester->name }}
{{ __('orders.status.'.strtoupper($o->status)) }}
{{ \Carbon\CarbonImmutable::instance($o->submitted_at)->setTimezone($dash['timezone'])->format('d.m.Y') }}
@if ($o->expected_delivery_date){{ \App\Domain\Time\BusinessCalendar::formatKey($o->expected_delivery_date->format('Y-m-d')) }} ({{ __('orders.delivery.provisional') }}) @endif
@endforeach
@endif
@endforeach
{{-- Team overview --}}
@if ($overview->isEmpty())
{{ __('teamOverview.empty') }}
@else
@foreach ($overview as $w)
{{ collect(preg_split('/\s+/', trim($w['name'])))->take(2)->map(fn ($p) => mb_strtoupper(mb_substr($p, 0, 1)))->implode('') }}
{{ $w['name'] }}
@if ($w['point']) @endif{{ $w['last'] ? __('teamOverview.lastEvent', ['time' => $w['last']]) : __('teamOverview.noEvent') }}@if ($w['late'] !== null) · {{ __('teamOverview.late', ['minutes' => $w['late']]) }}@endif
@if ($w['state'])
{{ __('workStatus.'.$w['state']->langKey()) }}
@else
{{ __('workStatus.noRecord') }}
@endif
@endforeach
@endif
{{-- Activity --}}
{{ __('dashboardUI.live') }}
@if ($dash['activity'] === [])
{{ __('activityFeed.empty') }}
@else
@foreach ($dash['activity'] as $a)
@php($toneCls = ['brand' => 'bg-info-soft text-primary', 'success' => 'bg-success-soft text-success', 'warning' => 'bg-warning-soft text-warning', 'neutral' => 'bg-muted text-muted-foreground'][$a['tone']])
{{ __('activityFeed.'.$a['key'], ['name' => $a['name'], 'number' => $a['number']]) }}
@if ($a['minutes'] !== null)
{{ __('activityFeed.lateDetail', ['minutes' => $a['minutes']]) }}
@endif
{{ $a['at']->setTimezone($dash['timezone'])->format($a['at']->setTimezone($dash['timezone'])->format('Y-m-d') === $dash['today'] ? 'H:i' : 'd.m H:i') }}
@endforeach
@endif
{{-- Hours chart (day / week / month of the selected period) --}}
@foreach (['day', 'week', 'month'] as $p)
@foreach ([1, 0.75, 0.5, 0.25, 0] as $i => $line)
{{ rtrim(rtrim(number_format($max * $line, 1, '.', ''), '0'), '.') }} h
@endforeach
@foreach ($dash['hours'][$p] as $bar)
{{ rtrim(rtrim(number_format($bar['hours'], 1, '.', ''), '0'), '.') ?: '0' }} h
@endforeach
@foreach ($dash['hours'][$p] as $bar){{ $bar['label'] }} @endforeach
@endforeach
{{ __('adminDash.hours.note') }}@if ($dash['hours']['incomplete'] > 0) {{ __('adminDash.hours.incomplete', ['count' => $dash['hours']['incomplete']]) }}@endif
{{-- Reports shortcuts --}}
{{ __('adminDash.reports.latestWeekly') }}
@forelse ($dash['weekly'] as $w)
{{ \App\Domain\Time\BusinessCalendar::formatKey($w->week_start->format('Y-m-d')) }} – {{ \App\Domain\Time\BusinessCalendar::formatKey(\App\Domain\Time\BusinessCalendar::addDaysToKey($w->week_start->format('Y-m-d'), 6)) }}
{{ $w->preparer_name }}
@if ($w->delivery){{ __('reports.delivery.status.'.strtoupper($w->delivery->status)) }} @endif
@empty
{{ __('adminDash.reports.noWeekly') }}
@endforelse