# Flowchart — `dashboard`

> Produced by the Reversa **Archaeologist** (phase: excavation) · doc_level: `complete`
> Generated on 2026-09-16

**Confidence scale:** 🟢 CONFIRMED · 🟡 INFERRED · 🔴 GAP

## `DashboardController::index` 🟢

```mermaid
flowchart TD
    A["GET /dashboard"] --> B["KPIs:<br/>products=count, customers=count,<br/>orders=count(status='done' AND today)"]
    B --> C{"request()->range ?: 'month'"}
    C -->|day| D["buckets: Sáng 06-12 / Trưa 12-18 / Chiều 18-24<br/>🟢 sequential via mutating $startDay (verified correct)"]
    C -->|week| E["one WHEN per day<br/>startOfWeek..endOfWeek"]
    C -->|month| F["5-day windows across month<br/>label 'dd/mm-dd/mm'; yearRange"]
    D --> G["build raw SQL CASE ... END AS range_date"]
    E --> G
    F --> G
    G --> H["Order::select(DB::raw(query))<br/>->groupBy('range_date')<br/>->pluck('quantity','range_date')"]
    H --> I["map rangeData → labelChart / valueChart"]
    I --> J["top products:<br/>order_product ⋈ products (not deleted)<br/>SUM(qty) desc, limit 10"]
    J --> K["view('pages.dashboard', total, chartRange,<br/>range, yearRange, labelChart, valueChart, products)"]
```

**Notes:**
- 🟢 Day-range `CASE`: all three `WHEN` branches reuse `$startDay`, mutated in place by `Carbon::addHours(6)` (Carbon `1.25.*`) at each use. Because PHP evaluates `.` concatenation left-to-right, this yields three correct, non-overlapping 6h windows (Sáng 06-12, Trưa 12-18, Chiều 18-24) — not a bug, though fragile/non-obvious. Verified by manual trace.
- 🟢 Orders in 00:00–06:00 fall outside all buckets and are excluded from the "day" chart — confirmed intentional: the store is closed overnight and orders in that window are negligible.
- 🟢 `App\Models\OrderProduct` and `Cassandra\Custom` imports are unused/erroneous but confirmed harmless (dead imports, never referenced).
