Fix various issues with product table and details components
This commit is contained in:
@@ -688,7 +688,10 @@ async function calculateMetrics() {
|
||||
AVG(o.quantity) as avg_quantity_per_order,
|
||||
-- Calculate rolling averages using configured windows
|
||||
SUM(CASE WHEN o.date >= DATE_SUB(CURDATE(), INTERVAL ? DAY) THEN o.quantity ELSE 0 END) as last_30_days_qty,
|
||||
SUM(CASE WHEN o.date >= DATE_SUB(CURDATE(), INTERVAL ? DAY) THEN o.quantity ELSE 0 END) as last_7_days_qty,
|
||||
CASE
|
||||
WHEN SUM(CASE WHEN o.date >= DATE_SUB(CURDATE(), INTERVAL ? DAY) THEN o.quantity ELSE 0 END) IS NULL THEN 0
|
||||
ELSE SUM(CASE WHEN o.date >= DATE_SUB(CURDATE(), INTERVAL ? DAY) THEN o.quantity ELSE 0 END)
|
||||
END as rolling_weekly_avg,
|
||||
SUM(CASE WHEN o.date >= DATE_SUB(CURDATE(), INTERVAL ? DAY) THEN o.quantity ELSE 0 END) as last_month_qty
|
||||
FROM orders o
|
||||
JOIN products p ON o.product_id = p.product_id
|
||||
@@ -704,13 +707,14 @@ async function calculateMetrics() {
|
||||
number_of_orders,
|
||||
avg_quantity_per_order,
|
||||
last_30_days_qty / ? as rolling_daily_avg,
|
||||
last_7_days_qty / ? as rolling_weekly_avg,
|
||||
rolling_weekly_avg / ? as rolling_weekly_avg,
|
||||
last_month_qty / ? as rolling_monthly_avg,
|
||||
total_quantity_sold as total_sales_to_date
|
||||
FROM sales_summary
|
||||
`, [
|
||||
config.daily_window_days,
|
||||
config.weekly_window_days,
|
||||
config.weekly_window_days,
|
||||
config.monthly_window_days,
|
||||
product.product_id,
|
||||
config.daily_window_days,
|
||||
|
||||
Reference in New Issue
Block a user