From faaa8cc47a39f9cfda13015ad92d7d6701a3bb65 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 6 Sep 2025 23:49:59 -0400 Subject: [PATCH] Fix vendors page query issue --- inventory-server/src/routes/vendorsAggregate.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) 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}