@extends('layouts.admin') @section('header', 'Finances') @section('content')

Revenu Total

{{ number_format($totalRevenue, 2) }} MAD

Aujourd'hui

{{ number_format($todayRevenue, 2) }} MAD

Cette Semaine

{{ number_format($weekRevenue, 2) }} MAD

Ce Mois

{{ number_format($monthRevenue, 2) }} MAD

Cette Année

{{ number_format($yearRevenue, 2) }} MAD

Prix Moyen / Commande

{{ number_format($avgOrderValue, 2) }} MAD

{{ $totalOrders }} commandes ({{ $cancelledOrders }} annulées)

Revenu Annulé

{{ number_format($cancelledRevenue, 2) }} MAD

Commandes Traitées

{{ $totalOrders - $cancelledOrders }}

Revenu par Mois ({{ now()->year }})

@php $maxMonth = $months->max('total'); @endphp
@php $qColors = ['#3b82f6', '#22c55e', '#a855f7', '#f59e0b']; $quarters = []; $qLabels = ['T1', 'T2', 'T3', 'T4']; $qMonthRanges = [['Jan','Feb','Mar'], ['Apr','May','Jun'], ['Jul','Aug','Sep'], ['Oct','Nov','Dec']]; $qTotal = 0; foreach ($qLabels as $i => $label) { $total = collect($months)->filter(fn($m) => in_array($m['label'], $qMonthRanges[$i]))->sum('total'); $quarters[] = ['label' => $label, 'total' => $total, 'color' => $qColors[$i]]; $qTotal += $total; } $qTotal = max(1, $qTotal); $conicParts = ''; $cumAngle = 0; foreach ($quarters as $i => $q) { $angle = ($q['total'] / $qTotal) * 360; if ($q['total'] > 0) { $conicParts .= ($i > 0 ? ', ' : '') . $q['color'] . ' ' . round($cumAngle) . 'deg ' . round($cumAngle + $angle) . 'deg'; $cumAngle += $angle; } } @endphp
Total {{ number_format($qTotal, 0) }}
@foreach($quarters as $q)
{{ $q['label'] }} {{ number_format($q['total'], 2) }}
@endforeach

Revenu (30 derniers jours)

@php $maxDay = max(1, $last30Days->max('total')); @endphp
@php $weeks = collect(); $weekTotal = 0; $weekCount = 0; $weekLabel = ''; foreach ($last30Days as $i => $day) { $weekTotal += $day['total']; $weekCount++; if ($weekCount == 1) { $weekLabel = $day['date']; } if ($weekCount == 7 || $i == count($last30Days) - 1) { $weeks->push(['label' => $weekLabel, 'total' => $weekTotal]); $weekTotal = 0; $weekCount = 0; } } $weekMax = max(1, $weeks->max('total')); @endphp @foreach($weeks as $w) @php $wpct = max(5, ($w['total'] / $weekMax) * 100); @endphp
Sem. {{ $loop->index + 1 }}
{{ number_format($w['total'], 0) }}
{{ number_format($w['total'], 2) }}
@endforeach

Revenu par Catégorie

@if($revenueByCategory->isNotEmpty()) @php $maxCat = $revenueByCategory->max('total'); @endphp
@foreach($revenueByCategory as $cat) @php $pct = $maxCat > 0 ? max(4, ($cat->total / $maxCat) * 100) : 0; @endphp
{{ $cat->name }}
{{ number_format($cat->total, 0) }}
{{ number_format($cat->total, 2) }}
@endforeach
@else

Aucune donnée.

@endif

Top 10 Produits (Revenu)

@if($topProducts->isNotEmpty())
@foreach($topProducts as $p) @endforeach
Produit Vendus Revenu
{{ $p->name }} {{ $p->sold }} {{ number_format($p->revenue, 2) }}
@else

Aucune vente pour le moment.

@endif
@endsection