Update frontend to match part 1

This commit is contained in:
2025-01-28 01:30:48 -05:00
parent 8323ae7703
commit 64d9ab2f83
25 changed files with 936 additions and 686 deletions

View File

@@ -42,7 +42,7 @@ router.get('/', async (req, res) => {
po_id,
SUM(ordered) as total_ordered,
SUM(received) as total_received,
SUM(ordered * cost_price) as total_cost
CAST(SUM(ordered * cost_price) AS DECIMAL(15,3)) as total_cost
FROM purchase_orders po
WHERE ${whereClause}
GROUP BY po_id
@@ -54,8 +54,8 @@ router.get('/', async (req, res) => {
ROUND(
SUM(total_received) / NULLIF(SUM(total_ordered), 0), 3
) as fulfillment_rate,
SUM(total_cost) as total_value,
ROUND(AVG(total_cost), 2) as avg_cost
CAST(SUM(total_cost) AS DECIMAL(15,3)) as total_value,
CAST(AVG(total_cost) AS DECIMAL(15,3)) as avg_cost
FROM po_totals
`, params);
@@ -78,9 +78,9 @@ router.get('/', async (req, res) => {
vendor,
date,
status,
COUNT(DISTINCT product_id) as total_items,
COUNT(DISTINCT pid) as total_items,
SUM(ordered) as total_quantity,
SUM(ordered * cost_price) as total_cost,
CAST(SUM(ordered * cost_price) AS DECIMAL(15,3)) as total_cost,
SUM(received) as total_received,
ROUND(
SUM(received) / NULLIF(SUM(ordered), 0), 3
@@ -104,8 +104,8 @@ router.get('/', async (req, res) => {
CASE
WHEN ? = 'order_date' THEN date
WHEN ? = 'vendor_name' THEN vendor
WHEN ? = 'total_cost' THEN CAST(total_cost AS DECIMAL(15,2))
WHEN ? = 'total_received' THEN CAST(total_received AS DECIMAL(15,2))
WHEN ? = 'total_cost' THEN CAST(total_cost AS DECIMAL(15,3))
WHEN ? = 'total_received' THEN CAST(total_received AS DECIMAL(15,3))
WHEN ? = 'total_items' THEN CAST(total_items AS SIGNED)
WHEN ? = 'total_quantity' THEN CAST(total_quantity AS SIGNED)
WHEN ? = 'fulfillment_rate' THEN CAST(fulfillment_rate AS DECIMAL(5,3))
@@ -203,10 +203,10 @@ router.get('/vendor-metrics', async (req, res) => {
ROUND(
SUM(received) / NULLIF(SUM(ordered), 0), 3
) as fulfillment_rate,
ROUND(
CAST(ROUND(
SUM(ordered * cost_price) / NULLIF(SUM(ordered), 0), 2
) as avg_unit_cost,
SUM(ordered * cost_price) as total_spend,
) AS DECIMAL(15,3)) as avg_unit_cost,
CAST(SUM(ordered * cost_price) AS DECIMAL(15,3)) as total_spend,
ROUND(
AVG(NULLIF(delivery_days, 0)), 1
) as avg_delivery_days
@@ -244,18 +244,15 @@ router.get('/cost-analysis', async (req, res) => {
const [analysis] = await pool.query(`
SELECT
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,
MAX(po.cost_price) as max_cost,
ROUND(
STDDEV(po.cost_price), 2
) as cost_variance,
SUM(po.ordered * po.cost_price) as total_spend
COUNT(DISTINCT po.pid) as unique_products,
CAST(AVG(po.cost_price) AS DECIMAL(15,3)) as avg_cost,
CAST(MIN(po.cost_price) AS DECIMAL(15,3)) as min_cost,
CAST(MAX(po.cost_price) AS DECIMAL(15,3)) as max_cost,
CAST(STDDEV(po.cost_price) AS DECIMAL(15,3)) as cost_std_dev,
CAST(SUM(po.ordered * po.cost_price) AS DECIMAL(15,3)) as total_spend
FROM purchase_orders po
JOIN products p ON po.product_id = p.product_id
JOIN product_categories pc ON p.product_id = pc.product_id
JOIN categories c ON pc.category_id = c.id
JOIN product_categories pc ON po.pid = pc.pid
JOIN categories c ON pc.cat_id = c.cat_id
GROUP BY c.name
ORDER BY total_spend DESC
`);