Use new categories correctly in existing components and handle category names with commas

This commit is contained in:
2025-01-11 01:25:52 -05:00
parent 0bc86a3fee
commit d805e49449
9 changed files with 556 additions and 53 deletions

View File

@@ -243,7 +243,7 @@ router.get('/cost-analysis', async (req, res) => {
const [analysis] = await pool.query(`
SELECT
p.categories,
c.name as categories,
COUNT(DISTINCT po.product_id) as unique_products,
ROUND(AVG(po.cost_price), 2) as avg_cost,
MIN(po.cost_price) as min_cost,
@@ -254,7 +254,9 @@ router.get('/cost-analysis', async (req, res) => {
SUM(po.ordered * po.cost_price) as total_spend
FROM purchase_orders po
JOIN products p ON po.product_id = p.product_id
GROUP BY p.categories
JOIN product_categories pc ON p.product_id = pc.product_id
JOIN categories c ON pc.category_id = c.id
GROUP BY c.name
ORDER BY total_spend DESC
`);