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)}