| 1 | == Main Restaurant Report Summary Table |
| 2 | CREATE TABLE restaurant_weekly_report ( |
| 3 | report_id SERIAL PRIMARY KEY, |
| 4 | restaurant_id INT NOT NULL, |
| 5 | report_week DATE NOT NULL, -- Monday of the week |
| 6 | week_number INT NOT NULL, -- Week 1, 2, or 3 (most recent) |
| 7 | |
| 8 | -- Order Statistics |
| 9 | total_orders INTEGER DEFAULT 0, |
| 10 | completed_orders INTEGER DEFAULT 0, |
| 11 | cancelled_orders INTEGER DEFAULT 0, |
| 12 | |
| 13 | -- Financial Metrics |
| 14 | gross_revenue DECIMAL(12,2) DEFAULT 0.00, |
| 15 | net_revenue DECIMAL(12,2) DEFAULT 0.00, -- After platform commission |
| 16 | average_order_value DECIMAL(10,2) DEFAULT 0.00, |
| 17 | total_items_sold INTEGER DEFAULT 0, |
| 18 | |
| 19 | -- Operational Metrics |
| 20 | avg_preparation_time_minutes DECIMAL(8,2) DEFAULT 0.00, |
| 21 | peak_hour INTEGER, -- Hour with most orders |
| 22 | busiest_day INTEGER, -- Day of week (0=Sunday, 6=Saturday) |
| 23 | |
| 24 | -- Performance Indicators |
| 25 | completion_rate DECIMAL(5,2) DEFAULT 0.00, -- % of orders completed |
| 26 | customer_satisfaction DECIMAL(3,2) DEFAULT 0.00, -- Placeholder for ratings |
| 27 | orders_per_hour DECIMAL(8,2) DEFAULT 0.00, |
| 28 | |
| 29 | -- Timestamps |
| 30 | generated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
| 31 | last_updated TIMESTAMP DEFAULT CURRENT_TIMESTAMP, |
| 32 | |
| 33 | CONSTRAINT fk_weekly_report_restaurant FOREIGN KEY (restaurant_id) REFERENCES restaurant(restaurant_id), |
| 34 | CONSTRAINT uq_restaurant_week UNIQUE (restaurant_id, report_week) |
| 35 | ); |