@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')
DADYCAR FLEET MANAGER

{{ $meta['title'] }}

Carburant & Énergie {{ $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

Électrique vs Diesel
{{ $kpis['ev_vs_diesel']['value'] !== null ? ($kpis['ev_vs_diesel']['value'] >= 0 ? '+' : '') . $kpis['ev_vs_diesel']['value'] : '—' }}{{ $kpis['ev_vs_diesel']['unit'] }}
{{ $kpis['ev_vs_diesel']['delta_label'] }}
Électrique vs Essence
{{ $kpis['ev_vs_essence']['value'] !== null ? ($kpis['ev_vs_essence']['value'] >= 0 ? '+' : '') . $kpis['ev_vs_essence']['value'] : '—' }}{{ $kpis['ev_vs_essence']['unit'] }}
{{ $kpis['ev_vs_essence']['delta_label'] }}
Seuil rentabilité VE
{{ $fmtNum($kpis['breakeven_km']['value']) }}{{ $kpis['breakeven_km']['unit'] }}
{{ $kpis['breakeven_km']['delta_label'] }}
Économie annuelle / VE
{{ $fmtNum($kpis['annual_savings']['value']) }}{{ $kpis['annual_savings']['unit'] }}
{{ $kpis['annual_savings']['delta_label'] }}

Décomposition du coût au km par énergie

@if (!empty($perEnergy)) @foreach ($perEnergy as $i => $e) @php $x = $barPadX + $i * $barSlot + ($barSlot - $barWidth) / 2; $accY = $barH - $barPadY; @endphp @foreach ($components as $compKey => $compMeta) @php $val = (float) ($e['components'][$compKey] ?? 0); $segH = $energyMax > 0 ? ($val / $energyMax) * ($barH - 2 * $barPadY) : 0; $accY -= $segH; @endphp @if ($segH > 0.5) @endif @endforeach {{ $e['label'] }} {{ $e['cost_per_100km'] !== null ? number_format($e['cost_per_100km'], 1, ',', ' ') . ' €' : '—' }} @endforeach
@foreach ($components as $compMeta) {{ $compMeta['label'] }} @endforeach
@else

Aucune donnée par énergie.

@endif

Seuil de rentabilité VE vs Diesel (coût cumulé)

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

Données insuffisantes pour la courbe.

@endif @if (!empty($action['label']))
{{ $action['label'] }}
@endif
@endsection