# TANRAIL ONE — Reporting & Analytics Architecture

## 1. Overview
Reporting in TANRAIL ONE operates on two distinct levels: Consolidated (Executive) and Local (Business Unit/Branch). The architecture must support fast aggregation of data across millions of rows without blocking operational database performance.

## 2. Executive Consolidated Reporting
These reports span across the entire organization, ignoring BU scoping boundaries.

### 2.1 Core KPIs
- Total Gross/Net Revenue (Cross-BU)
- Total Cash Received vs. Accounts Receivable
- Total Operational Expenses
- Organization-wide Profit & Loss (P&L) estimate
- Inventory Valuation (Global)

### 2.2 Technical Implementation
- **Query Strategy:** Queries run without the BU Global Scope (`withoutGlobalScope()`).
- **Performance:** For heavy aggregations (e.g., YTD Revenue), the system should utilize background Jobs to calculate totals nightly and store them in a `reporting_aggregates` table, rather than calculating on-the-fly.

## 3. Business-Specific Reporting
These reports are strictly scoped to the active Business Unit and/or Branch.

### 3.1 Standard Core Reports (Available to all BUs)
- **Sales Summary:** Revenue grouped by Day/Week/Month, filtered by Branch.
- **Inventory Movement:** Stock In/Out logs, Low Stock alerts.
- **Accounts Receivable:** Outstanding invoices for this BU.
- **Tax Report:** Tax collected for this BU.

### 3.2 BU-Specific Extension Reports
These reports depend on the BU's unique modules.
- **Restaurant:** Table Turnaround Time, Top Selling Menu Items, Kitchen Ticket Preparation Time.
- **Catering:** Event Profitability (Actual vs Estimated Cost), Quote Conversion Rate.

## 4. Reporting Extensibility
- When a new Business Unit is added (e.g., Water), it automatically inherits all the Standard Core Reports without writing new reporting code.
- Custom reports for the Water BU are placed in the `Extensions/Water/Reports` directory to keep the Core clean.

## 5. Export Requirements
All Data Tables and Reports must support export to:
- CSV
- Excel (XLSX)
- PDF (for formatted documents like Invoices and formal P&L statements)
