diff --git a/inventory-server/src/routes/vendorsAggregate.js b/inventory-server/src/routes/vendorsAggregate.js index 7e9b11b..84e0544 100644 --- a/inventory-server/src/routes/vendorsAggregate.js +++ b/inventory-server/src/routes/vendorsAggregate.js @@ -107,10 +107,10 @@ router.get('/stats', async (req, res) => { // Get overall cost metrics from purchase orders const { rows: [overallCostMetrics] } = await pool.query(` SELECT - ROUND((SUM(ordered * cost_price)::numeric / NULLIF(SUM(ordered), 0)), 2) as avg_unit_cost, - ROUND(SUM(ordered * cost_price)::numeric, 3) as total_spend + ROUND((SUM(ordered * po_cost_price)::numeric / NULLIF(SUM(ordered), 0)), 2) as avg_unit_cost, + ROUND(SUM(ordered * po_cost_price)::numeric, 3) as total_spend FROM purchase_orders - WHERE cost_price IS NOT NULL + WHERE po_cost_price IS NOT NULL AND ordered > 0 AND vendor IS NOT NULL AND vendor != '' `); @@ -261,10 +261,10 @@ router.get('/', async (req, res) => { LEFT JOIN ( SELECT vendor, - ROUND((SUM(ordered * cost_price)::numeric / NULLIF(SUM(ordered), 0)), 2) as avg_unit_cost, - ROUND(SUM(ordered * cost_price)::numeric, 3) as total_spend + ROUND((SUM(ordered * po_cost_price)::numeric / NULLIF(SUM(ordered), 0)), 2) as avg_unit_cost, + ROUND(SUM(ordered * po_cost_price)::numeric, 3) as total_spend FROM purchase_orders - WHERE cost_price IS NOT NULL AND ordered > 0 + WHERE po_cost_price IS NOT NULL AND ordered > 0 GROUP BY vendor ) po ON vm.vendor_name = po.vendor ${whereClause}