diff --git a/src/app/api/po/index.ts b/src/app/api/po/index.ts index 1a0f944..a240005 100644 --- a/src/app/api/po/index.ts +++ b/src/app/api/po/index.ts @@ -30,11 +30,23 @@ export interface PurchaseOrderLine { processed: number; receivedQty: number; uom: Uom; + stockUom: StockUomForPoLine; price: number; status: string; stockInLine: StockInLine[]; } +export interface StockUomForPoLine { + id: number; + stockUomCode: string; + stockUomDesc: string; + stockQty: number; + stockRatioN: number; + stockRatioD: number; + purchaseRatioN: number; + purchaseRatioD: number; +} + export interface StockInLine { id: number; stockInId: number; diff --git a/src/components/PoDetail/PoDetail.tsx b/src/components/PoDetail/PoDetail.tsx index 59fff3c..bcfd6de 100644 --- a/src/components/PoDetail/PoDetail.tsx +++ b/src/components/PoDetail/PoDetail.tsx @@ -249,16 +249,23 @@ const PoDetail: React.FC = ({ po, qc, warehouse }) => { if (result) { setPurchaseOrder(result); setRows(result.pol || []); - if (result.pol && result.pol.length > 0 && result.id !== selectedPoId) { - setSelectedRow(result.pol[0]); - setStockInLine(result.pol[0].stockInLine); - setProcessedQty(result.pol[0].processed); + if (result.pol && result.pol.length > 0) { + if (result.id === selectedPoId) { + const polIndex = result.pol.findIndex((p) => p.id === selectedRow?.id) + // setSelectedRow(result.pol[polIndex]); + setStockInLine(result.pol[polIndex].stockInLine); + setProcessedQty(result.pol[polIndex].processed); + } else { + // setSelectedRow(result.pol[0]); + setStockInLine(result.pol[0].stockInLine); + setProcessedQty(result.pol[0].processed); + } } } } catch (error) { console.error("Failed to fetch PO detail:", error); } - }, []); + }, [selectedRow]); const handlePoSelect = useCallback( async (selectedPo: PoResult) => { @@ -470,6 +477,8 @@ const PoDetail: React.FC = ({ po, qc, warehouse }) => { {integerFormatter.format(row.qty)} {integerFormatter.format(processedQty)} {row.uom?.code} + {decimalFormatter.format(row.stockUom.stockQty)} + {row.stockUom.stockUomCode} {/* {decimalFormatter.format(totalWeight)} {weightUnit} */} @@ -491,7 +500,7 @@ const PoDetail: React.FC = ({ po, qc, warehouse }) => { = ({ po, qc, warehouse }) => { {t("qty")} {t("processed")} {t("uom")} + {t("Stock In Qty")} + {t("Stock UoM")} {/* {t("total weight")} */} {/* {`${t("price")} (HKD)`} */} {t("status")} @@ -793,7 +804,7 @@ const PoDetail: React.FC = ({ po, qc, warehouse }) => { - {selectedRow ? `已選擇: ${selectedRow?.itemNo ? selectedRow.itemNo : 'N/A'} - ${selectedRow?.itemName ? selectedRow?.itemName : 'N/A'}` : "未選擇貨品"} + {selectedRow ? `已選擇貨品: ${selectedRow?.itemNo ? selectedRow.itemNo : 'N/A'} - ${selectedRow?.itemName ? selectedRow?.itemName : 'N/A'}` : "未選擇貨品"} diff --git a/src/components/PoDetail/PoInputGrid.tsx b/src/components/PoDetail/PoInputGrid.tsx index cc4482b..35f0570 100644 --- a/src/components/PoDetail/PoInputGrid.tsx +++ b/src/components/PoDetail/PoInputGrid.tsx @@ -460,6 +460,11 @@ const closeNewModal = useCallback(() => { } // flex: 0.4, }, + { + field: "productLotNo", + headerName: t("productLotNo"), + width: 125, + }, // { // field: "itemName", // headerName: t("itemName"), @@ -487,6 +492,30 @@ const closeNewModal = useCallback(() => { return params.row.uom.code; }, }, + { + field: "stockQty", + headerName: t("Stock In Qty"), + // flex: 0.5, + width: 125, + type: "number", + // editable: true, + // replace with tooltip + content + renderCell: (params) => { + const baseQty = (params.row.acceptedQty ?? 0) * (itemDetail.stockUom.purchaseRatioN ?? 1) / (itemDetail.stockUom.purchaseRatioD ?? 1) + console.log(baseQty) + const stockQty = baseQty * (itemDetail.stockUom.stockRatioD ?? 1) / (itemDetail.stockUom.stockRatioN ?? 1) + return decimalFormatter.format(stockQty) + } + }, + { + field: "stockUom", + headerName: t("Stock UoM"), + width: 120, + // flex: 0.5, + renderCell: (params) => { + return itemDetail.stockUom.stockUomCode; + }, + }, // { // field: "weight", // headerName: t("weight"), @@ -684,7 +713,7 @@ const closeNewModal = useCallback(() => { }, }, ], - [t, handleStart, handleQC, handleEscalation, session?.user?.abilities, handleStockIn, handlePutAway, handleDelete, handleReject], + [t, handleStart, handleQC, handleEscalation, session?.user?.abilities, handleStockIn, handlePutAway, handleDelete, handleReject, itemDetail], ); const addRow = useCallback(() => { diff --git a/src/i18n/zh/inventory.json b/src/i18n/zh/inventory.json index 34df3b9..391d01c 100644 --- a/src/i18n/zh/inventory.json +++ b/src/i18n/zh/inventory.json @@ -10,7 +10,7 @@ "fg": "成品", "Available Qty": "可用數量 (倉存單位)", "Sales UoM": "銷售單位", - "Stock UoM": "倉存單位", + "Stock UoM": "庫存單位", "Available Qty Per Smallest Unit": "可用數量 (基本單位)", "Base UoM": "基本單位", "Lot No": "批號", diff --git a/src/i18n/zh/purchaseOrder.json b/src/i18n/zh/purchaseOrder.json index 6893e7d..2d41589 100644 --- a/src/i18n/zh/purchaseOrder.json +++ b/src/i18n/zh/purchaseOrder.json @@ -32,6 +32,8 @@ "Item Detail": "貨品詳情", "qty": "訂單數量", "uom": "計量單位", + "Stock UoM": "庫存單位", + "Stock In Qty": "入庫數量", "total weight": "總重量", "weight unit": "重量單位", "price": "訂單貨值",