diff --git a/inventory-server/src/routes/analytics.js b/inventory-server/src/routes/analytics.js index a463b89..6c83f82 100644 --- a/inventory-server/src/routes/analytics.js +++ b/inventory-server/src/routes/analytics.js @@ -575,7 +575,7 @@ router.get('/forecast', async (req, res) => { JSON_ARRAYAGG( JSON_OBJECT( 'product_id', pm.product_id, - 'name', pm.title, + 'title', pm.title, 'sku', pm.sku, 'stock_quantity', pm.stock_quantity, 'total_sold', pm.total_sold, diff --git a/inventory/src/components/forecasting/columns.tsx b/inventory/src/components/forecasting/columns.tsx index 9b9bdce..f7e24d8 100644 --- a/inventory/src/components/forecasting/columns.tsx +++ b/inventory/src/components/forecasting/columns.tsx @@ -1,18 +1,18 @@ -import { ColumnDef, Column } from "@tanstack/react-table"; -import { Button } from "@/components/ui/button"; +import { ColumnDef } from "@tanstack/react-table"; import { ArrowUpDown, ChevronDown, ChevronRight } from "lucide-react"; -import { Accordion, AccordionContent, AccordionItem, AccordionTrigger } from "@/components/ui/accordion"; - -export type ProductDetail = { +import { Button } from "@/components/ui/button"; +import { ScrollArea } from "@/components/ui/scroll-area"; +import { Table, TableBody, TableCell, TableHead, TableHeader, TableRow } from "@/components/ui/table"; +interface ProductDetail { product_id: string; name: string; sku: string; stock_quantity: number; total_sold: number; avg_price: number; -}; +} -export type ForecastItem = { +export interface ForecastItem { category: string; avgDailySales: number; totalSold: number; @@ -20,49 +20,36 @@ export type ForecastItem = { avgPrice: number; avgTotalSold: number; products?: ProductDetail[]; -}; +} export const columns: ColumnDef[] = [ { id: "expander", header: () => null, cell: ({ row }) => { - return row.original.products?.length ? ( + return row.getCanExpand() ? ( ) : null; }, }, { accessorKey: "category", - header: ({ column }: { column: Column }) => { - return ( - - ); - }, + header: "Category", }, { accessorKey: "avgDailySales", - header: ({ column }: { column: Column }) => { + header: ({ column }) => { return ( + ); + }, + cell: ({ row }) => { + const value = row.getValue("numProducts") as number; + return value?.toLocaleString() || "0"; + }, + }, + { + accessorKey: "avgTotalSold", + header: ({ column }) => { + return ( + - ); + return value?.toFixed(2) || "0.00"; }, }, { accessorKey: "avgPrice", - header: ({ column }: { column: Column }) => { + header: ({ column }) => { return (