# Phase 6: Dashboards (Filament Widgets + Manager API) — DONE

**Completed:** 2026-03-13

## What was delivered

### Services (2)

- `app/Services/RestaurantManager/RestaurantDashboardService.php` — Period resolution, base PAID orders query, sparkline, daily chart, percentage change, current service period detection, currency resolution
- `app/Services/RestaurantManager/RestaurantDashboardCacheService.php` — Redis caching with 5min TTL for standard periods, custom periods bypass cache, invalidation for all widgets

### API Controllers — Real-time (4)

- `LiveStatusController` — GET live-status: table counts by status, current covers (seated), active carts, pending reservations, current service period
- `TodaySummaryController` — GET today-summary: revenue, covers, reservations by status, average ticket, tips total, comparison vs yesterday
- `ServiceSnapshotController` — GET service-snapshot: metrics for current/specified service period (revenue, covers, orders, avg ticket, top items)
- `UpcomingReservationsController` — GET upcoming-reservations: next N confirmed/pending reservations for today with customer, tables, party size

### API Controllers — Analytics (6)

- `RevenueController` — GET revenue: total + chart + percentage change, period filter (today/7d/14d/30d/custom), custom date range support
- `CoversController` — GET covers: total, daily average, chart (date + covers + reservations), by service period
- `AffluenceController` — GET affluence: covers by hour of day (average + peak), peak/quietest hour detection
- `PopularItemsController` — GET popular-items: top selling menu items with quantity, revenue, percentage, filtered by type (food/drink/all)
- `AverageTicketController` — GET average-ticket: average + chart + by service period + by payment method
- `ReservationStatsController` — GET reservation-stats: total, confirmation rate, no-show rate, cancellation rate, avg party size, avg lead time, chart, by service period

### Filament Widgets (6)

- `app/Filament/Widgets/Restaurant/LiveStatusWidget.php` — Stats cards: available/occupied tables, current covers, active carts. Auto-refreshes every 30s
- `app/Filament/Widgets/Restaurant/TodaySummaryWidget.php` — Stats cards: today revenue, covers + reservations, orders count. Auto-refreshes every 60s
- `app/Filament/Widgets/Restaurant/RevenueChartWidget.php` — Line chart: revenue over 7d/14d/30d with period filter
- `app/Filament/Widgets/Restaurant/PopularItemsWidget.php` — Table widget: top 10 selling items (30d) with name, category, price
- `app/Filament/Widgets/Restaurant/AffluenceWidget.php` — Bar chart: covers by hour for today (7:00-23:00)
- `app/Filament/Widgets/Restaurant/ReservationStatsWidget.php` — Stats cards: total reservations, confirmation rate, no-show rate, cancellation rate (30d)

### Routes (10)

- 4 Real-time routes under `v1/places/{place}/restaurants/{restaurant}/dashboard/`:
  - GET live-status, GET today-summary, GET service-snapshot, GET upcoming-reservations
- 6 Analytics routes:
  - GET revenue, GET covers, GET affluence, GET popular-items, GET average-ticket, GET reservation-stats

### Modified Files

- `app/Filament/Resources/RestaurantResource.php` — Added getWidgets() with 6 dashboard widgets
- `app/Filament/Resources/RestaurantResource/Pages/EditRestaurant.php` — Added getHeaderWidgets() (LiveStatus + TodaySummary) and getFooterWidgets() (RevenueChart + Affluence + ReservationStats + PopularItems)
- `routes/api.php` — Added Phase 6 dashboard routes (10 endpoints)

### Tests

- `tests/Feature/Controllers/RestaurantManager/DashboardTest.php` — 18 test cases covering:
  - Live status returns correct table counts
  - Live status returns current covers from seated reservations
  - Today summary calculates correct revenue
  - Today summary includes reservation breakdown
  - Service snapshot for specified period
  - Upcoming reservations returned chronologically
  - Revenue analytics with chart data
  - Covers grouped by date correctly
  - Affluence grouped by hour
  - Popular items returns top sellers with public_id
  - Average ticket calculation correct
  - Reservation stats calculates rates correctly
  - All period filters work (today, 7d, 14d, 30d)
  - Custom date range support
  - Empty data returns zeros, not errors
  - Non-authorized users get 403
  - Public_id never internal id in upcoming reservations
  - Public_id in popular items

## Quality Checks

- `vendor/bin/pint` — PASS (22 files, 2 auto-fixed style issues)
- `vendor/bin/phpstan --level=7` — PASS (0 errors after fixing 12 initial issues)

## Files Summary

| Type | Count |
|---|---|
| Services | 2 |
| API Controllers (Real-time) | 4 |
| API Controllers (Analytics) | 6 |
| Filament Widgets | 6 |
| Tests | 1 (18 test cases) |
| Modified files | 3 (RestaurantResource.php, EditRestaurant.php, routes/api.php) |
| **Total new files** | **19** |
