From 1b4447f8863dcec62bfb37df137150085eeca356 Mon Sep 17 00:00:00 2001 From: Matt Date: Sat, 18 Jan 2025 00:43:57 -0500 Subject: [PATCH] Fix and restyle overstockmetrics and topoverstockedproducts, link products to backend --- inventory-server/src/routes/dashboard.js | 19 ++++++++++----- .../components/dashboard/OverstockMetrics.tsx | 17 +++++++------- .../dashboard/TopOverstockedProducts.tsx | 23 ++++++++++++++----- .../dashboard/TopReplenishProducts.tsx | 9 +++++++- 4 files changed, 47 insertions(+), 21 deletions(-) diff --git a/inventory-server/src/routes/dashboard.js b/inventory-server/src/routes/dashboard.js index 19a1194..ed1a3ac 100644 --- a/inventory-server/src/routes/dashboard.js +++ b/inventory-server/src/routes/dashboard.js @@ -357,7 +357,7 @@ router.get('/overstock/metrics', async (req, res) => { SUM(total_excess_units) as total_excess_units, SUM(total_excess_cost) as total_excess_cost, SUM(total_excess_retail) as total_excess_retail, - CAST(JSON_ARRAYAGG( + CONCAT('[', GROUP_CONCAT( JSON_OBJECT( 'category', category_name, 'products', overstocked_products, @@ -365,7 +365,7 @@ router.get('/overstock/metrics', async (req, res) => { 'cost', total_excess_cost, 'retail', total_excess_retail ) - ) AS JSON) as category_data + ), ']') as category_data FROM ( SELECT * FROM category_overstock @@ -378,10 +378,17 @@ router.get('/overstock/metrics', async (req, res) => { // Format response with explicit type conversion const response = { overstockedProducts: parseInt(rows[0].total_overstocked) || 0, - excessUnits: parseInt(rows[0].total_excess_units) || 0, - excessCost: parseFloat(rows[0].total_excess_cost) || 0, - excessRetail: parseFloat(rows[0].total_excess_retail) || 0, - categoryData: rows[0].category_data ? JSON.parse(rows[0].category_data) : [] + total_excess_units: parseInt(rows[0].total_excess_units) || 0, + total_excess_cost: parseFloat(rows[0].total_excess_cost) || 0, + total_excess_retail: parseFloat(rows[0].total_excess_retail) || 0, + category_data: rows[0].category_data ? + JSON.parse(rows[0].category_data).map(obj => ({ + category: obj.category, + products: parseInt(obj.products) || 0, + units: parseInt(obj.units) || 0, + cost: parseFloat(obj.cost) || 0, + retail: parseFloat(obj.retail) || 0 + })) : [] }; res.json(response); diff --git a/inventory/src/components/dashboard/OverstockMetrics.tsx b/inventory/src/components/dashboard/OverstockMetrics.tsx index 8a405df..c026a73 100644 --- a/inventory/src/components/dashboard/OverstockMetrics.tsx +++ b/inventory/src/components/dashboard/OverstockMetrics.tsx @@ -6,14 +6,15 @@ import { Package, Layers, DollarSign, ShoppingCart } from "lucide-react" interface OverstockMetricsData { overstockedProducts: number - overstockedUnits: number - overstockedCost: number - overstockedRetail: number - overstockByCategory: { + total_excess_units: number + total_excess_cost: number + total_excess_retail: number + category_data: { category: string products: number units: number cost: number + retail: number }[] } @@ -41,28 +42,28 @@ export function OverstockMetrics() {

Overstocked Products

-

{data?.overstockedProducts.toLocaleString() || 0}

+

{data?.overstockedProducts.toLocaleString() || 0}

Overstocked Units

-

{data?.overstockedUnits.toLocaleString() || 0}

+

{data?.total_excess_units.toLocaleString() || 0}

Overstocked Cost

-

{formatCurrency(data?.overstockedCost || 0)}

+

{formatCurrency(data?.total_excess_cost || 0)}

Overstocked Retail

-

{formatCurrency(data?.overstockedRetail || 0)}

+

{formatCurrency(data?.total_excess_retail || 0)}

diff --git a/inventory/src/components/dashboard/TopOverstockedProducts.tsx b/inventory/src/components/dashboard/TopOverstockedProducts.tsx index ec6e175..f963504 100644 --- a/inventory/src/components/dashboard/TopOverstockedProducts.tsx +++ b/inventory/src/components/dashboard/TopOverstockedProducts.tsx @@ -9,10 +9,10 @@ interface OverstockedProduct { product_id: number SKU: string title: string + stock_quantity: number overstocked_amt: number excess_cost: number excess_retail: number - days_of_inventory: number } export function TopOverstockedProducts() { @@ -38,9 +38,10 @@ export function TopOverstockedProducts() { Product - Units - Cost - Days + Current Stock + Overstock Amt + Overstock Cost + Overstock Retail @@ -48,10 +49,20 @@ export function TopOverstockedProducts() {
-

{product.title}

+ + {product.title} +

{product.SKU}

+ + {product.stock_quantity.toLocaleString()} + {product.overstocked_amt.toLocaleString()} @@ -59,7 +70,7 @@ export function TopOverstockedProducts() { {formatCurrency(product.excess_cost)} - {product.days_of_inventory} + {formatCurrency(product.excess_retail)}
))} diff --git a/inventory/src/components/dashboard/TopReplenishProducts.tsx b/inventory/src/components/dashboard/TopReplenishProducts.tsx index f420b24..41df022 100644 --- a/inventory/src/components/dashboard/TopReplenishProducts.tsx +++ b/inventory/src/components/dashboard/TopReplenishProducts.tsx @@ -49,7 +49,14 @@ export function TopReplenishProducts() {
-

{product.title}

+ + {product.title} +

{product.SKU}