# 07 - Analytics

**Status: NOT STARTED**

## Summary

Two-part feature: (A) Integrate Darshan's existing analytics dashboard into Arda, and (B) create a new report showing why orders are stuck and haven't shipped, categorized by blocking reason.

## Current State

Existing analytics in Arda:
- `/analytics` - Basic reports for jobs, orders, IPD breakdown
- `/shipper/stats` - Shipment statistics with stacked charts and moving averages
- `/shop/orders` with report views - Order filtering and querying
- `/inventory/report` - Inventory levels by product type

No unshipped orders analysis or Darshan's dashboard integration exists.

## Requirements

### Part A: Darshan's Dashboard
1. Embed or recreate the analytics dashboard that Darshan has built
2. Make it accessible within Arda navigation

### Part B: Unshipped Orders Analysis
1. Categorize unshipped orders by blocking reason:
    - **Waiting for face scan**: `WaitingForScanRequest` + no scan submitted
    - **In manufacturing**: `WaitingForManufacturing`
    - **Out of stock**: `WaitingForInventory`
    - **On hold**: `ReadyToShip` + `shipmentHold` set
    - **Address/payment issues**: `ShopifyProblem`
    - **System errors**: `Error`
2. Show counts per category
3. Show list of orders with their blocking reasons
4. Visualize blockers with charts

## Files to Create

| File | Purpose |
|------|---------|
| `webapps/src/components/Analytics/DarshanDashboard.jsx` | Embedded or recreated version of Darshan's dashboard |
| `webapps/src/components/Analytics/UnshippedOrdersReport.jsx` | Page showing why orders haven't shipped |
| `webapps/src/components/Analytics/UnshippedOrdersChart.jsx` | Visualization of order blockers by category |

## Files to Modify

| File | Change |
|------|--------|
| `api/src/fabricator/FabricatorAdminApi.ts` | Add endpoint for unshipped orders analysis |
| `api/src/fabricator/FabricatorDatabase.ts` | Add query to categorize unshipped orders by blocker reason |
| `webapps/src/components/Analytics/AnalyticsWrapper.jsx` | Add navigation links to new pages |
| `webapps/app/App.jsx` | Add routes for new analytics pages |

## API Endpoints

| Method | Endpoint | Purpose |
|--------|----------|---------|
| GET | `/api/admin/analytics/unshipped-reasons` | Get counts of orders by blocking reason |
| GET | `/api/admin/analytics/unshipped-orders` | Get list of unshipped orders with reasons |

## Implementation Notes

- Part A depends on understanding Darshan's dashboard format (iframe embed vs recreation)
- Part B categorization logic is based on Max's existing spreadsheet categories
- The unshipped reasons query needs to handle combinations (e.g. an order could be waiting for scan AND have a payment issue)
