Fix various issues with product table and details components
This commit is contained in:
@@ -252,15 +252,29 @@ router.get('/', async (req, res) => {
|
||||
pm.daily_sales_avg,
|
||||
pm.weekly_sales_avg,
|
||||
pm.monthly_sales_avg,
|
||||
pm.avg_quantity_per_order,
|
||||
pm.number_of_orders,
|
||||
pm.first_sale_date,
|
||||
pm.last_sale_date,
|
||||
pm.days_of_inventory,
|
||||
pm.weeks_of_inventory,
|
||||
pm.reorder_point,
|
||||
pm.safety_stock,
|
||||
pm.avg_margin_percent,
|
||||
pm.total_revenue,
|
||||
pm.inventory_value,
|
||||
pm.cost_of_goods_sold,
|
||||
pm.gross_profit,
|
||||
pm.gmroi,
|
||||
pm.avg_lead_time_days,
|
||||
pm.last_purchase_date,
|
||||
pm.last_received_date,
|
||||
pm.abc_class,
|
||||
pm.stock_status,
|
||||
pm.avg_lead_time_days,
|
||||
pm.turnover_rate,
|
||||
pm.current_lead_time,
|
||||
pm.target_lead_time,
|
||||
pm.lead_time_status,
|
||||
pm.days_of_inventory as days_of_stock,
|
||||
COALESCE(pm.days_of_inventory / NULLIF(pt.target_days, 0), 0) as stock_coverage_ratio
|
||||
FROM products p
|
||||
LEFT JOIN product_metrics pm ON p.product_id = pm.product_id
|
||||
@@ -281,15 +295,34 @@ router.get('/', async (req, res) => {
|
||||
categories: row.categories ? row.categories.split(',') : [],
|
||||
price: parseFloat(row.price),
|
||||
cost_price: parseFloat(row.cost_price),
|
||||
landing_cost_price: parseFloat(row.landing_cost_price),
|
||||
landing_cost_price: row.landing_cost_price ? parseFloat(row.landing_cost_price) : null,
|
||||
stock_quantity: parseInt(row.stock_quantity),
|
||||
daily_sales_avg: parseFloat(row.daily_sales_avg) || 0,
|
||||
weekly_sales_avg: parseFloat(row.weekly_sales_avg) || 0,
|
||||
monthly_sales_avg: parseFloat(row.monthly_sales_avg) || 0,
|
||||
avg_quantity_per_order: parseFloat(row.avg_quantity_per_order) || 0,
|
||||
number_of_orders: parseInt(row.number_of_orders) || 0,
|
||||
first_sale_date: row.first_sale_date || null,
|
||||
last_sale_date: row.last_sale_date || null,
|
||||
days_of_inventory: parseFloat(row.days_of_inventory) || 0,
|
||||
weeks_of_inventory: parseFloat(row.weeks_of_inventory) || 0,
|
||||
reorder_point: parseFloat(row.reorder_point) || 0,
|
||||
safety_stock: parseFloat(row.safety_stock) || 0,
|
||||
avg_margin_percent: parseFloat(row.avg_margin_percent) || 0,
|
||||
total_revenue: parseFloat(row.total_revenue) || 0,
|
||||
inventory_value: parseFloat(row.inventory_value) || 0,
|
||||
cost_of_goods_sold: parseFloat(row.cost_of_goods_sold) || 0,
|
||||
gross_profit: parseFloat(row.gross_profit) || 0,
|
||||
gmroi: parseFloat(row.gmroi) || 0,
|
||||
lead_time_days: parseInt(row.lead_time_days) || 0,
|
||||
days_of_stock: parseFloat(row.days_of_stock) || 0,
|
||||
avg_lead_time_days: parseFloat(row.avg_lead_time_days) || 0,
|
||||
last_purchase_date: row.last_purchase_date || null,
|
||||
last_received_date: row.last_received_date || null,
|
||||
abc_class: row.abc_class || null,
|
||||
stock_status: row.stock_status || null,
|
||||
turnover_rate: parseFloat(row.turnover_rate) || 0,
|
||||
current_lead_time: parseFloat(row.current_lead_time) || 0,
|
||||
target_lead_time: parseFloat(row.target_lead_time) || 0,
|
||||
lead_time_status: row.lead_time_status || null,
|
||||
stock_coverage_ratio: parseFloat(row.stock_coverage_ratio) || 0
|
||||
}));
|
||||
|
||||
@@ -617,7 +650,7 @@ router.get('/:id/metrics', async (req, res) => {
|
||||
LEFT JOIN product_metrics pm ON p.product_id = pm.product_id
|
||||
LEFT JOIN inventory_status is ON p.product_id = is.product_id
|
||||
WHERE p.product_id = ?
|
||||
`, [id, id]);
|
||||
`, [id]);
|
||||
|
||||
if (!metrics.length) {
|
||||
// Return default metrics structure if no data found
|
||||
|
||||
Reference in New Issue
Block a user