Add new dashboard backend
This commit is contained in:
@@ -43,6 +43,9 @@ CREATE TABLE IF NOT EXISTS product_metrics (
|
||||
avg_margin_percent DECIMAL(10,3),
|
||||
total_revenue DECIMAL(10,3),
|
||||
inventory_value DECIMAL(10,3),
|
||||
cost_of_goods_sold DECIMAL(10,3),
|
||||
gross_profit DECIMAL(10,3),
|
||||
gmroi DECIMAL(10,3),
|
||||
-- Purchase metrics
|
||||
avg_lead_time_days INT,
|
||||
last_purchase_date DATE,
|
||||
@@ -50,9 +53,18 @@ CREATE TABLE IF NOT EXISTS product_metrics (
|
||||
-- Classification
|
||||
abc_class CHAR(1),
|
||||
stock_status VARCHAR(20),
|
||||
-- Turnover metrics
|
||||
turnover_rate DECIMAL(10,3),
|
||||
-- Lead time metrics
|
||||
current_lead_time INT,
|
||||
target_lead_time INT,
|
||||
lead_time_status VARCHAR(20),
|
||||
PRIMARY KEY (product_id),
|
||||
FOREIGN KEY (product_id) REFERENCES products(product_id) ON DELETE CASCADE,
|
||||
INDEX idx_metrics_revenue (total_revenue)
|
||||
INDEX idx_metrics_revenue (total_revenue),
|
||||
INDEX idx_metrics_stock_status (stock_status),
|
||||
INDEX idx_metrics_lead_time (lead_time_status),
|
||||
INDEX idx_metrics_turnover (turnover_rate)
|
||||
);
|
||||
|
||||
-- New table for time-based aggregates
|
||||
@@ -71,6 +83,8 @@ CREATE TABLE IF NOT EXISTS product_time_aggregates (
|
||||
-- Calculated fields
|
||||
avg_price DECIMAL(10,3),
|
||||
profit_margin DECIMAL(10,3),
|
||||
inventory_value DECIMAL(10,3),
|
||||
gmroi DECIMAL(10,3),
|
||||
PRIMARY KEY (product_id, year, month),
|
||||
FOREIGN KEY (product_id) REFERENCES products(product_id) ON DELETE CASCADE,
|
||||
INDEX idx_date (year, month)
|
||||
@@ -85,7 +99,10 @@ CREATE TABLE IF NOT EXISTS vendor_metrics (
|
||||
order_fill_rate DECIMAL(5,2),
|
||||
total_orders INT,
|
||||
total_late_orders INT,
|
||||
PRIMARY KEY (vendor)
|
||||
total_purchase_value DECIMAL(10,3),
|
||||
avg_order_value DECIMAL(10,3),
|
||||
PRIMARY KEY (vendor),
|
||||
INDEX idx_vendor_performance (on_time_delivery_rate)
|
||||
);
|
||||
|
||||
-- Re-enable foreign key checks
|
||||
|
||||
Reference in New Issue
Block a user