{{-- Statistics — IMPULSA skin. 4 KPI cards, then a compact two-panel row: a REAL, interactive "Recent orders" area chart (orders/day + a turquoise per-day spend trend, hover a point for that day's count and spend) on the LEFT, and an "Order status" donut (real per-status breakdown, total at the centre + a colour legend) on the RIGHT. The donut legend REPLACES the old row of status cards, so the same breakdown is never rendered twice. "Latest orders" and "Orders in process" follow. Everything is fed by the cached aggregates ($stats) and the live $recent / $inProcess collections. --}} @php use Illuminate\Support\Str; // Real 7-day series → interactive chart points. `extra` (formatted spend) is // only attached on days the client actually spent, so the tooltip shows a // spend line only when it is meaningful. $chartPoints = array_map(fn ($p) => [ 'label' => $p['label'], 'value' => $p['value'], 'extra' => ($p['spend'] ?? 0) > 0 ? client_money($p['spend']) : null, ], $stats['series'] ?? []); // Secondary trend: per-day spend, drawn as a light turquoise line beside the // orders line — but only when the client spent something in the window. $spendPoints = array_map(fn ($p) => ['value' => $p['spend'] ?? 0], $stats['series'] ?? []); $hasSpend = array_sum(array_column($spendPoints, 'value')) > 0; // One geometry pass shared by both series (identical box) so the two lines // line up exactly. Compact height keeps the chart from dominating the fold. $cOpts = ['vh' => 250, 'padX' => 30, 'padTop' => 14, 'padBottom' => 34, 'showAxis' => true]; $chart = impulsa_chart($chartPoints, $cOpts); $chart2 = impulsa_chart($spendPoints, ['showAxis' => false] + $cOpts); $kpis = [ ['label' => __('Your Balance'), 'value' => $stats['balance'], 'icon' => 'wallet', 'tint' => 'linear-gradient(135deg,#12c2b8,#0fb0a7)'], ['label' => __('Total Spent'), 'value' => $stats['spent'], 'icon' => 'trending-up', 'tint' => 'linear-gradient(135deg,#3b82f6,#2563eb)'], ['label' => __('Total Orders'), 'value' => number_format($stats['orders']), 'icon' => 'shopping-cart','tint' => 'linear-gradient(135deg,#f59e0b,#f97316)'], ['label' => __('Total Tickets'), 'value' => number_format($stats['tickets']), 'icon' => 'ticket', 'tint' => 'linear-gradient(135deg,#ec4899,#db2777)'], ]; // Order-status donut — the HONEST full breakdown (every status the client // actually has, from the raw group-by), so the ring sums to Total Orders. // Colours mirror the status badges; this is what the old status cards showed, // folded into one place. $statusMeta = [ 'completed' => ['label' => __('Completed'), 'color' => '#22c55e'], 'processing' => ['label' => __('Processing'), 'color' => '#3b82f6'], 'in_progress' => ['label' => __('In progress'), 'color' => '#14b8a6'], 'active' => ['label' => __('Active'), 'color' => '#06b6d4'], 'awaiting' => ['label' => __('Awaiting'), 'color' => '#a78bfa'], 'pending' => ['label' => __('Pending'), 'color' => '#f59e0b'], 'partial' => ['label' => __('Partial'), 'color' => '#ec4899'], 'canceled' => ['label' => __('Canceled'), 'color' => '#64748b'], 'refunded' => ['label' => __('Refunded'), 'color' => '#8b5cf6'], 'error' => ['label' => __('Error'), 'color' => '#ef4444'], 'simulated' => ['label' => __('Simulated'), 'color' => '#f43f5e'], ]; $donut = []; foreach ($statusMeta as $key => $meta) { $v = (int) ($stats['byStatus'][$key] ?? 0); if ($v > 0) { $donut[] = ['label' => $meta['label'], 'color' => $meta['color'], 'value' => $v]; } } $donutTotal = array_sum(array_column($donut, 'value')); // Ring geometry: each slice is one arc on a shared circle, rotated to its // cumulative start (−90° puts 0 at 12 o'clock, clockwise). A small gap keeps // adjacent slices visually separated. $dR = 54; $dC = 2 * M_PI * $dR; $dGap = count($donut) > 1 ? 5.0 : 0.0; $dAcc = 0.0; $segs = []; foreach ($donut as $d) { $frac = $donutTotal > 0 ? $d['value'] / $donutTotal : 0; $len = $frac * $dC; $segs[] = [ 'color' => $d['color'], 'dash' => round(max(0.6, $len - $dGap), 2), 'rot' => round(-90 + ($dAcc / $dC) * 360, 2), ]; $dAcc += $len; } @endphp
{{ __('No orders yet') }}
{{ __('Nothing in process') }}
{{ __('All your orders are settled.') }}