@extends('reports.pdf.layout') @section('title', $data['meta']['title']) @php $meta = $data['meta']; $kpis = $data['kpis']; $perEnergy = $data['per_energy']; $curve = $data['curve']; $action = $data['action']; $fmtNum = function ($v, $unit = '') { if ($v === null) return '—'; $s = is_numeric($v) ? number_format((float) $v, 0, ',', ' ') : (string) $v; return trim($s . ' ' . $unit); }; $components = [ 'fuel' => ['label' => 'Carburant', 'color' => '#3B82F6'], 'maintenance' => ['label' => 'Maintenance', 'color' => '#F59E0B'], 'insurance' => ['label' => 'Assurance', 'color' => '#8B5CF6'], 'depreciation' => ['label' => 'Amortissement', 'color' => '#10B981'], ]; // Stacked bar geometry — vertical stacked bars per energy bucket. $barW = 320; $barH = 180; $barPadX = 30; $barPadY = 22; $energyMax = 0; foreach ($perEnergy as $e) { $stackTotal = array_sum($e['components'] ?? []); $energyMax = max($energyMax, $stackTotal); } if ($energyMax <= 0) $energyMax = 50; $barCount = count($perEnergy); $barSlot = $barCount > 0 ? ($barW - 2 * $barPadX) / $barCount : 0; $barWidth = $barSlot * 0.55; // Breakeven curve. $chartW = 480; $chartH = 170; $padX = 30; $padY = 22; $allValues = array_merge($curve['diesel'] ?? [], $curve['electric'] ?? []); $allValues = array_filter($allValues, fn ($v) => $v !== null); $minV = !empty($allValues) ? min($allValues) : 0; $maxV = !empty($allValues) ? max($allValues) : 1; if ($minV === $maxV) { $maxV = $minV + 1; } $stepX = count($curve['labels']) > 1 ? ($chartW - 2 * $padX) / (count($curve['labels']) - 1) : 0; $polylines = []; foreach ([['data' => $curve['diesel'], 'color' => '#6B7280', 'label' => 'Diesel'], ['data' => $curve['electric'], 'color' => '#10B981', 'label' => 'Électrique']] 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)]; } $toneBg = ['success' => '#D1FAE5', 'warning' => '#FEF3C7', 'danger' => '#FEE2E2', 'neutral' => '#F3F4F6']; $toneColor = ['success' => '#065F46', 'warning' => '#92400E', 'danger' => '#991B1B', 'neutral' => '#374151']; $aTone = $action['tone'] ?? 'neutral'; @endphp @section('content')
Aucune donnée par énergie.
@endifDonnées insuffisantes pour la courbe.
@endif @if (!empty($action['label']))