diff --git a/src/app/api/do/actions.tsx b/src/app/api/do/actions.tsx index 8605885..7d85247 100644 --- a/src/app/api/do/actions.tsx +++ b/src/app/api/do/actions.tsx @@ -35,6 +35,7 @@ export interface DoDetailLine { status: string; itemName?: string; uomCode?: string; + shortUom?: string; } export interface DoSearchAll { diff --git a/src/app/api/do/index.tsx b/src/app/api/do/index.tsx index 4aa1bc5..ae6c7df 100644 --- a/src/app/api/do/index.tsx +++ b/src/app/api/do/index.tsx @@ -21,6 +21,7 @@ export interface DoDetailLine { status: string; itemName?: string; uomCode?: string; + shortUom?: string; } diff --git a/src/components/DoDetail/DoInfoCard.tsx b/src/components/DoDetail/DoInfoCard.tsx index f15762f..1e2b23e 100644 --- a/src/components/DoDetail/DoInfoCard.tsx +++ b/src/components/DoDetail/DoInfoCard.tsx @@ -21,15 +21,8 @@ const DoInfoCard: React.FC = ({ - - - - + + = ({ watch } = useFormContext() + const [inventoryData, setInventoryData] = useState([]); + const deliveryOrderLines = watch("deliveryOrderLines"); + + useEffect(() => { + const fetchInventoryData = async () => { + try { + const inventoryResponse = await fetchInventories({ + code: "", + name: "", + type: "", + pageNum: 0, + pageSize: 1000 + }); + setInventoryData(inventoryResponse.records); + } catch (error) { + console.error("Error fetching inventory data:", error); + } + }; + + fetchInventoryData(); + }, [deliveryOrderLines]); + + const getStockAvailable = (line: any) => { + const inventory = inventoryData.find(inventory => + inventory.itemCode === line.itemNo || inventory.itemName === line.itemName + ); + + if (inventory) { + return inventory.availableQty || (inventory.onHandQty - inventory.onHoldQty - inventory.unavailableQty); + } + + return 0; + }; + + const isStockSufficient = (line: any) => { + const stockAvailable = getStockAvailable(line); + return stockAvailable >= line.qty; + }; + + const sufficientStockIcon = useMemo(() => { + return + }, []); + + const insufficientStockIcon = useMemo(() => { + return + }, []); + + const rowsWithCalculatedFields = useMemo(() => { + return deliveryOrderLines.map((line, index) => ({ + ...line, + id: line.id || index, + shortUom: line.shortUom, // 假设 shortUom 就是 uomCode,如果有其他字段请修改 + stockAvailable: getStockAvailable(line), + isStockSufficient: isStockSufficient(line), + })); + }, [deliveryOrderLines, inventoryData]); + const columns = useMemo(() => [ { field: "itemNo", headerName: t("Item No."), - flex: 1, + flex: 0.6, }, { field: "itemName", headerName: t("Item Name"), flex: 1, - renderCell: (row) => { - return isEmpty(row.value) ? "N/A" : row.value + renderCell: (params: GridRenderCellParams) => { + const name = isEmpty(params.value) ? "N/A" : params.value; + const uom = params.row.uomCode || ""; + return `${name} (${uom})`; }, }, { field: "qty", headerName: t("Quantity"), - flex: 1, + flex: 0.7, align: "right", headerAlign: "right", - renderCell: (row) => { - return decimalFormatter.format(row.value) + renderCell: (params: GridRenderCellParams) => { + return `${decimalFormatter.format(params.value)} (${params.row.shortUom})`; }, }, { - field: "price", - headerName: t("Price"), - flex: 1, + field: "stockAvailable", + headerName: t("Stock Available"), + flex: 0.7, align: "right", headerAlign: "right", - renderCell: (row) => { - return decimalFormatter.format(row.value) - }, - }, - { - field: "uomCode", - headerName: t("UoM"), - flex: 1, - align: "left", - headerAlign: "left", - renderCell: (row) => { - return isEmpty(row.value) ? "N/A" : row.value + type: "number", + renderCell: (params: GridRenderCellParams) => { + return `${decimalFormatter.format(params.value)} (${params.row.shortUom})`; }, }, { - field: "status", - headerName: t("Status"), - flex: 1, - renderCell: (row) => { - return t(upperFirst(row.value)) + field: "stockStatus", + headerName: t("Stock Status"), + flex: 0.5, + align: "right", + headerAlign: "right", + type: "boolean", + renderCell: (params: GridRenderCellParams) => { + return params.row.isStockSufficient ? sufficientStockIcon : insufficientStockIcon; }, }, - ], [t]) + + + ], [t, inventoryData]) return ( <> @@ -88,8 +159,9 @@ const DoLineTable: React.FC = ({ }, }} disableColumnMenu - rows={watch("deliveryOrderLines")} + rows={rowsWithCalculatedFields} columns={columns} + getRowHeight={() => 'auto'} /> ) diff --git a/src/components/FinishedGoodSearch/FinishedGoodSearch.tsx b/src/components/FinishedGoodSearch/FinishedGoodSearch.tsx index 5c8155c..93f1db2 100644 --- a/src/components/FinishedGoodSearch/FinishedGoodSearch.tsx +++ b/src/components/FinishedGoodSearch/FinishedGoodSearch.tsx @@ -640,7 +640,7 @@ const PickOrderSearch: React.FC = ({ pickOrders }) => {