@extends('reports.pdf.layout') @section('title', $data['meta']['title']) @php $meta = $data['meta']; $kpis = $data['kpis']; $items = $data['items']; $total = $data['total']; $proj = $data['projection']; $fmtNum = function ($v, $unit = '') { if ($v === null) return '—'; $s = is_numeric($v) ? number_format((float) $v, 0, ',', ' ') : (string) $v; return trim($s . ' ' . $unit); }; $fmtDelta = function ($v, $unit = '%') { if ($v === null) return null; $sign = $v > 0 ? '+' : ''; return $sign . number_format((float) $v, 1, ',', ' ') . $unit; }; $directionTone = ['success' => 'delta-up', 'danger' => 'delta-down', 'warning' => 'delta-down', 'neutral' => 'delta-flat']; $maxScale = 0; foreach ($items as $i) { $maxScale = max($maxScale, (float) $i['actual'], (float) $i['budget']); } if ($maxScale <= 0) { $maxScale = 1; } $barTrackW = 220; // Cumulative projection multi-line chart. $chartW = 480; $chartH = 170; $padX = 30; $padY = 22; $allValues = []; foreach ($proj['series'] as $s) { foreach ($s['data'] as $v) { if ($v !== null) $allValues[] = $v; } } $minV = !empty($allValues) ? min($allValues) : 0; $maxV = !empty($allValues) ? max($allValues) : 1; if ($minV === $maxV) { $maxV = $minV + 1; } $stepX = count($proj['labels']) > 1 ? ($chartW - 2 * $padX) / (count($proj['labels']) - 1) : 0; $polylines = []; foreach ($proj['series'] as $s) { $pts = []; foreach ($s['data'] as $i => $v) { if ($v === null) continue; $x = $padX + $i * $stepX; $y = $chartH - $padY - (($v - $minV) / ($maxV - $minV)) * ($chartH - 2 * $padY); $pts[] = "{$x},{$y}"; } $polylines[] = ['color' => $s['color'], 'label' => $s['label'], 'points' => implode(' ', $pts)]; } @endphp @section('content')
DADYCAR FLEET MANAGER

{{ $meta['title'] }}

Dépenses & Coûts {{ $meta['code'] }} Période : {{ $meta['period']['label'] }} · {{ $meta['site_label'] }} · Généré le {{ $meta['generated_at']->locale('fr')->isoFormat('D MMMM YYYY') }}

Indicateurs clés

Budget consommé
{{ $fmtNum($kpis['budget_consumed']['value']) }}{{ $kpis['budget_consumed']['unit'] }}
{{ $kpis['budget_consumed']['delta_label'] }}
Plus gros dépassement
{{ $fmtDelta($kpis['biggest_overrun']['value']) ?? '—' }}
{{ $kpis['biggest_overrun']['delta_label'] }}
Plus grosse économie
{{ $fmtDelta($kpis['biggest_saving']['value']) ?? '—' }}
{{ $kpis['biggest_saving']['delta_label'] }}
Projection fin d'année
{{ $fmtDelta($kpis['year_end_forecast']['value']) ?? '—' }}
{{ $kpis['year_end_forecast']['delta_label'] }}

Budget vs Réel par catégorie

@if (!empty($items)) @foreach ($items as $i) @php $actW = $maxScale > 0 ? ($i['actual'] / $maxScale) * $barTrackW : 0; $budW = $maxScale > 0 ? ($i['budget'] / $maxScale) * $barTrackW : 0; $tone = $directionTone[$i['direction'] ?? 'neutral'] ?? 'delta-flat'; @endphp @endforeach
{{ $i['label'] }}
Budget : {{ $fmtNum($i['budget']) }} €
{{ $i['consumption_pct'] !== null ? number_format($i['consumption_pct'], 1, ',', ' ') . ' %' : '—' }}
{{ $fmtNum($i['actual']) }} €
@if ($i['delta_pct'] !== null)
{{ $fmtDelta($i['delta_pct']) }}
@endif
{{ $total['label'] }}
{{ $total['consumption_pct'] !== null ? number_format($total['consumption_pct'], 1, ',', ' ') . ' %' : '—' }}
{{ $fmtNum($total['actual']) }} €
@else

Aucune dépense pour les filtres choisis.

@endif

Projection cumulée vs Budget annuel

@if (!empty($polylines)) @foreach ($polylines as $pl) @endforeach @foreach ($proj['labels'] as $i => $lbl) @php $x = $padX + $i * $stepX; @endphp {{ $lbl }} @endforeach
@foreach ($polylines as $pl) {{ $pl['label'] }} @endforeach
@else

Pas de données pour la projection.

@endif @endsection