Fix vendors page query issue
This commit is contained in:
@@ -107,10 +107,10 @@ router.get('/stats', async (req, res) => {
|
|||||||
// Get overall cost metrics from purchase orders
|
// Get overall cost metrics from purchase orders
|
||||||
const { rows: [overallCostMetrics] } = await pool.query(`
|
const { rows: [overallCostMetrics] } = await pool.query(`
|
||||||
SELECT
|
SELECT
|
||||||
ROUND((SUM(ordered * cost_price)::numeric / NULLIF(SUM(ordered), 0)), 2) as avg_unit_cost,
|
ROUND((SUM(ordered * po_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, 3) as total_spend
|
||||||
FROM purchase_orders
|
FROM purchase_orders
|
||||||
WHERE cost_price IS NOT NULL
|
WHERE po_cost_price IS NOT NULL
|
||||||
AND ordered > 0
|
AND ordered > 0
|
||||||
AND vendor IS NOT NULL AND vendor != ''
|
AND vendor IS NOT NULL AND vendor != ''
|
||||||
`);
|
`);
|
||||||
@@ -261,10 +261,10 @@ router.get('/', async (req, res) => {
|
|||||||
LEFT JOIN (
|
LEFT JOIN (
|
||||||
SELECT
|
SELECT
|
||||||
vendor,
|
vendor,
|
||||||
ROUND((SUM(ordered * cost_price)::numeric / NULLIF(SUM(ordered), 0)), 2) as avg_unit_cost,
|
ROUND((SUM(ordered * po_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, 3) as total_spend
|
||||||
FROM purchase_orders
|
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
|
GROUP BY vendor
|
||||||
) po ON vm.vendor_name = po.vendor
|
) po ON vm.vendor_name = po.vendor
|
||||||
${whereClause}
|
${whereClause}
|
||||||
|
|||||||
Reference in New Issue
Block a user