From cee2dc15f8f332dcce34c8d1327003e46179f822 Mon Sep 17 00:00:00 2001 From: Harry Groves Date: Wed, 16 Sep 2026 11:44:34 +0800 Subject: [PATCH 01/24] =?UTF-8?q?Merge=20branch=20'fix=E8=B2=A0=E6=95=B8?= =?UTF-8?q?=E5=80=89'=20of=20http://svn.2fi-solutions.com:8300/derek/FPSMS?= =?UTF-8?q?-frontend=20into=20fix=E8=B2=A0=E6=95=B8=E5=80=89?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit # Conflicts: # src/app/api/inventory/index.ts --- src/app/api/inventory/index.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/src/app/api/inventory/index.ts b/src/app/api/inventory/index.ts index 74a7bb52..f403d291 100644 --- a/src/app/api/inventory/index.ts +++ b/src/app/api/inventory/index.ts @@ -16,6 +16,7 @@ export interface InventoryResult { availableQty: number; /** Item Search / getRecordByPage (inventory bucket). */ stockUomId?: number | null; + stockUomCode?: string | null; /** Location Search / searchLatest (lot-line grouped row). Same UOM id space as stockUomId. */ uomId?: number; uomCode: string; From 533dd176c17f6bf458358e612773040dee1d2642 Mon Sep 17 00:00:00 2001 From: Harry Groves Date: Wed, 16 Sep 2026 16:57:00 +0800 Subject: [PATCH 02/24] [Fix] EN support on "Stock Ledger Fix" page --- .../(main)/settings/stockLedgerFix/page.tsx | 18 +- src/components/Breadcrumb/Breadcrumb.tsx | 1 + .../StockLedgerFixPageClient.tsx | 496 +++++++++++------- src/i18n/en/navigation.json | 2 + src/i18n/en/stockLedgerFix.json | 147 ++++++ src/i18n/zh/navigation.json | 2 + src/i18n/zh/stockLedgerFix.json | 147 ++++++ 7 files changed, 606 insertions(+), 207 deletions(-) create mode 100644 src/i18n/en/stockLedgerFix.json create mode 100644 src/i18n/zh/stockLedgerFix.json diff --git a/src/app/(main)/settings/stockLedgerFix/page.tsx b/src/app/(main)/settings/stockLedgerFix/page.tsx index 1602d68c..d477b351 100644 --- a/src/app/(main)/settings/stockLedgerFix/page.tsx +++ b/src/app/(main)/settings/stockLedgerFix/page.tsx @@ -1,16 +1,22 @@ import { Metadata } from "next"; import PageTitleBar from "@/components/PageTitleBar"; import StockLedgerFixPageClient from "@/components/StockLedgerFix/StockLedgerFixPageClient"; +import { getServerI18n, I18nProvider } from "@/i18n"; -export const metadata: Metadata = { - title: "Stock Ledger Fix", -}; +export async function generateMetadata(): Promise { + const { t } = await getServerI18n("stockLedgerFix"); + return { title: t("pageTitle") }; +} + +const StockLedgerFixPage: React.FC = async () => { + const { t } = await getServerI18n("stockLedgerFix"); -const StockLedgerFixPage: React.FC = () => { return ( <> - - + + + + ); }; diff --git a/src/components/Breadcrumb/Breadcrumb.tsx b/src/components/Breadcrumb/Breadcrumb.tsx index a5804a95..cea41b5e 100644 --- a/src/components/Breadcrumb/Breadcrumb.tsx +++ b/src/components/Breadcrumb/Breadcrumb.tsx @@ -35,6 +35,7 @@ const pathToLabelKey: { [path: string]: string } = { "/settings/qrCodeHandle": "nav.breadcrumb.qrCodeHandle", "/settings/deliveryOrderFloor": "nav.breadcrumb.deliveryOrderFloor", "/settings/masterDataIssues": "nav.breadcrumb.masterDataIssues", + "/settings/stockLedgerFix": "nav.breadcrumb.stockLedgerFix", "/settings/rss": "nav.breadcrumb.demandForecast", "/settings/equipment": "nav.breadcrumb.equipment", "/settings/equipment/MaintenanceEdit": "nav.breadcrumb.equipmentMaintenanceEdit", diff --git a/src/components/StockLedgerFix/StockLedgerFixPageClient.tsx b/src/components/StockLedgerFix/StockLedgerFixPageClient.tsx index c9be243a..ed79b094 100644 --- a/src/components/StockLedgerFix/StockLedgerFixPageClient.tsx +++ b/src/components/StockLedgerFix/StockLedgerFixPageClient.tsx @@ -24,8 +24,10 @@ import { import { DateCalendar } from "@mui/x-date-pickers/DateCalendar"; import { LocalizationProvider } from "@mui/x-date-pickers/LocalizationProvider"; import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs"; +import { useTranslation } from "react-i18next"; import dayjs, { type Dayjs } from "dayjs"; import "dayjs/locale/zh-hk"; +import "dayjs/locale/en"; import { fetchStockLedgerFixAdjPreview, runStockLedgerFixAdj, @@ -62,13 +64,13 @@ const ALL_DAY_STEPS: Record = { "2.5": true, "2.6": true, }; -const DAY_STEP_LABEL: Record = { - "2.1": "2.1 lot", - "2.2": "2.2 uom", - "2.3": "2.3 inventoryId", - "2.4": "2.4 lotQty", - "2.5": "2.5 balance", - "2.6": "2.6 日結", +const DAY_STEP_I18N: Record = { + "2.1": "step21", + "2.2": "step22", + "2.3": "step23", + "2.4": "step24", + "2.5": "step25", + "2.6": "step26", }; /** Export SQL parts (aligned with fix steps + 1.0 / 2.7). */ @@ -88,12 +90,12 @@ const FULL_EXPORT_PARTS: Record = { "2.6": true, "2.7": true, }; -const EXPORT_PART_LABEL: Record = { - "1.0": "1.0 inventory", - "2.3": "2.3 inventoryId", - ledger: "ledger lot/uom/lotQty/balance", - "2.6": "2.6 日結", - "2.7": "2.7 ADJ+入出倉單", +const EXPORT_PART_I18N: Record = { + "1.0": "export10", + "2.3": "export23", + ledger: "exportLedger", + "2.6": "export26", + "2.7": "export27", }; function selectedExportParts(flags: Record): ExportPart[] { @@ -153,7 +155,20 @@ function partVerdict( return "correct"; } +const VERDICT_LABEL: Record< + ReturnType, + "verdictCorrect" | "verdictMiss" | "verdictOverIssue" | "verdictCanFix" | "verdictCannotFix" | "verdictIncorrect" +> = { + correct: "verdictCorrect", + miss: "verdictMiss", + "over-issue": "verdictOverIssue", + "can-fix": "verdictCanFix", + "cannot-fix": "verdictCannotFix", + incorrect: "verdictIncorrect", +}; + function CheckPartsTable({ parts }: { parts: StockLedgerFixCheckPart[] }) { + const { t } = useTranslation("stockLedgerFix"); const field = parts.filter((p) => !p.group || p.group === "field"); const canFix = parts.filter( (p) => p.group === "canFix" && p.miss + p.incorrect > 0, @@ -166,23 +181,13 @@ function CheckPartsTable({ parts }: { parts: StockLedgerFixCheckPart[] }) { const v = partVerdict(p); return ( - {p.label} + + {t(`part.${p.key}`, { defaultValue: p.label })} + - +
- 項目 - 狀態 - 正確 - 缺 - 不正確 + {t("checkItem")} + {t("checkStatus")} + {t("checkCorrect")} + {t("checkMiss")} + {t("checkIncorrect")} {renderRows(field)}
{canFix.length > 0 && ( <> - 可自動修(按 Fix 會處理) + + {t("canAutoFix")} + - 原因 - 狀態 - 正確 - 列數 - — + {t("checkReason")} + {t("checkStatus")} + {t("checkCorrect")} + {t("checkRows")} + {t("checkDash")} {renderRows(canFix)} @@ -231,17 +238,17 @@ function CheckPartsTable({ parts }: { parts: StockLedgerFixCheckPart[] }) { )} {cannotFix.length > 0 && ( <> - - 不能自動修(Fix 不會消;舊 TKE 開新批/真超發/沒有 lot 來源) + + {t("cannotAutoFix")}
- 原因 - 狀態 - 正確 - — - 列數 + {t("checkReason")} + {t("checkStatus")} + {t("checkCorrect")} + {t("checkDash")} + {t("checkRows")} {renderRows(cannotFix)} @@ -253,6 +260,9 @@ function CheckPartsTable({ parts }: { parts: StockLedgerFixCheckPart[] }) { } const StockLedgerFixPageClient: React.FC = () => { + const { t, i18n } = useTranslation("stockLedgerFix"); + const isZh = (i18n.language || "zh").startsWith("zh"); + const listSep = isZh ? "、" : ", "; const [tab, setTab] = useState<"day" | "inventory" | "lot">("day"); const [selected, setSelected] = useState(() => dayjs().subtract(1, "day"), @@ -321,13 +331,13 @@ const StockLedgerFixPageClient: React.FC = () => { setInventoryPreview(data); } catch (e) { console.error(e); - setInventoryError("無法載入 inventory 1.0 預覽(需要 ADMIN / TESTING)"); + setInventoryError(t("inventory10LoadError")); setInventoryPreview(null); } finally { setInventoryLoading(false); inventoryLoadInFlight.current = false; } - }, []); + }, [t]); const loadDay = useCallback(async (date: string) => { if (detailInFlight.current) return; @@ -340,23 +350,23 @@ const StockLedgerFixPageClient: React.FC = () => { setDetail(data); } catch (e) { console.error(e); - setDetailError("無法載入當日檢查"); + setDetailError(t("dayLoadError")); setDetail(null); } finally { setDetailLoading(false); detailInFlight.current = false; } - }, []); + }, [t]); const loadAdjPreview = useCallback(async () => { if (adjLoadInFlight.current) return; const d = adjDate.trim(); if (!d) { - setAdjError("請填 ADJ 日期"); + setAdjError(t("adjDateRequired")); return; } if (d > dayjs().format("YYYY-MM-DD")) { - setAdjError("ADJ 日期不能是未來"); + setAdjError(t("adjDateFuture")); return; } adjLoadInFlight.current = true; @@ -366,13 +376,13 @@ const StockLedgerFixPageClient: React.FC = () => { setAdjPreview(await fetchStockLedgerFixAdjPreview(d)); } catch (e) { console.error(e); - setAdjError(apiErrorMessage(e, "無法載入 ADJ 預覽(需要 ADMIN / TESTING)")); + setAdjError(apiErrorMessage(e, t("adjLoadError"))); setAdjPreview(null); } finally { setAdjLoading(false); adjLoadInFlight.current = false; } - }, [adjDate]); + }, [adjDate, t]); useEffect(() => { void loadInventory(); @@ -388,19 +398,19 @@ const StockLedgerFixPageClient: React.FC = () => { if (!selected || fixInFlight.current) return; const date = selected.format("YYYY-MM-DD"); if (selected.isAfter(dayjs(), "day")) { - setFixError("不能修未來日期"); + setFixError(t("cannotFixFuture")); return; } const picked = selectedDaySteps(daySteps); if (picked.length === 0) { - setFixError("請至少勾一個步驟(預設全跑 2.1–2.6)"); + setFixError(t("pickAtLeastOneStep")); return; } const steps = stepsPayload(daySteps); - const stepLabel = steps?.join("、") ?? "全部 2.1–2.6"; + const stepLabel = steps?.join(listSep) ?? t("allSteps216"); if (steps) { const ok = window.confirm( - `只跑 ${stepLabel}(${date})。未勾的步驟不會重算。確定?`, + t("confirmPartialSteps", { steps: stepLabel, date }), ); if (!ok) return; } @@ -411,12 +421,21 @@ const StockLedgerFixPageClient: React.FC = () => { try { const res = await runStockLedgerFixDay(date, steps); setFixMessage( - `已修 ${res.date}(${stepLabel}):lot ${res.filledLotLineId}、uom ${res.filledUomId}、inventory ${res.filledInventoryId}、lotQty ${res.filledLotQty}、balance ${res.filledBalance}、日結 ${res.dayRowsWritten}`, + t("fixDayDone", { + date: res.date, + steps: stepLabel, + lot: res.filledLotLineId, + uom: res.filledUomId, + inventory: res.filledInventoryId, + lotQty: res.filledLotQty, + balance: res.filledBalance, + dayRows: res.dayRowsWritten, + }), ); await loadDay(date); } catch (e) { console.error(e); - setFixError(apiErrorMessage(e, "修復失敗")); + setFixError(apiErrorMessage(e, t("fixFailed"))); } finally { setFixing(false); fixInFlight.current = false; @@ -425,9 +444,7 @@ const StockLedgerFixPageClient: React.FC = () => { const onInventory = async () => { if (inventoryRunInFlight.current) return; - const ok = window.confirm( - "方案 A:保留現有 inventory.id;從 lot 回填 stockUomId(舊 uomId 是 stock 則改回 base);補缺 (itemId, stockUomId);用 lot 的 in−out 重算 onHand/unavailable。不寫 onHoldQty、不改 inventory_lot_line。確定執行?", - ); + const ok = window.confirm(t("inventory10Confirm")); if (!ok) return; inventoryRunInFlight.current = true; setInventoryRunning(true); @@ -436,12 +453,19 @@ const StockLedgerFixPageClient: React.FC = () => { try { const res = await runStockLedgerFixInventory(); setInventoryMessage( - `inventory 1.0 完成:回填 stockUomId ${res.patchedStockUomId} 列、新增 ${res.inserted} 列、殘列 deleted ${res.orphansDeleted ?? 0}、重算 ${res.updated} 列、之後仍缺 UOM ${res.missingUomPairsAfter}、仍 NULL stockUomId ${res.nullStockUomIdAfter}`, + t("inventory10Done", { + patched: res.patchedStockUomId, + inserted: res.inserted, + orphans: res.orphansDeleted ?? 0, + updated: res.updated, + missingAfter: res.missingUomPairsAfter, + nullAfter: res.nullStockUomIdAfter, + }), ); await loadInventory(); } catch (e) { console.error(e); - setInventoryError(apiErrorMessage(e, "inventory 1.0 失敗")); + setInventoryError(apiErrorMessage(e, t("inventory10Fail"))); } finally { setInventoryRunning(false); inventoryRunInFlight.current = false; @@ -452,11 +476,19 @@ const StockLedgerFixPageClient: React.FC = () => { if (adjRunInFlight.current) return; const d = adjDate.trim() || adjPreview?.adjDate; if (!d) { - setAdjError("請填 ADJ 日期並先預覽"); + setAdjError(t("adjDateAndPreviewRequired")); return; } const ok = window.confirm( - `會在 ${d} 先修超發 remain→0(${adjPreview?.overIssueCount ?? 0} 條 lot,合計 ${adjPreview?.sumOverIssue ?? "?"},會改 lot inQty)。再補 miss ADJ:入向 ${adjPreview?.adjInCount ?? 0} 筆、出向 ${adjPreview?.adjOutCount ?? 0} 筆。入向全部掛同一張入倉單、出向全部掛同一張出倉單(miss 不改 lot 數量)。缺入合計 ${adjPreview?.sumMissIn ?? "?"}、缺出合計 ${adjPreview?.sumMissOut ?? "?"}。確定?`, + t("adjConfirm", { + date: d, + overIssueCount: adjPreview?.overIssueCount ?? 0, + sumOverIssue: adjPreview?.sumOverIssue ?? "?", + adjInCount: adjPreview?.adjInCount ?? 0, + adjOutCount: adjPreview?.adjOutCount ?? 0, + sumMissIn: adjPreview?.sumMissIn ?? "?", + sumMissOut: adjPreview?.sumMissOut ?? "?", + }), ); if (!ok) return; adjRunInFlight.current = true; @@ -466,12 +498,20 @@ const StockLedgerFixPageClient: React.FC = () => { try { const res = await runStockLedgerFixAdj(d); setAdjMessage( - `ADJ ${res.adjDate}:超發 remain→0 ${res.overIssuePatched}、入 ${res.insertedIn}、出 ${res.insertedOut}、lotQty ${res.filledLotQty}、balance ${res.filledBalance}、日結 ${res.dayRowsWritten}`, + t("adjDone", { + date: res.adjDate, + overIssuePatched: res.overIssuePatched, + insertedIn: res.insertedIn, + insertedOut: res.insertedOut, + filledLotQty: res.filledLotQty, + filledBalance: res.filledBalance, + dayRowsWritten: res.dayRowsWritten, + }), ); await loadAdjPreview(); } catch (e) { console.error(e); - setAdjError(apiErrorMessage(e, "ADJ 對齊失敗")); + setAdjError(apiErrorMessage(e, t("adjFail"))); } finally { setAdjRunning(false); adjRunInFlight.current = false; @@ -489,7 +529,7 @@ const StockLedgerFixPageClient: React.FC = () => { setScope(null); } catch (e) { console.error(e); - setSearchError(apiErrorMessage(e, "搜尋失敗")); + setSearchError(apiErrorMessage(e, t("searchFailed"))); } finally { setSearching(false); searchInFlight.current = false; @@ -507,7 +547,7 @@ const StockLedgerFixPageClient: React.FC = () => { setScope(null); } catch (e) { console.error(e); - setSearchError(apiErrorMessage(e, "搜尋失敗")); + setSearchError(apiErrorMessage(e, t("searchFailed"))); } finally { setSearching(false); searchInFlight.current = false; @@ -524,7 +564,7 @@ const StockLedgerFixPageClient: React.FC = () => { setScope(await fetchStockLedgerFixInventoryScope(id)); } catch (e) { console.error(e); - setFixError(apiErrorMessage(e, "無法載入 inventory")); + setFixError(apiErrorMessage(e, t("invLoadError"))); setScope(null); } finally { setScopeLoading(false); @@ -542,7 +582,7 @@ const StockLedgerFixPageClient: React.FC = () => { setScope(await fetchStockLedgerFixLotScope(id)); } catch (e) { console.error(e); - setFixError(apiErrorMessage(e, "無法載入 lot")); + setFixError(apiErrorMessage(e, t("lotLoadError"))); setScope(null); } finally { setScopeLoading(false); @@ -552,9 +592,7 @@ const StockLedgerFixPageClient: React.FC = () => { const onFixInventoryScope = async () => { if (!scope || scope.kind !== "inventory" || fixInFlight.current) return; - const ok = window.confirm( - "會重算這顆 inventory 到今天為止全部 ledger 的 lotQty、日結,以及這顆料的 balance。確定?", - ); + const ok = window.confirm(t("invFixConfirm")); if (!ok) return; fixInFlight.current = true; setFixing(true); @@ -563,12 +601,20 @@ const StockLedgerFixPageClient: React.FC = () => { try { const res = await runStockLedgerFixInventoryScope(scope.id); setFixMessage( - `已修 inventory ${scope.id}:lot ${res.filledLotLineId}、uom ${res.filledUomId}、inventory ${res.filledInventoryId}、lotQty ${res.filledLotQty}、balance ${res.filledBalance}、日結 ${res.dayRowsWritten}`, + t("invFixDone", { + id: scope.id, + lot: res.filledLotLineId, + uom: res.filledUomId, + inventory: res.filledInventoryId, + lotQty: res.filledLotQty, + balance: res.filledBalance, + dayRows: res.dayRowsWritten, + }), ); await loadInventoryScope(scope.id); } catch (e) { console.error(e); - setFixError(apiErrorMessage(e, "修復失敗")); + setFixError(apiErrorMessage(e, t("fixFailed"))); } finally { setFixing(false); fixInFlight.current = false; @@ -577,9 +623,7 @@ const StockLedgerFixPageClient: React.FC = () => { const onFixLotScope = async () => { if (!scope || scope.kind !== "lot" || fixInFlight.current) return; - const ok = window.confirm( - "只修這張 lot 的 lotQty 與日結,不會改整顆料的 balance。確定?", - ); + const ok = window.confirm(t("lotFixConfirm")); if (!ok) return; fixInFlight.current = true; setFixing(true); @@ -588,12 +632,19 @@ const StockLedgerFixPageClient: React.FC = () => { try { const res = await runStockLedgerFixLotScope(scope.id); setFixMessage( - `已修 lot ${scope.id}:lot ${res.filledLotLineId}、uom ${res.filledUomId}、inventory ${res.filledInventoryId}、lotQty ${res.filledLotQty}、日結 ${res.dayRowsWritten}`, + t("lotFixDone", { + id: scope.id, + lot: res.filledLotLineId, + uom: res.filledUomId, + inventory: res.filledInventoryId, + lotQty: res.filledLotQty, + dayRows: res.dayRowsWritten, + }), ); await loadLotScope(scope.id); } catch (e) { console.error(e); - setFixError(apiErrorMessage(e, "修復失敗")); + setFixError(apiErrorMessage(e, t("fixFailed"))); } finally { setFixing(false); fixInFlight.current = false; @@ -608,30 +659,30 @@ const StockLedgerFixPageClient: React.FC = () => { const to = chainTo.trim(); const today = dayjs().format("YYYY-MM-DD"); if (!from || !to) { - setFixError("請填區間修 from / to"); + setFixError(t("rangeFromRequired")); return; } if (to < from) { - setFixError("to 必須 ≥ from"); + setFixError(t("toMustBeGteFrom")); return; } if (from < FIRST_LEDGER_DAY.format("YYYY-MM-DD")) { - setFixError(`from 不能早於 ${FIRST_LEDGER_DAY.format("YYYY-MM-DD")}`); + setFixError(t("fromTooEarly", { date: FIRST_LEDGER_DAY.format("YYYY-MM-DD") })); return; } if (to > today) { - setFixError("不能修未來日期(今天可以,給 freeze dump 夜修)"); + setFixError(t("cannotFixFutureRange")); return; } const picked = selectedDaySteps(daySteps); if (picked.length === 0) { - setFixError("請至少勾一個步驟(預設全跑 2.1–2.6)"); + setFixError(t("pickAtLeastOneStep")); return; } const steps = stepsPayload(daySteps); - const stepLabel = steps?.join("、") ?? "全部 2.1–2.6"; + const stepLabel = steps?.join(listSep) ?? t("allSteps216"); const ok = window.confirm( - `一次修 ${from} → ${to}(步驟:${stepLabel})。改為逐日跑(每天 commit)。中途失敗時已跑完的天會留下。確定?`, + t("rangeConfirm", { from, to, steps: stepLabel }), ); if (!ok) return; @@ -640,17 +691,26 @@ const StockLedgerFixPageClient: React.FC = () => { setFixing(true); setFixError(null); setFixMessage(null); - setChainProgress(`區間修 ${from} → ${to}(${stepLabel})進行中…`); + setChainProgress(t("rangeProgress", { from, to, steps: stepLabel })); try { const res = await runStockLedgerFixRange(from, to, steps); setFixMessage( - `區間修完成 ${res.date}(${stepLabel}):lot ${res.filledLotLineId}、uom ${res.filledUomId}、inventory ${res.filledInventoryId}、lotQty ${res.filledLotQty}、balance ${res.filledBalance}、日結 ${res.dayRowsWritten}`, + t("rangeDone", { + date: res.date, + steps: stepLabel, + lot: res.filledLotLineId, + uom: res.filledUomId, + inventory: res.filledInventoryId, + lotQty: res.filledLotQty, + balance: res.filledBalance, + dayRows: res.dayRowsWritten, + }), ); setSelected(dayjs(to)); setChainProgress(null); } catch (e) { console.error(e); - setFixError(apiErrorMessage(e, "區間修失敗")); + setFixError(apiErrorMessage(e, t("rangeFail"))); } finally { setFixing(false); setChainRunning(false); @@ -663,22 +723,20 @@ const StockLedgerFixPageClient: React.FC = () => { const from = exportFrom.trim(); const to = exportTo.trim(); if (!from || !to) { - setExportError("請填 from / to"); + setExportError(t("exportFromToRequired")); return; } if (to < from) { - setExportError("to 必須 ≥ from"); + setExportError(t("toMustBeGteFrom")); return; } const picked = selectedExportParts(exportParts); if (picked.length === 0) { - setExportError("請至少勾一個匯出項目"); + setExportError(t("exportPickAtLeastOne")); return; } if (exportParts["2.3"] && !exportParts["1.0"]) { - const ok = window.confirm( - "已勾 2.3 inventoryId 但未勾 1.0 inventory:正式庫若缺新 id,UPDATE 會指到空列。建議一併勾 1.0(完整檔)。仍要匯出?", - ); + const ok = window.confirm(t("export23Without10")); if (!ok) return; } const parts = exportPartsPayload(exportParts); @@ -693,12 +751,12 @@ const StockLedgerFixPageClient: React.FC = () => { if (data instanceof Blob) { try { const text = (await data.text()).trim().slice(0, 400); - setExportError(text || "匯出失敗"); + setExportError(text || t("exportFail")); } catch { - setExportError(apiErrorMessage(e, "匯出失敗")); + setExportError(apiErrorMessage(e, t("exportFail"))); } } else { - setExportError(apiErrorMessage(e, "匯出失敗")); + setExportError(apiErrorMessage(e, t("exportFail"))); } } finally { setExporting(false); @@ -710,11 +768,9 @@ const StockLedgerFixPageClient: React.FC = () => { - 1.0 inventory(方案 A) + {t("inventory10Title")} - 保留現有 id;lot 有、inventory 沒有的 UOM 會新增;onHand = Σ(in−out) 按 - item+UOM。沒有 lot 的列會變成 0。同一料多顆舊列時只留一顆 stock UOM - 桶,其餘 deleted=1。請在進出倉暫停時執行,再逐日 Fix。 + {t("inventory10Description")} {inventoryError && {inventoryError}} {inventoryMessage && ( @@ -723,10 +779,12 @@ const StockLedgerFixPageClient: React.FC = () => { {inventoryLoading && !inventoryPreview && } {inventoryPreview && ( - 現有 inventory {inventoryPreview.inventoryRows} 列;lot 的 - item+UOM {inventoryPreview.lotUomPairs} 組;缺{" "} - {inventoryPreview.missingUomPairs} 組;stockUomId 仍 NULL{" "} - {inventoryPreview.nullStockUomId} 列。 + {t("inventory10Preview", { + rows: inventoryPreview.inventoryRows, + lotPairs: inventoryPreview.lotUomPairs, + missing: inventoryPreview.missingUomPairs, + nullUom: inventoryPreview.nullStockUomId, + })} )} @@ -736,7 +794,7 @@ const StockLedgerFixPageClient: React.FC = () => { disabled={inventoryRunning || inventoryLoading} onClick={() => void onInventory()} > - {inventoryRunning ? "重算中…" : "Run inventory 1.0 (A)"} + {inventoryRunning ? t("inventory10Running") : t("inventory10Run")} @@ -744,19 +802,15 @@ const StockLedgerFixPageClient: React.FC = () => { - 2.7 ADJ:超發 remain→0,再對齊 ledger + {t("adjTitle")} - 請先選 ADJ 日期再預覽。預設昨天;freeze dump 夜可選今天(例如 31/8 23:17 寫 ADJ 到 - 31/8)。先處理超發(line 入少於出):把該 lot 的 inQty 補到等於 outQty(remain=0,trigger - 重算 inventory)。再處理 miss:line 與 ledger 有差就 ADJ,掛既有 lot 的入/出倉行(不改 lot - 數量)。一次 Apply 共用一張入倉單、一張出倉單,下面多行;同一 ADJ 日期再跑會沿用這兩張單。 - 明細最多 20 列。 + {t("adjDescription")} { setAdjDate(e.target.value); @@ -775,7 +829,7 @@ const StockLedgerFixPageClient: React.FC = () => { setAdjPreview(null); }} > - 今天(freeze 夜) + {t("adjTodayFreeze")} {adjError && {adjError}} @@ -793,36 +847,43 @@ const StockLedgerFixPageClient: React.FC = () => { {adjLoading && !adjPreview && } {adjPreview && ( - ADJ 日期 {adjPreview.adjDate};可處理 {adjPreview.lotCount} 條 - lot(超發 remain→0 {adjPreview.overIssueCount}、合計 {adjPreview.sumOverIssue};miss 入{" "} - {adjPreview.adjInCount}、出 {adjPreview.adjOutCount});缺入合計{" "} - {adjPreview.sumMissIn}、缺出合計 {adjPreview.sumMissOut};SKU 淨額{" "} - {adjPreview.skuNet} - {adjPreview.skuNet !== "0" ? "(非 0 表示有缺入沒有對應缺出)" : ""} - {adjPreview.skippedNegCount > 0 - ? `;含反向 ADJ ${adjPreview.skippedNegCount} 條(ledger 多記)` - : ""} - 。下列最多 20 列(超發優先)。 + {t("adjPreviewSummary", { + date: adjPreview.adjDate, + lotCount: adjPreview.lotCount, + overIssueCount: adjPreview.overIssueCount, + sumOverIssue: adjPreview.sumOverIssue, + adjInCount: adjPreview.adjInCount, + adjOutCount: adjPreview.adjOutCount, + sumMissIn: adjPreview.sumMissIn, + sumMissOut: adjPreview.sumMissOut, + skuNet: adjPreview.skuNet, + skuNetNote: + adjPreview.skuNet !== "0" ? t("adjSkuNetNote") : "", + revNote: + adjPreview.skippedNegCount > 0 + ? t("adjRevNote", { count: adjPreview.skippedNegCount }) + : "", + })} )} {adjPreview && adjPreview.rows.length > 0 && (
- lotLineId - itemCode - line in/out - ledger in/out - 缺入 - 缺出 - 超發 + {t("adjColLotLineId")} + {t("adjColItemCode")} + {t("adjColLineInOut")} + {t("adjColLedgerInOut")} + {t("adjColMissIn")} + {t("adjColMissOut")} + {t("adjColOverIssue")} {adjPreview.rows.map((r) => ( {r.lotLineId} - {r.itemCode ?? "—"} + {r.itemCode ?? t("checkDash")} {r.lineIn} / {r.lineOut} @@ -843,7 +904,11 @@ const StockLedgerFixPageClient: React.FC = () => { disabled={adjLoading || adjRunning} onClick={() => void loadAdjPreview()} > - {adjLoading ? "預覽中…" : adjPreview ? "重新預覽" : "預覽"} + {adjLoading + ? t("adjPreviewing") + : adjPreview + ? t("adjPreviewAgain") + : t("adjPreview")} @@ -867,16 +932,24 @@ const StockLedgerFixPageClient: React.FC = () => { setSearchError(null); }} > - - - + + + {tab === "day" && ( - - - + + + setSelected(v)} @@ -886,15 +959,19 @@ const StockLedgerFixPageClient: React.FC = () => { maxDate={dayjs()} /> - - 點左上標題可先選年再選月。換月不會查資料;點某一天才檢查當天。今天可修(freeze dump 夜)。 + + {t("calendarHint")} - + - {selected ? selected.format("YYYY-MM-DD") : "請選日期"} + {selected ? selected.format("YYYY-MM-DD") : t("selectDate")} {detailError && {detailError}} {fixError && {fixError}} @@ -904,22 +981,26 @@ const StockLedgerFixPageClient: React.FC = () => { {detail && !detailLoading && ( <> - 當天 ledger {detail.cnt} 列 + {t("dayLedgerCount", { cnt: detail.cnt })} )} - 步驟(預設全跑) + {t("stepsTitle")} - 套 SQL 後只改 inventoryId 時只勾 2.3。只跑部分時未勾的不會重算。 + {t("stepsHint")} {DAY_FIX_STEPS.map((step) => ( { } /> } - label={DAY_STEP_LABEL[step]} + label={t(DAY_STEP_I18N[step])} /> ))} @@ -948,21 +1029,21 @@ const StockLedgerFixPageClient: React.FC = () => { disabled={!canFixDay || fixing || chainRunning} onClick={() => void onFixDay()} > - {fixing && !chainRunning ? "修復中…" : "Fix this day"} + {fixing && !chainRunning ? t("fixing") : t("fixThisDay")} - 區間修(2.1–2.6 一次) + {t("rangeTitle")} - 使用上面勾的步驟,一次 API 但改為逐日(與單日修相同 SQL,每天 commit)。可含今天(freeze dump 夜)。前端最長約 20 分鐘;大區間仍建議匯出 SQL。 + {t("rangeHint")} setChainFrom(e.target.value)} disabled={chainRunning} @@ -971,7 +1052,7 @@ const StockLedgerFixPageClient: React.FC = () => { setChainTo(e.target.value)} disabled={chainRunning} @@ -982,23 +1063,26 @@ const StockLedgerFixPageClient: React.FC = () => { disabled={fixing || chainRunning} onClick={() => void onFixDayRange()} > - {chainRunning ? "區間修中…" : "區間修"} + {chainRunning ? t("rangeRunning") : t("rangeRun")} - 匯出已修 SQL(新庫用) + {t("exportTitle")} - 勾選要匯出的段落(同日修步驟)。套檔順序:1.0 → ledger(±2.3)→ 2.7 入出倉單+ADJ INSERT → - 2.6。完整檔(含 1.0+2.3)且正式庫 freeze/id 同源時,可跳過正式庫 1.0/2.3。預設只匯 - ledger+日結(舊行為)。 + {t("exportHint")} {EXPORT_PARTS.map((part) => ( { } /> } - label={EXPORT_PART_LABEL[part]} + label={t(EXPORT_PART_I18N[part])} /> ))} {exportError && {exportError}} @@ -1032,7 +1116,7 @@ const StockLedgerFixPageClient: React.FC = () => { setExportFrom(e.target.value)} InputLabelProps={{ shrink: true }} @@ -1040,7 +1124,7 @@ const StockLedgerFixPageClient: React.FC = () => { setExportTo(e.target.value)} InputLabelProps={{ shrink: true }} @@ -1050,7 +1134,7 @@ const StockLedgerFixPageClient: React.FC = () => { disabled={exporting} onClick={() => void onExportSql()} > - {exporting ? "匯出中…" : "匯出 .sql"} + {exporting ? t("exporting") : t("exportSql")} @@ -1063,13 +1147,12 @@ const StockLedgerFixPageClient: React.FC = () => { - 搜 itemCode 或 inventoryId。Fix 會重算這顆料到今天為止全部流水的 lotQty、日結與 - balance,不必逐日點日曆。白天倉還在寫這顆料時,修完後新流水仍由 live writer 接。 + {t("invTabHint")} setInvQuery(e.target.value)} onKeyDown={(e) => { @@ -1081,7 +1164,7 @@ const StockLedgerFixPageClient: React.FC = () => { disabled={searching || !invQuery.trim()} onClick={() => void onSearchInventory()} > - {searching ? "搜尋中…" : "搜尋"} + {searching ? t("searching") : t("search")} {searchError && {searchError}} @@ -1089,10 +1172,10 @@ const StockLedgerFixPageClient: React.FC = () => {
- inventoryId - itemCode - uomId - ledger 列 + {t("colInventoryId")} + {t("colItemCode")} + {t("colUomId")} + {t("colLedgerRows")} @@ -1105,8 +1188,8 @@ const StockLedgerFixPageClient: React.FC = () => { sx={{ cursor: "pointer" }} > {h.inventoryId} - {h.itemCode ?? "—"} - {h.uomId ?? "—"} + {h.itemCode ?? t("checkDash")} + {h.uomId ?? t("checkDash")} {h.ledgerCnt} ))} @@ -1119,9 +1202,15 @@ const StockLedgerFixPageClient: React.FC = () => { {scope?.kind === "inventory" && !scopeLoading && ( <> - {scope.itemCode ?? "?"} / inventory {scope.id} / uom {scope.uomId ?? "?"} - ;{scope.firstDate} → {scope.lastDate};{scope.cnt} 列;最後 - balance {scope.lastBalance ?? "—"} + {t("invScopeSummary", { + itemCode: scope.itemCode ?? "?", + id: scope.id, + uomId: scope.uomId ?? "?", + firstDate: scope.firstDate, + lastDate: scope.lastDate, + cnt: scope.cnt, + lastBalance: scope.lastBalance ?? t("checkDash"), + })} @@ -1130,7 +1219,7 @@ const StockLedgerFixPageClient: React.FC = () => { disabled={fixing || scope.cnt === 0} onClick={() => void onFixInventoryScope()} > - {fixing ? "修復中…" : "Fix this inventory"} + {fixing ? t("fixing") : t("fixThisInventory")} @@ -1143,13 +1232,12 @@ const StockLedgerFixPageClient: React.FC = () => { - 搜 lotNo 或 inventoryLotLineId。Fix 只重算這張 lot 的 lotQty 與日結,不改 - balance。 + {t("lotTabHint")} setLotQuery(e.target.value)} onKeyDown={(e) => { @@ -1161,7 +1249,7 @@ const StockLedgerFixPageClient: React.FC = () => { disabled={searching || !lotQuery.trim()} onClick={() => void onSearchLot()} > - {searching ? "搜尋中…" : "搜尋"} + {searching ? t("searching") : t("search")} {searchError && {searchError}} @@ -1169,11 +1257,11 @@ const StockLedgerFixPageClient: React.FC = () => {
- lot line id - lotNo - itemCode - inventoryId - ledger 列 + {t("colLotLineId")} + {t("colLotNo")} + {t("colItemCode")} + {t("colInventoryId")} + {t("colLedgerRows")} @@ -1186,9 +1274,9 @@ const StockLedgerFixPageClient: React.FC = () => { sx={{ cursor: "pointer" }} > {h.inventoryLotLineId} - {h.lotNo ?? "—"} - {h.itemCode ?? "—"} - {h.inventoryId ?? "—"} + {h.lotNo ?? t("checkDash")} + {h.itemCode ?? t("checkDash")} + {h.inventoryId ?? t("checkDash")} {h.ledgerCnt} ))} @@ -1201,9 +1289,15 @@ const StockLedgerFixPageClient: React.FC = () => { {scope?.kind === "lot" && !scopeLoading && ( <> - {scope.lotNo ?? "?"} / lot {scope.id} / {scope.itemCode ?? "?"} - ;{scope.firstDate} → {scope.lastDate};{scope.cnt} 列;最後 - lotQtyAfter {scope.lastLotQtyAfter ?? "—"} + {t("lotScopeSummary", { + lotNo: scope.lotNo ?? "?", + id: scope.id, + itemCode: scope.itemCode ?? "?", + firstDate: scope.firstDate, + lastDate: scope.lastDate, + cnt: scope.cnt, + lastLotQtyAfter: scope.lastLotQtyAfter ?? t("checkDash"), + })} @@ -1212,7 +1306,7 @@ const StockLedgerFixPageClient: React.FC = () => { disabled={fixing || scope.cnt === 0} onClick={() => void onFixLotScope()} > - {fixing ? "修復中…" : "Fix this lot"} + {fixing ? t("fixing") : t("fixThisLot")} diff --git a/src/i18n/en/navigation.json b/src/i18n/en/navigation.json index cb72caca..be5b4659 100644 --- a/src/i18n/en/navigation.json +++ b/src/i18n/en/navigation.json @@ -49,6 +49,8 @@ "nav.settings.demandForecast": "Demand Forecast Setting", "nav.settings.bomWeighting": "BOM Weighting Score List", "nav.settings.masterDataIssues": "BOM / Item UOM Issues", + "nav.settings.stockLedgerFix": "Stock Ledger Fix", + "nav.breadcrumb.stockLedgerFix": "Stock Ledger Fix", "nav.settings.qrCodeHandle": "QR Code Handle", "nav.settings.importTesting": "Import Testing", "nav.settings.importExcel": "Import Excel", diff --git a/src/i18n/en/stockLedgerFix.json b/src/i18n/en/stockLedgerFix.json new file mode 100644 index 00000000..7ec6dc0d --- /dev/null +++ b/src/i18n/en/stockLedgerFix.json @@ -0,0 +1,147 @@ +{ + "pageTitle": "Stock Ledger Fix", + "inventory10Title": "1.0 Inventory (Plan A)", + "inventory10Description": "Keeps existing IDs. Adds UOMs that exist on lots but not in inventory. onHand = Σ(in−out) by item+UOM. Rows with no lots become 0. When an item has multiple old rows, only one stock-UOM bucket is kept; the rest are marked deleted=1. Run this while inbound/outbound is paused, then Fix day by day.", + "inventory10LoadError": "Could not load inventory 1.0 preview (ADMIN / TESTING required)", + "inventory10Preview": "Existing inventory: {{rows}} rows; lot item+UOM pairs: {{lotPairs}}; missing: {{missing}}; stockUomId still NULL: {{nullUom}} rows.", + "inventory10Running": "Recalculating…", + "inventory10Run": "Run inventory 1.0 (A)", + "inventory10Confirm": "Plan A: keep existing inventory.id; backfill stockUomId from lots (if the old uomId is stock, revert it to base); insert missing (itemId, stockUomId) rows; recalculate onHand/unavailable from lot in−out. Does not write onHoldQty or change inventory_lot_line. Continue?", + "inventory10Done": "Inventory 1.0 complete: patched stockUomId {{patched}} rows, inserted {{inserted}}, orphans deleted {{orphans}}, recalculated {{updated}}, still missing UOM {{missingAfter}}, still NULL stockUomId {{nullAfter}}", + "inventory10Fail": "Inventory 1.0 failed", + "adjTitle": "2.7 ADJ: set over-issue remain to 0, then align ledger", + "adjDescription": "Choose an ADJ date, then preview. Default is yesterday. For a freeze-dump night you can pick today (e.g. write 31/8 23:17 ADJ onto 31/8). First handle over-issue (line in < out): raise that lot’s inQty to equal outQty (remain=0; trigger recalculates inventory). Then handle miss: if line and ledger differ, write ADJ against the existing lot’s inbound/outbound lines (lot quantities are not changed). One Apply shares one inbound document and one outbound document, with multiple lines under them. Running again on the same ADJ date reuses those two documents. Detail shows at most 20 rows.", + "adjDateLabel": "ADJ date", + "adjDateRequired": "Please enter an ADJ date", + "adjDateFuture": "ADJ date cannot be in the future", + "adjDateAndPreviewRequired": "Please enter an ADJ date and preview first", + "adjTodayFreeze": "Today (freeze night)", + "adjYesterday": "Yesterday", + "adjLoadError": "Could not load ADJ preview (ADMIN / TESTING required)", + "adjPreviewSummary": "ADJ date {{date}}; {{lotCount}} lots can be processed (over-issue remain→0: {{overIssueCount}}, total {{sumOverIssue}}; miss in {{adjInCount}}, out {{adjOutCount}}); missing in total {{sumMissIn}}, missing out total {{sumMissOut}}; SKU net {{skuNet}}{{skuNetNote}}{{revNote}}. Table shows at most 20 rows (over-issue first).", + "adjSkuNetNote": " (non-zero means missing in has no matching missing out)", + "adjRevNote": "; includes reverse ADJ {{count}} lots (ledger over-recorded)", + "adjColLotLineId": "lotLineId", + "adjColItemCode": "itemCode", + "adjColLineInOut": "line in/out", + "adjColLedgerInOut": "ledger in/out", + "adjColMissIn": "Missing in", + "adjColMissOut": "Missing out", + "adjColOverIssue": "Over-issue", + "adjPreviewing": "Previewing…", + "adjPreviewAgain": "Refresh preview", + "adjPreview": "Preview", + "adjApplying": "Writing ADJ…", + "adjApply": "Apply ADJ", + "adjConfirm": "On {{date}}, first patch over-issue remain→0 ({{overIssueCount}} lots, total {{sumOverIssue}}; this changes lot inQty). Then fill miss ADJ: inbound {{adjInCount}}, outbound {{adjOutCount}}. All inbound lines share one inbound document; all outbound lines share one outbound document (miss does not change lot qty). Missing in total {{sumMissIn}}, missing out total {{sumMissOut}}. Continue?", + "adjDone": "ADJ {{date}}: over-issue remain→0 {{overIssuePatched}}, in {{insertedIn}}, out {{insertedOut}}, lotQty {{filledLotQty}}, balance {{filledBalance}}, day close {{dayRowsWritten}}", + "adjFail": "ADJ align failed", + "tabCalendar": "Calendar", + "tabInventory": "Inventory", + "tabLot": "Lot line", + "calendarHint": "Click the title at the top-left to pick year, then month.\nChanging month does not load data; click a day to inspect that day.\nToday can be fixed (freeze-dump night).", + "selectDate": "Select a date", + "dayLoadError": "Could not load the day’s check", + "dayLedgerCount": "{{cnt}} ledger rows that day", + "cannotFixFuture": "Cannot fix a future date", + "cannotFixFutureRange": "Cannot fix a future date (today is allowed for freeze-dump night)", + "pickAtLeastOneStep": "Select at least one step (default runs all of 2.1–2.6)", + "allSteps216": "all 2.1–2.6", + "confirmPartialSteps": "Run only {{steps}} ({{date}}). Unchecked steps will not be recalculated. Continue?", + "fixDayDone": "Fixed {{date}} ({{steps}}): lot {{lot}}, uom {{uom}}, inventory {{inventory}}, lotQty {{lotQty}}, balance {{balance}}, day close {{dayRows}}", + "fixFailed": "Fix failed", + "fixing": "Fixing…", + "fixThisDay": "Fix this day", + "stepsTitle": "Steps (all selected by default)", + "stepsHint": "After applying SQL, if you only need to change inventoryId, tick 2.3 only. Unchecked steps are not recalculated.", + "selectAll": "Select all", + "step21": "2.1 lot", + "step22": "2.2 uom", + "step23": "2.3 inventoryId", + "step24": "2.4 lotQty", + "step25": "2.5 balance", + "step26": "2.6 day close", + "rangeTitle": "Range fix (2.1–2.6 in one run)", + "rangeHint": "Uses the steps ticked above. One API call, but runs day by day (same SQL as a single-day fix, commit per day). Today is allowed (freeze-dump night). Frontend timeout is about 20 minutes; for a large range, export SQL instead.", + "rangeFromRequired": "Please fill range from / to", + "toMustBeGteFrom": "to must be ≥ from", + "fromTooEarly": "from cannot be earlier than {{date}}", + "rangeConfirm": "Fix {{from}} → {{to}} (steps: {{steps}}). Runs day by day (commit each day). Days already finished are kept if it fails mid-way. Continue?", + "rangeProgress": "Range fix {{from}} → {{to}} ({{steps}}) in progress…", + "rangeDone": "Range fix complete {{date}} ({{steps}}): lot {{lot}}, uom {{uom}}, inventory {{inventory}}, lotQty {{lotQty}}, balance {{balance}}, day close {{dayRows}}", + "rangeFail": "Range fix failed", + "rangeRunning": "Range fix in progress…", + "rangeRun": "Range fix", + "from": "from", + "to": "to", + "exportTitle": "Export patched SQL (for the new database)", + "exportHint": "Tick the sections to export (same as day-fix steps). Apply order: 1.0 → ledger (±2.3) → 2.7 inbound/outbound documents + ADJ INSERT → 2.6. A full file (1.0 + 2.3) can skip production 1.0/2.3 when production is frozen and IDs match. Default exports only ledger + day close (legacy behaviour).", + "exportPickAtLeastOne": "Select at least one export section", + "export23Without10": "2.3 inventoryId is ticked but 1.0 inventory is not: if production is missing the new IDs, UPDATE will point at empty rows. Tick 1.0 as well (full file). Export anyway?", + "exportFail": "Export failed", + "exporting": "Exporting…", + "exportSql": "Export .sql", + "exportDefault": "Default", + "exportFull": "Full file", + "exportFromToRequired": "Please fill from / to", + "export10": "1.0 inventory", + "export23": "2.3 inventoryId", + "exportLedger": "ledger lot/uom/lotQty/balance", + "export26": "2.6 day close", + "export27": "2.7 ADJ + inbound/outbound documents", + "invTabHint": "Search by itemCode or inventoryId. Fix recalculates lotQty, day close, and balance for this item’s ledger up to today — no need to click the calendar day by day. If the warehouse is still writing this item during the day, new ledger rows after the fix are still handled by the live writer.", + "invSearchLabel": "itemCode / inventoryId", + "searching": "Searching…", + "search": "Search", + "searchFailed": "Search failed", + "colInventoryId": "inventoryId", + "colItemCode": "itemCode", + "colUomId": "uomId", + "colLedgerRows": "ledger rows", + "invLoadError": "Could not load inventory", + "invScopeSummary": "{{itemCode}} / inventory {{id}} / uom {{uomId}}; {{firstDate}} → {{lastDate}}; {{cnt}} rows; last balance {{lastBalance}}", + "invFixConfirm": "This will recalculate lotQty and day close for all ledger rows of this inventory up to today, plus this item’s balance. Continue?", + "invFixDone": "Fixed inventory {{id}}: lot {{lot}}, uom {{uom}}, inventory {{inventory}}, lotQty {{lotQty}}, balance {{balance}}, day close {{dayRows}}", + "fixThisInventory": "Fix this inventory", + "lotTabHint": "Search by lotNo or inventoryLotLineId. Fix only recalculates this lot’s lotQty and day close; it does not change balance.", + "lotSearchLabel": "lotNo / lot line id", + "colLotLineId": "lot line id", + "colLotNo": "lotNo", + "lotLoadError": "Could not load lot", + "lotScopeSummary": "{{lotNo}} / lot {{id}} / {{itemCode}}; {{firstDate}} → {{lastDate}}; {{cnt}} rows; last lotQtyAfter {{lastLotQtyAfter}}", + "lotFixConfirm": "This only fixes this lot’s lotQty and day close; it will not change the item’s balance. Continue?", + "lotFixDone": "Fixed lot {{id}}: lot {{lot}}, uom {{uom}}, inventory {{inventory}}, lotQty {{lotQty}}, day close {{dayRows}}", + "fixThisLot": "Fix this lot", + "checkItem": "Item", + "checkStatus": "Status", + "checkCorrect": "Correct", + "checkMiss": "Missing", + "checkIncorrect": "Incorrect", + "checkReason": "Reason", + "checkRows": "Rows", + "checkDash": "—", + "canAutoFix": "Can auto-fix (handled by Fix)", + "cannotAutoFix": "Cannot auto-fix (Fix will not clear these: old TKE new lots / true over-issue / no lot source)", + "verdictCorrect": "correct", + "verdictMiss": "miss", + "verdictOverIssue": "over-issue", + "verdictCanFix": "can fix", + "verdictCannotFix": "cannot fix", + "verdictIncorrect": "incorrect", + "part": { + "lot": "inventoryLotLineId", + "uom": "uomId", + "inventory": "inventoryId", + "lotQty": "lotQtyBefore/After (lot already exists)", + "overIssue": "over-issue (lotQty < 0)", + "balance": "balance", + "dayTable": "stock_lot_day", + "fixable21a": "Can fix 2.1a: SIL/SOL already has a lot line", + "fixable21b": "Can fix 2.1b: inventoryLotId has only one line", + "fixableLotQty": "Can fix: lot exists but lotQty is missing", + "cannotNoSource": "Cannot fix: no SIL/SOL lot source", + "cannotMultiLine": "Cannot fix: same lot has multiple warehouse lines", + "earlyTke": "Cannot fix: old TKE opened a new lot (sibling surplus)", + "realOver": "Cannot fix: over-issue is not old TKE (true over-issue / ledger mismatch)" + } +} diff --git a/src/i18n/zh/navigation.json b/src/i18n/zh/navigation.json index afbc1d79..156c7c81 100644 --- a/src/i18n/zh/navigation.json +++ b/src/i18n/zh/navigation.json @@ -81,6 +81,8 @@ "nav.settings.items": "物品", "nav.settings.itemDefaultShelfLife": "物品預設保質期", "nav.settings.masterDataIssues": "BOM / 物料單位問題", + "nav.settings.stockLedgerFix": "庫存帳修復", + "nav.breadcrumb.stockLedgerFix": "庫存帳修復", "nav.settings.priceInquiry": "價格查詢", "nav.settings.printer": "列印機", "nav.settings.qcCategory": "QC 品檢模板", diff --git a/src/i18n/zh/stockLedgerFix.json b/src/i18n/zh/stockLedgerFix.json new file mode 100644 index 00000000..0ad5e825 --- /dev/null +++ b/src/i18n/zh/stockLedgerFix.json @@ -0,0 +1,147 @@ +{ + "pageTitle": "庫存帳修復", + "inventory10Title": "1.0 inventory(方案 A)", + "inventory10Description": "保留現有 id;lot 有、inventory 沒有的 UOM 會新增;onHand = Σ(in−out) 按 item+UOM。沒有 lot 的列會變成 0。同一料多顆舊列時只留一顆 stock UOM 桶,其餘 deleted=1。請在進出倉暫停時執行,再逐日 Fix。", + "inventory10LoadError": "無法載入 inventory 1.0 預覽(需要 ADMIN / TESTING)", + "inventory10Preview": "現有 inventory {{rows}} 列;lot 的 item+UOM {{lotPairs}} 組;缺 {{missing}} 組;stockUomId 仍 NULL {{nullUom}} 列。", + "inventory10Running": "重算中…", + "inventory10Run": "Run inventory 1.0 (A)", + "inventory10Confirm": "方案 A:保留現有 inventory.id;從 lot 回填 stockUomId(舊 uomId 是 stock 則改回 base);補缺 (itemId, stockUomId);用 lot 的 in−out 重算 onHand/unavailable。不寫 onHoldQty、不改 inventory_lot_line。確定執行?", + "inventory10Done": "inventory 1.0 完成:回填 stockUomId {{patched}} 列、新增 {{inserted}} 列、殘列 deleted {{orphans}}、重算 {{updated}} 列、之後仍缺 UOM {{missingAfter}}、仍 NULL stockUomId {{nullAfter}}", + "inventory10Fail": "inventory 1.0 失敗", + "adjTitle": "2.7 ADJ:超發 remain→0,再對齊 ledger", + "adjDescription": "請先選 ADJ 日期再預覽。預設昨天;freeze dump 夜可選今天(例如 31/8 23:17 寫 ADJ 到 31/8)。先處理超發(line 入少於出):把該 lot 的 inQty 補到等於 outQty(remain=0,trigger 重算 inventory)。再處理 miss:line 與 ledger 有差就 ADJ,掛既有 lot 的入/出倉行(不改 lot 數量)。一次 Apply 共用一張入倉單、一張出倉單,下面多行;同一 ADJ 日期再跑會沿用這兩張單。明細最多 20 列。", + "adjDateLabel": "ADJ 日期", + "adjDateRequired": "請填 ADJ 日期", + "adjDateFuture": "ADJ 日期不能是未來", + "adjDateAndPreviewRequired": "請填 ADJ 日期並先預覽", + "adjTodayFreeze": "今天(freeze 夜)", + "adjYesterday": "昨天", + "adjLoadError": "無法載入 ADJ 預覽(需要 ADMIN / TESTING)", + "adjPreviewSummary": "ADJ 日期 {{date}};可處理 {{lotCount}} 條 lot(超發 remain→0 {{overIssueCount}}、合計 {{sumOverIssue}};miss 入 {{adjInCount}}、出 {{adjOutCount}});缺入合計 {{sumMissIn}}、缺出合計 {{sumMissOut}};SKU 淨額 {{skuNet}}{{skuNetNote}}{{revNote}}。下列最多 20 列(超發優先)。", + "adjSkuNetNote": "(非 0 表示有缺入沒有對應缺出)", + "adjRevNote": ";含反向 ADJ {{count}} 條(ledger 多記)", + "adjColLotLineId": "lotLineId", + "adjColItemCode": "itemCode", + "adjColLineInOut": "line in/out", + "adjColLedgerInOut": "ledger in/out", + "adjColMissIn": "缺入", + "adjColMissOut": "缺出", + "adjColOverIssue": "超發", + "adjPreviewing": "預覽中…", + "adjPreviewAgain": "重新預覽", + "adjPreview": "預覽", + "adjApplying": "寫入 ADJ 中…", + "adjApply": "Apply ADJ", + "adjConfirm": "會在 {{date}} 先修超發 remain→0({{overIssueCount}} 條 lot,合計 {{sumOverIssue}},會改 lot inQty)。再補 miss ADJ:入向 {{adjInCount}} 筆、出向 {{adjOutCount}} 筆。入向全部掛同一張入倉單、出向全部掛同一張出倉單(miss 不改 lot 數量)。缺入合計 {{sumMissIn}}、缺出合計 {{sumMissOut}}。確定?", + "adjDone": "ADJ {{date}}:超發 remain→0 {{overIssuePatched}}、入 {{insertedIn}}、出 {{insertedOut}}、lotQty {{filledLotQty}}、balance {{filledBalance}}、日結 {{dayRowsWritten}}", + "adjFail": "ADJ 對齊失敗", + "tabCalendar": "日曆", + "tabInventory": "Inventory", + "tabLot": "Lot line", + "calendarHint": "點左上標題可先選年再選月。換月不會查資料;點某一天才檢查當天。今天可修(freeze dump 夜)。", + "selectDate": "請選日期", + "dayLoadError": "無法載入當日檢查", + "dayLedgerCount": "當天 ledger {{cnt}} 列", + "cannotFixFuture": "不能修未來日期", + "cannotFixFutureRange": "不能修未來日期(今天可以,給 freeze dump 夜修)", + "pickAtLeastOneStep": "請至少勾一個步驟(預設全跑 2.1–2.6)", + "allSteps216": "全部 2.1–2.6", + "confirmPartialSteps": "只跑 {{steps}}({{date}})。未勾的步驟不會重算。確定?", + "fixDayDone": "已修 {{date}}({{steps}}):lot {{lot}}、uom {{uom}}、inventory {{inventory}}、lotQty {{lotQty}}、balance {{balance}}、日結 {{dayRows}}", + "fixFailed": "修復失敗", + "fixing": "修復中…", + "fixThisDay": "Fix this day", + "stepsTitle": "步驟(預設全跑)", + "stepsHint": "套 SQL 後只改 inventoryId 時只勾 2.3。只跑部分時未勾的不會重算。", + "selectAll": "全選", + "step21": "2.1 lot", + "step22": "2.2 uom", + "step23": "2.3 inventoryId", + "step24": "2.4 lotQty", + "step25": "2.5 balance", + "step26": "2.6 日結", + "rangeTitle": "區間修(2.1–2.6 一次)", + "rangeHint": "使用上面勾的步驟,一次 API 但改為逐日(與單日修相同 SQL,每天 commit)。可含今天(freeze dump 夜)。前端最長約 20 分鐘;大區間仍建議匯出 SQL。", + "rangeFromRequired": "請填區間修 from / to", + "toMustBeGteFrom": "to 必須 ≥ from", + "fromTooEarly": "from 不能早於 {{date}}", + "rangeConfirm": "一次修 {{from}} → {{to}}(步驟:{{steps}})。改為逐日跑(每天 commit)。中途失敗時已跑完的天會留下。確定?", + "rangeProgress": "區間修 {{from}} → {{to}}({{steps}})進行中…", + "rangeDone": "區間修完成 {{date}}({{steps}}):lot {{lot}}、uom {{uom}}、inventory {{inventory}}、lotQty {{lotQty}}、balance {{balance}}、日結 {{dayRows}}", + "rangeFail": "區間修失敗", + "rangeRunning": "區間修中…", + "rangeRun": "區間修", + "from": "from", + "to": "to", + "exportTitle": "匯出已修 SQL(新庫用)", + "exportHint": "勾選要匯出的段落(同日修步驟)。套檔順序:1.0 → ledger(±2.3)→ 2.7 入出倉單+ADJ INSERT → 2.6。完整檔(含 1.0+2.3)且正式庫 freeze/id 同源時,可跳過正式庫 1.0/2.3。預設只匯 ledger+日結(舊行為)。", + "exportPickAtLeastOne": "請至少勾一個匯出項目", + "export23Without10": "已勾 2.3 inventoryId 但未勾 1.0 inventory:正式庫若缺新 id,UPDATE 會指到空列。建議一併勾 1.0(完整檔)。仍要匯出?", + "exportFail": "匯出失敗", + "exporting": "匯出中…", + "exportSql": "匯出 .sql", + "exportDefault": "預設", + "exportFull": "完整檔", + "exportFromToRequired": "請填 from / to", + "export10": "1.0 inventory", + "export23": "2.3 inventoryId", + "exportLedger": "ledger lot/uom/lotQty/balance", + "export26": "2.6 日結", + "export27": "2.7 ADJ+入出倉單", + "invTabHint": "搜 itemCode 或 inventoryId。Fix 會重算這顆料到今天為止全部流水的 lotQty、日結與 balance,不必逐日點日曆。白天倉還在寫這顆料時,修完後新流水仍由 live writer 接。", + "invSearchLabel": "itemCode / inventoryId", + "searching": "搜尋中…", + "search": "搜尋", + "searchFailed": "搜尋失敗", + "colInventoryId": "inventoryId", + "colItemCode": "itemCode", + "colUomId": "uomId", + "colLedgerRows": "ledger 列", + "invLoadError": "無法載入 inventory", + "invScopeSummary": "{{itemCode}} / inventory {{id}} / uom {{uomId}};{{firstDate}} → {{lastDate}};{{cnt}} 列;最後 balance {{lastBalance}}", + "invFixConfirm": "會重算這顆 inventory 到今天為止全部 ledger 的 lotQty、日結,以及這顆料的 balance。確定?", + "invFixDone": "已修 inventory {{id}}:lot {{lot}}、uom {{uom}}、inventory {{inventory}}、lotQty {{lotQty}}、balance {{balance}}、日結 {{dayRows}}", + "fixThisInventory": "Fix this inventory", + "lotTabHint": "搜 lotNo 或 inventoryLotLineId。Fix 只重算這張 lot 的 lotQty 與日結,不改 balance。", + "lotSearchLabel": "lotNo / lot line id", + "colLotLineId": "lot line id", + "colLotNo": "lotNo", + "lotLoadError": "無法載入 lot", + "lotScopeSummary": "{{lotNo}} / lot {{id}} / {{itemCode}};{{firstDate}} → {{lastDate}};{{cnt}} 列;最後 lotQtyAfter {{lastLotQtyAfter}}", + "lotFixConfirm": "只修這張 lot 的 lotQty 與日結,不會改整顆料的 balance。確定?", + "lotFixDone": "已修 lot {{id}}:lot {{lot}}、uom {{uom}}、inventory {{inventory}}、lotQty {{lotQty}}、日結 {{dayRows}}", + "fixThisLot": "Fix this lot", + "checkItem": "項目", + "checkStatus": "狀態", + "checkCorrect": "正確", + "checkMiss": "缺", + "checkIncorrect": "不正確", + "checkReason": "原因", + "checkRows": "列數", + "checkDash": "—", + "canAutoFix": "可自動修(按 Fix 會處理)", + "cannotAutoFix": "不能自動修(Fix 不會消;舊 TKE 開新批/真超發/沒有 lot 來源)", + "verdictCorrect": "correct", + "verdictMiss": "miss", + "verdictOverIssue": "over-issue", + "verdictCanFix": "可修", + "verdictCannotFix": "不能修", + "verdictIncorrect": "incorrect", + "part": { + "lot": "inventoryLotLineId", + "uom": "uomId", + "inventory": "inventoryId", + "lotQty": "lotQtyBefore/After(lot 已有)", + "overIssue": "over-issue (lotQty < 0)", + "balance": "balance", + "dayTable": "stock_lot_day", + "fixable21a": "可修 2.1a:SIL/SOL 已有 lot line", + "fixable21b": "可修 2.1b:inventoryLotId 僅一條 line", + "fixableLotQty": "可修:lot 已有但缺 lotQty", + "cannotNoSource": "不能修:沒有 SIL/SOL lot 來源", + "cannotMultiLine": "不能修:同一 lot 有多條 warehouse line", + "earlyTke": "不能修:舊 TKE 開新批(sibling 盤盈)", + "realOver": "不能修:over-issue 非舊 TKE(真超發/帳不一致)" + } +} From 6a28a8e1e9abb70e3efa225ba658999e1abbf013 Mon Sep 17 00:00:00 2001 From: "PC-20260115JRSN\\Administrator" Date: Fri, 18 Sep 2026 00:33:23 +0800 Subject: [PATCH 03/24] added search criteria for pasting item code for stock balance report --- src/app/(main)/report/page.tsx | 100 ++++++++++++------- src/app/(main)/report/parseItemCodeTokens.ts | 47 +++++++++ src/app/(main)/report/reportI18n.ts | 8 +- src/config/reportConfig.ts | 12 +++ src/i18n/en/report.json | 6 +- src/i18n/zh/report.json | 6 +- 6 files changed, 138 insertions(+), 41 deletions(-) create mode 100644 src/app/(main)/report/parseItemCodeTokens.ts diff --git a/src/app/(main)/report/page.tsx b/src/app/(main)/report/page.tsx index 6dec1c10..dce43d73 100644 --- a/src/app/(main)/report/page.tsx +++ b/src/app/(main)/report/page.tsx @@ -26,6 +26,7 @@ import { import DownloadIcon from '@mui/icons-material/Download'; import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'; import { REPORTS } from '@/config/reportConfig'; +import { mergePastedItemCodes, buildStockBalanceRequestBody } from './parseItemCodeTokens'; import { NEXT_PUBLIC_API_URL } from '@/config/api'; import { clientAuthFetch } from '@/app/utils/clientAuthFetch'; import SemiFGProductionAnalysisReport from './SemiFGProductionAnalysisReport'; @@ -80,7 +81,7 @@ const FIELD_ERROR_SX = { /** FP-MTMS Version Checklist | Functions Ref. No. 82 | v1.0.0 | 2026-09-10 */ export default function ReportPage() { const { data: session } = useSession() as { data: SessionWithTokens | null }; - const { t, i18n, reportTitle, fieldLabel, optionLabel } = useReportLabels(); + const { t, i18n, reportTitle, fieldLabel, fieldHint, optionLabel } = useReportLabels(); const isZh = (i18n.language || 'zh').startsWith('zh'); const dateDisplayFormat = isZh ? 'DD/MM/YYYY' : 'DD/MM/YYYY'; const includeGrnFinancialColumns = @@ -358,6 +359,22 @@ export default function ReportPage() { return p.toString(); }; + const buildCriteriaQueryString = (): string => { + if (!currentReport) return ''; + if (currentReport.id === 'rep-012') return buildRep012QueryString(); + if (currentReport.id === 'rep-010') return buildRep010QueryString(); + const merged = mergePastedItemCodes(criteria); + const p = new URLSearchParams(merged); + if (currentReport.id === 'rep-016') { + const day = (merged.dateStart || '').trim(); + if (day) { + p.set('dateStart', day); + p.set('dateEnd', day); + } + } + return p.toString(); + }; + const handlePrint = async () => { if (!currentReport) return; if (!validateRequiredFields()) return; @@ -399,28 +416,24 @@ export default function ReportPage() { await generateShopOrderReplenishmentReportExcel(criteria, reportTitle(currentReport), t); } else { // Backend returns actual .xlsx bytes for this Excel endpoint. - let queryParams = - currentReport.id === 'rep-012' - ? buildRep012QueryString() - : currentReport.id === 'rep-010' - ? buildRep010QueryString() - : new URLSearchParams(criteria).toString(); - // rep-016: single-day UI — mirror dateStart to dateEnd for backend API. - if (currentReport.id === 'rep-016') { - const p = new URLSearchParams(criteria); - const day = (criteria.dateStart || '').trim(); - if (day) { - p.set('dateStart', day); - p.set('dateEnd', day); - } - queryParams = p.toString(); - } - const excelUrl = `${currentReport.apiEndpoint}-excel?${queryParams}`; - - const response = await clientAuthFetch(excelUrl, { - method: 'GET', - headers: { Accept: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }, - }); + const isStockBalance = currentReport.id === 'rep-007'; + const excelUrl = isStockBalance + ? `${currentReport.apiEndpoint}-excel` + : `${currentReport.apiEndpoint}-excel?${buildCriteriaQueryString()}`; + + const response = await clientAuthFetch(excelUrl, isStockBalance + ? { + method: 'POST', + headers: { + Accept: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'Content-Type': 'application/json', + }, + body: JSON.stringify(buildStockBalanceRequestBody(criteria)), + } + : { + method: 'GET', + headers: { Accept: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }, + }); if (response.status === 401 || response.status === 403) return; if (response.status === 204) { @@ -472,18 +485,24 @@ export default function ReportPage() { setLoading(true); try { - let queryParams = - currentReport.id === 'rep-012' - ? buildRep012QueryString() - : currentReport.id === 'rep-010' - ? buildRep010QueryString() - : new URLSearchParams(criteria).toString(); - const url = `${currentReport.apiEndpoint}?${queryParams}`; - - const response = await clientAuthFetch(url, { - method: 'GET', - headers: { 'Accept': 'application/pdf' }, - }); + const isStockBalance = currentReport.id === 'rep-007'; + const url = isStockBalance + ? currentReport.apiEndpoint + : `${currentReport.apiEndpoint}?${buildCriteriaQueryString()}`; + + const response = await clientAuthFetch(url, isStockBalance + ? { + method: 'POST', + headers: { + Accept: 'application/pdf', + 'Content-Type': 'application/json', + }, + body: JSON.stringify(buildStockBalanceRequestBody(criteria)), + } + : { + method: 'GET', + headers: { Accept: 'application/pdf' }, + }); if (response.status === 401 || response.status === 403) return; if (!response.ok) { @@ -574,7 +593,10 @@ export default function ReportPage() { : currentValue; // Use larger grid size for 成品/半成品生產分析報告 - const gridSize = currentReport.id === 'rep-005' ? { xs: 12, sm: 12, md: 6 } : { xs: 12, sm: 6 }; + const gridSize = field.multiline + ? { xs: 12 } + : currentReport.id === 'rep-005' ? { xs: 12, sm: 12, md: 6 } : { xs: 12, sm: 6 }; + const hintText = fieldHint(currentReport.id, field.name); const disabledByCheckedCheckbox = currentReport.fields.some((f) => { if (f.type !== 'checkbox' || criteria[f.name] !== 'true') return false; @@ -762,9 +784,11 @@ export default function ReportPage() { fullWidth required={field.required} error={Boolean(fieldErrors[field.name])} - helperText={fieldErrors[field.name] || undefined} + helperText={fieldErrors[field.name] || hintText || undefined} label={translatedLabel} - type={field.type} + type={field.multiline ? 'text' : field.type} + multiline={field.multiline} + minRows={field.multiline ? (field.minRows ?? 4) : undefined} placeholder={field.placeholder} disabled={disabledByCheckedCheckbox || disabledRep012Status || !!field.disabled} sx={{ diff --git a/src/app/(main)/report/parseItemCodeTokens.ts b/src/app/(main)/report/parseItemCodeTokens.ts new file mode 100644 index 00000000..148a08e2 --- /dev/null +++ b/src/app/(main)/report/parseItemCodeTokens.ts @@ -0,0 +1,47 @@ +/** Split pasted / typed item codes from Excel or a text field. */ +const ITEM_CODE_SEPARATORS = /[\s,;,、\u00A0\u3000]+/; + +export function parseItemCodeTokens(raw: string | undefined | null): string[] { + if (!raw) return []; + const seen = new Set(); + const tokens: string[] = []; + for (const part of raw.split(ITEM_CODE_SEPARATORS)) { + const token = part.trim(); + if (!token) continue; + const key = token.toUpperCase(); + if (seen.has(key)) continue; + seen.add(key); + tokens.push(token); + } + return tokens; +} + +/** Merge multi-select `itemCode` with pasted `itemCodePaste`; drop the paste field from API params. */ +export function mergePastedItemCodes(criteria: Record): Record { + const next: Record = { ...criteria }; + delete next.itemCodePaste; + const merged = parseItemCodeTokens( + [criteria.itemCode, criteria.itemCodePaste].filter(Boolean).join(" "), + ); + if (merged.length > 0) { + next.itemCode = merged.join(","); + } else { + delete next.itemCode; + } + return next; +} + +/** POST body for 庫存結餘報告 so pasted codes are not limited by URL length. */ +export function buildStockBalanceRequestBody(criteria: Record): { + stockDate?: string; + itemCodes?: string[]; +} { + const itemCodes = parseItemCodeTokens( + [criteria.itemCode, criteria.itemCodePaste].filter(Boolean).join(" "), + ); + const body: { stockDate?: string; itemCodes?: string[] } = {}; + const stockDate = criteria.stockDate?.trim(); + if (stockDate) body.stockDate = stockDate; + if (itemCodes.length) body.itemCodes = itemCodes; + return body; +} diff --git a/src/app/(main)/report/reportI18n.ts b/src/app/(main)/report/reportI18n.ts index 7e8be629..7031a3af 100644 --- a/src/app/(main)/report/reportI18n.ts +++ b/src/app/(main)/report/reportI18n.ts @@ -19,6 +19,12 @@ export function useReportLabels() { defaultValue: field.label, }); + const fieldHint = (reportId: string, fieldName: string, fallback = "") => { + const key = `reports.${reportId}.fieldHints.${fieldName}`; + if (!i18n.exists(key, { ns: "report" })) return fallback; + return String(t(key, { defaultValue: fallback })); + }; + const optionLabel = ( reportId: string, fieldName: string, @@ -35,7 +41,7 @@ export function useReportLabels() { const categoryTitle = (id: string, fallback: string) => t(`categories.${id}`, { defaultValue: fallback }); - return { t, i18n, reportTitle, fieldLabel, optionLabel, categoryTitle }; + return { t, i18n, reportTitle, fieldLabel, fieldHint, optionLabel, categoryTitle }; } export function reportExcelT( diff --git a/src/config/reportConfig.ts b/src/config/reportConfig.ts index c6ed8b5b..f34bcd93 100644 --- a/src/config/reportConfig.ts +++ b/src/config/reportConfig.ts @@ -25,6 +25,10 @@ export interface ReportField { minDate?: 'today'; /** Disable the input (e.g. date locked to today) */ disabled?: boolean; + /** Render a multiline text area (for pasting many values) */ + multiline?: boolean; + /** Rows for multiline text areas. Default 4. */ + minRows?: number; } export type ReportResponseType = 'pdf' | 'excel'; @@ -340,6 +344,14 @@ export const REPORTS: ReportDefinition[] = [ fields: [ { label: "庫存日期: Stock Date", name: "stockDate", type: "date", required: true }, asyncItemCodeField(), + { + label: "貼上貨品編號 Paste Item Codes", + name: "itemCodePaste", + type: "text", + required: false, + multiline: true, + minRows: 4, + }, ] }, diff --git a/src/i18n/en/report.json b/src/i18n/en/report.json index 17af3c26..eb761d48 100644 --- a/src/i18n/en/report.json +++ b/src/i18n/en/report.json @@ -122,7 +122,11 @@ "title": "Stock Balance Report", "fields": { "stockDate": "Stock Date", - "itemCode": "Item Code" + "itemCode": "Item Code", + "itemCodePaste": "Paste Item Codes" + }, + "fieldHints": { + "itemCodePaste": "Paste item codes from Excel. Separate with spaces, commas, or new lines" } }, "rep-014": { diff --git a/src/i18n/zh/report.json b/src/i18n/zh/report.json index 52a2a638..c0de47f6 100644 --- a/src/i18n/zh/report.json +++ b/src/i18n/zh/report.json @@ -122,7 +122,11 @@ "title": "庫存結餘報告", "fields": { "stockDate": "庫存日期", - "itemCode": "貨品編號" + "itemCode": "貨品編號", + "itemCodePaste": "貼上貨品編號" + }, + "fieldHints": { + "itemCodePaste": "可從 Excel 貼上多個貨品編號,以空格、逗號或換行分隔" } }, "rep-014": { From 6e912bd5dcf7ee3cc932965abdf9ba480abf80e5 Mon Sep 17 00:00:00 2001 From: "PC-20260115JRSN\\Administrator" Date: Fri, 18 Sep 2026 01:11:50 +0800 Subject: [PATCH 04/24] added unit description for the number before submit in PO stock in --- src/app/api/po/index.ts | 1 + src/app/api/settings/uom/index.ts | 2 + src/components/PoDetail/PoDetail.tsx | 8 +- src/components/PoDetail/PoDetailRow.tsx | 150 ++++++++++++++++++++--- src/components/PoDetail/PoInputGrid.tsx | 7 +- src/components/PoDetail/poPurchaseUom.ts | 96 +++++++++++++++ src/i18n/en/purchaseOrder.json | 2 + src/i18n/zh/purchaseOrder.json | 2 + 8 files changed, 245 insertions(+), 23 deletions(-) create mode 100644 src/components/PoDetail/poPurchaseUom.ts diff --git a/src/app/api/po/index.ts b/src/app/api/po/index.ts index ed051581..ac6dc583 100644 --- a/src/app/api/po/index.ts +++ b/src/app/api/po/index.ts @@ -54,6 +54,7 @@ export interface StockUomForPoLine { id: number; stockUomCode: string; stockUomDesc: string; + stockUomShortDesc?: string | null; stockQty: number; stockRatioN: number; stockRatioD: number; diff --git a/src/app/api/settings/uom/index.ts b/src/app/api/settings/uom/index.ts index e7e8526e..4f5765ca 100644 --- a/src/app/api/settings/uom/index.ts +++ b/src/app/api/settings/uom/index.ts @@ -9,6 +9,8 @@ export interface Uom { id: number; code: string; udfudesc: string; + /** Short UoM label from M18 (`udfShortDesc`), e.g. 箱. */ + udfShortDesc?: string | null; unit1: string; unit1Qty: number; unit2?: string; diff --git a/src/components/PoDetail/PoDetail.tsx b/src/components/PoDetail/PoDetail.tsx index 4b16fc53..993433dc 100644 --- a/src/components/PoDetail/PoDetail.tsx +++ b/src/components/PoDetail/PoDetail.tsx @@ -875,7 +875,13 @@ const PoDetail: React.FC = ({ po, warehouse, printerCombo }) => { {t("status")} {/* {renderFieldCondition(FIRST_IN_FIELD) ? {t("receivedQty")} : undefined} */} {t("productLotNo")} - {renderFieldCondition(SECOND_IN_FIELD) ? {t("dnQty")}
(以訂單單位計算)
: undefined} + {renderFieldCondition(SECOND_IN_FIELD) ? ( + + {t("dnQty")} +
+ ({t("dnQtyOrderUnitHint")}) +
+ ) : undefined} diff --git a/src/components/PoDetail/PoDetailRow.tsx b/src/components/PoDetail/PoDetailRow.tsx index 682aa4dd..0118fbb0 100644 --- a/src/components/PoDetail/PoDetailRow.tsx +++ b/src/components/PoDetail/PoDetailRow.tsx @@ -4,10 +4,13 @@ import { PurchaseOrderLine } from "@/app/api/po"; import { Box, Button, + InputAdornment, Radio, + Stack, TableCell, TableRow, TextField, + Typography, alpha, } from "@mui/material"; import { memo, useCallback, useEffect, useRef, useState } from "react"; @@ -16,6 +19,12 @@ import { decimalFormatter, integerFormatter } from "@/app/utils/formatUtil"; import { submitDialogWithWarning } from "../Swal/CustomAlerts"; import { createStockInLine } from "@/app/api/stockIn/actions"; import { previewPoBatchStockQty } from "./stockQtyRound"; +import { + formatQtyWithPurchaseUom, + formatQtyWithStockUom, + poLineNeedsStockQtyConversion, + purchaseUomShortDesc, +} from "./poPurchaseUom"; const PURCHASE_STOCK_IN_ALERT_STATUSES = new Set(["pending", "receiving"]); @@ -186,6 +195,27 @@ export const PoDetailRow = memo(function PoDetailRow({ Number(receivedTotalText.replace(/,/g, "")) <= 0 ? "red" : "inherit"; const needsStockInAttention = canSeeStockInReminders && purchaseOrderLineHasIncompleteStockIn(row); + const uomShort = purchaseUomShortDesc(row.uom); + const orderQtyWithUnit = formatQtyWithPurchaseUom(row.qty, row.uom); + const enteredBatchQty = Number(dnQtyInput.trim()); + const hasEnteredBatchQty = Number.isInteger(enteredBatchQty) && enteredBatchQty > 0; + const showStockConversion = + hasEnteredBatchQty && + poLineNeedsStockQtyConversion( + Number(row.qty ?? 0), + Number(row.stockUom?.stockQty ?? 0), + row.uom, + row.stockUom, + ); + const convertedStockQty = previewPoBatchStockQty( + Number(row.qty ?? 0), + Number(row.stockUom?.stockQty ?? 0), + enteredBatchQty, + ); + const convertedStockQtyWithUnit = formatQtyWithStockUom( + convertedStockQty, + row.stockUom, + ); return ( {row.itemName} - {integerFormatter.format(row.qty)} + + {orderQtyWithUnit} + {integerFormatter.format(row.processed)} {row.uom?.udfudesc} @@ -268,25 +310,95 @@ export const PoDetailRow = memo(function PoDetailRow({ /> {showDnQty ? ( - - setDnQtyInput(e.target.value.replace(/[^\d]/g, ""))} - onBlur={() => onInputBlur(row.id, lotNoInput, dnQtyInput)} + + e.stopPropagation()} - InputProps={{ - inputProps: { - min: 1, - step: 1, - inputMode: "numeric", - pattern: "[0-9]*", - }, - }} - /> + > + setDnQtyInput(e.target.value.replace(/[^\d]/g, ""))} + onBlur={() => onInputBlur(row.id, lotNoInput, dnQtyInput)} + onClick={(e) => e.stopPropagation()} + sx={{ minWidth: 132, width: 148, flexShrink: 0 }} + InputProps={{ + endAdornment: uomShort ? ( + + + {uomShort} + + + ) : undefined, + inputProps: { + min: 1, + step: 1, + inputMode: "numeric", + pattern: "[0-9]*", + "aria-label": `${t("dnQty")} ${uomShort}`.trim(), + }, + }} + /> + {showStockConversion && Number.isFinite(convertedStockQty) && convertedStockQty > 0 ? ( + alpha(theme.palette.primary.main, 0.1), + border: 1, + borderColor: "primary.main", + textAlign: "center", + }} + title={row.stockUom?.stockUomDesc || convertedStockQtyWithUnit} + > + + {t("stockQtyRef")} + + + {convertedStockQtyWithUnit} + + + ) : null} + ) : null} diff --git a/src/components/PoDetail/PoInputGrid.tsx b/src/components/PoDetail/PoInputGrid.tsx index b4572b58..c8c038b8 100644 --- a/src/components/PoDetail/PoInputGrid.tsx +++ b/src/components/PoDetail/PoInputGrid.tsx @@ -61,7 +61,7 @@ import DoDisturbIcon from "@mui/icons-material/DoDisturb"; import { useSession } from "next-auth/react"; // import { SessionWithTokens } from "src/config/authConfig"; import QcStockInModal from "../Qc/QcStockInModal"; -import { decimalFormatter, integerFormatter } from "@/app/utils/formatUtil"; +import { decimalFormatter } from "@/app/utils/formatUtil"; import { PrinterCombo } from "@/app/api/settings/printer"; import { EscalationResult } from "@/app/api/escalation"; import { fetchEscalationLogsByStockInLines } from "@/app/api/escalation/actions"; @@ -70,10 +70,11 @@ import { EscalationCombo } from "@/app/api/user"; import { deleteDialog } from "../Swal/CustomAlerts"; import StockInLineRowActions from "./StockInLineRowActions"; import { StockQtyRoundMode, needsPoQcStockQtyRound } from "./stockQtyRound"; +import { formatQtyWithPurchaseUom } from "./poPurchaseUom"; // 3 buttons after QC (view + print QR + delete): 176*3 + gap + cell padding const ACTIONS_COLUMN_WIDTH = 580; -const PURCHASE_QTY_COLUMN_WIDTH = 72; +const PURCHASE_QTY_COLUMN_WIDTH = 96; const UOM_COLUMN_WIDTH = 124; const STOCK_QTY_COLUMN_WIDTH = 110; const STOCK_IN_ROW_HEIGHT = 58; @@ -719,7 +720,7 @@ function PoInputGrid({ type: "number", renderCell: (params) => { const qty = params.row.purchaseAcceptedQty ?? 0; - return integerFormatter.format(qty); + return formatQtyWithPurchaseUom(qty, itemDetail.uom); }, }, { diff --git a/src/components/PoDetail/poPurchaseUom.ts b/src/components/PoDetail/poPurchaseUom.ts new file mode 100644 index 00000000..84b07f2f --- /dev/null +++ b/src/components/PoDetail/poPurchaseUom.ts @@ -0,0 +1,96 @@ +import { decimalFormatter, integerFormatter } from "@/app/utils/formatUtil"; + +type PurchaseUomLike = { + code?: string | null; + udfudesc?: string | null; + udfShortDesc?: string | null; +} | null | undefined; + +type StockUomLike = { + stockUomCode?: string | null; + stockUomDesc?: string | null; + stockUomShortDesc?: string | null; +} | null | undefined; + +function isCompactUnitLabel(value: string): boolean { + return value.length > 0 && value.length <= 6 && !/[x×]/i.test(value); +} + +function compactUomLabel( + shortDesc?: string | null, + fullDesc?: string | null, + code?: string | null, +): string { + const short = shortDesc?.trim(); + if (short) return short; + const full = fullDesc?.trim() ?? ""; + if (isCompactUnitLabel(full)) return full; + const unitCode = code?.trim() ?? ""; + if (isCompactUnitLabel(unitCode)) return unitCode; + return ""; +} + +function normUnitKey(...parts: Array): string { + return parts.map((p) => p?.trim().toLowerCase()).find((p) => p) ?? ""; +} + +/** Prefer UoM short desc (箱). Do not return long packing strings like 150克X100包X1箱. */ +export function purchaseUomShortDesc(uom: PurchaseUomLike): string { + return compactUomLabel(uom?.udfShortDesc, uom?.udfudesc, uom?.code); +} + +export function stockUomShortLabel(stockUom: StockUomLike): string { + return compactUomLabel( + stockUom?.stockUomShortDesc, + stockUom?.stockUomDesc, + stockUom?.stockUomCode, + ); +} + +export function purchaseUnitDiffersFromStock( + uom: PurchaseUomLike, + stockUom: StockUomLike, +): boolean { + const purchaseKey = normUnitKey(uom?.code, uom?.udfShortDesc, uom?.udfudesc); + const stockKey = normUnitKey( + stockUom?.stockUomCode, + stockUom?.stockUomShortDesc, + stockUom?.stockUomDesc, + ); + if (!purchaseKey || !stockKey) return false; + return purchaseKey !== stockKey; +} + +export function poLineNeedsStockQtyConversion( + orderQty: number, + orderStockQty: number, + uom: PurchaseUomLike, + stockUom: StockUomLike, +): boolean { + if (purchaseUnitDiffersFromStock(uom, stockUom)) return true; + return ( + Number.isFinite(orderQty) && + Number.isFinite(orderStockQty) && + orderQty > 0 && + orderStockQty > 0 && + Math.abs(orderStockQty - orderQty) > 1e-6 + ); +} + +/** e.g. 384箱 */ +export function formatQtyWithPurchaseUom(qty: number, uom: PurchaseUomLike): string { + const n = integerFormatter.format(qty); + const unit = purchaseUomShortDesc(uom); + return unit ? `${n}${unit}` : n; +} + +/** e.g. 57,600克 */ +export function formatQtyWithStockUom(qty: number, stockUom: StockUomLike): string { + const rounded = Math.round(qty); + const n = + Number.isFinite(qty) && Math.abs(qty - rounded) < 1e-9 + ? integerFormatter.format(rounded) + : decimalFormatter.format(qty); + const unit = stockUomShortLabel(stockUom) || stockUom?.stockUomDesc?.trim() || ""; + return unit ? `${n}${unit}` : n; +} diff --git a/src/i18n/en/purchaseOrder.json b/src/i18n/en/purchaseOrder.json index dd920e44..f75266b5 100644 --- a/src/i18n/en/purchaseOrder.json +++ b/src/i18n/en/purchaseOrder.json @@ -126,6 +126,8 @@ "Please scan warehouse qr code.": "Please scan warehouse QR code.", "receivedQty": "Received Qty", "dnQty": "Delivery Qty (This Batch)", + "dnQtyOrderUnitHint": "in order unit", + "stockQtyRef": "Stock", "Accept submit": "Accept Delivery", "qc processing": "Delivery & QC Processing", "putaway processing": "Delivery & Put Away Processing", diff --git a/src/i18n/zh/purchaseOrder.json b/src/i18n/zh/purchaseOrder.json index 0cac29af..99664477 100644 --- a/src/i18n/zh/purchaseOrder.json +++ b/src/i18n/zh/purchaseOrder.json @@ -126,6 +126,8 @@ "Please scan warehouse qr code.": "請掃描倉庫 QR 碼。", "receivedQty": "已來貨數量", "dnQty": "本批來貨數量", + "dnQtyOrderUnitHint": "以訂單單位計算", + "stockQtyRef": "庫存", "Accept submit": "接受來貨", "qc processing": "處理來貨及品檢", "putaway processing": "處理來貨及上架", From 2fd39d6b967ceac05077ec502515c0750d4bdccc Mon Sep 17 00:00:00 2001 From: "PC-20260115JRSN\\Administrator" Date: Fri, 18 Sep 2026 10:53:15 +0800 Subject: [PATCH 05/24] fixing the input field overlap words problem in stock in po --- src/components/PoDetail/PoDetailRow.tsx | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/components/PoDetail/PoDetailRow.tsx b/src/components/PoDetail/PoDetailRow.tsx index 0118fbb0..5bfdfb3e 100644 --- a/src/components/PoDetail/PoDetailRow.tsx +++ b/src/components/PoDetail/PoDetailRow.tsx @@ -329,10 +329,22 @@ export const PoDetailRow = memo(function PoDetailRow({ onChange={(e) => setDnQtyInput(e.target.value.replace(/[^\d]/g, ""))} onBlur={() => onInputBlur(row.id, lotNoInput, dnQtyInput)} onClick={(e) => e.stopPropagation()} - sx={{ minWidth: 132, width: 148, flexShrink: 0 }} + sx={{ + minWidth: 168, + width: 168, + flexShrink: 0, + "& .MuiInputLabel-root": { + maxWidth: "calc(100% - 44px)", + }, + "& .MuiInputBase-input": { + pr: 0.5, + }, + }} + InputLabelProps={{ shrink: true }} InputProps={{ + notched: true, endAdornment: uomShort ? ( - + Date: Fri, 18 Sep 2026 10:55:31 +0800 Subject: [PATCH 06/24] align the calculation of unit with stock in line data create calculation --- src/app/api/po/index.ts | 3 + src/components/PoDetail/PoDetailRow.tsx | 2 + src/components/PoDetail/stockQtyRound.ts | 85 +++++++++++++++++++++++- 3 files changed, 87 insertions(+), 3 deletions(-) diff --git a/src/app/api/po/index.ts b/src/app/api/po/index.ts index ac6dc583..e20cb25f 100644 --- a/src/app/api/po/index.ts +++ b/src/app/api/po/index.ts @@ -60,6 +60,9 @@ export interface StockUomForPoLine { stockRatioD: number; purchaseRatioN: number; purchaseRatioD: number; + sourceRatioN?: number | null; + sourceRatioD?: number | null; + stockQtyInteger?: boolean | null; } // DEPRECIATED diff --git a/src/components/PoDetail/PoDetailRow.tsx b/src/components/PoDetail/PoDetailRow.tsx index 5bfdfb3e..d16c5259 100644 --- a/src/components/PoDetail/PoDetailRow.tsx +++ b/src/components/PoDetail/PoDetailRow.tsx @@ -117,6 +117,7 @@ export const PoDetailRow = memo(function PoDetailRow({ orderQty, Number(row.stockUom?.stockQty ?? 0), acceptedQty, + row.stockUom, ); const doSubmit = () => { @@ -211,6 +212,7 @@ export const PoDetailRow = memo(function PoDetailRow({ Number(row.qty ?? 0), Number(row.stockUom?.stockQty ?? 0), enteredBatchQty, + row.stockUom, ); const convertedStockQtyWithUnit = formatQtyWithStockUom( convertedStockQty, diff --git a/src/components/PoDetail/stockQtyRound.ts b/src/components/PoDetail/stockQtyRound.ts index f3dcab3a..c2d066b6 100644 --- a/src/components/PoDetail/stockQtyRound.ts +++ b/src/components/PoDetail/stockQtyRound.ts @@ -7,16 +7,95 @@ export type StockQtyRoundChoice = { after: number; }; -/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.4 | 2026-09-10 */ +/** Keep in sync with ItemUomService.isIntegerCountStockUom */ +const INTEGER_COUNT_UNIT_TOKENS = new Set([ + "包", + "箱", + "件", + "個", + "PCS", + "PC", + "CTN", + "EA", + "PK", + "PKT", + "BOX", +]); + +export type PoStockQtyConvertHint = { + sourceRatioN?: number | null; + sourceRatioD?: number | null; + stockRatioN?: number | null; + stockRatioD?: number | null; + purchaseRatioN?: number | null; + purchaseRatioD?: number | null; + stockUomCode?: string | null; + stockUomShortDesc?: string | null; + stockQtyInteger?: boolean | null; +}; + +function toRatio(value: number | null | undefined): number | null { + const n = Number(value); + if (!Number.isFinite(n) || n === 0) return null; + return n; +} + +function stockQtyMustBeInteger(hint?: PoStockQtyConvertHint): boolean { + if (hint?.stockQtyInteger === true) return true; + if (hint?.stockQtyInteger === false) return false; + const code = hint?.stockUomCode?.trim() ?? ""; + if (code.toUpperCase().startsWith("PCS/CTN")) return true; + const short = hint?.stockUomShortDesc?.trim() ?? ""; + return INTEGER_COUNT_UNIT_TOKENS.has(short) || INTEGER_COUNT_UNIT_TOKENS.has(code.toUpperCase()); +} + +/** Java BigDecimal HALF_UP for non-negative qty. */ +function roundHalfUp(value: number, scale: number): number { + const factor = 10 ** scale; + return Math.round(value * factor) / factor; +} + +function finalizePoStockQty(raw: number, hint?: PoStockQtyConvertHint): number { + if (!Number.isFinite(raw)) return 0; + return stockQtyMustBeInteger(hint) ? roundHalfUp(raw, 0) : roundHalfUp(raw, 2); +} + +/** + * Same ratio path as backend convertQtyToStockQtyPrecise: + * base = qty * sourceRatioN / sourceRatioD + * stock = base * stockRatioD / stockRatioN + */ +function convertPoBatchToStockQty( + batchM18Qty: number, + hint?: PoStockQtyConvertHint, +): number | null { + if (!hint || !Number.isFinite(batchM18Qty)) return null; + const sourceN = toRatio(hint.sourceRatioN) ?? toRatio(hint.purchaseRatioN); + const sourceD = toRatio(hint.sourceRatioD) ?? toRatio(hint.purchaseRatioD); + const stockN = toRatio(hint.stockRatioN); + const stockD = toRatio(hint.stockRatioD); + if (sourceN == null || sourceD == null || stockN == null || stockD == null) return null; + const baseQty = (batchM18Qty * sourceN) / sourceD; + const stockQty = (baseQty * stockD) / stockN; + return finalizePoStockQty(stockQty, hint); +} + +/** + * Preview converted stock qty for a 來貨數 batch. + * Matches create-stock-in: ratio convert, then integer HALF_UP for 包/箱/PCS, else 2 decimals. + */ export function previewPoBatchStockQty( orderM18Qty: number, orderStockQty: number, batchM18Qty: number, + hint?: PoStockQtyConvertHint, ): number { + const fromRatios = convertPoBatchToStockQty(batchM18Qty, hint); + if (fromRatios != null) return fromRatios; if (!Number.isFinite(orderM18Qty) || orderM18Qty === 0) { - return Number(batchM18Qty.toFixed(2)); + return finalizePoStockQty(batchM18Qty, hint); } - return Number(((batchM18Qty * orderStockQty) / orderM18Qty).toFixed(2)); + return finalizePoStockQty((batchM18Qty * orderStockQty) / orderM18Qty, hint); } export function isNotIntegerQty(qty: number): boolean { From da1a0889c53c936e5f39d2ebbf5f5e6b3aadcd64 Mon Sep 17 00:00:00 2001 From: "PC-20260115JRSN\\Administrator" Date: Fri, 18 Sep 2026 14:35:57 +0800 Subject: [PATCH 07/24] added paste item code to some reports --- .../report/SemiFGProductionAnalysisReport.tsx | 12 ++-- src/app/(main)/report/bomShopSyncReportApi.ts | 12 ++-- src/app/(main)/report/grnReportApi.ts | 14 +++-- src/app/(main)/report/page.tsx | 37 ++++++++--- src/app/(main)/report/parseItemCodeTokens.ts | 45 ++++++++----- .../report/semiFGProductionAnalysisApi.ts | 23 ++++--- src/components/PoSearch/PoSearch.tsx | 63 ++++++++++++------- src/config/reportConfig.ts | 26 +++++--- src/i18n/en/report.json | 42 +++++++++++-- src/i18n/zh/report.json | 42 +++++++++++-- 10 files changed, 229 insertions(+), 87 deletions(-) diff --git a/src/app/(main)/report/SemiFGProductionAnalysisReport.tsx b/src/app/(main)/report/SemiFGProductionAnalysisReport.tsx index 5592a93c..f676ba66 100644 --- a/src/app/(main)/report/SemiFGProductionAnalysisReport.tsx +++ b/src/app/(main)/report/SemiFGProductionAnalysisReport.tsx @@ -26,6 +26,7 @@ import { generateSemiFGProductionAnalysisReportExcel, ItemCodeWithCategory, } from './semiFGProductionAnalysisApi'; +import { parseItemCodeTokens } from './parseItemCodeTokens'; interface SemiFGProductionAnalysisReportProps { criteria: Record; @@ -76,16 +77,15 @@ export default function SemiFGProductionAnalysisReport({ return; } - // If no itemCode is selected, export directly without confirmation - if (!criteria.itemCode) { + const selectedCodes = parseItemCodeTokens( + [criteria.itemCode, criteria.itemCodePaste].filter(Boolean).join(' '), + ); + if (selectedCodes.length === 0) { await executeExport(format); return; } - // If itemCode is selected, show confirmation dialog - const selectedCodes = criteria.itemCode.split(',').filter((code) => code.trim()); - const itemCodesInfo: ItemCodeWithCategory[] = selectedCodes.map((code) => { - const codeTrimmed = code.trim(); + const itemCodesInfo: ItemCodeWithCategory[] = selectedCodes.map((codeTrimmed) => { const categoryInfo = itemCodesWithCategory[codeTrimmed]; return { code: codeTrimmed, diff --git a/src/app/(main)/report/bomShopSyncReportApi.ts b/src/app/(main)/report/bomShopSyncReportApi.ts index 08b31c48..d3eee465 100644 --- a/src/app/(main)/report/bomShopSyncReportApi.ts +++ b/src/app/(main)/report/bomShopSyncReportApi.ts @@ -2,6 +2,7 @@ import { NEXT_PUBLIC_API_URL } from "@/config/api"; import { clientAuthFetch } from "@/app/utils/clientAuthFetch"; +import { buildItemCodePasteRequestBody } from "./parseItemCodeTokens"; import { exportMultiSheetToXlsx, } from "@/app/(main)/chart/_components/exportChartToXlsx"; @@ -124,12 +125,15 @@ function emptyMaterialSheetRow( export async function fetchBomShopSyncReportData( criteria: Record, ): Promise { - const queryParams = new URLSearchParams(criteria).toString(); - const url = `${NEXT_PUBLIC_API_URL}/report/bom-shop-sync-history?${queryParams}`; + const url = `${NEXT_PUBLIC_API_URL}/report/bom-shop-sync-history`; const response = await clientAuthFetch(url, { - method: "GET", - headers: { Accept: "application/json" }, + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + }, + body: JSON.stringify(buildItemCodePasteRequestBody(criteria, "finishedItemCode")), }); if (response.status === 401 || response.status === 403) diff --git a/src/app/(main)/report/grnReportApi.ts b/src/app/(main)/report/grnReportApi.ts index a8972cec..2e2f001f 100644 --- a/src/app/(main)/report/grnReportApi.ts +++ b/src/app/(main)/report/grnReportApi.ts @@ -1,6 +1,7 @@ "use client"; import { NEXT_PUBLIC_API_URL } from "@/config/api"; +import { buildItemCodePasteRequestBody } from './parseItemCodeTokens'; import { clientAuthFetch } from "@/app/utils/clientAuthFetch"; import { exportChartToXlsx, @@ -64,17 +65,20 @@ export interface GrnReportResponse { /** * Fetch GRN (Goods Received Note) report data by date range. - * Backend: GET /report/grn-report?receiptDateStart=&receiptDateEnd=&itemCode= + * Backend: POST /report/grn-report { receiptDateStart, receiptDateEnd, itemCodes } */ export async function fetchGrnReportData( criteria: Record ): Promise<{ rows: GrnReportRow[]; listedPoAmounts?: ListedPoAmounts }> { - const queryParams = new URLSearchParams(criteria).toString(); - const url = `${NEXT_PUBLIC_API_URL}/report/grn-report?${queryParams}`; + const url = `${NEXT_PUBLIC_API_URL}/report/grn-report`; const response = await clientAuthFetch(url, { - method: "GET", - headers: { Accept: "application/json" }, + method: "POST", + headers: { + Accept: "application/json", + "Content-Type": "application/json", + }, + body: JSON.stringify(buildItemCodePasteRequestBody(criteria, "itemCode")), }); if (response.status === 401 || response.status === 403) diff --git a/src/app/(main)/report/page.tsx b/src/app/(main)/report/page.tsx index dce43d73..89f442e8 100644 --- a/src/app/(main)/report/page.tsx +++ b/src/app/(main)/report/page.tsx @@ -26,7 +26,7 @@ import { import DownloadIcon from '@mui/icons-material/Download'; import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'; import { REPORTS } from '@/config/reportConfig'; -import { mergePastedItemCodes, buildStockBalanceRequestBody } from './parseItemCodeTokens'; +import { mergePastedItemCodes, buildItemCodePasteRequestBody } from './parseItemCodeTokens'; import { NEXT_PUBLIC_API_URL } from '@/config/api'; import { clientAuthFetch } from '@/app/utils/clientAuthFetch'; import SemiFGProductionAnalysisReport from './SemiFGProductionAnalysisReport'; @@ -75,6 +75,15 @@ const FIELD_ERROR_SX = { }, }; +const ITEM_CODE_PASTE_POST_REPORTS = new Set([ + 'rep-004', + 'rep-006', + 'rep-007', + 'rep-008', + 'rep-011', + 'rep-013', +]); + /** FP-MTMS Version Checklist | Functions Ref. No. 39 | v1.0.3 | 2026-09-10 */ /** FP-MTMS Version Checklist | Functions Ref. No. 60 | v1.0.1 | 2026-08-11 */ /** FP-MTMS Version Checklist | Functions Ref. No. 69 | v1.0.2 | 2026-09-10 */ @@ -359,11 +368,19 @@ export default function ReportPage() { return p.toString(); }; + const itemCodeFieldName = (): string => + currentReport?.fields.some((f) => f.name === 'finishedItemCode') + ? 'finishedItemCode' + : 'itemCode'; + + const isItemCodePastePostReport = (): boolean => + !!currentReport && ITEM_CODE_PASTE_POST_REPORTS.has(currentReport.id); + const buildCriteriaQueryString = (): string => { if (!currentReport) return ''; if (currentReport.id === 'rep-012') return buildRep012QueryString(); if (currentReport.id === 'rep-010') return buildRep010QueryString(); - const merged = mergePastedItemCodes(criteria); + const merged = mergePastedItemCodes(criteria, itemCodeFieldName()); const p = new URLSearchParams(merged); if (currentReport.id === 'rep-016') { const day = (merged.dateStart || '').trim(); @@ -416,19 +433,19 @@ export default function ReportPage() { await generateShopOrderReplenishmentReportExcel(criteria, reportTitle(currentReport), t); } else { // Backend returns actual .xlsx bytes for this Excel endpoint. - const isStockBalance = currentReport.id === 'rep-007'; - const excelUrl = isStockBalance + const usesItemCodePastePost = isItemCodePastePostReport(); + const excelUrl = usesItemCodePastePost ? `${currentReport.apiEndpoint}-excel` : `${currentReport.apiEndpoint}-excel?${buildCriteriaQueryString()}`; - const response = await clientAuthFetch(excelUrl, isStockBalance + const response = await clientAuthFetch(excelUrl, usesItemCodePastePost ? { method: 'POST', headers: { Accept: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'Content-Type': 'application/json', }, - body: JSON.stringify(buildStockBalanceRequestBody(criteria)), + body: JSON.stringify(buildItemCodePasteRequestBody(criteria, itemCodeFieldName())), } : { method: 'GET', @@ -485,19 +502,19 @@ export default function ReportPage() { setLoading(true); try { - const isStockBalance = currentReport.id === 'rep-007'; - const url = isStockBalance + const usesItemCodePastePost = isItemCodePastePostReport(); + const url = usesItemCodePastePost ? currentReport.apiEndpoint : `${currentReport.apiEndpoint}?${buildCriteriaQueryString()}`; - const response = await clientAuthFetch(url, isStockBalance + const response = await clientAuthFetch(url, usesItemCodePastePost ? { method: 'POST', headers: { Accept: 'application/pdf', 'Content-Type': 'application/json', }, - body: JSON.stringify(buildStockBalanceRequestBody(criteria)), + body: JSON.stringify(buildItemCodePasteRequestBody(criteria, itemCodeFieldName())), } : { method: 'GET', diff --git a/src/app/(main)/report/parseItemCodeTokens.ts b/src/app/(main)/report/parseItemCodeTokens.ts index 148a08e2..fcddfe79 100644 --- a/src/app/(main)/report/parseItemCodeTokens.ts +++ b/src/app/(main)/report/parseItemCodeTokens.ts @@ -16,32 +16,47 @@ export function parseItemCodeTokens(raw: string | undefined | null): string[] { return tokens; } -/** Merge multi-select `itemCode` with pasted `itemCodePaste`; drop the paste field from API params. */ -export function mergePastedItemCodes(criteria: Record): Record { +export function resolveItemCodeFieldName(criteria: Record): string { + return Object.prototype.hasOwnProperty.call(criteria, "finishedItemCode") + ? "finishedItemCode" + : "itemCode"; +} + +/** Merge multi-select item codes with pasted `itemCodePaste`; drop the paste field from API params. */ +export function mergePastedItemCodes( + criteria: Record, + codeField = resolveItemCodeFieldName(criteria), +): Record { const next: Record = { ...criteria }; delete next.itemCodePaste; const merged = parseItemCodeTokens( - [criteria.itemCode, criteria.itemCodePaste].filter(Boolean).join(" "), + [criteria[codeField], criteria.itemCodePaste].filter(Boolean).join(" "), ); if (merged.length > 0) { - next.itemCode = merged.join(","); + next[codeField] = merged.join(","); } else { - delete next.itemCode; + delete next[codeField]; } return next; } -/** POST body for 庫存結餘報告 so pasted codes are not limited by URL length. */ -export function buildStockBalanceRequestBody(criteria: Record): { - stockDate?: string; - itemCodes?: string[]; -} { +/** POST body so pasted codes are not limited by URL length. */ +export function buildItemCodePasteRequestBody( + criteria: Record, + codeField = resolveItemCodeFieldName(criteria), +): Record { const itemCodes = parseItemCodeTokens( - [criteria.itemCode, criteria.itemCodePaste].filter(Boolean).join(" "), + [criteria[codeField], criteria.itemCodePaste].filter(Boolean).join(" "), ); - const body: { stockDate?: string; itemCodes?: string[] } = {}; - const stockDate = criteria.stockDate?.trim(); - if (stockDate) body.stockDate = stockDate; - if (itemCodes.length) body.itemCodes = itemCodes; + const body: Record = {}; + for (const [key, value] of Object.entries(criteria)) { + if (key === "itemCodePaste" || key === codeField) continue; + const trimmed = value?.trim(); + if (trimmed) body[key] = trimmed; + } + if (itemCodes.length) { + body[codeField] = itemCodes.join(","); + body.itemCodes = itemCodes; + } return body; } diff --git a/src/app/(main)/report/semiFGProductionAnalysisApi.ts b/src/app/(main)/report/semiFGProductionAnalysisApi.ts index b4e8b69c..e77636e5 100644 --- a/src/app/(main)/report/semiFGProductionAnalysisApi.ts +++ b/src/app/(main)/report/semiFGProductionAnalysisApi.ts @@ -2,6 +2,7 @@ import { NEXT_PUBLIC_API_URL } from '@/config/api'; import { clientAuthFetch } from '@/app/utils/clientAuthFetch'; +import { buildItemCodePasteRequestBody } from './parseItemCodeTokens'; export interface ItemCodeWithName { code: string; @@ -72,12 +73,15 @@ export const generateSemiFGProductionAnalysisReport = async ( criteria: Record, reportTitle: string = '成品/半成品生產分析報告' ): Promise => { - const queryParams = new URLSearchParams(criteria).toString(); - const url = `${NEXT_PUBLIC_API_URL}/report/print-semi-fg-production-analysis?${queryParams}`; + const url = `${NEXT_PUBLIC_API_URL}/report/print-semi-fg-production-analysis`; const response = await clientAuthFetch(url, { - method: 'GET', - headers: { Accept: 'application/pdf' }, + method: 'POST', + headers: { + Accept: 'application/pdf', + 'Content-Type': 'application/json', + }, + body: JSON.stringify(buildItemCodePasteRequestBody(criteria, 'itemCode')), }); if (response.status === 401 || response.status === 403) throw new Error("Unauthorized"); @@ -111,12 +115,15 @@ export const generateSemiFGProductionAnalysisReportExcel = async ( criteria: Record, reportTitle: string = '成品/半成品生產分析報告' ): Promise => { - const queryParams = new URLSearchParams(criteria).toString(); - const url = `${NEXT_PUBLIC_API_URL}/report/print-semi-fg-production-analysis-excel?${queryParams}`; + const url = `${NEXT_PUBLIC_API_URL}/report/print-semi-fg-production-analysis-excel`; const response = await clientAuthFetch(url, { - method: 'GET', - headers: { Accept: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet' }, + method: 'POST', + headers: { + Accept: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', + 'Content-Type': 'application/json', + }, + body: JSON.stringify(buildItemCodePasteRequestBody(criteria, 'itemCode')), }); if (response.status === 401 || response.status === 403) throw new Error('Unauthorized'); diff --git a/src/components/PoSearch/PoSearch.tsx b/src/components/PoSearch/PoSearch.tsx index 45294d56..5d28527e 100644 --- a/src/components/PoSearch/PoSearch.tsx +++ b/src/components/PoSearch/PoSearch.tsx @@ -305,34 +305,45 @@ const PoSearch: React.FC = ({ const res = await baseListResp.json(); if (!res) return; - if (res.records && res.records.length > 0) { - setFilteredPo(res.records); - setTotalCount(res.total); - return; - } - + const records: PoResult[] = res.records ?? []; const searchedCodeRaw = (filterArgs as any)?.code; const searchedCode = typeof searchedCodeRaw === "string" ? searchedCodeRaw.trim() : ""; - - const shouldAutoSyncFromM18 = + const isM18PoCode = searchedCode.length > 14 && (searchedCode.startsWith("PP") || searchedCode.startsWith("PF")); + const hasLocalPending = records.some( + (row) => String(row.status ?? "").toLowerCase() === "pending", + ); + const shouldLookupMissing = records.length === 0 && isM18PoCode; + const shouldRefreshPending = hasLocalPending && isM18PoCode; - if (!shouldAutoSyncFromM18 || autoSyncInProgressRef.current) { - setFilteredPo(res.records); + if ( + (!shouldLookupMissing && !shouldRefreshPending) || + autoSyncInProgressRef.current + ) { + setFilteredPo(records); setTotalCount(res.total); return; } + if (shouldRefreshPending) { + setFilteredPo(records); + setTotalCount(res.total); + } + try { autoSyncInProgressRef.current = true; - setIsM18LookupLoading(true); - setAutoSyncStatus("正在從M18找尋PO..."); + setIsM18LookupLoading(shouldLookupMissing); + setAutoSyncStatus( + shouldLookupMissing + ? "正在從M18找尋PO..." + : "正在檢查M18是否有更新...", + ); const syncResp = await clientAuthFetch( `${NEXT_PUBLIC_API_URL}/m18/test/po-by-code?code=${encodeURIComponent( searchedCode, - )}`, + )}&ifNewer=true`, { method: "GET" }, ); @@ -350,8 +361,13 @@ const PoSearch: React.FC = ({ } const syncOk = Boolean(syncJson?.totalSuccess && syncJson.totalSuccess > 0); + const skippedIfNewer = String(syncJson?.query ?? "").includes( + "skipped (ifNewer)", + ); if (syncOk) { - setAutoSyncStatus("成功找到PO"); + setAutoSyncStatus( + shouldLookupMissing ? "成功找到PO" : "已從M18更新PO", + ); const listResp = await clientAuthFetch( `${NEXT_PUBLIC_API_URL}/po/list?${new URLSearchParams( @@ -363,21 +379,24 @@ const PoSearch: React.FC = ({ const listJson = await listResp.json(); setFilteredPo(listJson.records ?? []); setTotalCount(listJson.total ?? 0); - setAutoSyncStatus("成功找到PO"); + setAutoSyncStatus( + shouldLookupMissing ? "成功找到PO" : "已從M18更新PO", + ); return; } - setAutoSyncStatus("找不到PO"); + setAutoSyncStatus(shouldLookupMissing ? "找不到PO" : null); + } else if (skippedIfNewer || shouldRefreshPending) { + setAutoSyncStatus(null); } else { setAutoSyncStatus("找不到PO"); } - // Ensure UI updates even if sync didn't change results - setFilteredPo(res.records); + setFilteredPo(records); setTotalCount(res.total ?? 0); } catch (e) { console.error("Auto sync error:", e); - setAutoSyncStatus("找不到PO"); - setFilteredPo(res.records); + setAutoSyncStatus(shouldLookupMissing ? "找不到PO" : null); + setFilteredPo(records); setTotalCount(res.total ?? 0); } finally { setIsM18LookupLoading(false); @@ -481,7 +500,9 @@ const PoSearch: React.FC = ({ sx={{ color: "#fff", zIndex: (theme) => theme.zIndex.modal + 1, flexDirection: "column", gap: 1 }} > - 正在從M18找尋PO... + + {autoSyncStatus || "正在從M18找尋PO..."} + diff --git a/src/config/reportConfig.ts b/src/config/reportConfig.ts index f34bcd93..f60a290a 100644 --- a/src/config/reportConfig.ts +++ b/src/config/reportConfig.ts @@ -57,6 +57,15 @@ const asyncItemCodeField = ( placeholder: "e.g. FA0591", }); +const pasteItemCodeField = (): ReportField => ({ + label: "貼上貨品編號 Paste Item Codes", + name: "itemCodePaste", + type: "text", + required: false, + multiline: true, + minRows: 4, +}); + export const REPORTS: ReportDefinition[] = [ //{ // id: "rep-001", @@ -109,6 +118,7 @@ export const REPORTS: ReportDefinition[] = [ { label: "入倉日期:由 Last In Date Start", name: "lastInDateStart", type: "date", required: false }, { label: "入倉日期:至 Last In Date End", name: "lastInDateEnd", type: "date", required: false }, asyncItemCodeField(), + pasteItemCodeField(), { label: "樓層 Store ID", name: "storeId", @@ -148,6 +158,7 @@ export const REPORTS: ReportDefinition[] = [ { label: "出貨日期:至 Last Out Date End", name: "lastOutDateEnd", type: "date", required: false }, { label: "年份 Year", name: "year", type: "text", required: false, placeholder: "e.g. 2026" }, asyncItemCodeField(), + pasteItemCodeField(), ] }, /* @@ -302,6 +313,7 @@ export const REPORTS: ReportDefinition[] = [ { label: "庫存日期:由 Last In Date Start", name: "lastInDateStart", type: "date", required: false }, { label: "庫存日期:至 Last In Date End", name: "lastInDateEnd", type: "date", required: false }, asyncItemCodeField(), + pasteItemCodeField(), ] }, /* Hidden for now: 庫存流水帳報告 (rep-020) @@ -344,14 +356,7 @@ export const REPORTS: ReportDefinition[] = [ fields: [ { label: "庫存日期: Stock Date", name: "stockDate", type: "date", required: true }, asyncItemCodeField(), - { - label: "貼上貨品編號 Paste Item Codes", - name: "itemCodePaste", - type: "text", - required: false, - multiline: true, - minRows: 4, - }, + pasteItemCodeField(), ] }, @@ -365,6 +370,7 @@ export const REPORTS: ReportDefinition[] = [ { label: "收貨日期:由 Receipt Date Start", name: "receiptDateStart", type: "date", required: false }, { label: "收貨日期:至 Receipt Date End", name: "receiptDateEnd", type: "date", required: false }, asyncItemCodeField(), + pasteItemCodeField(), ], }, @@ -417,6 +423,7 @@ export const REPORTS: ReportDefinition[] = [ { label: "出倉日期:由 Last Out Date Start", name: "lastOutDateStart", type: "date", required: false }, { label: "出倉日期:至 Last Out Date End", name: "lastOutDateEnd", type: "date", required: false }, asyncItemCodeField(), + pasteItemCodeField(), { label: "提料人 Handler", name: "handler", type: "select", required: false, multiple: true, dynamicOptions: true, @@ -449,6 +456,7 @@ export const REPORTS: ReportDefinition[] = [ dynamicOptionsEndpoint: `${NEXT_PUBLIC_API_URL}/report/stock-item-code-prefixes`, dynamicOptionsParam: "stockCategory", options: [] }, + pasteItemCodeField(), ] }, @@ -475,6 +483,7 @@ export const REPORTS: ReportDefinition[] = [ dynamicOptionsEndpoint: `${NEXT_PUBLIC_API_URL}/report/semi-fg-item-codes`, dynamicOptionsParam: "stockCategory", options: [] }, + pasteItemCodeField(), ] }, { @@ -486,6 +495,7 @@ export const REPORTS: ReportDefinition[] = [ { label: "同步日期:由 Sync Date Start", name: "syncDateStart", type: "date", required: false }, { label: "同步日期:至 Sync Date End", name: "syncDateEnd", type: "date", required: false }, asyncItemCodeField("成品貨號 Finished Item Code", "finishedItemCode"), + pasteItemCodeField(), { label: "同步狀態 Sync Status", name: "syncStatus", diff --git a/src/i18n/en/report.json b/src/i18n/en/report.json index eb761d48..a9558ab7 100644 --- a/src/i18n/en/report.json +++ b/src/i18n/en/report.json @@ -52,6 +52,7 @@ "lastInDateStart": "Last In Date Start", "lastInDateEnd": "Last In Date End", "itemCode": "Item Code", + "itemCodePaste": "Paste Item Codes", "storeId": "Floor", "warehouse": "Warehouse", "area": "Area", @@ -68,6 +69,9 @@ "PP": "PP", "PF": "PF" } + }, + "fieldHints": { + "itemCodePaste": "Paste item codes from Excel. Separate with spaces, commas, or new lines" } }, "rep-008": { @@ -76,7 +80,11 @@ "lastOutDateStart": "Last Out Date Start", "lastOutDateEnd": "Last Out Date End", "year": "Year", - "itemCode": "Item Code" + "itemCode": "Item Code", + "itemCodePaste": "Paste Item Codes" + }, + "fieldHints": { + "itemCodePaste": "Paste item codes from Excel. Separate with spaces, commas, or new lines" } }, "rep-012": { @@ -115,7 +123,11 @@ "fields": { "lastInDateStart": "Stock Date Start", "lastInDateEnd": "Stock Date End", - "itemCode": "Item Code" + "itemCode": "Item Code", + "itemCodePaste": "Paste Item Codes" + }, + "fieldHints": { + "itemCodePaste": "Paste item codes from Excel. Separate with spaces, commas, or new lines" } }, "rep-007": { @@ -134,7 +146,11 @@ "fields": { "receiptDateStart": "Receipt Date Start", "receiptDateEnd": "Receipt Date End", - "itemCode": "Item Code" + "itemCode": "Item Code", + "itemCodePaste": "Paste Item Codes" + }, + "fieldHints": { + "itemCodePaste": "Paste item codes from Excel. Separate with spaces, commas, or new lines" } }, "rep-009": { @@ -173,7 +189,11 @@ "lastOutDateStart": "Last Out Date Start", "lastOutDateEnd": "Last Out Date End", "itemCode": "Item Code", + "itemCodePaste": "Paste Item Codes", "handler": "Handler" + }, + "fieldHints": { + "itemCodePaste": "Paste item codes from Excel. Separate with spaces, commas, or new lines" } }, "rep-006": { @@ -183,7 +203,11 @@ "lastOutDateEnd": "Consumption Date End", "year": "Year", "stockCategory": "Category", - "itemCode": "Item Code" + "itemCode": "Item Code", + "itemCodePaste": "Paste Item Codes" + }, + "fieldHints": { + "itemCodePaste": "Paste item codes from Excel. Separate with spaces, commas, or new lines" } }, "rep-005": { @@ -193,7 +217,11 @@ "lastOutDateEnd": "Production Complete Date End", "year": "Year", "stockCategory": "Category", - "itemCode": "Item Code" + "itemCode": "Item Code", + "itemCodePaste": "Paste Item Codes" + }, + "fieldHints": { + "itemCodePaste": "Paste item codes from Excel. Separate with spaces, commas, or new lines" } }, "rep-015": { @@ -202,8 +230,12 @@ "syncDateStart": "Sync Date Start", "syncDateEnd": "Sync Date End", "finishedItemCode": "Finished Item Code", + "itemCodePaste": "Paste Item Codes", "syncStatus": "Sync Status" }, + "fieldHints": { + "itemCodePaste": "Paste item codes from Excel. Separate with spaces, commas, or new lines" + }, "options": { "syncStatus": { "all": "All", diff --git a/src/i18n/zh/report.json b/src/i18n/zh/report.json index c0de47f6..86517558 100644 --- a/src/i18n/zh/report.json +++ b/src/i18n/zh/report.json @@ -52,6 +52,7 @@ "lastInDateStart": "入倉日期:由", "lastInDateEnd": "入倉日期:至", "itemCode": "貨品編號", + "itemCodePaste": "貼上貨品編號", "storeId": "樓層", "warehouse": "倉庫", "area": "區域", @@ -68,6 +69,9 @@ "PP": "PP", "PF": "PF" } + }, + "fieldHints": { + "itemCodePaste": "可從 Excel 貼上多個貨品編號,以空格、逗號或換行分隔" } }, "rep-008": { @@ -76,7 +80,11 @@ "lastOutDateStart": "出貨日期:由", "lastOutDateEnd": "出貨日期:至", "year": "年份", - "itemCode": "貨品編號" + "itemCode": "貨品編號", + "itemCodePaste": "貼上貨品編號" + }, + "fieldHints": { + "itemCodePaste": "可從 Excel 貼上多個貨品編號,以空格、逗號或換行分隔" } }, "rep-012": { @@ -115,7 +123,11 @@ "fields": { "lastInDateStart": "庫存日期:由", "lastInDateEnd": "庫存日期:至", - "itemCode": "貨品編號" + "itemCode": "貨品編號", + "itemCodePaste": "貼上貨品編號" + }, + "fieldHints": { + "itemCodePaste": "可從 Excel 貼上多個貨品編號,以空格、逗號或換行分隔" } }, "rep-007": { @@ -134,7 +146,11 @@ "fields": { "receiptDateStart": "收貨日期:由", "receiptDateEnd": "收貨日期:至", - "itemCode": "貨品編號" + "itemCode": "貨品編號", + "itemCodePaste": "貼上貨品編號" + }, + "fieldHints": { + "itemCodePaste": "可從 Excel 貼上多個貨品編號,以空格、逗號或換行分隔" } }, "rep-009": { @@ -173,7 +189,11 @@ "lastOutDateStart": "出倉日期:由", "lastOutDateEnd": "出倉日期:至", "itemCode": "貨品編號", + "itemCodePaste": "貼上貨品編號", "handler": "提料人" + }, + "fieldHints": { + "itemCodePaste": "可從 Excel 貼上多個貨品編號,以空格、逗號或換行分隔" } }, "rep-006": { @@ -183,7 +203,11 @@ "lastOutDateEnd": "材料消耗日期:至", "year": "年份", "stockCategory": "類別", - "itemCode": "貨品編號" + "itemCode": "貨品編號", + "itemCodePaste": "貼上貨品編號" + }, + "fieldHints": { + "itemCodePaste": "可從 Excel 貼上多個貨品編號,以空格、逗號或換行分隔" } }, "rep-005": { @@ -193,7 +217,11 @@ "lastOutDateEnd": "完成生產日期:至", "year": "年份", "stockCategory": "類別", - "itemCode": "貨品編號" + "itemCode": "貨品編號", + "itemCodePaste": "貼上貨品編號" + }, + "fieldHints": { + "itemCodePaste": "可從 Excel 貼上多個貨品編號,以空格、逗號或換行分隔" } }, "rep-015": { @@ -202,8 +230,12 @@ "syncDateStart": "同步日期:由", "syncDateEnd": "同步日期:至", "finishedItemCode": "成品貨號", + "itemCodePaste": "貼上貨品編號", "syncStatus": "同步狀態" }, + "fieldHints": { + "itemCodePaste": "可從 Excel 貼上多個貨品編號,以空格、逗號或換行分隔" + }, "options": { "syncStatus": { "all": "全部", From 0ed8b42c8e7551f70c1375dac72e94b5e4e5ea03 Mon Sep 17 00:00:00 2001 From: "PC-20260115JRSN\\Administrator" Date: Fri, 18 Sep 2026 16:16:17 +0800 Subject: [PATCH 08/24] added a sync for stock in PO, when entered poNum and status = pending, and also the database settings M18.po.stockIn.refreshIfNewer.enabled = true (liquidbase default is false), then ask m18 to sync with lastModified after MTMS PO modified datetime --- src/components/PoSearch/PoSearch.tsx | 114 ++++++--------------------- 1 file changed, 22 insertions(+), 92 deletions(-) diff --git a/src/components/PoSearch/PoSearch.tsx b/src/components/PoSearch/PoSearch.tsx index 5d28527e..0d82819c 100644 --- a/src/components/PoSearch/PoSearch.tsx +++ b/src/components/PoSearch/PoSearch.tsx @@ -294,117 +294,47 @@ const PoSearch: React.FC = ({ if (typeof v === "string" && (v as string).trim() === "") return; cleanedQuery[k] = String(v); }); - try { - const baseListResp = await clientAuthFetch( - `${NEXT_PUBLIC_API_URL}/po/list?${new URLSearchParams(cleanedQuery).toString()}`, - { method: "GET" }, - ); - if (!baseListResp.ok) { - throw new Error(`PO list fetch failed: ${baseListResp.status}`); - } - const res = await baseListResp.json(); - if (!res) return; - - const records: PoResult[] = res.records ?? []; const searchedCodeRaw = (filterArgs as any)?.code; const searchedCode = typeof searchedCodeRaw === "string" ? searchedCodeRaw.trim() : ""; const isM18PoCode = searchedCode.length > 14 && (searchedCode.startsWith("PP") || searchedCode.startsWith("PF")); - const hasLocalPending = records.some( - (row) => String(row.status ?? "").toLowerCase() === "pending", - ); - const shouldLookupMissing = records.length === 0 && isM18PoCode; - const shouldRefreshPending = hasLocalPending && isM18PoCode; - - if ( - (!shouldLookupMissing && !shouldRefreshPending) || - autoSyncInProgressRef.current - ) { - setFilteredPo(records); - setTotalCount(res.total); - return; - } - - if (shouldRefreshPending) { - setFilteredPo(records); - setTotalCount(res.total); + if (isM18PoCode) { + cleanedQuery.refreshFromM18 = "true"; + setIsM18LookupLoading(true); + setAutoSyncStatus("載入中..."); } try { - autoSyncInProgressRef.current = true; - setIsM18LookupLoading(shouldLookupMissing); - setAutoSyncStatus( - shouldLookupMissing - ? "正在從M18找尋PO..." - : "正在檢查M18是否有更新...", - ); - const syncResp = await clientAuthFetch( - `${NEXT_PUBLIC_API_URL}/m18/test/po-by-code?code=${encodeURIComponent( - searchedCode, - )}&ifNewer=true`, + const baseListResp = await clientAuthFetch( + `${NEXT_PUBLIC_API_URL}/po/list?${new URLSearchParams(cleanedQuery).toString()}`, { method: "GET" }, ); - - if (!syncResp.ok) { - throw new Error(`M18 sync failed: ${syncResp.status}`); - } - - let syncJson: any = null; - try { - syncJson = await syncResp.json(); - } catch { - // Some endpoints may respond with plain text - const txt = await syncResp.text(); - syncJson = { raw: txt }; - } - - const syncOk = Boolean(syncJson?.totalSuccess && syncJson.totalSuccess > 0); - const skippedIfNewer = String(syncJson?.query ?? "").includes( - "skipped (ifNewer)", - ); - if (syncOk) { - setAutoSyncStatus( - shouldLookupMissing ? "成功找到PO" : "已從M18更新PO", - ); - - const listResp = await clientAuthFetch( - `${NEXT_PUBLIC_API_URL}/po/list?${new URLSearchParams( - cleanedQuery, - ).toString()}`, - { method: "GET" }, - ); - if (listResp.ok) { - const listJson = await listResp.json(); - setFilteredPo(listJson.records ?? []); - setTotalCount(listJson.total ?? 0); - setAutoSyncStatus( - shouldLookupMissing ? "成功找到PO" : "已從M18更新PO", - ); - return; - } - setAutoSyncStatus(shouldLookupMissing ? "找不到PO" : null); - } else if (skippedIfNewer || shouldRefreshPending) { - setAutoSyncStatus(null); - } else { - setAutoSyncStatus("找不到PO"); + if (!baseListResp.ok) { + throw new Error(`PO list fetch failed: ${baseListResp.status}`); } + const res = await baseListResp.json(); + if (!res) return; + const records: PoResult[] = res.records ?? []; setFilteredPo(records); setTotalCount(res.total ?? 0); + if (isM18PoCode) { + const refreshAction = baseListResp.headers.get("X-M18-Po-Refresh"); + if (refreshAction === "synced") { + setAutoSyncStatus(records.length > 0 ? "已從M18同步PO" : "找不到PO"); + } else { + setAutoSyncStatus(null); + } + } } catch (e) { - console.error("Auto sync error:", e); - setAutoSyncStatus(shouldLookupMissing ? "找不到PO" : null); - setFilteredPo(records); - setTotalCount(res.total ?? 0); + console.error("PO list fetch error:", e); + if (isM18PoCode) setAutoSyncStatus("找不到PO"); } finally { setIsM18LookupLoading(false); autoSyncInProgressRef.current = false; } - } catch (e) { - console.error("PO list fetch error:", e); - } }, [], ); @@ -501,7 +431,7 @@ const PoSearch: React.FC = ({ > - {autoSyncStatus || "正在從M18找尋PO..."} + {autoSyncStatus || "載入中..."} From 83eb8df464e2d6b50a2010a3ebbfdd611ef4c266 Mon Sep 17 00:00:00 2001 From: "CANCERYS\\kw093" Date: Fri, 18 Sep 2026 17:51:37 +0800 Subject: [PATCH 09/24] qc detail putawayed qty fix --- src/components/PoDetail/PoDetail.tsx | 2 +- src/components/PoDetail/PoDetailRow.tsx | 2 +- src/components/PoDetail/PoInputGrid.tsx | 2 +- src/components/PoDetail/PutAwayForm.tsx | 13 +++- src/components/PoDetail/QcStockInModal.tsx | 5 +- .../PoDetail/StockInLineRowActions.tsx | 2 +- .../PoDetail/originSilPutAwayQty.ts | 60 +++++++++++++++++++ src/components/PoDetail/stockQtyRound.ts | 5 +- src/components/Qc/QcStockInModal.tsx | 5 +- 9 files changed, 83 insertions(+), 13 deletions(-) create mode 100644 src/components/PoDetail/originSilPutAwayQty.ts diff --git a/src/components/PoDetail/PoDetail.tsx b/src/components/PoDetail/PoDetail.tsx index 993433dc..403cd0c6 100644 --- a/src/components/PoDetail/PoDetail.tsx +++ b/src/components/PoDetail/PoDetail.tsx @@ -207,7 +207,7 @@ interface PolInputResult { dnQty: string, } -/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.4 | 2026-09-10 */ +/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.5 | 2026-09-18 */ const PoDetail: React.FC = ({ po, warehouse, printerCombo }) => { const cameras = useContext(CameraContext); const { data: session } = useSession(); diff --git a/src/components/PoDetail/PoDetailRow.tsx b/src/components/PoDetail/PoDetailRow.tsx index d16c5259..d688df85 100644 --- a/src/components/PoDetail/PoDetailRow.tsx +++ b/src/components/PoDetail/PoDetailRow.tsx @@ -77,7 +77,7 @@ type Props = { onSubmitted: (row: PurchaseOrderLine) => void; }; -/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.4 | 2026-09-10 */ +/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.5 | 2026-09-18 */ export const PoDetailRow = memo(function PoDetailRow({ row, selected, diff --git a/src/components/PoDetail/PoInputGrid.tsx b/src/components/PoDetail/PoInputGrid.tsx index c8c038b8..c41dbef7 100644 --- a/src/components/PoDetail/PoInputGrid.tsx +++ b/src/components/PoDetail/PoInputGrid.tsx @@ -155,7 +155,7 @@ class ProcessRowUpdateError extends Error { } } -/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.4 | 2026-09-10 */ +/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.5 | 2026-09-18 */ function PoInputGrid({ // qc, setRows, diff --git a/src/components/PoDetail/PutAwayForm.tsx b/src/components/PoDetail/PutAwayForm.tsx index 0aa74b4b..545273b6 100644 --- a/src/components/PoDetail/PutAwayForm.tsx +++ b/src/components/PoDetail/PutAwayForm.tsx @@ -55,6 +55,7 @@ import dayjs from "dayjs"; import arraySupport from "dayjs/plugin/arraySupport"; import { dummyPutAwayLine } from "../Qc/dummyQcTemplate"; import { GridRowModesModel } from "@mui/x-data-grid"; +import { displayPutAwayLineQtyFromOriginSil } from "./originSilPutAwayQty"; dayjs.extend(arraySupport); interface Props { @@ -86,6 +87,7 @@ const style = { width: "auto", }; +/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.5 | 2026-09-18 */ const PutAwayForm: React.FC = ({ itemDetail, warehouse=[], disabled, suggestedLocationCode, setRowModesModel, setRowSelectionModel }) => { const { t } = useTranslation("purchaseOrder"); const apiRef = useGridApiRef(); @@ -241,8 +243,13 @@ const PutAwayForm: React.FC = ({ itemDetail, warehouse=[], disabled, sugg headerAlign: "right", align: "right", renderCell(params) { + const displayQty = displayPutAwayLineQtyFromOriginSil( + itemDetail, + Number(params.value), + params.row._isNew, + ); return - {params.value} + {displayQty} } }, @@ -309,7 +316,7 @@ const PutAwayForm: React.FC = ({ itemDetail, warehouse=[], disabled, sugg // return <>100 // }, // }, - ], []) + ], [itemDetail, t]) const validation = useCallback( (newRow: GridRowModel): EntryError => { @@ -395,7 +402,7 @@ const PutAwayForm: React.FC = ({ itemDetail, warehouse=[], disabled, sugg diff --git a/src/components/PoDetail/QcStockInModal.tsx b/src/components/PoDetail/QcStockInModal.tsx index 56d5a87a..841f3111 100644 --- a/src/components/PoDetail/QcStockInModal.tsx +++ b/src/components/PoDetail/QcStockInModal.tsx @@ -21,6 +21,7 @@ import { useTranslation } from "react-i18next"; import StockInForm from "../StockIn/StockInForm"; import QcComponent from "../Qc/QcComponent"; import PutAwayForm from "./PutAwayForm"; +import { mapPutAwayLinesFromOriginSil } from "./originSilPutAwayQty"; import { GridRowModes, GridRowSelectionModel, useGridApiRef } from "@mui/x-data-grid"; import {msg, submitDialogWithWarning} from "../Swal/CustomAlerts"; import { INPUT_DATE_FORMAT, arrayToDateString, dayjsToDateTimeString } from "@/app/utils/formatUtil"; @@ -71,7 +72,7 @@ interface CommonProps extends Omit { interface Props extends CommonProps { // itemDetail: StockInLine & { qcResult?: PurchaseQcResult[] } & { escResult?: EscalationResult[] }; } -/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.4 | 2026-09-10 */ +/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.5 | 2026-09-18 */ const PoQcStockInModalVer2: React.FC = ({ open, onClose, @@ -205,7 +206,7 @@ const PoQcStockInModalVer2: React.FC = ({ // escResult: (d.escResult && d.escResult?.length > 0) ? d.escResult : [], // qcResult: (d.qcResult && d.qcResult?.length > 0) ? d.qcResult : [],//[...dummyQCData], warehouseId: d.defaultWarehouseId ?? 1, - putAwayLines: d.putAwayLines?.map((line) => ({...line, printQty: 1, _isNew: false, _disableDelete: true})) ?? [], + putAwayLines: mapPutAwayLinesFromOriginSil(d, d.putAwayLines), } as ModalFormInput ) } return undefined diff --git a/src/components/PoDetail/StockInLineRowActions.tsx b/src/components/PoDetail/StockInLineRowActions.tsx index c1431741..c34e153c 100644 --- a/src/components/PoDetail/StockInLineRowActions.tsx +++ b/src/components/PoDetail/StockInLineRowActions.tsx @@ -26,7 +26,7 @@ type Props = { onRound?: (mode: StockQtyRoundMode) => void; }; -/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.4 | 2026-09-10 */ +/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.5 | 2026-09-18 */ export default function StockInLineRowActions({ btnSx, onPrimaryClick, diff --git a/src/components/PoDetail/originSilPutAwayQty.ts b/src/components/PoDetail/originSilPutAwayQty.ts new file mode 100644 index 00000000..2e3fa15d --- /dev/null +++ b/src/components/PoDetail/originSilPutAwayQty.ts @@ -0,0 +1,60 @@ +import { PutAwayLine, StockInLine } from "@/app/api/stockIn"; + +type OriginSil = Pick< + StockInLine, + "jobOrderId" | "purchaseAcceptedQty" | "acceptedQty" +>; + +/** + * FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.5 | 2026-09-18 + * Path A: inventory_lot_line → inventory_lot → stock_in_line (the SIL that opened the lot). + * Never use inventory_lot_line.inQty — ADJ/TKE is added onto the same line later. + * + * PO: purchaseAcceptedQty (M18 / 採購單位) + * JO: acceptedQty (庫存/生產單位;JO 通常沒有 acceptedQtyM18) + */ +export function originSilPutAwayDisplayQty(origin: OriginSil): number { + if (origin.jobOrderId) { + const stock = Number(origin.acceptedQty); + return Number.isFinite(stock) && stock > 0 ? stock : 0; + } + const purchase = Number(origin.purchaseAcceptedQty); + if (Number.isFinite(purchase) && purchase > 0) return purchase; + const stock = Number(origin.acceptedQty); + return Number.isFinite(stock) && stock > 0 ? stock : 0; +} + +/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.5 | 2026-09-18 */ +export function originSilPutAwayStockQty(origin: OriginSil): number { + const stock = Number(origin.acceptedQty); + return Number.isFinite(stock) && stock > 0 ? stock : 0; +} + +/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.5 | 2026-09-18 */ +export function mapPutAwayLinesFromOriginSil( + origin: OriginSil, + lines: PutAwayLine[] | undefined, +): PutAwayLine[] { + const existing = lines ?? []; + const displayQty = originSilPutAwayDisplayQty(origin); + const stockQty = originSilPutAwayStockQty(origin); + return existing.map((line) => ({ + ...line, + printQty: 1, + _isNew: false, + _disableDelete: true, + ...(displayQty > 0 ? { qty: displayQty } : {}), + ...(stockQty > 0 ? { stockQty } : {}), + })); +} + +/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.5 | 2026-09-18 */ +export function displayPutAwayLineQtyFromOriginSil( + origin: OriginSil, + lineQty: number, + isNew: boolean | undefined, +): number { + if (isNew) return lineQty; + const originQty = originSilPutAwayDisplayQty(origin); + return originQty > 0 ? originQty : lineQty; +} diff --git a/src/components/PoDetail/stockQtyRound.ts b/src/components/PoDetail/stockQtyRound.ts index c2d066b6..630c9acc 100644 --- a/src/components/PoDetail/stockQtyRound.ts +++ b/src/components/PoDetail/stockQtyRound.ts @@ -81,6 +81,7 @@ function convertPoBatchToStockQty( } /** + * FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.5 | 2026-09-18 * Preview converted stock qty for a 來貨數 batch. * Matches create-stock-in: ratio convert, then integer HALF_UP for 包/箱/PCS, else 2 decimals. */ @@ -104,7 +105,7 @@ export function isNotIntegerQty(qty: number): boolean { } /** - * FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.4 | 2026-09-10 + * FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.5 | 2026-09-18 * PO 收貨/品檢:pending 或 escalated 且庫存數量非整數時需選擇 CEILING / FLOOR */ export function needsPoQcStockQtyRound( @@ -118,7 +119,7 @@ export function needsPoQcStockQtyRound( return isNotIntegerQty(Number(acceptedQty ?? 0)); } -/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.4 | 2026-09-10 */ +/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.5 | 2026-09-18 */ export function roundStockQty(before: number, mode: StockQtyRoundMode): number { if (mode === "CEILING") return Math.ceil(before); return Math.floor(before); diff --git a/src/components/Qc/QcStockInModal.tsx b/src/components/Qc/QcStockInModal.tsx index c6b2b53d..b38d37dd 100644 --- a/src/components/Qc/QcStockInModal.tsx +++ b/src/components/Qc/QcStockInModal.tsx @@ -24,6 +24,7 @@ import PutAwayForm from "../PoDetail/PutAwayForm"; import { GridRowModes, GridRowSelectionModel, useGridApiRef } from "@mui/x-data-grid"; import {msg, submitDialogWithWarning} from "../Swal/CustomAlerts"; import { needsPoQcStockQtyRound } from "../PoDetail/stockQtyRound"; +import { mapPutAwayLinesFromOriginSil } from "../PoDetail/originSilPutAwayQty"; import { INPUT_DATE_FORMAT, arrayToDateString, dayjsToDateTimeString } from "@/app/utils/formatUtil"; import dayjs from "dayjs"; import { fetchPoQrcode } from "@/app/api/pdf/actions"; @@ -73,7 +74,7 @@ interface Props extends CommonProps { // itemDetail: StockInLine & { qcResult?: PurchaseQcResult[] } & { escResult?: EscalationResult[] }; } -/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.4 | 2026-09-10 */ +/** FP-MTMS Version Checklist | Functions Ref. No. 56 | v1.0.5 | 2026-09-18 */ const QcStockInModal: React.FC = ({ open, onClose, @@ -231,7 +232,7 @@ const QcStockInModal: React.FC = ({ // escResult: (d.escResult && d.escResult?.length > 0) ? d.escResult : [], // qcResult: (d.qcResult && d.qcResult?.length > 0) ? d.qcResult : [],//[...dummyQCData], warehouseId: d.defaultWarehouseId ?? 1141, - putAwayLines: d.putAwayLines?.map((line) => ({...line, printQty: 1, _isNew: false, _disableDelete: true})) ?? [], + putAwayLines: mapPutAwayLinesFromOriginSil(d, d.putAwayLines), } as ModalFormInput ) } return undefined From 26ab7cc1175915e7cf9ba6948228822ab82c62c4 Mon Sep 17 00:00:00 2001 From: "PC-20260115JRSN\\Administrator" Date: Sun, 20 Sep 2026 22:48:21 +0800 Subject: [PATCH 10/24] allow mutli sync for do in m18 sync ui --- src/app/(main)/m18Syn/page.tsx | 69 +++++++++++++++++++++++++--------- 1 file changed, 51 insertions(+), 18 deletions(-) diff --git a/src/app/(main)/m18Syn/page.tsx b/src/app/(main)/m18Syn/page.tsx index df97ff33..8a84520d 100644 --- a/src/app/(main)/m18Syn/page.tsx +++ b/src/app/(main)/m18Syn/page.tsx @@ -135,26 +135,55 @@ export default function M18SynPage() { } }; + /** 送貨訂單:手動按 code 同步(可輸入多個 code,用逗號或換行分隔) */ const handleSyncM18DoByCode = async () => { if (m18DoInFlightRef.current) return; - if (!m18DoCode.trim()) { - alert("Please enter DO / shop PO code."); + const raw = m18DoCode.trim(); + if (!raw) { + alert("Please enter DO / shop PO code(s)."); + return; + } + const codes = raw + .split(/[\n,]+/g) + .map((s) => s.trim()) + .filter(Boolean); + if (codes.length === 0) { + alert("Please enter at least one code."); return; } m18DoInFlightRef.current = true; setIsSyncingM18Do(true); setM18DoSyncResult(""); try { - const response = await clientAuthFetch( - `${NEXT_PUBLIC_API_URL}/m18/test/do-by-code?code=${encodeURIComponent(m18DoCode.trim())}`, - { method: "GET" }, - ); - if (response.status === 401 || response.status === 403) return; - const text = await response.text(); - setM18DoSyncResult(formatSyncResultText("送貨訂單", text)); - if (!response.ok) { - alert(`Sync failed: ${response.status}`); + const outputs: string[] = []; + const okCodes: string[] = []; + const notFoundCodes: string[] = []; + const otherFailCodes: string[] = []; + for (const code of codes) { + const response = await clientAuthFetch( + `${NEXT_PUBLIC_API_URL}/m18/test/do-by-code?code=${encodeURIComponent(code)}`, + { method: "GET" }, + ); + if (response.status === 401 || response.status === 403) return; + const text = await response.text(); + const parsed = parseSyncResult("送貨訂單", text || ""); + if (parsed.kind === "success") okCodes.push(code); + else if (parsed.kind === "not_found") notFoundCodes.push(code); + else otherFailCodes.push(code); + + const perCodeMsg = + parsed.kind === "success" ? "成功同步" : + parsed.kind === "not_found" ? parsed.message : + parsed.message; + outputs.push(`${code}: ${perCodeMsg}${response.ok ? "" : ` (HTTP ${response.status})`}`); } + + outputs.push(""); + outputs.push(`共${okCodes.length}張送貨訂單成功`); + if (notFoundCodes.length > 0) outputs.push(`共${notFoundCodes.length}張在M18找不到訂單 (${notFoundCodes.join(", ")})`); + if (otherFailCodes.length > 0) outputs.push(`共${otherFailCodes.length}張同步失敗 (${otherFailCodes.join(", ")})`); + + setM18DoSyncResult(outputs.join("\n")); } catch (e) { console.error("M18 DO Sync By Code Error:", e); alert("M18 DO sync failed. Check console/network."); @@ -312,18 +341,22 @@ export default function M18SynPage() {
- + setM18DoCode(e.target.value)} - placeholder="e.g. same document code as M18 shop PO" - sx={{ minWidth: 320 }} + placeholder="可輸入多個 code,用逗號或換行分隔" + fullWidth + multiline + minRows={6} + maxRows={14} /> - + + + {m18DoSyncResult ? ( Date: Mon, 21 Sep 2026 12:34:36 +0800 Subject: [PATCH 11/24] Revert inventory Location Search; restore latest-inventory one-row-per-item search. Keep report item-code typeahead and multi-value filters unchanged. Co-authored-by: Cursor --- src/app/api/inventory/actions.ts | 12 +- src/app/api/inventory/index.ts | 1 - .../InventorySearch/InventoryLotLineTable.tsx | 14 +- .../InventorySearch/InventorySearch.tsx | 153 +++--------- .../InventorySearch/InventorySearchPage.tsx | 54 ----- .../InventorySearchWrapper.tsx | 15 +- .../InventorySearch/LocationFilterBar.tsx | 229 ------------------ src/components/SearchBox/SearchBox.tsx | 5 - src/i18n/en/inventory.json | 8 - src/i18n/zh/inventory.json | 8 - 10 files changed, 39 insertions(+), 460 deletions(-) delete mode 100644 src/components/InventorySearch/InventorySearchPage.tsx delete mode 100644 src/components/InventorySearch/LocationFilterBar.tsx diff --git a/src/app/api/inventory/actions.ts b/src/app/api/inventory/actions.ts index 3330a8f0..fb7d8643 100644 --- a/src/app/api/inventory/actions.ts +++ b/src/app/api/inventory/actions.ts @@ -28,12 +28,8 @@ export interface LotLineInfo { export interface SearchInventoryLotLine extends Pageable { itemId: number; - uomId?: number; /** Non-expired lots with in > out; includes available and unavailable. */ stockIssueBadItem?: boolean; - storeId?: string; - warehouse?: string; - area?: string; } export interface SearchStockIssueBadItemLotLine extends Pageable { @@ -48,9 +44,6 @@ export interface SearchInventory extends Pageable { name: string; type: string; lotNo?: string; - storeId?: string; - warehouse?: string; - area?: string; } export interface InventoryResultByPage { @@ -179,8 +172,8 @@ async function fetchInventoriesLatestImpl(data: SearchInventory) { export const fetchInventories = cache(fetchInventoriesImpl); /** - * FP-MTMS Version Checklist | Functions Ref. No. 18 | v1.0.4 | 2026-09-10 - * Inventory search page: latest inventory row per item + stock UoM, with optional location filters. + * FP-MTMS Version Checklist | Functions Ref. No. 18 | v1.0.3 | 2026-09-07 + * Inventory search page: latest inventory row per item (no baseUnit/uomId filter). */ export const fetchInventoriesLatest = cache(fetchInventoriesLatestImpl); @@ -202,7 +195,6 @@ async function fetchInventoryLotLinesImpl(data: SearchInventoryLotLine) { ); } -/** FP-MTMS Version Checklist | Functions Ref. No. 18 | v1.0.4 | 2026-09-10 */ export const fetchInventoryLotLines = cache(fetchInventoryLotLinesImpl); /** Bypass React cache() after mutations so lists show fresh qty. */ diff --git a/src/app/api/inventory/index.ts b/src/app/api/inventory/index.ts index 711de65e..869bed2e 100644 --- a/src/app/api/inventory/index.ts +++ b/src/app/api/inventory/index.ts @@ -14,7 +14,6 @@ export interface InventoryResult { onHoldQty: number; unavailableQty: number; availableQty: number; - uomId?: number; uomCode: string; uomUdfudesc: string; uomShortDesc: string; diff --git a/src/components/InventorySearch/InventoryLotLineTable.tsx b/src/components/InventorySearch/InventoryLotLineTable.tsx index 237112dc..9e3a041f 100644 --- a/src/components/InventorySearch/InventoryLotLineTable.tsx +++ b/src/components/InventorySearch/InventoryLotLineTable.tsx @@ -54,18 +54,15 @@ interface Props { totalCount: number; inventory: InventoryResult | null; filterLotNo?: string; - /** Location search: show only the slot (e.g. 00), not the full warehouse code. */ - warehouseDisplay?: "full" | "slot"; onStockTransferSuccess?: () => void | Promise; printerCombo?: PrinterCombo[]; onStockAdjustmentSuccess?: () => void | Promise; } -/** FP-MTMS Version Checklist | Functions Ref. No. 3 | v1.0.8 | 2026-09-10 */ +/** FP-MTMS Version Checklist | Functions Ref. No. 3 | v1.0.7 | 2026-09-08 */ const InventoryLotLineTable: React.FC = ({ inventoryLotLines, pagingController, setPagingController, totalCount, inventory, filterLotNo, - warehouseDisplay = "full", onStockTransferSuccess, printerCombo = [], onStockAdjustmentSuccess, }) => { @@ -482,12 +479,9 @@ const prevAdjustmentModalOpenRef = useRef(false); }, { name: "warehouse", - label: warehouseDisplay === "slot" ? t("Slot") : t("Warehouse"), + label: t("Warehouse"), renderCell: (params) => { - const code = params.warehouse?.code ?? ""; - if (warehouseDisplay !== "slot") return code; - const parts = code.split("-").filter(Boolean); - return parts[parts.length - 1] || code; + return `${params.warehouse.code}` }, }, { @@ -528,7 +522,7 @@ const prevAdjustmentModalOpenRef = useRef(false); // } // }, ], - [t, onDetailClick, downloadQrCode, handleStockTransfer, handlePrintClick, warehouseDisplay], + [t, onDetailClick, downloadQrCode, handleStockTransfer, handlePrintClick], ); diff --git a/src/components/InventorySearch/InventorySearch.tsx b/src/components/InventorySearch/InventorySearch.tsx index 2f85f678..a59ff224 100644 --- a/src/components/InventorySearch/InventorySearch.tsx +++ b/src/components/InventorySearch/InventorySearch.tsx @@ -20,19 +20,10 @@ import { fetchItemsByPage } from '@/app/api/settings/item/actions'; import { useSession } from 'next-auth/react'; import { AUTH, hasAbility } from '@/authorities'; import { Button, Box } from '@mui/material'; -import { WarehouseResult } from '@/app/api/warehouse'; -import { fetchWarehouseListClient } from '@/app/api/warehouse/client'; -import LocationFilterBar, { - emptyLocationFilter, - isLocationAll, - LocationFilterValue, -} from './LocationFilterBar'; interface Props { inventories: InventoryResult[]; printerCombo?: PrinterCombo[]; - warehouses?: WarehouseResult[]; - enableLocationFilter?: boolean; } type SearchQuery = Partial< @@ -71,13 +62,8 @@ const extractItemRecords = (res: unknown): ItemLookupRow[] => { return []; }; -/** FP-MTMS Version Checklist | Functions Ref. No. 18 | v1.0.4 | 2026-09-10 */ -const InventorySearch: React.FC = ({ - inventories, - printerCombo, - warehouses = [], - enableLocationFilter = false, -}) => { +/** FP-MTMS Version Checklist | Functions Ref. No. 18 | v1.0.3 | 2026-09-07 */ +const InventorySearch: React.FC = ({ inventories, printerCombo }) => { const { t } = useTranslation(['inventory', 'common', 'item']); const { data: session } = useSession(); const abilities = session?.abilities ?? session?.user?.abilities ?? []; @@ -153,19 +139,6 @@ const InventorySearch: React.FC = ({ // Resolved lot no for filtering const [lotNoFilter, setLotNoFilter] = useState(''); const [scannedItemId, setScannedItemId] = useState(null); - const [location, setLocation] = useState(emptyLocationFilter); - const [locationWarehouses, setLocationWarehouses] = useState(warehouses); - - useEffect(() => { - if (!enableLocationFilter) return; - if (warehouses.length) { - setLocationWarehouses(warehouses); - return; - } - fetchWarehouseListClient() - .then(setLocationWarehouses) - .catch(console.error); - }, [enableLocationFilter, warehouses]); const defaultInputs = useMemo( () => ({ @@ -212,43 +185,28 @@ const InventorySearch: React.FC = ({ ); // Inventory - const withLocationParams = useCallback( - (params: T, loc: LocationFilterValue): T & Partial => { - if (!enableLocationFilter) return params; - return { - ...params, - ...(!isLocationAll(loc.storeId) ? { storeId: loc.storeId } : {}), - ...(!isLocationAll(loc.warehouse) ? { warehouse: loc.warehouse } : {}), - ...(!isLocationAll(loc.area) ? { area: loc.area } : {}), - }; - }, - [enableLocationFilter], - ); - const refetchInventoryData = useCallback( async ( query: Record, actionType: 'reset' | 'search' | 'paging' | 'init', pagingController: typeof defaultPagingController, lotNo: string, - loc: LocationFilterValue = location, ) => { + //console.log('%c Action Type 1.', 'color:red', actionType); // Avoid loading data again if (actionType === 'paging' && pagingController === defaultPagingController) { return; } - - const params: SearchInventory = withLocationParams( - { - code: query?.itemCode ?? '', - name: query?.itemName ?? '', - type: query?.itemType.toLowerCase() === 'all' ? '' : query?.itemType ?? '', - lotNo: lotNo?.trim() ? lotNo.trim() : undefined, - pageNum: pagingController.pageNum - 1, - pageSize: pagingController.pageSize, - }, - loc, - ); + // console.log('%c Action Type 2.', 'color:blue', actionType); + + const params: SearchInventory = { + code: query?.itemCode ?? '', + name: query?.itemName ?? '', + type: query?.itemType.toLowerCase() === 'all' ? '' : query?.itemType ?? '', + lotNo: lotNo?.trim() ? lotNo.trim() : undefined, + pageNum: pagingController.pageNum - 1, + pageSize: pagingController.pageSize, + }; const response = await fetchInventoriesLatest(params); @@ -262,21 +220,19 @@ const InventorySearch: React.FC = ({ break; case 'paging': setFilteredInventories((fi) => - uniqBy([...fi, ...response.records], (row) => `${row.itemId}-${row.uomId ?? row.uomUdfudesc ?? ''}`), + uniqBy([...fi, ...response.records], 'itemId'), ); } } return response; }, - [enableLocationFilter, location, withLocationParams], + [], ); useEffect(() => { refetchInventoryData(defaultInputs, 'init', defaultPagingController, ''); - // Mount / tab open only. Location changes search via handleLocationChange. - // eslint-disable-next-line react-hooks/exhaustive-deps - }, [defaultInputs]); + }, [defaultInputs, refetchInventoryData]); useEffect(() => { // if (!isEqual(inventoriesPagingController, defaultPagingController)) { @@ -290,8 +246,6 @@ const InventorySearch: React.FC = ({ itemId: number | null, actionType: 'reset' | 'search' | 'paging', pagingController: typeof defaultPagingController, - loc: LocationFilterValue = location, - uomId?: number, ) => { if (!itemId) { setSelectedInventory(null); @@ -305,15 +259,11 @@ const InventorySearch: React.FC = ({ return; } - const params: SearchInventoryLotLine = withLocationParams( - { - itemId, - uomId: uomId || undefined, - pageNum: pagingController.pageNum - 1, - pageSize: pagingController.pageSize, - }, - loc, - ); + const params: SearchInventoryLotLine = { + itemId, + pageNum: pagingController.pageNum - 1, + pageSize: pagingController.pageSize, + }; const response = await fetchInventoryLotLines(params); if (response) { @@ -328,27 +278,20 @@ const InventorySearch: React.FC = ({ } } }, - [location, withLocationParams], + [], ); useEffect(() => { // if (!isEqual(inventoryLotLinesPagingController, defaultPagingController)) { - refetchInventoryLotLineData( - selectedInventory?.itemId ?? null, - 'paging', - inventoryLotLinesPagingController, - location, - selectedInventory?.uomId, - ) + refetchInventoryLotLineData(selectedInventory?.itemId ?? null, 'paging', inventoryLotLinesPagingController) // } }, [inventoryLotLinesPagingController]) // Reset const onReset = useCallback(() => { - const clearedLocation = emptyLocationFilter(); - setLocation(clearedLocation); - refetchInventoryData(defaultInputs, 'reset', defaultPagingController, '', clearedLocation); - refetchInventoryLotLineData(null, 'reset', defaultPagingController, clearedLocation); + refetchInventoryData(defaultInputs, 'reset', defaultPagingController, ''); + refetchInventoryLotLineData(null, 'reset', defaultPagingController); + // setFilteredInventories(inventories); setLotNoFilter(''); setScannedItemId(null); @@ -361,32 +304,14 @@ const InventorySearch: React.FC = ({ setInventoryLotLinesPagingController(() => defaultPagingController) }, [defaultInputs, qrScanner, refetchInventoryData, refetchInventoryLotLineData]); - const handleLocationChange = useCallback( - (next: LocationFilterValue) => { - setLocation(next); - setSelectedInventory(null); - setFilteredInventoryLotLines([]); - setInventoryLotLinesTotalCount(0); - setInventoryLotLinesPagingController(() => defaultPagingController); - setInventoriesPagingController(() => defaultPagingController); - if (searchInFlightRef.current) return; - searchInFlightRef.current = true; - refetchInventoryData(inputs, 'search', defaultPagingController, lotNoFilter, next) - .finally(() => { - searchInFlightRef.current = false; - }); - }, - [inputs, lotNoFilter, refetchInventoryData], - ); - // Click Row const onInventoryRowClick = useCallback( (item: InventoryResult) => { - refetchInventoryLotLineData(item.itemId, 'search', defaultPagingController, location, item.uomId); + refetchInventoryLotLineData(item.itemId, 'search', defaultPagingController); setSelectedInventory(item); setInventoryLotLinesPagingController(() => defaultPagingController); }, - [location, refetchInventoryLotLineData], + [refetchInventoryLotLineData], ); // On Search @@ -409,7 +334,7 @@ const InventorySearch: React.FC = ({ setInventoryLotLinesPagingController(() => defaultPagingController); // No inventory rows: look up item master so 0-qty rows can be selected for stock adjustment. - if (canStockAdjust && !enableLocationFilter && invRes?.records?.length === 0) { + if (canStockAdjust && invRes?.records?.length === 0) { try { const items = await lookupItemsByCodeOrName(query.itemCode, query.itemName); const typeFilter = query.itemType?.trim(); @@ -441,7 +366,6 @@ const InventorySearch: React.FC = ({ lookupItemsByCodeOrName, applyItemsAsSyntheticInventories, canStockAdjust, - enableLocationFilter, ], ); @@ -527,15 +451,6 @@ const InventorySearch: React.FC = ({ onSearch(query); }} onReset={onReset} - extraCriteria={ - enableLocationFilter ? ( - - ) : undefined - } extraActions={ {scanUiMode === 'idle' ? ( @@ -569,20 +484,16 @@ const InventorySearch: React.FC = ({ totalCount={inventoryLotLinesTotalCount} inventory={selectedInventory} filterLotNo={lotNoFilter} - warehouseDisplay={enableLocationFilter ? "slot" : "full"} printerCombo={printerCombo ?? []} onStockTransferSuccess={() => refetchInventoryLotLineData( selectedInventory?.itemId ?? null, 'search', inventoryLotLinesPagingController, - location, - selectedInventory?.uomId, ) } onStockAdjustmentSuccess={async () => { const itemId = selectedInventory?.itemId ?? null; - const uomId = selectedInventory?.uomId; // Refresh both blocks: // - middle: InventoryTable (inventories list) @@ -598,15 +509,11 @@ const InventorySearch: React.FC = ({ itemId, 'search', inventoryLotLinesPagingController, - location, - uomId, ); // If inventory becomes available again after OPEN/ADJ, sync selected row. if (itemId != null && invRes?.records?.length) { - const target = invRes.records.find( - (r) => r.itemId === itemId && (uomId == null || r.uomId === uomId), - ); + const target = invRes.records.find((r) => r.itemId === itemId); if (target) setSelectedInventory(target); } }} diff --git a/src/components/InventorySearch/InventorySearchPage.tsx b/src/components/InventorySearch/InventorySearchPage.tsx deleted file mode 100644 index b494bde6..00000000 --- a/src/components/InventorySearch/InventorySearchPage.tsx +++ /dev/null @@ -1,54 +0,0 @@ -"use client"; - -import { InventoryResult } from "@/app/api/inventory"; -import { PrinterCombo } from "@/app/api/settings/printer"; -import { WarehouseResult } from "@/app/api/warehouse"; -import { Box, Tab, Tabs } from "@mui/material"; -import { useCallback, useState } from "react"; -import { useTranslation } from "react-i18next"; -import InventorySearch from "./InventorySearch"; - -type TabValue = "item" | "location"; - -interface Props { - inventories: InventoryResult[]; - printerCombo?: PrinterCombo[]; - warehouses?: WarehouseResult[]; -} - -/** FP-MTMS Version Checklist | Functions Ref. No. 79 | v1.0.0 | 2026-09-10 */ -const InventorySearchPage: React.FC = ({ - inventories, - printerCombo, - warehouses = [], -}) => { - const { t } = useTranslation("inventory"); - const [tab, setTab] = useState("item"); - - const handleTabChange = useCallback((_: React.SyntheticEvent, value: string) => { - setTab(value as TabValue); - }, []); - - return ( - - - - - - - {tab === "item" && ( - - )} - {tab === "location" && ( - - )} - - ); -}; - -export default InventorySearchPage; diff --git a/src/components/InventorySearch/InventorySearchWrapper.tsx b/src/components/InventorySearch/InventorySearchWrapper.tsx index 6b9227bd..cffbfc52 100644 --- a/src/components/InventorySearch/InventorySearchWrapper.tsx +++ b/src/components/InventorySearch/InventorySearchWrapper.tsx @@ -1,29 +1,20 @@ import React from "react"; import GeneralLoading from "../General/GeneralLoading"; import { fetchInventories } from "@/app/api/inventory"; -import InventorySearchPage from "./InventorySearchPage"; +import InventorySearch from "./InventorySearch"; import { fetchPrinterCombo } from "@/app/api/settings/printer"; -import { fetchWarehouseList } from "@/app/api/warehouse"; interface SubComponents { Loading: typeof GeneralLoading; } -/** FP-MTMS Version Checklist | Functions Ref. No. 79 | v1.0.0 | 2026-09-10 */ const InventorySearchWrapper: React.FC & SubComponents = async () => { - const [inventories, printerCombo, warehouses] = await Promise.all([ + const [inventories, printerCombo] = await Promise.all([ fetchInventories(), fetchPrinterCombo(), - fetchWarehouseList().catch(() => []), ]); - return ( - - ); + return ; }; InventorySearchWrapper.Loading = GeneralLoading; diff --git a/src/components/InventorySearch/LocationFilterBar.tsx b/src/components/InventorySearch/LocationFilterBar.tsx deleted file mode 100644 index 469b6b17..00000000 --- a/src/components/InventorySearch/LocationFilterBar.tsx +++ /dev/null @@ -1,229 +0,0 @@ -"use client"; - -import { WarehouseResult } from "@/app/api/warehouse"; -import { Box, ToggleButton, ToggleButtonGroup, Typography } from "@mui/material"; -import { useMemo } from "react"; -import { useTranslation } from "react-i18next"; - -export const LOCATION_ALL = "ALL"; -const BUTTONS_PER_ROW = 15; -const BUTTON_WIDTH = 80; - -export type LocationFilterValue = { - storeId: string; - warehouse: string; - area: string; -}; - -const EMPTY_LOCATION: LocationFilterValue = { - storeId: "", - warehouse: "", - area: "", -}; - -export const emptyLocationFilter = (): LocationFilterValue => ({ ...EMPTY_LOCATION }); - -export const isLocationAll = (value?: string) => !value || value === LOCATION_ALL; - -const warehouseSegments = (w: WarehouseResult) => { - const parts = (w.code || "").split("-"); - return { - storeId: w.store_id?.trim() || parts[0] || "", - warehouse: w.warehouse?.trim() || parts[1] || "", - area: w.area?.trim() || parts[2] || "", - }; -}; - -const compareAlphanumeric = (a: string, b: string) => - a.localeCompare(b, undefined, { numeric: true, sensitivity: "base" }); - -const chunk = (items: T[], size: number): T[][] => { - const rows: T[][] = []; - for (let i = 0; i < items.length; i += size) { - rows.push(items.slice(i, i + size)); - } - return rows; -}; - -const withAllOption = (options: string[]) => - options.length > 1 ? [LOCATION_ALL, ...options] : options; - -interface Props { - warehouses: WarehouseResult[]; - value: LocationFilterValue; - onChange: (next: LocationFilterValue) => void; -} - -/** FP-MTMS Version Checklist | Functions Ref. No. 79 | v1.0.0 | 2026-09-10 */ -const LocationFilterBar: React.FC = ({ warehouses, value, onChange }) => { - const { t } = useTranslation("inventory"); - - const floors = useMemo(() => { - const set = new Set(); - warehouses.forEach((w) => { - const storeId = warehouseSegments(w).storeId; - if (storeId) set.add(storeId); - }); - return Array.from(set).sort(compareAlphanumeric); - }, [warehouses]); - - const warehouseEnabled = Boolean(value.storeId); - const areaEnabled = Boolean(value.storeId && value.warehouse); - - const warehouseZones = useMemo(() => { - if (!value.storeId) return []; - const set = new Set(); - warehouses.forEach((w) => { - const seg = warehouseSegments(w); - if (!isLocationAll(value.storeId) && seg.storeId !== value.storeId) return; - if (seg.warehouse) set.add(seg.warehouse); - }); - return Array.from(set).sort(compareAlphanumeric); - }, [warehouses, value.storeId]); - - const areas = useMemo(() => { - if (!value.storeId || !value.warehouse) return []; - const set = new Set(); - warehouses.forEach((w) => { - const seg = warehouseSegments(w); - if (!isLocationAll(value.storeId) && seg.storeId !== value.storeId) return; - if (!isLocationAll(value.warehouse) && seg.warehouse !== value.warehouse) return; - if (seg.area) set.add(seg.area); - }); - return Array.from(set).sort(compareAlphanumeric); - }, [warehouses, value.storeId, value.warehouse]); - - const floorOptions = useMemo(() => withAllOption(floors), [floors]); - - const warehouseRows = useMemo( - () => chunk(withAllOption(warehouseZones), BUTTONS_PER_ROW), - [warehouseZones], - ); - - const areaRows = useMemo( - () => chunk(withAllOption(areas), BUTTONS_PER_ROW), - [areas], - ); - - return ( - - - - {t("Floor")} - - { - onChange({ storeId: next ?? "", warehouse: "", area: "" }); - }} - > - {floorOptions.map((floor) => ( - - {floor === LOCATION_ALL ? t("All") : floor} - - ))} - - - - - - {t("Warehouse")} - - - {warehouseRows.map((row, rowIndex) => ( - { - if (next == null) return; - onChange({ ...value, warehouse: next, area: "" }); - }} - sx={{ - "& .MuiToggleButtonGroup-grouped": { - width: BUTTON_WIDTH, - minWidth: BUTTON_WIDTH, - maxWidth: BUTTON_WIDTH, - px: 0, - boxSizing: "border-box", - }, - }} - > - {row.map((zone) => ( - - {zone === LOCATION_ALL ? t("All") : zone} - - ))} - - ))} - - {!warehouseEnabled && ( - - {t("Select floor first")} - - )} - - - - - {t("Area")} - - - {areaRows.map((row, rowIndex) => ( - { - if (next == null) return; - onChange({ ...value, area: next }); - }} - sx={{ - "& .MuiToggleButtonGroup-grouped": { - width: BUTTON_WIDTH, - minWidth: BUTTON_WIDTH, - maxWidth: BUTTON_WIDTH, - px: 0, - boxSizing: "border-box", - }, - }} - > - {row.map((area) => ( - - {area === LOCATION_ALL ? t("All") : area} - - ))} - - ))} - - {!areaEnabled && ( - - {value.storeId ? t("Select warehouse first") : t("Select floor first")} - - )} - - - ); -}; - -export default LocationFilterBar; diff --git a/src/components/SearchBox/SearchBox.tsx b/src/components/SearchBox/SearchBox.tsx index 5ecec020..45331726 100644 --- a/src/components/SearchBox/SearchBox.tsx +++ b/src/components/SearchBox/SearchBox.tsx @@ -124,19 +124,15 @@ interface Props { onReset?: () => void; /** Optional actions rendered in the same row as Reset/Search (e.g. Download, Upload buttons) */ extraActions?: React.ReactNode; - /** Optional filters rendered above the standard criteria fields */ - extraCriteria?: React.ReactNode; /** Disable inputs/actions while external task is running */ disabled?: boolean; } -/** FP-MTMS Version Checklist | Functions Ref. No. 79 | v1.0.0 | 2026-09-10 */ function SearchBox({ criteria, onSearch, onReset, extraActions, - extraCriteria, disabled = false, }: Props) { const { t } = useTranslation("common"); @@ -299,7 +295,6 @@ function SearchBox({ {t("Search Criteria")} - {extraCriteria} {criteria.map((c) => { return ( diff --git a/src/i18n/en/inventory.json b/src/i18n/en/inventory.json index 5d170b12..716b1ab5 100644 --- a/src/i18n/en/inventory.json +++ b/src/i18n/en/inventory.json @@ -16,14 +16,7 @@ "Download QR Code": "Download QR Code", "Edit mode": "Edit mode", "Enter item code or name to search": "Enter item code or name to search", - "Area": "Area", "Expiry Date": "Expiry Date", - "Floor": "Floor", - "Item Search": "Item Search", - "Location Search": "Location Search", - "Select a floor to search by location.": "Select a floor to search by location.", - "Select floor first": "Select a floor first", - "Select warehouse first": "Select a warehouse first", "FG": "Finished good", "Failed to transfer stock": "Failed to transfer stock", "Failed to transfer stock. Please try again.": "Failed to transfer stock. Please try again.", @@ -60,7 +53,6 @@ "Remove": "Remove", "Reset": "Reset", "SFG": "Semi-finished good", - "Slot": "Slot", "Save": "Save", "Save failed": "Save failed", "Saved successfully": "Saved successfully", diff --git a/src/i18n/zh/inventory.json b/src/i18n/zh/inventory.json index 8513855b..79c76ecf 100644 --- a/src/i18n/zh/inventory.json +++ b/src/i18n/zh/inventory.json @@ -16,14 +16,7 @@ "Download QR Code": "下載", "Edit mode": "編輯模式", "Enter item code or name to search": "輸入貨品編號或名稱以搜索", - "Area": "區域", "Expiry Date": "到期日", - "Floor": "樓層", - "Item Search": "貨品搜尋", - "Location Search": "倉位搜尋", - "Select a floor to search by location.": "請先選擇樓層以搜尋倉位。", - "Select floor first": "請先選擇樓層", - "Select warehouse first": "請先選擇倉庫", "FG": "成品", "Failed to transfer stock": "轉倉失敗", "Failed to transfer stock. Please try again.": "轉倉失敗,請重試。", @@ -60,7 +53,6 @@ "Remove": "移除", "Reset": "重置", "SFG": "半成品", - "Slot": "儲位", "Save": "儲存", "Save failed": "儲存失敗", "Saved successfully": "儲存成功", From 971d20da068a66b8445cb08ae554b01028802162 Mon Sep 17 00:00:00 2001 From: "CANCERYS\\kw093" Date: Mon, 21 Sep 2026 12:37:58 +0800 Subject: [PATCH 12/24] Update FP-MTMS checklist comments for inventory Location Search revert. Co-authored-by: Cursor --- src/app/api/inventory/actions.ts | 2 +- src/components/InventorySearch/InventoryLotLineTable.tsx | 2 +- src/components/InventorySearch/InventorySearch.tsx | 2 +- src/components/InventorySearch/InventorySearchWrapper.tsx | 1 + src/components/SearchBox/SearchBox.tsx | 1 + 5 files changed, 5 insertions(+), 3 deletions(-) diff --git a/src/app/api/inventory/actions.ts b/src/app/api/inventory/actions.ts index fb7d8643..d481eef9 100644 --- a/src/app/api/inventory/actions.ts +++ b/src/app/api/inventory/actions.ts @@ -172,7 +172,7 @@ async function fetchInventoriesLatestImpl(data: SearchInventory) { export const fetchInventories = cache(fetchInventoriesImpl); /** - * FP-MTMS Version Checklist | Functions Ref. No. 18 | v1.0.3 | 2026-09-07 + * FP-MTMS Version Checklist | Functions Ref. No. 18 | v1.0.5 | 2026-09-21 * Inventory search page: latest inventory row per item (no baseUnit/uomId filter). */ export const fetchInventoriesLatest = cache(fetchInventoriesLatestImpl); diff --git a/src/components/InventorySearch/InventoryLotLineTable.tsx b/src/components/InventorySearch/InventoryLotLineTable.tsx index 9e3a041f..a4d3ce6c 100644 --- a/src/components/InventorySearch/InventoryLotLineTable.tsx +++ b/src/components/InventorySearch/InventoryLotLineTable.tsx @@ -59,7 +59,7 @@ interface Props { onStockAdjustmentSuccess?: () => void | Promise; } -/** FP-MTMS Version Checklist | Functions Ref. No. 3 | v1.0.7 | 2026-09-08 */ +/** FP-MTMS Version Checklist | Functions Ref. No. 3 | v1.0.9 | 2026-09-21 */ const InventoryLotLineTable: React.FC = ({ inventoryLotLines, pagingController, setPagingController, totalCount, inventory, filterLotNo, diff --git a/src/components/InventorySearch/InventorySearch.tsx b/src/components/InventorySearch/InventorySearch.tsx index a59ff224..097aec9c 100644 --- a/src/components/InventorySearch/InventorySearch.tsx +++ b/src/components/InventorySearch/InventorySearch.tsx @@ -62,7 +62,7 @@ const extractItemRecords = (res: unknown): ItemLookupRow[] => { return []; }; -/** FP-MTMS Version Checklist | Functions Ref. No. 18 | v1.0.3 | 2026-09-07 */ +/** FP-MTMS Version Checklist | Functions Ref. No. 18 | v1.0.5 | 2026-09-21 */ const InventorySearch: React.FC = ({ inventories, printerCombo }) => { const { t } = useTranslation(['inventory', 'common', 'item']); const { data: session } = useSession(); diff --git a/src/components/InventorySearch/InventorySearchWrapper.tsx b/src/components/InventorySearch/InventorySearchWrapper.tsx index cffbfc52..3a09483a 100644 --- a/src/components/InventorySearch/InventorySearchWrapper.tsx +++ b/src/components/InventorySearch/InventorySearchWrapper.tsx @@ -8,6 +8,7 @@ interface SubComponents { Loading: typeof GeneralLoading; } +/** FP-MTMS Version Checklist | Functions Ref. No. 79 | v1.0.1 | 2026-09-21 */ const InventorySearchWrapper: React.FC & SubComponents = async () => { const [inventories, printerCombo] = await Promise.all([ fetchInventories(), diff --git a/src/components/SearchBox/SearchBox.tsx b/src/components/SearchBox/SearchBox.tsx index 45331726..b70a9fec 100644 --- a/src/components/SearchBox/SearchBox.tsx +++ b/src/components/SearchBox/SearchBox.tsx @@ -128,6 +128,7 @@ interface Props { disabled?: boolean; } +/** FP-MTMS Version Checklist | Functions Ref. No. 79 | v1.0.1 | 2026-09-21 */ function SearchBox({ criteria, onSearch, From 163b634c7e592e92903f4d20f5f9379034e7a415 Mon Sep 17 00:00:00 2001 From: Harry Groves Date: Mon, 21 Sep 2026 12:41:41 +0800 Subject: [PATCH 13/24] [Fix] DO Workbench EN language --- .../DoWorkbench/DoWorkbenchTabs.tsx | 34 ++- .../TruckRoutingSummaryTabWorkbench.tsx | 25 +- .../WorkbenchGoodPickExecutionDetail.tsx | 42 ++-- .../WorkbenchLotLabelPrintModal.tsx | 92 ++++---- .../FinishedGoodCartonDashboardTab.tsx | 101 ++++---- .../WorkbenchPickExecution.tsx | 8 +- src/i18n/en/common.json | 220 +++++++++--------- src/i18n/en/doWorkbench.json | 21 +- src/i18n/en/pickOrder.json | 92 +++++++- src/i18n/en/ticketReleaseTable.json | 6 +- src/i18n/zh/doWorkbench.json | 16 +- src/i18n/zh/pickOrder.json | 81 ++++++- src/utils/workbenchPickLotUtils.ts | 38 ++- 13 files changed, 518 insertions(+), 258 deletions(-) diff --git a/src/components/DoWorkbench/DoWorkbenchTabs.tsx b/src/components/DoWorkbench/DoWorkbenchTabs.tsx index 69015ee6..c247d87b 100644 --- a/src/components/DoWorkbench/DoWorkbenchTabs.tsx +++ b/src/components/DoWorkbench/DoWorkbenchTabs.tsx @@ -186,7 +186,7 @@ const DoWorkbenchTabsInner: React.FC = ({ defaultTabIndex = 0, printerCom const confirmResult = await Swal.fire({ title: t("Batch Print"), - text: `${t("Confirm print: (")}${releasedOrders.length}${t("piece(s))")}`, + text: t("Confirm print drafts", { count: releasedOrders.length }), icon: "question", showCancelButton: true, confirmButtonText: t("Confirm"), @@ -276,18 +276,29 @@ const DoWorkbenchTabsInner: React.FC = ({ defaultTabIndex = 0, printerCom @@ -297,7 +308,7 @@ const DoWorkbenchTabsInner: React.FC = ({ defaultTabIndex = 0, printerCom sx={{ overflow: "visible", /* 徽章在標籤右側外凸,預留空間避免與下一個 Tab 貼死 */ - pr: etraIncompleteDopoCount > 99 ? 5 : etraIncompleteDopoCount > 0 ? 4 : 2, + pr: etraIncompleteDopoCount > 99 ? 2.5 : etraIncompleteDopoCount > 0 ? 2 : 1, }} label={ = ({ defaultTabIndex = 0, printerCom 0 ? 1 : 0 }} + sx={{ + pr: etraIncompleteDopoCount > 0 ? 1 : 0, + whiteSpace: "normal", + lineHeight: 1.2, + textAlign: "center", + }} > {t("Etra Pick Order Detail")} @@ -341,8 +357,8 @@ const DoWorkbenchTabsInner: React.FC = ({ defaultTabIndex = 0, printerCom - - + + diff --git a/src/components/DoWorkbench/TruckRoutingSummaryTabWorkbench.tsx b/src/components/DoWorkbench/TruckRoutingSummaryTabWorkbench.tsx index 3325a539..c47689f1 100644 --- a/src/components/DoWorkbench/TruckRoutingSummaryTabWorkbench.tsx +++ b/src/components/DoWorkbench/TruckRoutingSummaryTabWorkbench.tsx @@ -3,6 +3,7 @@ import { useEffect, useState } from "react"; import { Box, Button, MenuItem, Stack, TextField, Typography } from "@mui/material"; import DownloadIcon from "@mui/icons-material/Download"; +import { useTranslation } from "react-i18next"; import { clientAuthFetch } from "@/app/utils/clientAuthFetch"; import { NEXT_PUBLIC_API_URL } from "@/config/api"; import { @@ -18,6 +19,7 @@ import { } from "@/lib/featureUsageLog"; const TruckRoutingSummaryTabWorkbench: React.FC = () => { + const { t } = useTranslation(); const [storeOptions, setStoreOptions] = useState([]); const [laneOptions, setLaneOptions] = useState([]); const [storeId, setStoreId] = useState(""); @@ -45,6 +47,9 @@ const TruckRoutingSummaryTabWorkbench: React.FC = () => { const canDownload = storeId && truckLanceCode && date && !loading; + const displayOptionLabel = (label: string) => + String(label).trim() === "車線-X" ? t("Truck X") : label; + const onDownload = async () => { if (!canDownload) return; try { @@ -55,7 +60,9 @@ const TruckRoutingSummaryTabWorkbench: React.FC = () => { }); if (precheck.hasUnpickedOrders) { const confirmed = window.confirm( - `此車線仍有 ${precheck.unpickedOrderCount} 張訂單未執拾。\n是否仍要列印 / 下載送貨路線摘要?` + t("Unpicked orders confirm download", { + count: precheck.unpickedOrderCount, + }), ); if (!confirmed) return; } @@ -92,7 +99,7 @@ const TruckRoutingSummaryTabWorkbench: React.FC = () => { ); } catch (error) { console.error("Failed to download Workbench Truck Routing Summary", error); - alert("下載 Workbench 送貨路線摘要失敗,請稍後再試。"); + alert(t("Failed to download Workbench truck routing summary. Please try again later.")); } finally { setLoading(false); } @@ -101,39 +108,39 @@ const TruckRoutingSummaryTabWorkbench: React.FC = () => { return ( - 送貨路線摘要 (Workbench) + {t("Truck Routing Summary (Workbench)")} onStoreChange(e.target.value)} > {storeOptions.map((opt) => ( - {opt.label} + {displayOptionLabel(opt.label)} ))} setTruckLanceCode(e.target.value)} disabled={!storeId} > {laneOptions.map((opt) => ( - {opt.label} + {displayOptionLabel(opt.label)} ))} { disabled={!canDownload} onClick={onDownload} > - {loading ? "生成中..." : "下載報告 (PDF)"} + {loading ? t("Generating...") : t("Download report (PDF)")} ); diff --git a/src/components/DoWorkbench/WorkbenchGoodPickExecutionDetail.tsx b/src/components/DoWorkbench/WorkbenchGoodPickExecutionDetail.tsx index 29536591..91578a07 100644 --- a/src/components/DoWorkbench/WorkbenchGoodPickExecutionDetail.tsx +++ b/src/components/DoWorkbench/WorkbenchGoodPickExecutionDetail.tsx @@ -421,22 +421,30 @@ function isWorkbenchSourceLotExpired(lot: any): boolean { return false; } -function getWorkbenchSourceLotStatusSummary(lot: any): { +type PickOrderT = (key: string, options?: Record) => string; + +function getWorkbenchSourceLotStatusSummary(lot: any, t: PickOrderT): { severity: "success" | "warning" | "error"; text: string; } { if (!lot) { - return { severity: "warning", text: "無法判斷此批號狀態" }; + return { severity: "warning", text: t("Cannot determine this lot status") }; } if (isWorkbenchSourceLotExpired(lot)) { - return { severity: "error", text: "此批號狀態:已過期" }; + return { severity: "error", text: t("Lot status: expired") }; } const solSt = String(lot.stockOutLineStatus || "").toLowerCase(); if (solSt === "rejected") { - return { severity: "warning", text: "此出庫行:已拒絕,請改掃其他批號" }; + return { + severity: "warning", + text: t("This pick line was rejected. Please scan another lot."), + }; } if (solSt === "completed" || solSt === "partially_completed") { - return { severity: "warning", text: "此出庫行:已完成,無需再提貨" }; + return { + severity: "warning", + text: t("This pick line is already completed. No further pick needed."), + }; } /** * 無批次列:後端仍標 insufficient_stock,語意是「尚無可出庫批號」而非「已用畢」。 @@ -449,28 +457,28 @@ function getWorkbenchSourceLotStatusSummary(lot: any): { if (isNoLotRow) { return { severity: "warning", - text: "尚未綁定批號/無可用庫存列:請掃描週邊入庫或轉倉 QR", + text: t( + "No lot bound / no available stock line. Please scan nearby inbound or transfer QR.", + ), }; } const av = String(lot.lotAvailability || "").toLowerCase(); if (av === "insufficient_stock") { - return { severity: "warning", text: "此批號狀態:已用畢(無剩餘庫存)" }; + return { severity: "warning", text: t("Lot status: depleted (no remaining stock)") }; } const avail = Number(lot.availableQty); if (lot.lotNo && Number.isFinite(avail) && avail <= 0) { - return { severity: "warning", text: "此批號狀態:已用畢(可用量為 0)" }; + return { severity: "warning", text: t("Lot status: depleted (available qty is 0)") }; } if (isInventoryLotLineUnavailable(lot)) { return { severity: "warning", - text: "此批號狀態:庫存不可用(未上架或行狀態不可用)", + text: t("Lot status: unavailable (not put away or line unavailable)"), }; } - return { severity: "success", text: "此批號狀態:可提貨" }; + return { severity: "success", text: t("Lot status: ready to pick") }; } -type PickOrderT = (key: string, options?: Record) => string; - function translateWorkbenchRejectMessage(raw: string, t: PickOrderT): string { const msg = raw.trim(); if (!msg) return msg; @@ -1334,9 +1342,9 @@ const fetchAllCombinedLotData = useCallback(async (userId?: number, pickOrderIdO severity: undefined as "success" | "warning" | "error" | undefined, }; } - const s = getWorkbenchSourceLotStatusSummary(workbenchLotLabelContextLot); + const s = getWorkbenchSourceLotStatusSummary(workbenchLotLabelContextLot, t); return { text: s.text, severity: s.severity }; - }, [workbenchLotLabelModalOpen, workbenchLotLabelContextLot]); + }, [workbenchLotLabelModalOpen, workbenchLotLabelContextLot, t]); const workbenchLotLabelSubmitQty = useMemo(() => { if (!workbenchLotLabelContextLot) return 0; @@ -1811,7 +1819,9 @@ const fetchAllCombinedLotData = useCallback(async (userId?: number, pickOrderIdO setQrScanError(true); setQrScanSuccess(false); setQrScanErrorMsg( - `此批次(${scannedLot.lotNo || scannedStockInLineId})已被拒绝,无法使用。请扫描其他批次。` + t("This lot ({{lot}}) was rejected and cannot be used. Please scan another lot.", { + lot: scannedLot.lotNo || scannedStockInLineId, + }), ); }); // Mark this SOL as processed to prevent re-processing @@ -1864,7 +1874,7 @@ const fetchAllCombinedLotData = useCallback(async (userId?: number, pickOrderIdO startTransition(() => { setQrScanError(true); setQrScanSuccess(false); - setQrScanErrorMsg("当前订单中没有此物品的批次信息"); + setQrScanErrorMsg(t("No lot information for this item in the current order")); }); return; } diff --git a/src/components/DoWorkbench/WorkbenchLotLabelPrintModal.tsx b/src/components/DoWorkbench/WorkbenchLotLabelPrintModal.tsx index 2863a5b9..1d477005 100644 --- a/src/components/DoWorkbench/WorkbenchLotLabelPrintModal.tsx +++ b/src/components/DoWorkbench/WorkbenchLotLabelPrintModal.tsx @@ -37,6 +37,7 @@ import { printWorkbenchLotLabel, } from "@/app/api/doworkbench/actions"; import { QRCodeSVG } from "qrcode.react"; +import { useTranslation } from "react-i18next"; type ScanPayload = { itemId: number; @@ -167,6 +168,7 @@ const WorkbenchLotLabelPrintModal: React.FC = submitQty = null, onSubmitQtyChange, }) => { + const { t } = useTranslation(); const scanInputRef = useRef(null); const [scanInput, setScanInput] = useState(""); const [scanError, setScanError] = useState(null); @@ -210,8 +212,8 @@ const WorkbenchLotLabelPrintModal: React.FC = useEffect(() => { if (!open) return; resetAll(); - const t = setTimeout(() => scanInputRef.current?.focus(), 50); - return () => clearTimeout(t); + const focusTimer = setTimeout(() => scanInputRef.current?.focus(), 50); + return () => clearTimeout(focusTimer); }, [open, resetAll]); const loadPrinters = useCallback(async () => { @@ -224,13 +226,13 @@ const WorkbenchLotLabelPrintModal: React.FC = setPrinters([]); setSnackbar({ open: true, - message: e instanceof Error ? e.message : "載入印表機清單失敗", + message: e instanceof Error ? e.message : t("Failed to load printer list"), severity: "error", }); } finally { setPrintersLoading(false); } - }, []); + }, [t]); useEffect(() => { if (!open) return; @@ -283,23 +285,23 @@ const WorkbenchLotLabelPrintModal: React.FC = setAnalysis(data); setSnackbar({ open: true, - message: "已載入同品可用批號清單", + message: t("Loaded available lots for this item"), severity: "success", }); } catch (e) { setAnalysis(null); - setScanError(e instanceof Error ? e.message : "分析失敗"); + setScanError(e instanceof Error ? e.message : t("Analysis failed")); } finally { setAnalysisLoading(false); } }, - [resolveExpectedUomId], + [resolveExpectedUomId, t], ); const analyzeByItem = useCallback( async (itemId: number) => { if (!Number.isFinite(itemId) || itemId <= 0) { - setScanError("無效 itemId,無法載入批號清單。"); + setScanError(t("Invalid itemId, cannot load lot list.")); return; } setLastItemId(itemId); @@ -325,17 +327,17 @@ const WorkbenchLotLabelPrintModal: React.FC = }); setSnackbar({ open: true, - message: "已載入同品可用批號清單", + message: t("Loaded available lots for this item"), severity: "success", }); } catch (e) { setAnalysis(null); - setScanError(e instanceof Error ? e.message : "分析失敗"); + setScanError(e instanceof Error ? e.message : t("Analysis failed")); } finally { setAnalysisLoading(false); } }, - [resolveExpectedUomId], + [resolveExpectedUomId, t], ); const handleAnalyze = useCallback(async () => { @@ -343,13 +345,13 @@ const WorkbenchLotLabelPrintModal: React.FC = const payload = safeParseScanPayload(raw); if (!payload) { setScanError( - '掃碼內容格式錯誤,請重新掃碼', + t("Invalid scan format. Please scan again."), ); setAnalysis(null); return; } await analyzePayload(payload); - }, [scanInput, analyzePayload]); + }, [scanInput, analyzePayload, t]); const handleRefreshLots = useCallback(async () => { const payload = lastPayload ?? safeParseScanPayload(scanInput.trim()); @@ -368,12 +370,12 @@ const WorkbenchLotLabelPrintModal: React.FC = if (!payload) { setSnackbar({ open: true, - message: "請先掃碼或查詢一次,才可刷新批號清單。", + message: t("Scan or look up once before refreshing the lot list."), severity: "info", }); return; } - }, [analyzeByItem, analyzePayload, initialItemId, lastItemId, lastPayload, scanInput]); + }, [analyzeByItem, analyzePayload, initialItemId, lastItemId, lastPayload, scanInput, t]); useEffect(() => { if (!open) return; @@ -470,7 +472,7 @@ const WorkbenchLotLabelPrintModal: React.FC = if (selectedPrinterId === "") { setSnackbar({ open: true, - message: "請先選擇印表機", + message: t("Please select a printer first"), severity: "error", }); return; @@ -478,7 +480,7 @@ const WorkbenchLotLabelPrintModal: React.FC = if (printQty < 1 || !Number.isFinite(printQty)) { setSnackbar({ open: true, - message: "列印張數需為大於等於 1 的整數", + message: t("Print quantity must be an integer of 1 or more"), severity: "error", }); return; @@ -493,25 +495,25 @@ const WorkbenchLotLabelPrintModal: React.FC = }); setSnackbar({ open: true, - message: `已送出列印:Lot ${lotNo}`, + message: t("Print sent: Lot {{lotNo}}", { lotNo }), severity: "success", }); } catch (e) { setSnackbar({ open: true, - message: e instanceof Error ? e.message : "列印失敗", + message: e instanceof Error ? e.message : t("Print failed"), severity: "error", }); } finally { setPrintingLotLineId(null); } }, - [selectedPrinterId, printQty], + [selectedPrinterId, printQty, t], ); return ( - 批號標籤列印(提貨台) + {t("Lot label print (pick station)")} {statusTitleText ? ( @@ -548,13 +550,13 @@ const WorkbenchLotLabelPrintModal: React.FC = > setScanInput(e.target.value)} fullWidth size="small" error={!!scanError} - helperText={scanError || "掃描後按 Enter 或點「查詢」"} + helperText={scanError || t("Scan then press Enter or click Look up")} onKeyDown={(e) => { if (e.key === "Enter") { e.preventDefault(); @@ -568,7 +570,7 @@ const WorkbenchLotLabelPrintModal: React.FC = onClick={() => void handleAnalyze()} disabled={analysisLoading || !scanInput.trim()} > - {analysisLoading ? : "查詢"} + {analysisLoading ? : t("Look up")} @@ -594,16 +596,16 @@ const WorkbenchLotLabelPrintModal: React.FC = sx={{ minWidth: 260 }} disabled={printersLoading} > - 印表機 + {t("Printer")}
- 2/F 出箱數 - {summary.floor2F.toLocaleString("zh-HK")} + {t("2/F carton qty")} + {summary.floor2F.toLocaleString(numberLocale)} - 4/F 出箱數 - {summary.floor4F.toLocaleString("zh-HK")} + {t("4/F carton qty")} + {summary.floor4F.toLocaleString(numberLocale)} - 車線-X 出箱數 - {summary.truckX.toLocaleString("zh-HK")} + {t("Truck X carton qty")} + {summary.truckX.toLocaleString(numberLocale)} - 總出箱數 - {summary.total.toLocaleString("zh-HK")} + {t("Total carton qty")} + {summary.total.toLocaleString(numberLocale)}
diff --git a/src/components/PickOrderSearch/WorkbenchPickExecution.tsx b/src/components/PickOrderSearch/WorkbenchPickExecution.tsx index 03b91061..da9a2b0a 100644 --- a/src/components/PickOrderSearch/WorkbenchPickExecution.tsx +++ b/src/components/PickOrderSearch/WorkbenchPickExecution.tsx @@ -654,11 +654,11 @@ const WorkbenchPickExecution: React.FC = ({ filterArgs }) => { } const reminder = workbenchLotLabelReminderText?.trim() ?? ""; if (reminder && isExpiredWorkbenchReminderMessage(reminder)) { - return { text: "此批號狀態:已過期", severity: "error" as const }; + return { text: t("Lot status: expired"), severity: "error" as const }; } - const s = getWorkbenchSourceLotStatusSummary(workbenchLotLabelContextLot); + const s = getWorkbenchSourceLotStatusSummary(workbenchLotLabelContextLot, t); return { text: s.text, severity: s.severity }; - }, [workbenchLotLabelModalOpen, workbenchLotLabelContextLot, workbenchLotLabelReminderText]); + }, [workbenchLotLabelModalOpen, workbenchLotLabelContextLot, workbenchLotLabelReminderText, t]); const handleJustComplete = useCallback( async (row: LotRow) => { @@ -1714,7 +1714,7 @@ const WorkbenchPickExecution: React.FC = ({ filterArgs }) => { onClick={() => openWorkbenchLotLabelModalForLot(r)} sx={{ flexShrink: 0, fontSize: "0.7rem", py: 0.25, minWidth: "auto", px: 1, whiteSpace: "nowrap" }} > - {t(" 批號 QR 碼")} + {t("lot QR code")} ) : null} diff --git a/src/i18n/en/common.json b/src/i18n/en/common.json index a3b15c4e..795915fc 100644 --- a/src/i18n/en/common.json +++ b/src/i18n/en/common.json @@ -1,131 +1,131 @@ { - "Actions": "操作", - "Add Document": "新增文件", + "Actions": "Actions", + "Add Document": "Add Document", "All": "All", - "Allergic Substances": "過敏原", + "Allergic Substances": "Allergens", "An error has occurred. Please try again later.": "An error has occurred. Please try again later.", - "Are you sure you want to delete this item?": "您確定要刪除此項目嗎?", - "Back": "返回", - "Basic Info": "基本資訊", + "Are you sure you want to delete this item?": "Are you sure you want to delete this item?", + "Back": "Back", + "Basic Info": "Basic Info", "Bom Required Qty": "BOM Required Qty", "Bom UOM": "BOM UOM", - "Brand": "品牌", - "CMB": "消耗品", - "CO": "消耗品", - "Cancel": "取消", - "Column Name": "欄位名稱", - "Coming soon": "即將推出", - "Complexity": "複雜度", - "Confirm": "確認", - "Confirm Delete": "確認刪除", - "Cost (HKD)": "費用 (HKD)", - "Current total": "目前總和", - "Day Before Yesterday": "前天", - "Delete": "刪除", - "Delete Failed": "刪除失敗", + "Brand": "Brand", + "CMB": "Consumable", + "CO": "Consumable", + "Cancel": "Cancel", + "Column Name": "Column Name", + "Coming soon": "Coming soon", + "Complexity": "Complexity", + "Confirm": "Confirm", + "Confirm Delete": "Confirm Delete", + "Cost (HKD)": "Cost (HKD)", + "Current total": "Current total", + "Day Before Yesterday": "Day Before Yesterday", + "Delete": "Delete", + "Delete Failed": "Delete Failed", "Do you want to delete?": "Do you want to delete?", - "Density": "濃淡", - "Depth": "顔色深淺度 深1淺5", - "Description": "描述", - "Details": "詳情", - "Duration (Minutes)": "時間(分)", - "Edit": "編輯", - "Enter any additional observations or notes...": "輸入其他觀察或備註...", - "Enter or select remark": "輸入或選擇備註", + "Density": "Density", + "Depth": "Color depth (dark 1 / light 5)", + "Description": "Description", + "Details": "Details", + "Duration (Minutes)": "Duration (Minutes)", + "Edit": "Edit", + "Enter any additional observations or notes...": "Enter any additional observations or notes...", + "Enter or select remark": "Enter or select remark", "Error saving data": "Error saving data", - "Failed to fetch data": "無法取得資料", - "Filter": "過濾", - "Finished Good Detail": "成品出倉詳情", - "Finished Good Management": "成品出倉管理", - "Finished Good Order": "成品出倉", - "Float": "浮沉", - "General Data": "基本資料", - "Grade {{grade}}": "等級 {{grade}}", - "Invoice": "發票", - "Invoice Date": "發票日期", + "Failed to fetch data": "Failed to fetch data", + "Filter": "Filter", + "Finished Good Detail": "Finished Good Detail", + "Finished Good Management": "Finished Good Management", + "Finished Good Order": "Finished Good Order", + "Float": "Float", + "General Data": "General Data", + "Grade {{grade}}": "Grade {{grade}}", + "Invoice": "Invoice", + "Invoice Date": "Invoice Date", "IP": "IP", "Item Code": "Item Code", "Item Name": "Item Name", - "Loading": "載入中...", - "Loading order summary": "正在載入訂單摘要", - "Location": "位置", - "MA": "材料", - "MAT": "材料", - "MI": "雜項", - "Material Name": "材料清單", + "Loading": "Loading...", + "Loading order summary": "Loading order summary", + "Location": "Location", + "MA": "Material", + "MAT": "Material", + "MI": "Miscellaneous", + "Material Name": "Material List", "Name": "Name", - "Min": "最小值", - "NM": "雜項及非消耗品", - "No": "否", - "No Lot": "沒有批號", - "No data available": "沒有資料", - "No options": "沒有選項", - "Order": "順序", + "Min": "Min", + "NM": "Miscellaneous and non-consumables", + "No": "No", + "No Lot": "No Lot", + "No data available": "No data available", + "No options": "No options", + "Order": "Order", "Pending": "Pending", "Port": "Port", - "Please Select BOM": "請選擇 BOM", - "Please try again later.": "請稍後重試。", - "Project Code": "專案代碼", - "Project Code and Name": "專案代碼與名稱", - "QC Template not found": "找不到 QC 範本", - "Qty": "數量", - "RM": "原料", - "Range": "範圍", - "Refresh": "重新載入", - "Remarks": "備註", - "Remove Document": "移除文件", - "Report": "報告", + "Please Select BOM": "Please select BOM", + "Please try again later.": "Please try again later.", + "Project Code": "Project Code", + "Project Code and Name": "Project Code and Name", + "QC Template not found": "QC template not found", + "Qty": "Qty", + "RM": "Raw material", + "Range": "Range", + "Refresh": "Refresh", + "Remarks": "Remarks", + "Remove Document": "Remove Document", + "Report": "Report", "Reset": "Reset", - "Row per page": "每頁行數", - "Rows per page": "每頁行數", - "Sales Qty": "銷售數量", - "Sales UOM": "銷售單位", - "Save": "儲存", - "Saving": "儲存中", + "Row per page": "Rows per page", + "Rows per page": "Rows per page", + "Sales Qty": "Sales Qty", + "Sales UOM": "Sales UOM", + "Save": "Save", + "Saving": "Saving", "Search": "Search", "Search Criteria": "Search Criteria", - "Select Date": "選擇日期", - "Session expired or unauthorized.": "工作階段已過期或未經授權。", + "Select Date": "Select Date", + "Session expired or unauthorized.": "Session expired or unauthorized.", "Sign out": "Sign out", "Language": "Language", - "Status": "狀態", - "Stock Qty": "庫存數量", - "Supporting Document": "證明文件", - "Task": "任務", - "Time Sequence": "時段", + "Status": "Status", + "Stock Qty": "Stock Qty", + "Supporting Document": "Supporting Document", + "Task": "Task", + "Time Sequence": "Time Sequence", "Type": "Type", - "Today": "今天", - "Total weighting must equal 1": "權重總和必須等於 1", - "Unauthorized: Please log in again": "未經授權:請重新登入", - "Uom": "單位", - "Update Failed": "更新失敗", - "Update Success": "更新成功", - "Weighting must be a number": "權重必須為數字", - "Yes": "是", - "Yesterday": "昨天", - "all": "全部", + "Today": "Today", + "Total weighting must equal 1": "Total weighting must equal 1", + "Unauthorized: Please log in again": "Unauthorized: Please log in again", + "Uom": "UOM", + "Update Failed": "Update Failed", + "Update Success": "Update Success", + "Weighting must be a number": "Weighting must be a number", + "Yes": "Yes", + "Yesterday": "Yesterday", + "all": "All", "bomWeighting": "BOM Weighting Score", - "cmb": "消耗品", - "collapsible table": "可折疊表格", - "consumable": "消耗品", - "consumables": "消耗品", - "create": "新增", - "edit": "編輯", - "expand row": "展開行", - "group mode": "群組模式", - "item": "貨品", - "items": "物品", - "mat": "原料", - "menu": "選單", - "nm": "雜項及非消耗品", - "non-consumables": "非消耗品", - "other": "其他", - "profile": "個人資料", - "revert": "還原", - "settings": "設定", - "stockRecord": "盤點記錄", - "stocktakemanagement": "盤點管理", - "testing sections tabs": "測試區域分頁", - "warehouse": "倉庫", - "材料": "材料" + "cmb": "Consumable", + "collapsible table": "Collapsible table", + "consumable": "Consumable", + "consumables": "Consumables", + "create": "Create", + "edit": "Edit", + "expand row": "Expand row", + "group mode": "Group mode", + "item": "Item", + "items": "Items", + "mat": "Raw material", + "menu": "Menu", + "nm": "Miscellaneous and non-consumables", + "non-consumables": "Non-consumables", + "other": "Other", + "profile": "Profile", + "revert": "Revert", + "settings": "Settings", + "stockRecord": "Stock record", + "stocktakemanagement": "Stock take management", + "testing sections tabs": "Testing section tabs", + "warehouse": "Warehouse", + "材料": "Material" } diff --git a/src/i18n/en/doWorkbench.json b/src/i18n/en/doWorkbench.json index 321a91a6..108d183a 100644 --- a/src/i18n/en/doWorkbench.json +++ b/src/i18n/en/doWorkbench.json @@ -45,5 +45,24 @@ "DO Workbench Search": "DO Workbench Search", "completed": "completed", "items": "items", - "pending": "pending" + "pending": "pending", + "Pick Order Detail": "Pick Detail", + "Etra Pick Order Detail": "Etra", + "Finished Good Record": "FG Record", + "Finished Good Record (All)": "FG Record (All)", + "Ticket Release Table": "Ticket Release", + "FG Carton Qty": "Carton Qty", + "成品出倉出箱數量": "Carton Qty", + "Truck Routing Summary": "Routing Summary", + "送貨路線摘要": "Truck Routing Summary", + "車線-X": "Truck X", + "Confirm print drafts": "Print {{count}} draft(s)?", + "Truck Routing Summary (Workbench)": "Truck Routing Summary (Workbench)", + "2/F or 4/F": "2/F or 4/F", + "Lane": "Lane", + "Date": "Date", + "Generating...": "Generating...", + "Download report (PDF)": "Download report (PDF)", + "Unpicked orders confirm download": "This lane still has {{count}} unpicked order(s).\nPrint / download the truck routing summary anyway?", + "Failed to download Workbench truck routing summary. Please try again later.": "Failed to download Workbench truck routing summary. Please try again later." } diff --git a/src/i18n/en/pickOrder.json b/src/i18n/en/pickOrder.json index db082bee..7760686c 100644 --- a/src/i18n/en/pickOrder.json +++ b/src/i18n/en/pickOrder.json @@ -58,7 +58,7 @@ "Lines": "Lines", "Before Today": "Before Today", "Truck X": "Truck X", - "Finsihed good items": "Finsihed good items", + "Finsihed good items": "Finished good items", "kinds": "kinds", "Completed Date": "Completed Date", "Completed Time": "Completed Time", @@ -147,8 +147,8 @@ "Etra": "Etra", "Exit Etra view": "Exit Etra view", "Etra Pick Order Detail": "Etra Pick Order Detail", - "Etra incomplete badge tooltip": "Etra incomplete badge tooltip", - "Etra incomplete badge tooltip none": "Etra incomplete badge tooltip none", + "Etra incomplete badge tooltip": "Incomplete extra tickets today: {{count}} (pending/released, excluding completed)", + "Etra incomplete badge tooltip none": "No incomplete extra tickets", "Back to normal assign tab": "Back to normal assign tab", "Enter isExtra workbench view?": "Enter isExtra workbench view?", "Etra view groups all add-on tickets by shop and lane for the selected date.": "Etra view groups all add-on tickets by shop and lane for the selected date.", @@ -179,7 +179,6 @@ "Confirm Search": "Search", "Merge Etra ticket search prompt": "Enter shop (optional) and date, then click Search to load merge candidates.", "Merge Etra ticket search failed": "Failed to load merge candidates. Ensure the backend is updated and restarted.", - "Truck X": "Truck X", "Pick Order": "Pick Order", "Type": "Type", "Product Type": "Product Type", @@ -529,14 +528,14 @@ "Floor ticket": "Floor ticket", "2F ticket": "2F ticket", "4F ticket": "4F ticket", - "4F lane panel legend": "4F lane panel legend", - "Loading sequence n": "Loading sequence n", - "lot QR code": "lot QR code", + "4F lane panel legend": "Lane — loading sequence (unassigned/total)", + "Loading sequence n": "Board {{n}}", + "lot QR code": "Lot QR Code", "label Printer": "label Printer", "Loading Sequence": "Loading Sequence", "Ticket No": "Ticket No", "The scanned lot inventory line is unavailable. Cannot switch or bind; pick line was not updated.": "The scanned lot inventory line is unavailable. Cannot switch or bind; pick line was not updated.", - "is unavable. Please check around have available QR code or not.": "is unavable. Please check around have available QR code or not.", + "is unavable. Please check around have available QR code or not.": "This lot is unavailable. Please check around for an available QR code.", "Lot switch failed; pick line was not marked as checked.": "Lot switch failed; pick line was not marked as checked.", "Lot confirmation failed. Please try again.": "Lot confirmation failed. Please try again.", "Powder Mixture": "Powder Mixture", @@ -559,5 +558,80 @@ "passed": "Passed", "failed": "Failed", "confirm_accept_with_fail": "There are failed QC items. Confirm to accept stock out?", - "No pending pick line left for this item. It may already be completed or fully processed.": "No pending pick line left for this item. It may already be completed or fully processed." + "No pending pick line left for this item. It may already be completed or fully processed.": "No pending pick line left for this item. It may already be completed or fully processed.", + "FG Carton Qty": "FG Carton Qty", + "成品出倉出箱數量": "FG Carton Qty", + "Truck Routing Summary": "Truck Routing Summary", + "送貨路線摘要": "Truck Routing Summary", + "車線-X": "Truck X", + "Lot QR Code": "Lot QR Code", + " 批號 QR 碼": "Lot QR Code", + "Cannot determine this lot status": "Cannot determine this lot status", + "Lot status: expired": "Lot status: expired", + "This pick line was rejected. Please scan another lot.": "This pick line was rejected. Please scan another lot.", + "This pick line is already completed. No further pick needed.": "This pick line is already completed. No further pick needed.", + "No lot bound / no available stock line. Please scan nearby inbound or transfer QR.": "No lot bound / no available stock line. Please scan nearby inbound or transfer QR.", + "Lot status: depleted (no remaining stock)": "Lot status: depleted (no remaining stock)", + "Lot status: depleted (available qty is 0)": "Lot status: depleted (available qty is 0)", + "Lot status: unavailable (not put away or line unavailable)": "Lot status: unavailable (not put away or line unavailable)", + "Lot status: ready to pick": "Lot status: ready to pick", + "This lot ({{lot}}) was rejected and cannot be used. Please scan another lot.": "This lot ({{lot}}) was rejected and cannot be used. Please scan another lot.", + "No lot information for this item in the current order": "No lot information for this item in the current order", + "Lot label print (pick station)": "Lot label print (pick station)", + "Scan content": "Scan content", + "Scan then press Enter or click Look up": "Scan then press Enter or click Look up", + "Look up": "Look up", + "Clear": "Clear", + "Printer": "Printer", + "Please select": "Please select", + "Print copies": "Print copies", + "Refresh lot list": "Refresh lot list", + "Selected printer": "Selected: {{printer}}", + "Item code name": "Item: {{code}} {{name}}", + "No available lots on this floor": "No available lots on this floor (available qty > 0).", + " (current lot)": " (current lot)", + "Location with value": "Location: {{location}}", + "Available qty with uom": "Available qty: {{qty}} UOM: {{uom}}", + "Print label": "Print label", + "Show QR": "Show QR", + "This row has no QR payload": "This row has no QR payload (stockInLineId required)", + "This pick line already scanned or completed, QR cannot be shown": "This pick line is already scanned or completed, so QR cannot be shown", + "No lots available to print labels": "No lots available to print labels", + "Failed to load printer list": "Failed to load printer list", + "Loaded available lots for this item": "Loaded available lots for this item", + "Analysis failed": "Look-up failed", + "Invalid itemId, cannot load lot list.": "Invalid item ID, cannot load lot list.", + "Invalid scan format. Please scan again.": "Invalid scan format. Please scan again.", + "Scan or look up once before refreshing the lot list.": "Scan or look up once before refreshing the lot list.", + "Print quantity must be an integer of 1 or more": "Print quantity must be an integer of 1 or more", + "Print sent: Lot {{lotNo}}": "Print sent: Lot {{lotNo}}", + "Print failed": "Print failed", + "Failed to load FG carton quantity. Please try again later.": "Failed to load FG carton quantity. Please try again later.", + "Cartons": "Cartons", + "{{count}} cartons": "{{count}} cartons", + "No chart data": "No chart data", + "2/F carton qty": "2/F carton qty", + "4/F carton qty": "4/F carton qty", + "Truck X carton qty": "Truck X carton qty", + "Total carton qty": "Total carton qty", + "Summary": "Summary", + "All floors": "All floors", + "Last 7 days": "Last 7 days", + "This month": "This month", + "This year": "This year", + "FG carton qty last 7 days title": "FG carton qty (last 7 days) - {{floor}} - as of {{date}}", + "FG carton qty this month title": "FG carton qty (this month) - {{floor}} - {{period}}", + "FG carton qty this year title": "FG carton qty (this year) - {{floor}} - {{period}}", + "Exporting...": "Exporting...", + "Download Excel": "Download Excel", + "Truck Routing Summary (Workbench)": "Truck Routing Summary (Workbench)", + "2/F or 4/F": "2/F or 4/F", + "Lane": "Lane", + "Generating...": "Generating...", + "Download report (PDF)": "Download report (PDF)", + "Unpicked orders confirm download": "This lane still has {{count}} unpicked order(s).\nPrint / download the truck routing summary anyway?", + "Failed to download Workbench truck routing summary. Please try again later.": "Failed to download Workbench truck routing summary. Please try again later.", + "Confirm print drafts": "Print {{count}} draft(s)?", + "Floor": "Floor", + "All": "All" } diff --git a/src/i18n/en/ticketReleaseTable.json b/src/i18n/en/ticketReleaseTable.json index 6fc5468a..bb0a9732 100644 --- a/src/i18n/en/ticketReleaseTable.json +++ b/src/i18n/en/ticketReleaseTable.json @@ -16,11 +16,11 @@ "Departure Time": "Departure Time", "Floor": "Floor", "Force complete DO": "Force complete DO", - "Force complete hint": "Force complete hint", + "Force complete hint": "Marks the ticket completed and archived without changing picked quantities. Use when all lines are submitted but the system did not complete.", "Handler Name": "Handler Name", "Last updated": "Last updated", "Loading Sequence": "Loading Sequence", - "Manager only hint": "Manager only hint", + "Manager only hint": "Admin only", "No data available": "No data available", "Now": "Now", "Number of FG Items (Order Item(s) Count)": "Number of FG Items (Order Item(s) Count)", @@ -29,7 +29,7 @@ "Reload data": "Reload data", "Required Delivery Date": "Required Delivery Date", "Revert assignment": "Revert assignment", - "Revert assignment hint": "Revert assignment hint", + "Revert assignment hint": "Clears the assigned handler so the ticket returns to unassigned and can be taken again.", "Rows per page": "Rows per page", "Select All": "Select All", "Select Date": "Select Date", diff --git a/src/i18n/zh/doWorkbench.json b/src/i18n/zh/doWorkbench.json index 367c74db..2628d6e8 100644 --- a/src/i18n/zh/doWorkbench.json +++ b/src/i18n/zh/doWorkbench.json @@ -45,5 +45,19 @@ "Auto-refresh every 5 minutes": "每5分鐘自動刷新", "Last updated": "最後更新", "Truck Information": "車線資訊", - "Actions": "操作" + "Actions": "操作", + "FG Carton Qty": "成品出倉出箱數量", + "成品出倉出箱數量": "成品出倉出箱數量", + "Truck Routing Summary": "送貨路線摘要", + "送貨路線摘要": "送貨路線摘要", + "車線-X": "車線-X", + "Confirm print drafts": "確認列印 {{count}} 張草稿?", + "Truck Routing Summary (Workbench)": "送貨路線摘要 (Workbench)", + "2/F or 4/F": "2/F 或 4/F", + "Lane": "車線", + "Date": "日期", + "Generating...": "生成中...", + "Download report (PDF)": "下載報告 (PDF)", + "Unpicked orders confirm download": "此車線仍有 {{count}} 張訂單未執拾。\n是否仍要列印 / 下載送貨路線摘要?", + "Failed to download Workbench truck routing summary. Please try again later.": "下載 Workbench 送貨路線摘要失敗,請稍後再試。" } diff --git a/src/i18n/zh/pickOrder.json b/src/i18n/zh/pickOrder.json index d9465c5e..d738c00f 100644 --- a/src/i18n/zh/pickOrder.json +++ b/src/i18n/zh/pickOrder.json @@ -568,5 +568,82 @@ "Lot status is unavailable. Cannot switch or bind; pick line was not updated.": "批號狀態為「不可用」,無法換批或綁定;揀貨行未更新。", "No lot rows. Select a line in the table above.": "尚無批號資料。請在上方表格勾選一行提料單明細。", "No stock out line for this lot": "此批號尚無出庫行,無法提交。", - "No pending pick line left for this item. It may already be completed or fully processed.": "此貨品已無待揀行,可能已完成或不在本單可掃範圍。" - } \ No newline at end of file + "No pending pick line left for this item. It may already be completed or fully processed.": "此貨品已無待揀行,可能已完成或不在本單可掃範圍。", + + "FG Carton Qty": "成品出倉出箱數量", + "成品出倉出箱數量": "成品出倉出箱數量", + "Truck Routing Summary": "送貨路線摘要", + "送貨路線摘要": "送貨路線摘要", + "車線-X": "車線-X", + "Lot QR Code": "批號 QR 碼", + " 批號 QR 碼": "批號 QR 碼", + "Cannot determine this lot status": "無法判斷此批號狀態", + "Lot status: expired": "此批號狀態:已過期", + "This pick line was rejected. Please scan another lot.": "此出庫行:已拒絕,請改掃其他批號", + "This pick line is already completed. No further pick needed.": "此出庫行:已完成,無需再提貨", + "No lot bound / no available stock line. Please scan nearby inbound or transfer QR.": "尚未綁定批號/無可用庫存列:請掃描週邊入庫或轉倉 QR", + "Lot status: depleted (no remaining stock)": "此批號狀態:已用畢(無剩餘庫存)", + "Lot status: depleted (available qty is 0)": "此批號狀態:已用畢(可用量為 0)", + "Lot status: unavailable (not put away or line unavailable)": "此批號狀態:庫存不可用(未上架或行狀態不可用)", + "Lot status: ready to pick": "此批號狀態:可提貨", + "This lot ({{lot}}) was rejected and cannot be used. Please scan another lot.": "此批次({{lot}})已被拒絕,無法使用。請掃描其他批次。", + "No lot information for this item in the current order": "當前訂單中沒有此物品的批次資訊", + "Lot label print (pick station)": "批號標籤列印(提貨台)", + "Scan content": "掃碼內容", + "Scan then press Enter or click Look up": "掃描後按 Enter 或點「查詢」", + "Look up": "查詢", + "Clear": "清除", + "Printer": "印表機", + "Please select": "請選擇", + "Print copies": "列印張數", + "Refresh lot list": "刷新批號清單", + "Selected printer": "已選:{{printer}}", + "Item code name": "品號:{{code}} {{name}}", + "No available lots on this floor": "找不到該樓層有可用批號(availableQty > 0)。", + " (current lot)": "(當前批次)", + "Location with value": "位置:{{location}}", + "Available qty with uom": "可用量:{{qty}} 單位:{{uom}}", + "Print label": "列印標籤", + "Show QR": "顯示 QR", + "This row has no QR payload": "此列無法取得 QR payload(需 stockInLineId)", + "This pick line already scanned or completed, QR cannot be shown": "此出庫行已掃碼或已完成,無法顯示 QR", + "No lots available to print labels": "沒有任何批號可列印標籤", + "Failed to load printer list": "載入印表機清單失敗", + "Loaded available lots for this item": "已載入同品可用批號清單", + "Analysis failed": "分析失敗", + "Invalid itemId, cannot load lot list.": "無效 itemId,無法載入批號清單。", + "Invalid scan format. Please scan again.": "掃碼內容格式錯誤,請重新掃碼", + "Scan or look up once before refreshing the lot list.": "請先掃碼或查詢一次,才可刷新批號清單。", + "Print quantity must be an integer of 1 or more": "列印張數需為大於等於 1 的整數", + "Print sent: Lot {{lotNo}}": "已送出列印:Lot {{lotNo}}", + "Print failed": "列印失敗", + "Failed to load FG carton quantity. Please try again later.": "載入成品出倉出箱數量失敗,請稍後再試。", + "Cartons": "箱數", + "{{count}} cartons": "{{count}} 箱", + "No chart data": "沒有圖表資料", + "Total": "總數", + "2/F carton qty": "2/F 出箱數", + "4/F carton qty": "4/F 出箱數", + "Truck X carton qty": "車線-X 出箱數", + "Total carton qty": "總出箱數", + "Summary": "彙總", + "All floors": "全部樓層", + "Last 7 days": "最近7天", + "This month": "本月", + "This year": "本年", + "FG carton qty last 7 days title": "成品出倉出箱數量(最近7天)- {{floor}} - 基準日 {{date}}", + "FG carton qty this month title": "成品出倉出箱數量(本月)- {{floor}} - {{period}}", + "FG carton qty this year title": "成品出倉出箱數量(本年)- {{floor}} - {{period}}", + "Exporting...": "匯出中...", + "Download Excel": "下載 Excel", + "Truck Routing Summary (Workbench)": "送貨路線摘要 (Workbench)", + "2/F or 4/F": "2/F 或 4/F", + "Lane": "車線", + "Generating...": "生成中...", + "Download report (PDF)": "下載報告 (PDF)", + "Unpicked orders confirm download": "此車線仍有 {{count}} 張訂單未執拾。\n是否仍要列印 / 下載送貨路線摘要?", + "Failed to download Workbench truck routing summary. Please try again later.": "下載 Workbench 送貨路線摘要失敗,請稍後再試。", + "Confirm print drafts": "確認列印 {{count}} 張草稿?", + "Floor": "樓層", + "All": "全部" +} diff --git a/src/utils/workbenchPickLotUtils.ts b/src/utils/workbenchPickLotUtils.ts index de0ab460..d73af4f6 100644 --- a/src/utils/workbenchPickLotUtils.ts +++ b/src/utils/workbenchPickLotUtils.ts @@ -150,44 +150,62 @@ export function buildUnpickableScanRowPatch( return patch; } -export function getWorkbenchSourceLotStatusSummary(lot: WorkbenchPickLotLike | null | undefined): { +export function getWorkbenchSourceLotStatusSummary( + lot: WorkbenchPickLotLike | null | undefined, + t?: PickOrderT, +): { severity: "success" | "warning" | "error"; text: string; } { + const tr = (key: string) => (t ? t(key) : key); if (!lot) { - return { severity: "warning", text: "無法判斷此批號狀態" }; + return { severity: "warning", text: tr("Cannot determine this lot status") }; } if (isWorkbenchSourceLotExpired(lot)) { - return { severity: "error", text: "此批號狀態:已過期" }; + return { severity: "error", text: tr("Lot status: expired") }; } const solSt = solStatusOf(lot); if (solSt === "rejected") { - return { severity: "warning", text: "此出庫行:已拒絕,請改掃其他批號" }; + return { + severity: "warning", + text: tr("This pick line was rejected. Please scan another lot."), + }; } if (solSt === "completed" || solSt === "partially_completed" || solSt === "partially_complete") { - return { severity: "warning", text: "此出庫行:已完成,無需再提貨" }; + return { + severity: "warning", + text: tr("This pick line is already completed. No further pick needed."), + }; } const isNoLotRow = lot.noLot === true || !lot.lotNo || String(lot.lotNo || "").trim() === ""; if (isNoLotRow) { return { severity: "warning", - text: "尚未綁定批號/無可用庫存列:請掃描週邊入庫或轉倉 QR", + text: tr( + "No lot bound / no available stock line. Please scan nearby inbound or transfer QR.", + ), }; } const av = String(lot.lotAvailability || "").toLowerCase(); if (av === "insufficient_stock") { - return { severity: "warning", text: "此批號狀態:已用畢(無剩餘庫存)" }; + return { + severity: "warning", + text: tr("Lot status: depleted (no remaining stock)"), + }; } const avail = Number(lot.availableQty); if (lot.lotNo && Number.isFinite(avail) && avail <= 0) { - return { severity: "warning", text: "此批號狀態:已用畢(可用量為 0)" }; + return { + severity: "warning", + text: tr("Lot status: depleted (available qty is 0)"), + }; } if (isInventoryLotLineUnavailable(lot)) { return { severity: "warning", - text: "此批號狀態:庫存不可用(未上架或行狀態不可用)", + text: tr("Lot status: unavailable (not put away or line unavailable)"), }; } - return { severity: "success", text: "此批號狀態:可提貨" }; + return { severity: "success", text: tr("Lot status: ready to pick") }; } From 4665592671afd12abde3fb951d12724a7b123ce0 Mon Sep 17 00:00:00 2001 From: Harry Groves Date: Mon, 21 Sep 2026 18:14:35 +0800 Subject: [PATCH 14/24] [Feat] DO Workbench -> Carton Qty now can search lane and shop + download btn for specified filters --- src/app/api/doworkbench/actions.ts | 2 - src/app/api/pickOrder/actions.ts | 2 - .../FinishedGoodCartonDashboardTab.tsx | 907 +++++++++++++++--- src/components/charts/SafeApexCharts.tsx | 91 +- src/i18n/en/doWorkbench.json | 21 + src/i18n/en/pickOrder.json | 18 + src/i18n/zh/doWorkbench.json | 21 + src/i18n/zh/pickOrder.json | 18 + 8 files changed, 905 insertions(+), 175 deletions(-) diff --git a/src/app/api/doworkbench/actions.ts b/src/app/api/doworkbench/actions.ts index 65af3d6e..60a0040d 100644 --- a/src/app/api/doworkbench/actions.ts +++ b/src/app/api/doworkbench/actions.ts @@ -216,7 +216,6 @@ export async function fetchWorkbenchStoreLaneSummary( return serverFetchJson(url, { method: "GET", cache: "no-store", - next: { revalidate: 0 }, }); } @@ -235,7 +234,6 @@ export async function fetchWorkbenchEtraLaneSummary( const data = await serverFetchJson(url, { method: "GET", cache: "no-store", - next: { revalidate: 0 }, }); return Array.isArray(data) ? data : []; } diff --git a/src/app/api/pickOrder/actions.ts b/src/app/api/pickOrder/actions.ts index f21a60b4..25409697 100644 --- a/src/app/api/pickOrder/actions.ts +++ b/src/app/api/pickOrder/actions.ts @@ -632,7 +632,6 @@ export async function fetchStoreLaneSummary(storeId: string, requiredDate?: stri const response = await serverFetchJson(url, { method: "GET", cache: "no-store", - next: { revalidate: 0 }, }); console.timeEnd(label); return response; @@ -856,7 +855,6 @@ export const fetchFGPickOrdersByUserIdWorkbench = async (userId: number) => { method: "GET", // Must be fresh: determines whether shell shows Floor/Lane panel or Detail. cache: "no-store", - next: { revalidate: 0 }, }, ); }; diff --git a/src/components/FinishedGoodSearch/FinishedGoodCartonDashboardTab.tsx b/src/components/FinishedGoodSearch/FinishedGoodCartonDashboardTab.tsx index cdf8d0e2..ba895bdb 100644 --- a/src/components/FinishedGoodSearch/FinishedGoodCartonDashboardTab.tsx +++ b/src/components/FinishedGoodSearch/FinishedGoodCartonDashboardTab.tsx @@ -1,8 +1,9 @@ "use client"; -import { useCallback, useEffect, useMemo, useState } from "react"; +import { useCallback, useEffect, useMemo, useRef, useState } from "react"; import { Alert, + Autocomplete, Box, Button, CircularProgress, @@ -10,13 +11,8 @@ import { MenuItem, Paper, Stack, - Table, - TableBody, - TableCell, - TableContainer, - TableHead, - TableRow, TextField, + Tooltip, Typography, } from "@mui/material"; import type { ApexOptions } from "apexcharts"; @@ -31,6 +27,7 @@ import SafeApexCharts from "@/components/charts/SafeApexCharts"; import { useTranslation } from "react-i18next"; type FloorFilter = "all" | "2/F" | "4/F"; +type BreakdownDimension = "lane" | "shop" | "floor"; type DailySummaryRow = { date: string; @@ -40,19 +37,143 @@ type DailySummaryRow = { total: number; }; +type BreakdownRow = { + key: string; + label: string; + qty: number; +}; + type Props = { mode?: "normal" | "workbench"; }; +const TRUCK_X_LANE = "車線-X"; +const ALL = "all"; +const CHART_ROW_H = 38; + +type FilterOption = { value: string; label: string }; + +function normalizeTruckLane(raw: string | null | undefined): string { + const value = String(raw ?? "").trim(); + return value || TRUCK_X_LANE; +} + +function shortLaneLabel(raw: string | null | undefined): string { + const value = normalizeTruckLane(raw); + const stripped = value + .replace(/^(車線)[-–—]?\s*/u, "") + .replace(/^(truck)\s*[-–—]?\s*/i, "") + .trim(); + return stripped || value; +} + +function normalizeShopCode(raw: string | null | undefined): string { + return String(raw ?? "").trim(); +} + +function shopGroup(raw: string | null | undefined): string { + const code = normalizeShopCode(raw).toUpperCase(); + if (!code) return ""; + return code.slice(0, 2); +} + +function isShopGroupValue(shop: string): boolean { + if (shop === ALL) return false; + const code = normalizeShopCode(shop).toUpperCase(); + return code.length > 0 && code === shopGroup(code); +} + +function recordMatchesShop( + recordShop: string | null | undefined, + shop: string, +): boolean { + if (shop === ALL) return true; + const code = normalizeShopCode(recordShop).toUpperCase(); + if (!code) return false; + const selected = normalizeShopCode(shop).toUpperCase(); + if (isShopGroupValue(selected)) { + return shopGroup(code) === selected; + } + return code === selected; +} + +function recordMatchesFilters( + record: CompletedDoPickOrderResponse, + floor: FloorFilter, + lane: string, + shop: string, +): boolean { + if (floor !== ALL && record.storeId !== floor) return false; + if (lane !== ALL && normalizeTruckLane(record.truckLanceCode) !== lane) return false; + if (!recordMatchesShop(record.shopCode, shop)) return false; + return true; +} + +function resolveBreakdownDimension(lane: string, shop: string): BreakdownDimension { + if (isShopGroupValue(shop)) return "shop"; + if (shop !== ALL && lane !== ALL) return "floor"; + if (lane !== ALL) return "shop"; + if (shop !== ALL) return "lane"; + return "lane"; +} + +type SearchableFilterProps = { + label: string; + options: FilterOption[]; + value: string; + onChange: (next: string) => void; +}; + +function SearchableFilterSelect({ label, options, value, onChange }: SearchableFilterProps) { + const selectable = options.filter((option) => option.value !== ALL); + const selected = selectable.find((option) => option.value === value) ?? null; + const placeholder = options.find((option) => option.value === ALL)?.label ?? ""; + + return ( + onChange(option?.value ?? ALL)} + getOptionLabel={(option) => option?.label ?? ""} + isOptionEqualToValue={(a, b) => a?.value === b?.value} + selectOnFocus + autoHighlight + handleHomeEndKeys + autoComplete + includeInputInList + size="small" + sx={{ width: "100%" }} + renderInput={(params) => ( + + )} + /> + ); +} + const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => { const { t, i18n } = useTranslation(); const numberLocale = i18n.language?.startsWith("zh") ? "zh-HK" : "en-US"; - const [floor, setFloor] = useState("all"); + const [floor, setFloor] = useState(ALL); + const [lane, setLane] = useState(ALL); + const [shop, setShop] = useState(ALL); const [date, setDate] = useState(dayjs().format("YYYY-MM-DD")); const [loading, setLoading] = useState(false); const [isExporting, setIsExporting] = useState(false); + const [isExportingFiltered, setIsExportingFiltered] = useState(false); + const exportInFlightRef = useRef(false); + const filteredExportInFlightRef = useRef(false); const [error, setError] = useState(""); const [records, setRecords] = useState([]); + const todayDate = dayjs().format("YYYY-MM-DD"); + const filtersAreActive = + floor !== ALL || lane !== ALL || shop !== ALL || date !== todayDate; + + const resetFilters = useCallback(() => { + setFloor(ALL); + setLane(ALL); + setShop(ALL); + setDate(dayjs().format("YYYY-MM-DD")); + }, []); const loadData = useCallback(async () => { setLoading(true); @@ -80,13 +201,61 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => loadData(); }, [loadData]); - const rows = useMemo(() => { - const filtered = - floor === "all" ? records : records.filter((record) => record.storeId === floor); + const laneOptions = useMemo(() => { + const byRaw = new Map(); + records.forEach((record) => { + if (floor !== ALL && record.storeId !== floor) return; + if (!recordMatchesShop(record.shopCode, shop)) return; + const raw = normalizeTruckLane(record.truckLanceCode); + if (!byRaw.has(raw)) byRaw.set(raw, shortLaneLabel(raw)); + }); + return Array.from(byRaw.entries()) + .map(([value, label]) => ({ value, label })) + .sort((a, b) => { + if (a.value === TRUCK_X_LANE) return 1; + if (b.value === TRUCK_X_LANE) return -1; + return a.label.localeCompare(b.label, "zh-Hant"); + }); + }, [records, floor, shop]); + const shopOptions = useMemo(() => { + const groups = new Set(); + records.forEach((record) => { + if (floor !== ALL && record.storeId !== floor) return; + if (lane !== ALL && normalizeTruckLane(record.truckLanceCode) !== lane) return; + const group = shopGroup(record.shopCode); + if (group) groups.add(group); + }); + return Array.from(groups) + .sort((a, b) => a.localeCompare(b, "zh-Hant")) + .map((group) => ({ value: group, label: group })); + }, [records, floor, lane]); + + const laneFilterOptions = useMemo(() => { + const options: FilterOption[] = [{ value: ALL, label: t("All lanes") }, ...laneOptions]; + if (lane !== ALL && !options.some((option) => option.value === lane)) { + options.splice(1, 0, { value: lane, label: shortLaneLabel(lane) }); + } + return options; + }, [laneOptions, lane, t]); + + const shopFilterOptions = useMemo(() => { + const options: FilterOption[] = [{ value: ALL, label: t("All shops") }, ...shopOptions]; + if (shop !== ALL && !options.some((option) => option.value === shop)) { + options.splice(1, 0, { value: shop, label: shop }); + } + return options; + }, [shopOptions, shop, t]); + + const filteredRecords = useMemo( + () => records.filter((record) => recordMatchesFilters(record, floor, lane, shop)), + [records, floor, lane, shop], + ); + + const rows = useMemo(() => { const summary = new Map(); - filtered.forEach((record) => { + filteredRecords.forEach((record) => { const day = dayjs(record.deliveryDate).isValid() ? dayjs(record.deliveryDate).format("YYYY-MM-DD") : "-"; @@ -106,7 +275,7 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => if (record.storeId === "4/F") { current.floor4F += cartonQty; } - if (String(record.truckLanceCode ?? "").trim() === "車線-X") { + if (normalizeTruckLane(record.truckLanceCode) === TRUCK_X_LANE) { current.truckX += cartonQty; } @@ -115,88 +284,252 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => }); return Array.from(summary.values()).sort((a, b) => b.date.localeCompare(a.date)); - }, [records, floor]); + }, [filteredRecords]); + + const breakdownDimension = resolveBreakdownDimension(lane, shop); + + const breakdownRows = useMemo(() => { + const toSorted = (slices: BreakdownRow[]) => + slices.sort((a, b) => b.qty - a.qty || a.label.localeCompare(b.label, "zh-Hant")); + + if (breakdownDimension === "floor") { + let floor2F = 0; + let floor4F = 0; + let truckX = 0; + filteredRecords.forEach((record) => { + const cartonQty = Number(record.numberOfCartons ?? 0); + if (record.storeId === "2/F") floor2F += cartonQty; + if (record.storeId === "4/F") floor4F += cartonQty; + if (normalizeTruckLane(record.truckLanceCode) === TRUCK_X_LANE) truckX += cartonQty; + }); + return toSorted( + [ + { key: "2/F", label: "2/F", qty: floor2F }, + { key: "4/F", label: "4/F", qty: floor4F }, + { key: TRUCK_X_LANE, label: shortLaneLabel(TRUCK_X_LANE), qty: truckX }, + ].filter((row) => { + if (row.qty > 0) return true; + if (row.key === "2/F" || row.key === "4/F") return floor === row.key; + return lane === TRUCK_X_LANE && row.key === TRUCK_X_LANE; + }), + ); + } + + const grouped = new Map(); + filteredRecords.forEach((record) => { + const cartonQty = Number(record.numberOfCartons ?? 0); + if (breakdownDimension === "lane") { + const key = normalizeTruckLane(record.truckLanceCode); + const current = grouped.get(key) ?? { + key, + label: shortLaneLabel(key), + qty: 0, + }; + current.qty += cartonQty; + grouped.set(key, current); + return; + } + + const key = + shop !== ALL + ? normalizeShopCode(record.shopCode).toUpperCase() + : shopGroup(record.shopCode); + if (!key) return; + const current = grouped.get(key) ?? { key, label: key, qty: 0 }; + current.qty += cartonQty; + grouped.set(key, current); + }); + + return toSorted( + Array.from(grouped.values()).filter((row) => { + if (row.qty > 0) return true; + if (breakdownDimension === "shop") return shop !== ALL && row.key === shop; + return lane !== ALL && row.key === lane; + }), + ); + }, [breakdownDimension, filteredRecords, floor, lane, shop]); + + const breakdownCaption = + breakdownDimension === "shop" + ? shop !== ALL + ? t("Cartons by shop") + : t("Cartons by shop group") + : breakdownDimension === "floor" + ? t("Cartons by floor") + : t("Cartons by lane"); + + const applyBreakdownClick = useCallback( + (row: BreakdownRow) => { + if (breakdownDimension === "lane") { + setLane((prev) => (prev === row.key ? ALL : row.key)); + return; + } + if (breakdownDimension === "shop") { + setShop((prev) => { + if (prev === row.key) { + const group = shopGroup(row.key); + return group && group !== row.key ? group : ALL; + } + return row.key; + }); + return; + } + if (row.key === "2/F" || row.key === "4/F") { + setFloor((prev) => (prev === row.key ? ALL : row.key)); + return; + } + if (row.key === TRUCK_X_LANE) { + setLane((prev) => (prev === TRUCK_X_LANE ? ALL : TRUCK_X_LANE)); + } + }, + [breakdownDimension], + ); + + const isBreakdownRowActive = useCallback( + (row: BreakdownRow) => { + if (breakdownDimension === "lane") return lane === row.key; + if (breakdownDimension === "shop") return shop === row.key; + if (row.key === "2/F" || row.key === "4/F") return floor === row.key; + return lane === TRUCK_X_LANE && row.key === TRUCK_X_LANE; + }, + [breakdownDimension, floor, lane, shop], + ); + + const summary = useMemo(() => { + return rows.reduce( + (acc, row) => { + acc.floor2F += row.floor2F; + acc.floor4F += row.floor4F; + acc.truckX += row.truckX; + acc.total += row.total; + return acc; + }, + { floor2F: 0, floor4F: 0, truckX: 0, total: 0 }, + ); + }, [rows]); + + const chartMaxQty = Math.max(1, ...breakdownRows.map((row) => row.qty)); + const chartHeight = Math.max(CHART_ROW_H, breakdownRows.length * CHART_ROW_H); const chartOptions = useMemo( () => ({ chart: { type: "bar", toolbar: { show: false }, + sparkline: { enabled: false }, + parentHeightOffset: 0, + offsetY: 0, + animations: { + enabled: true, + easing: "easeinout", + speed: 450, + animateGradually: { enabled: true, delay: 40 }, + }, + selection: { enabled: false }, + zoom: { enabled: false }, + }, + states: { + hover: { filter: { type: "none" } }, + active: { filter: { type: "none" } }, + }, + colors: ["#1976d2"], + dataLabels: { + enabled: true, + formatter: (val) => Number(val || 0).toLocaleString(numberLocale), + offsetX: 12, + textAnchor: "start", + style: { + fontSize: "15px", + fontWeight: 800, + colors: ["#ffffff"], + }, + background: { + enabled: true, + foreColor: "#102a43", + padding: 6, + borderRadius: 4, + opacity: 1, + borderWidth: 1, + borderColor: "#90a4ae", + dropShadow: { + enabled: true, + color: "#000000", + top: 1, + left: 0, + blur: 3, + opacity: 0.22, + }, + }, }, - colors: ["#1976d2", "#9c27b0", "#ff9800", "#2e7d32"], - dataLabels: { enabled: false }, stroke: { show: true, width: 1, colors: ["transparent"] }, plotOptions: { bar: { - horizontal: false, - borderRadius: 3, - columnWidth: "55%", + horizontal: true, + borderRadius: 4, + barHeight: 22, + dataLabels: { + position: "top", + }, }, }, + grid: { + show: true, + borderColor: "#eceff1", + padding: { top: -8, bottom: -8, left: 4, right: 64 }, + xaxis: { lines: { show: true } }, + yaxis: { lines: { show: false } }, + }, xaxis: { - categories: rows.map((row) => row.date), - title: { text: t("Date") }, + categories: breakdownRows.map((row) => row.label), + labels: { show: false }, + axisBorder: { show: false }, + axisTicks: { show: false }, + min: 0, + max: Math.max(chartMaxQty * 1.4, chartMaxQty + 12), }, yaxis: { - title: { text: t("Cartons") }, - labels: { - formatter: (val) => Number(val || 0).toLocaleString(numberLocale), - }, + labels: { show: false }, }, tooltip: { + x: { + formatter: (_val, opts) => + breakdownRows[opts?.dataPointIndex ?? -1]?.label ?? String(_val ?? ""), + }, y: { - formatter: (val) => - t("{{count}} cartons", { - count: Number(val || 0).toLocaleString(numberLocale), - }), + formatter: (val, opts) => { + const qty = Number(val || 0); + const share = summary.total > 0 ? (qty / summary.total) * 100 : 0; + const label = breakdownRows[opts?.dataPointIndex ?? -1]?.label ?? ""; + return `${label}: ${qty.toLocaleString(numberLocale)} (${share.toFixed(1)}%)`; + }, }, }, - legend: { - position: "top", - }, - noData: { - text: t("No chart data"), - }, + legend: { show: false }, + noData: { text: t("No chart data") }, }), - [rows, t, numberLocale], + [breakdownRows, chartMaxQty, numberLocale, summary.total, t], ); const chartSeries = useMemo( - () => [ - { name: "2/F", data: rows.map((row) => row.floor2F) }, - { name: "4/F", data: rows.map((row) => row.floor4F) }, - { name: t("Truck X"), data: rows.map((row) => row.truckX) }, - { name: t("Total"), data: rows.map((row) => row.total) }, - ], - [rows, t], + () => [{ name: t("Cartons"), data: breakdownRows.map((row) => row.qty) }], + [breakdownRows, t], ); - const summary = useMemo(() => { - return rows.reduce( - (acc, row) => { - acc.floor2F += row.floor2F; - acc.floor4F += row.floor4F; - acc.truckX += row.truckX; - acc.total += row.total; - return acc; - }, - { floor2F: 0, floor4F: 0, truckX: 0, total: 0 }, - ); - }, [rows]); - const buildDailyRowsFromRecords = useCallback( ( sourceRecords: CompletedDoPickOrderResponse[], startDate: dayjs.Dayjs, endDate: dayjs.Dayjs, selectedFloor: FloorFilter, + selectedLane: string, + selectedShop: string, ): DailySummaryRow[] => { const summaryMap = new Map(); const start = startDate.startOf("day"); const end = endDate.endOf("day"); sourceRecords.forEach((record) => { - if (selectedFloor !== "all" && record.storeId !== selectedFloor) { + if (!recordMatchesFilters(record, selectedFloor, selectedLane, selectedShop)) { return; } @@ -217,7 +550,7 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => if (record.storeId === "2/F") current.floor2F += cartonQty; if (record.storeId === "4/F") current.floor4F += cartonQty; - if (String(record.truckLanceCode ?? "").trim() === "車線-X") current.truckX += cartonQty; + if (normalizeTruckLane(record.truckLanceCode) === TRUCK_X_LANE) current.truckX += cartonQty; current.total += cartonQty; summaryMap.set(dayKey, current); @@ -346,7 +679,84 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => [calcSummary, styleWorksheet, t], ); + const addBreakdownSheet = useCallback( + ( + workbook: XLSX.WorkBook, + sheetName: string, + reportTitle: string, + categoryLabel: string, + slices: BreakdownRow[], + totalQty: number, + ) => { + const aoa: (string | number)[][] = [ + [reportTitle, "", ""], + ["", "", ""], + [categoryLabel, t("Cartons"), t("Share")], + ...slices.map((row) => { + const share = totalQty > 0 ? (row.qty / totalQty) * 100 : 0; + return [row.label, row.qty, `${share.toFixed(1)}%`]; + }), + ["", "", ""], + [t("Total carton qty"), totalQty, ""], + ]; + + const worksheet = XLSX.utils.aoa_to_sheet(aoa); + worksheet["!cols"] = [{ wch: 28 }, { wch: 14 }, { wch: 12 }]; + worksheet["!merges"] = [{ s: { r: 0, c: 0 }, e: { r: 0, c: 2 } }]; + + const titleStyle = { + font: { bold: true, sz: 14, color: { rgb: "1F2D3D" } }, + alignment: { horizontal: "center", vertical: "center" }, + fill: { fgColor: { rgb: "EAF3FF" } }, + }; + const headerStyle = { + font: { bold: true, color: { rgb: "FFFFFF" } }, + fill: { fgColor: { rgb: "1976D2" } }, + alignment: { horizontal: "center", vertical: "center" }, + }; + const cellStyle = { + alignment: { vertical: "center" }, + border: { + top: { style: "thin", color: { rgb: "D0D7DE" } }, + bottom: { style: "thin", color: { rgb: "D0D7DE" } }, + left: { style: "thin", color: { rgb: "D0D7DE" } }, + right: { style: "thin", color: { rgb: "D0D7DE" } }, + }, + }; + const numberStyle = { + ...cellStyle, + alignment: { horizontal: "right", vertical: "center" }, + numFmt: "#,##0", + }; + + if (worksheet["A1"]) worksheet["A1"].s = titleStyle; + for (let c = 0; c <= 2; c += 1) { + const headerCell = XLSX.utils.encode_cell({ r: 2, c }); + if (worksheet[headerCell]) worksheet[headerCell].s = headerStyle; + } + slices.forEach((_, index) => { + const r = 3 + index; + const labelAddr = XLSX.utils.encode_cell({ r, c: 0 }); + const qtyAddr = XLSX.utils.encode_cell({ r, c: 1 }); + const shareAddr = XLSX.utils.encode_cell({ r, c: 2 }); + if (worksheet[labelAddr]) worksheet[labelAddr].s = cellStyle; + if (worksheet[qtyAddr]) worksheet[qtyAddr].s = numberStyle; + if (worksheet[shareAddr]) worksheet[shareAddr].s = cellStyle; + }); + const totalRow = 4 + slices.length; + const totalLabelAddr = XLSX.utils.encode_cell({ r: totalRow, c: 0 }); + const totalValueAddr = XLSX.utils.encode_cell({ r: totalRow, c: 1 }); + if (worksheet[totalLabelAddr]) worksheet[totalLabelAddr].s = cellStyle; + if (worksheet[totalValueAddr]) worksheet[totalValueAddr].s = numberStyle; + + XLSX.utils.book_append_sheet(workbook, worksheet, sheetName.slice(0, 31)); + }, + [t], + ); + const handleDownloadExcel = useCallback(async () => { + if (exportInFlightRef.current || filteredExportInFlightRef.current) return; + exportInFlightRef.current = true; setIsExporting(true); try { const allRecords = @@ -355,7 +765,9 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => : await fetchCompletedDoPickOrdersAll(); const baseDate = dayjs(date || undefined).isValid() ? dayjs(date) : dayjs(); - const floorLabel = floor === "all" ? t("All floors") : floor; + const floorLabel = floor === ALL ? t("All floors") : floor; + const laneLabel = lane === ALL ? t("All lanes") : lane; + const shopLabel = shop === ALL ? t("All shops") : shop; const dateLabel = baseDate.format("YYYY-MM-DD"); const monthPeriod = i18n.language?.startsWith("zh") ? baseDate.format("YYYY年MM月") @@ -369,18 +781,24 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => baseDate.subtract(6, "day"), baseDate, floor, + lane, + shop, ); const monthRows = buildDailyRowsFromRecords( allRecords, baseDate.startOf("month"), baseDate.endOf("month"), floor, + lane, + shop, ); const yearRows = buildDailyRowsFromRecords( allRecords, baseDate.startOf("year"), baseDate.endOf("year"), floor, + lane, + shop, ); const workbook = XLSX.utils.book_new(); @@ -403,26 +821,131 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => yearRows, ); - XLSX.writeFile( + const fileBits = [ + "FG_carton_qty", + floorLabel.replace("/", ""), + lane === ALL ? "" : laneLabel, + shop === ALL ? "" : shopLabel, + dateLabel, + ].filter(Boolean); + + XLSX.writeFile(workbook, `${fileBits.join("_")}.xlsx`); + } finally { + setIsExporting(false); + exportInFlightRef.current = false; + } + }, [mode, date, floor, lane, shop, buildDailyRowsFromRecords, addReportSheet, t, i18n.language]); + + const handleDownloadFilteredExcel = useCallback(async () => { + if (filteredExportInFlightRef.current || exportInFlightRef.current) return; + filteredExportInFlightRef.current = true; + setIsExportingFiltered(true); + try { + const baseDate = dayjs(date || undefined).isValid() ? dayjs(date) : dayjs(); + const floorLabel = floor === ALL ? t("All floors") : floor; + const laneLabel = lane === ALL ? t("All lanes") : shortLaneLabel(lane); + const shopLabel = shop === ALL ? t("All shops") : shop; + const dateLabel = baseDate.format("YYYY-MM-DD"); + const reportTitle = t("FG carton qty filtered title", { + floor: floorLabel, + lane: laneLabel, + shop: shopLabel, + date: dateLabel, + }); + const categoryLabel = + breakdownDimension === "shop" + ? t("Shop Code") + : breakdownDimension === "floor" + ? t("Floor") + : t("Lane"); + + const dailyRows = buildDailyRowsFromRecords( + records, + baseDate.startOf("day"), + baseDate.endOf("day"), + floor, + lane, + shop, + ); + const filteredTotal = calcSummary(dailyRows).total; + + const workbook = XLSX.utils.book_new(); + addReportSheet(workbook, t("Filtered"), reportTitle, dailyRows); + addBreakdownSheet( workbook, - `FG_carton_qty_${floorLabel.replace("/", "")}_${dateLabel}.xlsx`, + t("Breakdown"), + breakdownCaption, + categoryLabel, + breakdownRows, + filteredTotal, ); + + const fileBits = [ + "FG_carton_qty_filtered", + floorLabel.replace("/", ""), + lane === ALL ? "" : laneLabel, + shop === ALL ? "" : shopLabel, + dateLabel, + ].filter(Boolean); + + XLSX.writeFile(workbook, `${fileBits.join("_")}.xlsx`); } finally { - setIsExporting(false); + setIsExportingFiltered(false); + filteredExportInFlightRef.current = false; } - }, [mode, date, floor, buildDailyRowsFromRecords, addReportSheet, t, i18n.language]); + }, [ + date, + floor, + lane, + shop, + records, + breakdownDimension, + breakdownCaption, + breakdownRows, + buildDailyRowsFromRecords, + addReportSheet, + addBreakdownSheet, + calcSummary, + t, + ]); + + const isAnyExporting = isExporting || isExportingFiltered; return ( {t("FG Carton Qty")} - + + + + + + + + + + + + + {error && ( @@ -431,77 +954,183 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => )} - {loading ? ( - - - - ) : ( - - - - setFloor(event.target.value as FloorFilter)} - > - {t("All")} - 2/F - 4/F - - - - setDate(event.target.value)} - /> - + + + + setFloor(event.target.value as FloorFilter)} + > + {t("All")} + 2/F + 4/F + - - - - - - - - {t("2/F carton qty")} - {summary.floor2F.toLocaleString(numberLocale)} - - - {t("4/F carton qty")} - {summary.floor4F.toLocaleString(numberLocale)} - - - {t("Truck X carton qty")} - {summary.truckX.toLocaleString(numberLocale)} - - - {t("Total carton qty")} - {summary.total.toLocaleString(numberLocale)} - - -
-
-
- - - - - + + -
- )} + + + + + setDate(event.target.value)} + /> + +
+ + {loading ? ( + + + + ) : ( + + + + {[ + { label: t("2/F carton qty"), value: summary.floor2F }, + { label: t("4/F carton qty"), value: summary.floor4F }, + { label: t("Truck X carton qty"), value: summary.truckX }, + { label: t("Total carton qty"), value: summary.total }, + ].map((kpi, index) => ( + + + {kpi.label} + + + {kpi.value.toLocaleString(numberLocale)} + + + ))} + + + + + + {breakdownCaption} + + + {t("Click a row to filter")} + + {breakdownRows.length === 0 ? ( + + {t("No data available")} + + ) : ( + + + {breakdownRows.map((row) => { + const active = isBreakdownRowActive(row); + return ( + applyBreakdownClick(row)} + onKeyDown={(event) => { + if (event.key === "Enter" || event.key === " ") { + event.preventDefault(); + applyBreakdownClick(row); + } + }} + sx={{ + height: CHART_ROW_H, + display: "flex", + alignItems: "center", + minWidth: 0, + cursor: "pointer", + borderRadius: 1, + px: 0.5, + bgcolor: active ? "action.selected" : "transparent", + "&:hover": { bgcolor: "action.hover" }, + }} + > + + {row.label} + + + ); + })} + + { + const rect = event.currentTarget.getBoundingClientRect(); + const index = Math.floor((event.clientY - rect.top) / CHART_ROW_H); + const row = breakdownRows[index]; + if (row) applyBreakdownClick(row); + }} + > + + + + )} + + + )} +
); }; diff --git a/src/components/charts/SafeApexCharts.tsx b/src/components/charts/SafeApexCharts.tsx index 9b29f4b1..0e41126b 100644 --- a/src/components/charts/SafeApexCharts.tsx +++ b/src/components/charts/SafeApexCharts.tsx @@ -150,6 +150,34 @@ function buildApexConfig( const EMPTY_MESSAGE = "暫無圖表資料(後端無法連線或此區間無資料)。"; +/** Apex mutates `options` in place (circular refs). Never throw during render. */ +function safeStringify(value: unknown): string { + const seen = new WeakSet(); + try { + return JSON.stringify(value, (_key, nested) => { + if (typeof nested === "function") return undefined; + if (typeof nested === "object" && nested !== null) { + if (seen.has(nested)) return undefined; + seen.add(nested); + } + return nested; + }); + } catch { + return ""; + } +} + +function destroyChart(chartRef: { current: { destroy: () => void } | null }) { + const current = chartRef.current; + chartRef.current = null; + if (!current) return; + try { + current.destroy(); + } catch { + /* ignore */ + } +} + export default function SafeApexCharts(props: SafeApexChartsProps) { const { type, series, options, height, width, chartRevision, allowZeroSeries = false, ...rest } = props; const containerRef = useRef(null); @@ -162,18 +190,11 @@ export default function SafeApexCharts(props: SafeApexChartsProps) { sanitized = alignSeriesToCategoryCount(sanitized, cats.length); } - if (shouldShowPlaceholder(type, options, sanitized, allowZeroSeries)) { - return ( - - {EMPTY_MESSAGE} - - ); - } - let chartOptions = options; let renderSeries: ApexChartProps["series"] = sanitized; + let showPlaceholder = shouldShowPlaceholder(type, options, sanitized, allowZeroSeries); - if (isRadialChart(type) && isNumberArray(sanitized)) { + if (!showPlaceholder && isRadialChart(type) && isNumberArray(sanitized)) { const prev = Array.isArray(options?.labels) ? (options!.labels as unknown[]) : []; const pairs = sanitized.map((v, i) => { const n = Number.isFinite(v) ? v : 0; @@ -183,20 +204,31 @@ export default function SafeApexCharts(props: SafeApexChartsProps) { }); const nonzero = pairs.filter((p) => p.v > 0); if (nonzero.length === 0) { - return ( - - {EMPTY_MESSAGE} - - ); + showPlaceholder = true; + } else { + renderSeries = nonzero.map((p) => p.v); + chartOptions = { ...options, labels: nonzero.map((p) => p.label) }; } - renderSeries = nonzero.map((p) => p.v); - chartOptions = { ...options, labels: nonzero.map((p) => p.label) }; } const chartType = String(type ?? "line"); - const configSnapshot = `${String(chartRevision ?? "")}|${chartType}|${JSON.stringify(renderSeries ?? null)}|${JSON.stringify(chartOptions ?? {})}|${String(height ?? "")}|${String(width ?? "")}`; + const configSnapshot = [ + String(chartRevision ?? ""), + chartType, + String(showPlaceholder), + safeStringify(renderSeries ?? null), + safeStringify(cats ?? null), + safeStringify(chartOptions?.labels ?? null), + String(height ?? ""), + String(width ?? ""), + ].join("|"); useEffect(() => { + if (showPlaceholder) { + destroyChart(chartRef); + return; + } + const el = containerRef.current; if (!el) return; @@ -219,12 +251,7 @@ export default function SafeApexCharts(props: SafeApexChartsProps) { if (disposed || containerRef.current !== el) { if (chartRef.current === instance) { - try { - instance.destroy(); - } catch { - /* ignore */ - } - chartRef.current = null; + destroyChart(chartRef); } return; } @@ -236,21 +263,21 @@ export default function SafeApexCharts(props: SafeApexChartsProps) { return () => { disposed = true; - const c = chartRef.current; - chartRef.current = null; - if (c) { - try { - c.destroy(); - } catch { - /* ignore */ - } - } + destroyChart(chartRef); }; }, [configSnapshot]); const minH = typeof height === "number" ? height : typeof height === "string" ? height : 240; const dom = rest as { className?: string; id?: string; style?: CSSProperties; sx?: object }; + if (showPlaceholder) { + return ( + + {EMPTY_MESSAGE} + + ); + } + return ( Date: Tue, 22 Sep 2026 17:40:00 +0800 Subject: [PATCH 15/24] [Fix] Amend few visual issues --- .../DoWorkbench/DoWorkbenchTabs.tsx | 12 +- .../FinishedGoodCartonDashboardTab.tsx | 604 ++++++++++-------- src/i18n/en/doWorkbench.json | 4 +- src/i18n/en/pickOrder.json | 4 +- src/i18n/zh/doWorkbench.json | 4 +- src/i18n/zh/pickOrder.json | 4 +- 6 files changed, 356 insertions(+), 276 deletions(-) diff --git a/src/components/DoWorkbench/DoWorkbenchTabs.tsx b/src/components/DoWorkbench/DoWorkbenchTabs.tsx index c247d87b..87a1eb2a 100644 --- a/src/components/DoWorkbench/DoWorkbenchTabs.tsx +++ b/src/components/DoWorkbench/DoWorkbenchTabs.tsx @@ -282,7 +282,7 @@ const DoWorkbenchTabsInner: React.FC = ({ defaultTabIndex = 0, printerCom sx={{ width: "100%", maxWidth: "100%", - minHeight: 56, + minHeight: 48, borderBottom: 1, borderColor: "divider", "& .MuiTabs-flexContainer": { @@ -291,12 +291,12 @@ const DoWorkbenchTabsInner: React.FC = ({ defaultTabIndex = 0, printerCom /* 否則 Tab 內 overflow:hidden 會把 Badge 數字裁成紅點 */ "& .MuiTab-root": { overflow: "visible", - minHeight: 56, + minHeight: 48, minWidth: 72, - maxWidth: 120, - px: 1, + maxWidth: "none", + px: 1.5, py: 0.75, - whiteSpace: "normal", + whiteSpace: "nowrap", lineHeight: 1.2, textAlign: "center", }, @@ -342,7 +342,7 @@ const DoWorkbenchTabsInner: React.FC = ({ defaultTabIndex = 0, printerCom variant="inherit" sx={{ pr: etraIncompleteDopoCount > 0 ? 1 : 0, - whiteSpace: "normal", + whiteSpace: "nowrap", lineHeight: 1.2, textAlign: "center", }} diff --git a/src/components/FinishedGoodSearch/FinishedGoodCartonDashboardTab.tsx b/src/components/FinishedGoodSearch/FinishedGoodCartonDashboardTab.tsx index ba895bdb..5f74c65a 100644 --- a/src/components/FinishedGoodSearch/FinishedGoodCartonDashboardTab.tsx +++ b/src/components/FinishedGoodSearch/FinishedGoodCartonDashboardTab.tsx @@ -15,15 +15,18 @@ import { Tooltip, Typography, } from "@mui/material"; -import type { ApexOptions } from "apexcharts"; +import ArrowBackIcon from "@mui/icons-material/ArrowBack"; +import { DatePicker, LocalizationProvider } from "@mui/x-date-pickers"; +import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs"; import dayjs from "dayjs"; +import "dayjs/locale/zh-hk"; import * as XLSX from "xlsx-js-style"; import { CompletedDoPickOrderResponse, fetchCompletedDoPickOrdersAll, fetchCompletedDoPickOrdersWorkbenchAll, } from "@/app/api/pickOrder/actions"; -import SafeApexCharts from "@/components/charts/SafeApexCharts"; +import { OUTPUT_DATE_FORMAT } from "@/app/utils/formatUtil"; import { useTranslation } from "react-i18next"; type FloorFilter = "all" | "2/F" | "4/F"; @@ -37,6 +40,17 @@ type DailySummaryRow = { total: number; }; +type ShopDailyRow = DailySummaryRow & { + shopCode: string; + shopName: string; +}; + +type ShopQtyRow = { + code: string; + name: string; + qty: number; +}; + type BreakdownRow = { key: string; label: string; @@ -50,6 +64,9 @@ type Props = { const TRUCK_X_LANE = "車線-X"; const ALL = "all"; const CHART_ROW_H = 38; +/** Jasper / report standard used across FPSMS Excel output. */ +const EXCEL_FONT_NAME = "微軟正黑體"; +const DAILY_SHEET_LAST_COL = 6; type FilterOption = { value: string; label: string }; @@ -61,7 +78,7 @@ function normalizeTruckLane(raw: string | null | undefined): string { function shortLaneLabel(raw: string | null | undefined): string { const value = normalizeTruckLane(raw); const stripped = value - .replace(/^(車線)[-–—]?\s*/u, "") + .replace(/^(車線)[-–—]?\s*/, "") .replace(/^(truck)\s*[-–—]?\s*/i, "") .trim(); return stripped || value; @@ -77,6 +94,77 @@ function shopGroup(raw: string | null | undefined): string { return code.slice(0, 2); } +function digitsWithoutLeadingZeros(digits: string): string { + const stripped = digits.replace(/^0+/, ""); + return stripped || (digits ? "0" : ""); +} + +/** Shop names often already start with the code, sometimes zero-padded (`HP23` vs `HP023`). */ +function shopNameWithoutCode(code: string, name: string | null | undefined): string { + const shopName = String(name ?? "").trim(); + if (!shopName) return ""; + const normalized = normalizeShopCode(code).toUpperCase(); + const codeParts = normalized.match(/^([A-Z]+)(\d*)$/); + const nameParts = shopName.match(/^([A-Za-z]+)(\d*)(?:\s*[-–—]\s*|\s+)([\s\S]*)$/); + if (codeParts && nameParts) { + const sameLetters = nameParts[1].toUpperCase() === codeParts[1]; + const sameDigits = + !nameParts[2] || + digitsWithoutLeadingZeros(nameParts[2]) === digitsWithoutLeadingZeros(codeParts[2]); + if (sameLetters && sameDigits) return nameParts[3].trim(); + } + if (normalized && shopName.toUpperCase().startsWith(normalized)) { + return shopName.slice(normalized.length).replace(/^[\s\-–—]+/, "").trim(); + } + return shopName; +} + +function formatShopLabel(code: string, name: string | null | undefined): string { + const normalized = normalizeShopCode(code).toUpperCase(); + const displayName = shopNameWithoutCode(normalized, name); + if (!normalized) return displayName; + if (!displayName || displayName.toUpperCase() === normalized) return normalized; + return `${normalized} ${displayName}`; +} + +function applyProjectExcelFont(worksheet: XLSX.WorkSheet) { + if (!worksheet["!ref"]) return; + const range = XLSX.utils.decode_range(worksheet["!ref"]); + for (let r = range.s.r; r <= range.e.r; r += 1) { + for (let c = range.s.c; c <= range.e.c; c += 1) { + const addr = XLSX.utils.encode_cell({ r, c }); + const cell = worksheet[addr]; + if (!cell) continue; + const style = (cell.s ?? {}) as XLSX.CellStyle; + const font = style.font ?? {}; + cell.s = { + ...style, + font: { + ...font, + name: EXCEL_FONT_NAME, + sz: font.sz ?? 11, + }, + }; + } + } +} + +function buildShopQtyRows(source: CompletedDoPickOrderResponse[]): ShopQtyRow[] { + const grouped = new Map(); + source.forEach((record) => { + const code = normalizeShopCode(record.shopCode).toUpperCase(); + if (!code) return; + const name = shopNameWithoutCode(code, record.shopName); + const current = grouped.get(code) ?? { code, name, qty: 0 }; + if (!current.name && name) current.name = name; + current.qty += Number(record.numberOfCartons ?? 0); + grouped.set(code, current); + }); + return Array.from(grouped.values()).sort( + (a, b) => b.qty - a.qty || a.code.localeCompare(b.code, "zh-Hant"), + ); +} + function isShopGroupValue(shop: string): boolean { if (shop === ALL) return false; const code = normalizeShopCode(shop).toUpperCase(); @@ -110,10 +198,8 @@ function recordMatchesFilters( } function resolveBreakdownDimension(lane: string, shop: string): BreakdownDimension { - if (isShopGroupValue(shop)) return "shop"; - if (shop !== ALL && lane !== ALL) return "floor"; + if (shop !== ALL) return "shop"; if (lane !== ALL) return "shop"; - if (shop !== ALL) return "lane"; return "lane"; } @@ -239,13 +325,18 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => return options; }, [laneOptions, lane, t]); + const shopFilterValue = shop === ALL ? ALL : shopGroup(shop); + const shopFilterOptions = useMemo(() => { const options: FilterOption[] = [{ value: ALL, label: t("All shops") }, ...shopOptions]; - if (shop !== ALL && !options.some((option) => option.value === shop)) { - options.splice(1, 0, { value: shop, label: shop }); + if ( + shopFilterValue !== ALL && + !options.some((option) => option.value === shopFilterValue) + ) { + options.splice(1, 0, { value: shopFilterValue, label: shopFilterValue }); } return options; - }, [shopOptions, shop, t]); + }, [shopOptions, shopFilterValue, t]); const filteredRecords = useMemo( () => records.filter((record) => recordMatchesFilters(record, floor, lane, shop)), @@ -330,12 +421,13 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => return; } - const key = - shop !== ALL - ? normalizeShopCode(record.shopCode).toUpperCase() - : shopGroup(record.shopCode); + const code = normalizeShopCode(record.shopCode).toUpperCase(); + const name = String(record.shopName ?? "").trim(); + const key = shop !== ALL ? code : shopGroup(record.shopCode); if (!key) return; - const current = grouped.get(key) ?? { key, label: key, qty: 0 }; + const label = shop !== ALL ? formatShopLabel(code, name) : key; + const current = grouped.get(key) ?? { key, label, qty: 0 }; + if (shop !== ALL && name) current.label = formatShopLabel(code, name); current.qty += cartonQty; grouped.set(key, current); }); @@ -372,19 +464,27 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => } return row.key; }); - return; - } - if (row.key === "2/F" || row.key === "4/F") { - setFloor((prev) => (prev === row.key ? ALL : row.key)); - return; - } - if (row.key === TRUCK_X_LANE) { - setLane((prev) => (prev === TRUCK_X_LANE ? ALL : TRUCK_X_LANE)); } }, [breakdownDimension], ); + const viewingSpecificShop = shop !== ALL && !isShopGroupValue(shop); + const chartClicksEnabled = !viewingSpecificShop; + const chartCanGoBack = lane !== ALL || shop !== ALL; + + const goBackChartLevel = useCallback(() => { + if (shop !== ALL && !isShopGroupValue(shop)) { + setShop(shopGroup(shop) || ALL); + return; + } + if (shop !== ALL) { + setShop(ALL); + return; + } + if (lane !== ALL) setLane(ALL); + }, [lane, shop]); + const isBreakdownRowActive = useCallback( (row: BreakdownRow) => { if (breakdownDimension === "lane") return lane === row.key; @@ -409,111 +509,6 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => }, [rows]); const chartMaxQty = Math.max(1, ...breakdownRows.map((row) => row.qty)); - const chartHeight = Math.max(CHART_ROW_H, breakdownRows.length * CHART_ROW_H); - - const chartOptions = useMemo( - () => ({ - chart: { - type: "bar", - toolbar: { show: false }, - sparkline: { enabled: false }, - parentHeightOffset: 0, - offsetY: 0, - animations: { - enabled: true, - easing: "easeinout", - speed: 450, - animateGradually: { enabled: true, delay: 40 }, - }, - selection: { enabled: false }, - zoom: { enabled: false }, - }, - states: { - hover: { filter: { type: "none" } }, - active: { filter: { type: "none" } }, - }, - colors: ["#1976d2"], - dataLabels: { - enabled: true, - formatter: (val) => Number(val || 0).toLocaleString(numberLocale), - offsetX: 12, - textAnchor: "start", - style: { - fontSize: "15px", - fontWeight: 800, - colors: ["#ffffff"], - }, - background: { - enabled: true, - foreColor: "#102a43", - padding: 6, - borderRadius: 4, - opacity: 1, - borderWidth: 1, - borderColor: "#90a4ae", - dropShadow: { - enabled: true, - color: "#000000", - top: 1, - left: 0, - blur: 3, - opacity: 0.22, - }, - }, - }, - stroke: { show: true, width: 1, colors: ["transparent"] }, - plotOptions: { - bar: { - horizontal: true, - borderRadius: 4, - barHeight: 22, - dataLabels: { - position: "top", - }, - }, - }, - grid: { - show: true, - borderColor: "#eceff1", - padding: { top: -8, bottom: -8, left: 4, right: 64 }, - xaxis: { lines: { show: true } }, - yaxis: { lines: { show: false } }, - }, - xaxis: { - categories: breakdownRows.map((row) => row.label), - labels: { show: false }, - axisBorder: { show: false }, - axisTicks: { show: false }, - min: 0, - max: Math.max(chartMaxQty * 1.4, chartMaxQty + 12), - }, - yaxis: { - labels: { show: false }, - }, - tooltip: { - x: { - formatter: (_val, opts) => - breakdownRows[opts?.dataPointIndex ?? -1]?.label ?? String(_val ?? ""), - }, - y: { - formatter: (val, opts) => { - const qty = Number(val || 0); - const share = summary.total > 0 ? (qty / summary.total) * 100 : 0; - const label = breakdownRows[opts?.dataPointIndex ?? -1]?.label ?? ""; - return `${label}: ${qty.toLocaleString(numberLocale)} (${share.toFixed(1)}%)`; - }, - }, - }, - legend: { show: false }, - noData: { text: t("No chart data") }, - }), - [breakdownRows, chartMaxQty, numberLocale, summary.total, t], - ); - - const chartSeries = useMemo( - () => [{ name: t("Cartons"), data: breakdownRows.map((row) => row.qty) }], - [breakdownRows, t], - ); const buildDailyRowsFromRecords = useCallback( ( @@ -523,8 +518,8 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => selectedFloor: FloorFilter, selectedLane: string, selectedShop: string, - ): DailySummaryRow[] => { - const summaryMap = new Map(); + ): ShopDailyRow[] => { + const summaryMap = new Map(); const start = startDate.startOf("day"); const end = endDate.endOf("day"); @@ -539,24 +534,33 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => } const dayKey = deliveryDay.format("YYYY-MM-DD"); + const shopCode = normalizeShopCode(record.shopCode).toUpperCase() || "-"; + const shopName = shopNameWithoutCode(shopCode, record.shopName); + const mapKey = `${dayKey}|${shopCode}`; const cartonQty = Number(record.numberOfCartons ?? 0); - const current = summaryMap.get(dayKey) ?? { + const current = summaryMap.get(mapKey) ?? { date: dayKey, + shopCode, + shopName, floor2F: 0, floor4F: 0, truckX: 0, total: 0, }; + if (!current.shopName && shopName) current.shopName = shopName; if (record.storeId === "2/F") current.floor2F += cartonQty; if (record.storeId === "4/F") current.floor4F += cartonQty; if (normalizeTruckLane(record.truckLanceCode) === TRUCK_X_LANE) current.truckX += cartonQty; current.total += cartonQty; - summaryMap.set(dayKey, current); + summaryMap.set(mapKey, current); }); - return Array.from(summaryMap.values()).sort((a, b) => a.date.localeCompare(b.date)); + return Array.from(summaryMap.values()).sort( + (a, b) => + a.date.localeCompare(b.date) || a.shopCode.localeCompare(b.shopCode, "zh-Hant"), + ); }, [], ); @@ -578,10 +582,18 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => const summaryTitleRow = 4 + dataRowsCount; const summaryStartRow = 5 + dataRowsCount; - worksheet["!cols"] = [{ wch: 16 }, { wch: 14 }, { wch: 14 }, { wch: 16 }, { wch: 14 }]; + worksheet["!cols"] = [ + { wch: 14 }, + { wch: 14 }, + { wch: 28 }, + { wch: 16 }, + { wch: 16 }, + { wch: 18 }, + { wch: 14 }, + ]; worksheet["!merges"] = [ - { s: { r: 0, c: 0 }, e: { r: 0, c: 4 } }, - { s: { r: summaryTitleRow, c: 0 }, e: { r: summaryTitleRow, c: 4 } }, + { s: { r: 0, c: 0 }, e: { r: 0, c: DAILY_SHEET_LAST_COL } }, + { s: { r: summaryTitleRow, c: 0 }, e: { r: summaryTitleRow, c: DAILY_SHEET_LAST_COL } }, ]; const titleStyle = { @@ -620,29 +632,32 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => alignment: { horizontal: "left", vertical: "center" }, }; - for (let c = 0; c <= 4; c += 1) { + for (let c = 0; c <= DAILY_SHEET_LAST_COL; c += 1) { const headerCell = XLSX.utils.encode_cell({ r: 2, c }); if (worksheet[headerCell]) worksheet[headerCell].s = headerStyle; } for (let r = 3; r < 3 + dataRowsCount; r += 1) { - for (let c = 0; c <= 4; c += 1) { + for (let c = 0; c <= DAILY_SHEET_LAST_COL; c += 1) { const addr = XLSX.utils.encode_cell({ r, c }); if (!worksheet[addr]) continue; - worksheet[addr].s = c === 0 ? cellStyle : numberStyle; + worksheet[addr].s = c < 3 ? cellStyle : numberStyle; } } for (let r = summaryStartRow; r <= summaryStartRow + 3; r += 1) { - const labelAddr = XLSX.utils.encode_cell({ r, c: 0 }); - const valueAddr = XLSX.utils.encode_cell({ r, c: 1 }); - if (worksheet[labelAddr]) worksheet[labelAddr].s = cellStyle; - if (worksheet[valueAddr]) worksheet[valueAddr].s = numberStyle; + for (let c = 0; c <= DAILY_SHEET_LAST_COL; c += 1) { + const addr = XLSX.utils.encode_cell({ r, c }); + const cell = worksheet[addr]; + if (!cell) continue; + cell.s = typeof cell.v === "number" ? numberStyle : cellStyle; + } } if (worksheet["A1"]) worksheet["A1"].s = titleStyle; const summaryTitleAddr = XLSX.utils.encode_cell({ r: summaryTitleRow, c: 0 }); if (worksheet[summaryTitleAddr]) worksheet[summaryTitleAddr].s = summaryTitleStyle; + applyProjectExcelFont(worksheet); }, []); const addReportSheet = useCallback( @@ -650,26 +665,37 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => workbook: XLSX.WorkBook, sheetName: string, reportTitle: string, - dailyRows: DailySummaryRow[], + dailyRows: ShopDailyRow[], ) => { const reportSummary = calcSummary(dailyRows); + const blank = ["", "", "", "", "", "", ""]; const aoa: (string | number)[][] = [ - [reportTitle, "", "", "", ""], - ["", "", "", "", ""], + [reportTitle, ...blank.slice(1)], + [...blank], [ t("Date"), + t("Shop code"), + t("Shop Name"), t("2/F carton qty"), t("4/F carton qty"), t("Truck X carton qty"), t("Total carton qty"), ], - ...dailyRows.map((row) => [row.date, row.floor2F, row.floor4F, row.truckX, row.total]), - ["", "", "", "", ""], - [t("Summary"), "", "", "", ""], - [t("2/F carton qty"), reportSummary.floor2F, "", "", ""], - [t("4/F carton qty"), reportSummary.floor4F, "", "", ""], - [t("Truck X carton qty"), reportSummary.truckX, "", "", ""], - [t("Total carton qty"), reportSummary.total, "", "", ""], + ...dailyRows.map((row) => [ + row.date, + row.shopCode, + row.shopName, + row.floor2F, + row.floor4F, + row.truckX, + row.total, + ]), + [...blank], + [t("Summary"), ...blank.slice(1)], + [t("2/F carton qty"), "", "", reportSummary.floor2F, "", "", ""], + [t("4/F carton qty"), "", "", "", reportSummary.floor4F, "", ""], + [t("Truck X carton qty"), "", "", "", "", reportSummary.truckX, ""], + [t("Total carton qty"), "", "", "", "", "", reportSummary.total], ]; const worksheet = XLSX.utils.aoa_to_sheet(aoa); @@ -684,25 +710,24 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => workbook: XLSX.WorkBook, sheetName: string, reportTitle: string, - categoryLabel: string, - slices: BreakdownRow[], + shops: ShopQtyRow[], totalQty: number, ) => { const aoa: (string | number)[][] = [ - [reportTitle, "", ""], - ["", "", ""], - [categoryLabel, t("Cartons"), t("Share")], - ...slices.map((row) => { + [reportTitle, "", "", ""], + ["", "", "", ""], + [t("Shop code"), t("Shop Name"), t("Cartons"), t("Share")], + ...shops.map((row) => { const share = totalQty > 0 ? (row.qty / totalQty) * 100 : 0; - return [row.label, row.qty, `${share.toFixed(1)}%`]; + return [row.code, row.name, row.qty, `${share.toFixed(1)}%`]; }), - ["", "", ""], - [t("Total carton qty"), totalQty, ""], + ["", "", "", ""], + [t("Total carton qty"), "", totalQty, ""], ]; const worksheet = XLSX.utils.aoa_to_sheet(aoa); - worksheet["!cols"] = [{ wch: 28 }, { wch: 14 }, { wch: 12 }]; - worksheet["!merges"] = [{ s: { r: 0, c: 0 }, e: { r: 0, c: 2 } }]; + worksheet["!cols"] = [{ wch: 14 }, { wch: 28 }, { wch: 14 }, { wch: 12 }]; + worksheet["!merges"] = [{ s: { r: 0, c: 0 }, e: { r: 0, c: 3 } }]; const titleStyle = { font: { bold: true, sz: 14, color: { rgb: "1F2D3D" } }, @@ -730,24 +755,27 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => }; if (worksheet["A1"]) worksheet["A1"].s = titleStyle; - for (let c = 0; c <= 2; c += 1) { + for (let c = 0; c <= 3; c += 1) { const headerCell = XLSX.utils.encode_cell({ r: 2, c }); if (worksheet[headerCell]) worksheet[headerCell].s = headerStyle; } - slices.forEach((_, index) => { + shops.forEach((_, index) => { const r = 3 + index; - const labelAddr = XLSX.utils.encode_cell({ r, c: 0 }); - const qtyAddr = XLSX.utils.encode_cell({ r, c: 1 }); - const shareAddr = XLSX.utils.encode_cell({ r, c: 2 }); - if (worksheet[labelAddr]) worksheet[labelAddr].s = cellStyle; + const codeAddr = XLSX.utils.encode_cell({ r, c: 0 }); + const nameAddr = XLSX.utils.encode_cell({ r, c: 1 }); + const qtyAddr = XLSX.utils.encode_cell({ r, c: 2 }); + const shareAddr = XLSX.utils.encode_cell({ r, c: 3 }); + if (worksheet[codeAddr]) worksheet[codeAddr].s = cellStyle; + if (worksheet[nameAddr]) worksheet[nameAddr].s = cellStyle; if (worksheet[qtyAddr]) worksheet[qtyAddr].s = numberStyle; if (worksheet[shareAddr]) worksheet[shareAddr].s = cellStyle; }); - const totalRow = 4 + slices.length; + const totalRow = 4 + shops.length; const totalLabelAddr = XLSX.utils.encode_cell({ r: totalRow, c: 0 }); - const totalValueAddr = XLSX.utils.encode_cell({ r: totalRow, c: 1 }); + const totalValueAddr = XLSX.utils.encode_cell({ r: totalRow, c: 2 }); if (worksheet[totalLabelAddr]) worksheet[totalLabelAddr].s = cellStyle; if (worksheet[totalValueAddr]) worksheet[totalValueAddr].s = numberStyle; + applyProjectExcelFont(worksheet); XLSX.utils.book_append_sheet(workbook, worksheet, sheetName.slice(0, 31)); }, @@ -844,7 +872,8 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => const baseDate = dayjs(date || undefined).isValid() ? dayjs(date) : dayjs(); const floorLabel = floor === ALL ? t("All floors") : floor; const laneLabel = lane === ALL ? t("All lanes") : shortLaneLabel(lane); - const shopLabel = shop === ALL ? t("All shops") : shop; + const shopLabel = + shop === ALL ? t("All shops") : isShopGroupValue(shop) ? shop : formatShopLabel(shop, ""); const dateLabel = baseDate.format("YYYY-MM-DD"); const reportTitle = t("FG carton qty filtered title", { floor: floorLabel, @@ -852,12 +881,6 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => shop: shopLabel, date: dateLabel, }); - const categoryLabel = - breakdownDimension === "shop" - ? t("Shop Code") - : breakdownDimension === "floor" - ? t("Floor") - : t("Lane"); const dailyRows = buildDailyRowsFromRecords( records, @@ -868,15 +891,17 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => shop, ); const filteredTotal = calcSummary(dailyRows).total; + const shopRows = buildShopQtyRows( + records.filter((record) => recordMatchesFilters(record, floor, lane, shop)), + ); const workbook = XLSX.utils.book_new(); addReportSheet(workbook, t("Filtered"), reportTitle, dailyRows); addBreakdownSheet( workbook, t("Breakdown"), - breakdownCaption, - categoryLabel, - breakdownRows, + t("Cartons by shop"), + shopRows, filteredTotal, ); @@ -899,9 +924,6 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => lane, shop, records, - breakdownDimension, - breakdownCaption, - breakdownRows, buildDailyRowsFromRecords, addReportSheet, addBreakdownSheet, @@ -982,20 +1004,29 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => - setDate(event.target.value)} - /> + + { + if (newValue && dayjs(newValue).isValid()) { + setDate(dayjs(newValue).format(OUTPUT_DATE_FORMAT)); + } + }} + slotProps={{ + textField: { size: "small", fullWidth: true }, + }} + /> + @@ -1038,93 +1069,134 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => - - {breakdownCaption} - - - {t("Click a row to filter")} - + + + + {breakdownCaption} + + {chartClicksEnabled && ( + + {t("Click a row to filter")} + + )} + + + {breakdownRows.length === 0 ? ( {t("No data available")} ) : ( - - - {breakdownRows.map((row) => { - const active = isBreakdownRowActive(row); - return ( - applyBreakdownClick(row)} - onKeyDown={(event) => { - if (event.key === "Enter" || event.key === " ") { - event.preventDefault(); - applyBreakdownClick(row); - } + + {breakdownRows.map((row) => { + const active = isBreakdownRowActive(row); + const share = summary.total > 0 ? (row.qty / summary.total) * 100 : 0; + const barWidth = + row.qty <= 0 ? "0%" : `${(row.qty / chartMaxQty) * 100}%`; + return ( + { + if (chartClicksEnabled) applyBreakdownClick(row); + }} + onKeyDown={(event) => { + if (!chartClicksEnabled) return; + if (event.key === "Enter" || event.key === " ") { + event.preventDefault(); + applyBreakdownClick(row); + } + }} + title={`${row.label}: ${row.qty.toLocaleString(numberLocale)} (${share.toFixed(1)}%)`} + sx={{ + height: CHART_ROW_H, + display: "grid", + gridTemplateColumns: { + xs: "132px minmax(0, 1fr) 84px", + sm: "200px minmax(0, 1fr) 84px", + md: "280px minmax(0, 1fr) 84px", + }, + columnGap: 1, + alignItems: "center", + minWidth: 0, + cursor: chartClicksEnabled ? "pointer" : "default", + borderRadius: 1, + px: 0.5, + bgcolor: active ? "action.selected" : "transparent", + "&:hover": chartClicksEnabled ? { bgcolor: "action.hover" } : undefined, + }} + > + + {row.label} + + - 0 ? 4 : 0, + bgcolor: "#1976d2", + borderRadius: "4px", }} - > - {row.label} - + /> - ); - })} - - { - const rect = event.currentTarget.getBoundingClientRect(); - const index = Math.floor((event.clientY - rect.top) / CHART_ROW_H); - const row = breakdownRows[index]; - if (row) applyBreakdownClick(row); - }} - > - - + + {row.qty.toLocaleString(numberLocale)} + + + ); + })} )} diff --git a/src/i18n/en/doWorkbench.json b/src/i18n/en/doWorkbench.json index 5031d223..a74b25be 100644 --- a/src/i18n/en/doWorkbench.json +++ b/src/i18n/en/doWorkbench.json @@ -61,6 +61,8 @@ "2/F or 4/F": "2/F or 4/F", "Lane": "Lane", "Shop Code": "Shop group", + "Shop code": "Shop code", + "Back to previous level": "Back", "All lanes": "All lanes", "All shops": "All shop groups", "Cartons by lane": "Cartons by lane", @@ -75,7 +77,7 @@ "Date": "Date", "Download Excel": "Download Excel", "Download this view Excel": "Download Excel (Selected)", - "Download period Excel": "Download Excel (All)", + "Download period Excel": "Download Excel (Complete)", "Download this view Excel hint": "Excel of the current floor, lane, shop, and date, plus the chart breakdown.", "Download period Excel hint": "Excel with last 7 days, this month, and this year. Not limited to the current view.", "Filtered": "Filtered", diff --git a/src/i18n/en/pickOrder.json b/src/i18n/en/pickOrder.json index 6622011a..9bda0fff 100644 --- a/src/i18n/en/pickOrder.json +++ b/src/i18n/en/pickOrder.json @@ -625,7 +625,7 @@ "Exporting...": "Exporting...", "Download Excel": "Download Excel", "Download this view Excel": "Download Excel (Selected)", - "Download period Excel": "Download Excel (All)", + "Download period Excel": "Download Excel (Complete)", "Download this view Excel hint": "Excel of the current floor, lane, shop, and date, plus the chart breakdown.", "Download period Excel hint": "Excel with last 7 days, this month, and this year. Not limited to the current view.", "Filtered": "Filtered", @@ -635,6 +635,8 @@ "2/F or 4/F": "2/F or 4/F", "Lane": "Lane", "Shop Code": "Shop group", + "Shop code": "Shop code", + "Back to previous level": "Back", "All lanes": "All lanes", "All shops": "All shop groups", "Cartons by lane": "Cartons by lane", diff --git a/src/i18n/zh/doWorkbench.json b/src/i18n/zh/doWorkbench.json index 6fed28a9..2d446a83 100644 --- a/src/i18n/zh/doWorkbench.json +++ b/src/i18n/zh/doWorkbench.json @@ -56,6 +56,8 @@ "2/F or 4/F": "2/F 或 4/F", "Lane": "車線", "Shop Code": "店鋪組別", + "Shop code": "店鋪編號", + "Back to previous level": "返回上一層", "All lanes": "全部車線", "All shops": "全部店鋪組別", "Cartons by lane": "按車線統計箱數", @@ -70,7 +72,7 @@ "Date": "日期", "Download Excel": "下載 Excel", "Download this view Excel": "下載 Excel(已選)", - "Download period Excel": "下載 Excel(全部)", + "Download period Excel": "下載 Excel(完整)", "Download this view Excel hint": "匯出目前樓層、車線、店鋪組別、日期的箱數,以及圖表分項。", "Download period Excel hint": "匯出近7天、本月、本年的箱數,不限目前篩選畫面。", "Filtered": "篩選", diff --git a/src/i18n/zh/pickOrder.json b/src/i18n/zh/pickOrder.json index 5d596eb8..bdde2cf7 100644 --- a/src/i18n/zh/pickOrder.json +++ b/src/i18n/zh/pickOrder.json @@ -637,7 +637,7 @@ "Exporting...": "匯出中...", "Download Excel": "下載 Excel", "Download this view Excel": "下載 Excel(已選)", - "Download period Excel": "下載 Excel(全部)", + "Download period Excel": "下載 Excel(完整)", "Download this view Excel hint": "匯出目前樓層、車線、店鋪組別、日期的箱數,以及圖表分項。", "Download period Excel hint": "匯出近7天、本月、本年的箱數,不限目前篩選畫面。", "Filtered": "篩選", @@ -647,6 +647,8 @@ "2/F or 4/F": "2/F 或 4/F", "Lane": "車線", "Shop Code": "店鋪組別", + "Shop code": "店鋪編號", + "Back to previous level": "返回上一層", "All lanes": "全部車線", "All shops": "全部店鋪組別", "Cartons by lane": "按車線統計箱數", From acb34cbb6171f3ca9d149ddbec50f84e6b961088 Mon Sep 17 00:00:00 2001 From: Harry Groves Date: Tue, 22 Sep 2026 18:10:52 +0800 Subject: [PATCH 16/24] Version Checlist comments update --- src/components/DoWorkbench/DoWorkbenchTabs.tsx | 2 +- .../FinishedGoodSearch/FinishedGoodCartonDashboardTab.tsx | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/components/DoWorkbench/DoWorkbenchTabs.tsx b/src/components/DoWorkbench/DoWorkbenchTabs.tsx index 69015ee6..70019418 100644 --- a/src/components/DoWorkbench/DoWorkbenchTabs.tsx +++ b/src/components/DoWorkbench/DoWorkbenchTabs.tsx @@ -401,7 +401,7 @@ const DoWorkbenchTabsInner: React.FC = ({ defaultTabIndex = 0, printerCom /** * FP-MTMS Version Checklist | Functions Ref. No. 20 | v1.0.0 | 2026-07-19 - * FP-MTMS Version Checklist | Functions Ref. No. 55 | v1.0.0 | 2026-08-06 + * FP-MTMS Version Checklist | Functions Ref. No. 55 | v1.0.1 | 2026-09-22 */ const DoWorkbenchTabs: React.FC = (props) => ( = ({ mode = "normal" }) => { const [floor, setFloor] = useState("all"); const [date, setDate] = useState(dayjs().format("YYYY-MM-DD")); @@ -334,6 +335,7 @@ const FinishedGoodCartonDashboardTab: React.FC = ({ mode = "normal" }) => [calcSummary, styleWorksheet], ); + /** FP-MTMS Version Checklist | Functions Ref. No. 86 | v1.0.0 | 2026-09-22 */ const handleDownloadExcel = useCallback(async () => { setIsExporting(true); try { From ed5b984ead97567aeff4f2d974ad829ccd7cf067 Mon Sep 17 00:00:00 2001 From: "PC-20260115JRSN\\Administrator" Date: Thu, 24 Sep 2026 00:22:42 +0800 Subject: [PATCH 17/24] added unit showing refine in stock take, allow user to set a warning percent to remind stock take difference when inputing the stock qty --- package.json | 1 + scripts/warmup-menu.mjs | 88 +++++++++++++ src/app/api/stockTake/actions.ts | 2 + .../StockTakeManagement/ApproverStockTake.tsx | 45 ++++++- .../ApproverStockTakeAll.tsx | 86 +++++++++--- .../StockTakeManagement/PickerReStockTake.tsx | 99 ++++++++++---- .../StockTakeManagement/PickerStockTake.tsx | 123 +++++++++++------- .../StockTakeQtyGapHint.tsx | 40 ++++++ .../StockTakeManagement/StockTakeTab.tsx | 86 +++++++++++- .../qtyGapWarnSettingClient.ts | 49 +++++++ .../stockTakeQtyAdornment.tsx | 55 ++++++++ .../stockTakeQtyGapWarning.ts | 62 +++++++++ .../useStockTakeQtyGapWarnPercent.ts | 33 +++++ src/i18n/en/stockTake.json | 7 +- src/i18n/zh/stockTake.json | 7 +- 15 files changed, 681 insertions(+), 102 deletions(-) create mode 100644 scripts/warmup-menu.mjs create mode 100644 src/components/StockTakeManagement/StockTakeQtyGapHint.tsx create mode 100644 src/components/StockTakeManagement/qtyGapWarnSettingClient.ts create mode 100644 src/components/StockTakeManagement/stockTakeQtyAdornment.tsx create mode 100644 src/components/StockTakeManagement/stockTakeQtyGapWarning.ts create mode 100644 src/components/StockTakeManagement/useStockTakeQtyGapWarnPercent.ts diff --git a/package.json b/package.json index 3a630eb6..20f4f65d 100644 --- a/package.json +++ b/package.json @@ -4,6 +4,7 @@ "private": true, "scripts": { "dev": "next dev", + "warmup": "node scripts/warmup-menu.mjs", "build": "next build", "start": "set NODE_OPTIONS=--inspect --max-old-space-size=6144&& next start", "lint": "next lint", diff --git a/scripts/warmup-menu.mjs b/scripts/warmup-menu.mjs new file mode 100644 index 00000000..03910fa1 --- /dev/null +++ b/scripts/warmup-menu.mjs @@ -0,0 +1,88 @@ +const BASE = process.env.WARMUP_BASE || "http://localhost:3000"; +const COOKIE = process.env.WARMUP_COOKIE || ""; + +const PATHS = [ + "/dashboard", + "/po", + "/pickOrder", + "/inventory", + "/itemTracing", + "/stocktakemanagement", + "/stockIssue", + "/putAway", + "/finishedGood/management", + "/stockRecord", + "/doworkbench", + "/do", + "/ps", + "/jo", + "/jodetail", + "/productionProcess", + "/bag", + "/bagPrint", + "/laserPrint", + "/report", + "/m18Syn", + "/chart/purchase", + "/chart/joborder", + "/chart/joborder/board", + "/chart/delivery", + "/chart/warehouse", + "/chart/forecast", + "/settings/user", + "/settings/clientMonitor", + "/settings/items", + "/settings/itemDefaultShelfLife", + "/settings/equipment", + "/settings/warehouse", + "/settings/printer", + "/settings/itemPrice", + "/settings/qcItem", + "/settings/qcCategory", + "/settings/qcItemAll", + "/settings/shop/board", + "/settings/deliveryOrderFloor", + "/settings/rss", + "/settings/bomWeighting", + "/settings/masterDataIssues", + "/settings/qrCodeHandle", + "/settings/m18ImportTesting", + "/settings/importExcel", + "/settings/importBom", +]; + +async function waitReady() { + const deadline = Date.now() + 120_000; + while (Date.now() < deadline) { + try { + const res = await fetch(`${BASE}/login`); + if (res.status < 500) return; + } catch { + // server still starting + } + await new Promise((r) => setTimeout(r, 1000)); + } + throw new Error(`dev server not ready at ${BASE}`); +} + +console.log(`Waiting for ${BASE}/login (Next compiles this on first hit; the site will look stuck until it finishes)…`); +await waitReady(); +console.log(`Dev server answered. Warming ${PATHS.length} menu pages at ${BASE}`); +if (!COOKIE) { + console.log( + "No WARMUP_COOKIE — private pages (/dashboard, /ps, /report, /settings, …) will redirect and stay uncompiled.", + ); +} + +for (const path of PATHS) { + process.stdout.write(`compiling ${path} … `); + const t0 = Date.now(); + const res = await fetch(`${BASE}${path}`, { + redirect: "manual", + headers: COOKIE ? { cookie: COOKIE } : {}, + }); + const redirected = res.status >= 300 && res.status < 400; + console.log( + `${res.status} ${Date.now() - t0}ms${redirected ? " (redirect, page not compiled)" : ""}`, + ); +} diff --git a/src/app/api/stockTake/actions.ts b/src/app/api/stockTake/actions.ts index f674efe0..4118c777 100644 --- a/src/app/api/stockTake/actions.ts +++ b/src/app/api/stockTake/actions.ts @@ -24,6 +24,8 @@ export interface InventoryLotDetailResponse { holdQty: number; availableQty: number; uom: string; + /** Stock UoM short label (e.g. 包) for the count input. */ + uomShortDesc?: string | null; warehouseCode: string; warehouseName: string; warehouseSlot: string; diff --git a/src/components/StockTakeManagement/ApproverStockTake.tsx b/src/components/StockTakeManagement/ApproverStockTake.tsx index e2bdbb13..a4c0754a 100644 --- a/src/components/StockTakeManagement/ApproverStockTake.tsx +++ b/src/components/StockTakeManagement/ApproverStockTake.tsx @@ -33,6 +33,10 @@ import { batchSaveApproverStockTakeRecords, updateStockTakeRecordStatusToNotMatch, } from "@/app/api/stockTake/actions"; +import { stockTakeQtyEndAdornment } from "./stockTakeQtyAdornment"; +import StockTakeQtyGapHint from "./StockTakeQtyGapHint"; +import { stockTakeHiddenOnHand, stockTakeQtyGapWarnText } from "./stockTakeQtyGapWarning"; +import { useStockTakeQtyGapWarnPercent } from "./useStockTakeQtyGapWarnPercent"; import { useSession } from "next-auth/react"; import { SessionWithTokens } from "@/config/authConfig"; import dayjs from "dayjs"; @@ -52,6 +56,7 @@ const ApproverStockTake: React.FC = ({ onSnackbar, }) => { const { t } = useTranslation(["stockTake", "common"]); + const qtyGapWarnPercent = useStockTakeQtyGapWarnPercent(); const { data: session } = useSession() as { data: SessionWithTokens | null }; const [inventoryLotDetails, setInventoryLotDetails] = useState([]); @@ -61,6 +66,7 @@ const ApproverStockTake: React.FC = ({ // 每个记录的选择状态,key 为 detail.id const [qtySelection, setQtySelection] = useState>({}); const [approverQty, setApproverQty] = useState>({}); + const [gapCheckOpen, setGapCheckOpen] = useState>({}); const [approverBadQty, setApproverBadQty] = useState>({}); const [saving, setSaving] = useState(false); const [batchSaving, setBatchSaving] = useState(false); @@ -255,7 +261,19 @@ const ApproverStockTake: React.FC = ({ selectedSession.stockTakeId ); - onSnackbar(t("Approver stock take record saved successfully"), "success"); + const gapText = + selection === "approver" + ? stockTakeQtyGapWarnText(t, approverQty[detail.id] || "", stockTakeHiddenOnHand(detail), qtyGapWarnPercent) + : null; + if (selection === "approver") { + setGapCheckOpen((prev) => ({ ...prev, [`${detail.id}:approver`]: true })); + } + onSnackbar( + gapText + ? `${t("Approver stock take record saved successfully")} ${gapText}` + : t("Approver stock take record saved successfully"), + gapText ? "warning" : "success", + ); // 計算最終數量(合格數) const goodQty = finalQty - finalBadQty; @@ -292,7 +310,7 @@ const ApproverStockTake: React.FC = ({ } finally { setSaving(false); } - }, [selectedSession, qtySelection, approverQty, approverBadQty, t, currentUserId, onSnackbar, page, pageSize, loadDetails]); + }, [selectedSession, qtySelection, approverQty, approverBadQty, t, currentUserId, onSnackbar, page, pageSize, loadDetails, qtyGapWarnPercent]); const handleUpdateStatusToNotMatch = useCallback(async (detail: InventoryLotDetailResponse) => { if (!detail.stockTakeRecordId) { @@ -598,17 +616,28 @@ const ApproverStockTake: React.FC = ({ size="small" type="number" value={approverQty[detail.id] || ""} + onFocus={() => { + setGapCheckOpen((prev) => ({ ...prev, [`${detail.id}:approver`]: false })); + if (selection !== "approver") { + setQtySelection({ ...qtySelection, [detail.id]: "approver" }); + } + }} + onBlur={() => + setGapCheckOpen((prev) => ({ ...prev, [`${detail.id}:approver`]: true })) + } onChange={(e) => setApproverQty({ ...approverQty, [detail.id]: e.target.value })} + InputProps={{ + endAdornment: stockTakeQtyEndAdornment(detail.uomShortDesc), + }} sx={{ - width: 130, - minWidth: 130, + width: 168, + minWidth: 168, '& .MuiInputBase-input': { height: '1.4375em', padding: '4px 8px' } }} placeholder={t("Stock Take Qty") } - disabled={selection !== "approver"} /> = ({ = {formatNumber(parseFloat(approverQty[detail.id] || "0") - parseFloat(approverBadQty[detail.id] || "0"))} + )} {(() => { diff --git a/src/components/StockTakeManagement/ApproverStockTakeAll.tsx b/src/components/StockTakeManagement/ApproverStockTakeAll.tsx index 91f57485..11f94ec4 100644 --- a/src/components/StockTakeManagement/ApproverStockTakeAll.tsx +++ b/src/components/StockTakeManagement/ApproverStockTakeAll.tsx @@ -53,6 +53,10 @@ import { type ApproverInventoryLotDetailsQuery, } from "@/app/api/stockTake/actions"; import { fetchStockTakeSections } from "@/app/api/warehouse/actions"; +import { stockTakeQtyEndAdornment, StockTakeQtyWithUnit } from "./stockTakeQtyAdornment"; +import StockTakeQtyGapHint from "./StockTakeQtyGapHint"; +import { stockTakeHiddenOnHand, stockTakeQtyGapWarnText } from "./stockTakeQtyGapWarning"; +import { useStockTakeQtyGapWarnPercent } from "./useStockTakeQtyGapWarnPercent"; import { useSession } from "next-auth/react"; import { SessionWithTokens } from "@/config/authConfig"; import dayjs from "dayjs"; @@ -226,6 +230,7 @@ const ApproverStockTakeAll: React.FC = ({ onSnackbar, }) => { const { t } = useTranslation(["stockTake", "common"]); + const qtyGapWarnPercent = useStockTakeQtyGapWarnPercent(); const { data: session } = useSession() as { data: SessionWithTokens | null }; const [inventoryLotDetails, setInventoryLotDetails] = useState([]); @@ -235,6 +240,7 @@ const ApproverStockTakeAll: React.FC = ({ const [searchVarianceFilterStrict, setSearchVarianceFilterStrict] = useState(false); const [qtySelection, setQtySelection] = useState>({}); const [approverQty, setApproverQty] = useState>({}); + const [gapCheckOpen, setGapCheckOpen] = useState>({}); const [approverBadQty, setApproverBadQty] = useState>({}); const [saving, setSaving] = useState(false); const [batchSaving, setBatchSaving] = useState(false); @@ -654,7 +660,19 @@ const ApproverStockTakeAll: React.FC = ({ try { await saveApproverStockTakeRecord(request, selectedSession.stockTakeId); - onSnackbar(t("Approver stock take record saved successfully"), "success"); + const gapText = + selection === "approver" + ? stockTakeQtyGapWarnText(t, approverQty[detail.id] || "", stockTakeHiddenOnHand(detail), qtyGapWarnPercent) + : null; + if (selection === "approver") { + setGapCheckOpen((prev) => ({ ...prev, [`${detail.id}:approver`]: true })); + } + onSnackbar( + gapText + ? `${t("Approver stock take record saved successfully")} ${gapText}` + : t("Approver stock take record saved successfully"), + gapText ? "warning" : "success", + ); setInventoryLotDetails((prev) => prev.map((d) => @@ -688,7 +706,7 @@ const ApproverStockTakeAll: React.FC = ({ setSaving(false); } }, - [selectedSession, currentUserId, qtySelection, approverQty, approverBadQty, t, onSnackbar, mode] + [selectedSession, currentUserId, qtySelection, approverQty, approverBadQty, t, onSnackbar, mode, qtyGapWarnPercent] ); const handleUpdateStatusToNotMatch = useCallback( @@ -934,10 +952,13 @@ const ApproverStockTakeAll: React.FC = ({ flex: 1, sortable: false, renderCell: (params) => ( - - + + {params.row.itemCode || "-"} {params.row.itemName || "-"} - + {params.row.lotNo || "-"} {params.row.expiryDate @@ -1052,12 +1073,12 @@ const ApproverStockTakeAll: React.FC = ({ /> {t("First")}:{" "} - {formatNumber( - (detail.firstStockTakeQty ?? 0) + (detail.firstBadQty ?? 0) - )}{" "} - {/* - = {formatNumber(detail.firstStockTakeQty ?? 0)} - */} + )} @@ -1077,12 +1098,12 @@ const ApproverStockTakeAll: React.FC = ({ /> {t("Second")}:{" "} - {formatNumber( - (detail.secondStockTakeQty ?? 0) + (detail.secondBadQty ?? 0) - )}{" "} - {/* - = {formatNumber(detail.secondStockTakeQty ?? 0)} - */} + @@ -1108,6 +1129,18 @@ const ApproverStockTakeAll: React.FC = ({ size="small" type="number" value={approverQty[detail.id] || ""} + onFocus={() => { + setGapCheckOpen((prev) => ({ ...prev, [`${detail.id}:approver`]: false })); + if (mode !== "approved" && selection !== "approver") { + setQtySelection({ + ...qtySelection, + [detail.id]: "approver", + }); + } + }} + onBlur={() => + setGapCheckOpen((prev) => ({ ...prev, [`${detail.id}:approver`]: true })) + } onKeyDown={blockNonIntegerKeys} onChange={(e) => { const clean = sanitizeIntegerInput(e.target.value); @@ -1116,18 +1149,29 @@ const ApproverStockTakeAll: React.FC = ({ [detail.id]: clean, }); }} + InputProps={{ + endAdornment: stockTakeQtyEndAdornment(detail.uomShortDesc), + }} sx={{ - width: 72, - minWidth: 72, + width: 120, + minWidth: 120, "& .MuiInputBase-input": { py: 0.5, px: 1, }, }} // placeholder={t("Stock Take Qty")} - disabled={mode === "approved" || selection !== "approver"} + disabled={mode === "approved"} inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }} /> + + + {/* = {formatNumber(approverGoodQty)} @@ -1152,7 +1196,7 @@ const ApproverStockTakeAll: React.FC = ({ {summaryLine( `${t("Selected Qty")}:`, - formatNumber(selectedQty) + [formatNumber(selectedQty), detail.uomShortDesc?.trim()].filter(Boolean).join(" ") )} {summaryLine(`${t("Book Qty")}:`, formatNumber(bookQty))} {summaryLine( diff --git a/src/components/StockTakeManagement/PickerReStockTake.tsx b/src/components/StockTakeManagement/PickerReStockTake.tsx index 1c8ebd3b..925b1bbb 100644 --- a/src/components/StockTakeManagement/PickerReStockTake.tsx +++ b/src/components/StockTakeManagement/PickerReStockTake.tsx @@ -30,6 +30,10 @@ import { getInventoryLotDetailsBySectionNotMatch } from "@/app/api/stockTake/actions"; import { buildPickerBatchSaveRequests } from "./buildPickerBatchSaveRequests"; +import { stockTakeQtyEndAdornment, StockTakeQtyWithUnit } from "./stockTakeQtyAdornment"; +import StockTakeQtyGapHint from "./StockTakeQtyGapHint"; +import { stockTakeHiddenOnHand, stockTakeQtyGapWarnText } from "./stockTakeQtyGapWarning"; +import { useStockTakeQtyGapWarnPercent } from "./useStockTakeQtyGapWarnPercent"; import PickerBatchSaveFab from "./PickerBatchSaveFab"; import { useSession } from "next-auth/react"; import { SessionWithTokens } from "@/config/authConfig"; @@ -52,6 +56,7 @@ const PickerReStockTake: React.FC = ({ onSnackbar, }) => { const { t } = useTranslation(["stockTake", "common"]); + const qtyGapWarnPercent = useStockTakeQtyGapWarnPercent(); const { data: session } = useSession() as { data: SessionWithTokens | null }; const [inventoryLotDetails, setInventoryLotDetails] = useState([]); @@ -65,6 +70,7 @@ const PickerReStockTake: React.FC = ({ remark: string; }>>({}); const [saving, setSaving] = useState(false); + const [gapCheckOpen, setGapCheckOpen] = useState>({}); const [batchSaving, setBatchSaving] = useState(false); const [shortcutInput, setShortcutInput] = useState(""); const [page, setPage] = useState(0); @@ -246,7 +252,19 @@ const PickerReStockTake: React.FC = ({ currentUserId ); - onSnackbar(t("Stock take record saved successfully"), "success"); + const gapText = stockTakeQtyGapWarnText( + t, + totalQtyStr ?? "", + stockTakeHiddenOnHand(detail), + qtyGapWarnPercent, + ); + setGapCheckOpen((prev) => ({ ...prev, [`${detail.id}:${isFirstSubmit ? "first" : "second"}`]: true })); + onSnackbar( + gapText + ? `${t("Stock take record saved successfully")} ${gapText}` + : t("Stock take record saved successfully"), + gapText ? "warning" : "success", + ); const savedId = result?.id ?? detail.stockTakeRecordId; setInventoryLotDetails((prev) => @@ -286,7 +304,7 @@ const PickerReStockTake: React.FC = ({ } finally { setSaving(false); } - }, [selectedSession, recordInputs, t, currentUserId, onSnackbar, page, pageSize, loadDetails]); + }, [selectedSession, recordInputs, t, currentUserId, onSnackbar, page, pageSize, loadDetails, qtyGapWarnPercent]); const isSubmitDisabled = useCallback((detail: InventoryLotDetailResponse): boolean => { if (selectedSession?.status?.toLowerCase() === "completed") { @@ -492,7 +510,7 @@ const PickerReStockTake: React.FC = ({ {t("Warehouse Location")} {t("Item-lotNo-ExpiryDate")} {t("UOM")} - {t("Stock Take Qty(include Bad Qty)= Available Qty")} + {t("Stock Take Qty(include Bad Qty)= Available Qty")} {t("Action")} {/*{t("Remark")}*/} {t("Record Status")} @@ -520,28 +538,40 @@ const PickerReStockTake: React.FC = ({ {detail.warehouseArea || "-"}{detail.warehouseSlot || "-"} - {detail.itemCode || "-"} {detail.itemName || "-"} + + {detail.itemCode || "-"} {detail.itemName || "-"} + {detail.lotNo || "-"} {detail.expiryDate ? dayjs(detail.expiryDate).format(OUTPUT_DATE_FORMAT) : "-"} {detail.uom || "-"} - + {/* First */} {!submitDisabled && isFirstSubmit ? ( + {t("First")}: + setGapCheckOpen((prev) => ({ ...prev, [`${detail.id}:first`]: false })) + } + onBlur={() => + setGapCheckOpen((prev) => ({ ...prev, [`${detail.id}:first`]: true })) + } inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }} onKeyDown={blockNonIntegerKeys} onChange={(e) => { @@ -553,9 +583,12 @@ const PickerReStockTake: React.FC = ({ [detail.id]: { ...(prev[detail.id] ?? defaultInputs), firstQty: val } })); }} + InputProps={{ + endAdornment: stockTakeQtyEndAdornment(detail.uomShortDesc), + }} sx={{ - width: 130, - minWidth: 130, + width: 148, + minWidth: 148, "& .MuiInputBase-input": { height: "1.4375em", padding: "4px 8px", @@ -590,28 +623,39 @@ const PickerReStockTake: React.FC = ({ placeholder={t("Bad Qty")} /> */} - - = {formatNumber(parseFloat(inputs.firstQty || "0") - parseFloat(inputs.firstBadQty || "0"))} - + + ) : detail.firstStockTakeQty != null ? ( {t("First")}:{" "} - {formatNumber((detail.firstStockTakeQty ?? 0) + (detail.firstBadQty ?? 0))}{" "} - {/* ({formatNumber(detail.firstBadQty ?? 0)}) */} - ={" "} - {formatNumber(detail.firstStockTakeQty ?? 0)} + ) : null} {/* Second */} {!submitDisabled && isSecondSubmit ? ( + {t("Second")}: + setGapCheckOpen((prev) => ({ ...prev, [`${detail.id}:second`]: false })) + } + onBlur={() => + setGapCheckOpen((prev) => ({ ...prev, [`${detail.id}:second`]: true })) + } inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }} onKeyDown={blockNonIntegerKeys} onChange={(e) => { @@ -623,9 +667,12 @@ const PickerReStockTake: React.FC = ({ [detail.id]: { ...(prev[detail.id] ?? defaultInputs), secondQty: clean } })); }} + InputProps={{ + endAdornment: stockTakeQtyEndAdornment(detail.uomShortDesc), + }} sx={{ - width: 130, - minWidth: 130, + width: 148, + minWidth: 148, "& .MuiInputBase-input": { height: "1.4375em", padding: "4px 8px", @@ -660,17 +707,21 @@ const PickerReStockTake: React.FC = ({ placeholder={t("Bad Qty")} /> */} - - = {formatNumber(parseFloat(inputs.secondQty || "0") - parseFloat(inputs.secondBadQty || "0"))} - + + ) : detail.secondStockTakeQty != null ? ( {t("Second")}:{" "} - {formatNumber((detail.secondStockTakeQty ?? 0) + (detail.secondBadQty ?? 0))}{" "} - {/* ({formatNumber(detail.secondBadQty ?? 0)}) */} - ={" "} - {formatNumber(detail.secondStockTakeQty ?? 0)} + ) : null} diff --git a/src/components/StockTakeManagement/PickerStockTake.tsx b/src/components/StockTakeManagement/PickerStockTake.tsx index 220c7b3a..6d63b6b0 100644 --- a/src/components/StockTakeManagement/PickerStockTake.tsx +++ b/src/components/StockTakeManagement/PickerStockTake.tsx @@ -35,6 +35,10 @@ import { batchSavePickerStockTakeInputs, } from "@/app/api/stockTake/actions"; import { buildPickerBatchSaveRequests } from "./buildPickerBatchSaveRequests"; +import { stockTakeQtyEndAdornment, StockTakeQtyWithUnit } from "./stockTakeQtyAdornment"; +import StockTakeQtyGapHint from "./StockTakeQtyGapHint"; +import { stockTakeHiddenOnHand, stockTakeQtyGapWarnText } from "./stockTakeQtyGapWarning"; +import { useStockTakeQtyGapWarnPercent } from "./useStockTakeQtyGapWarnPercent"; import PickerBatchSaveFab from "./PickerBatchSaveFab"; import { useSession } from "next-auth/react"; import { SessionWithTokens } from "@/config/authConfig"; @@ -57,6 +61,7 @@ const PickerStockTake: React.FC = ({ onSnackbar, }) => { const { t } = useTranslation(["stockTake", "common"]); + const qtyGapWarnPercent = useStockTakeQtyGapWarnPercent(); const { data: session } = useSession() as { data: SessionWithTokens | null }; const [inventoryLotDetails, setInventoryLotDetails] = useState([]); @@ -72,6 +77,8 @@ const PickerStockTake: React.FC = ({ const [savingRecordId, setSavingRecordId] = useState(null); const [remark, setRemark] = useState(""); const [saving, setSaving] = useState(false); + /** Qty fields the user has left, or just saved. Warning stays hidden while typing. */ + const [gapCheckOpen, setGapCheckOpen] = useState>({}); const [batchSaving, setBatchSaving] = useState(false); const [shortcutInput, setShortcutInput] = useState(""); const [page, setPage] = useState(0); @@ -240,7 +247,19 @@ const PickerStockTake: React.FC = ({ await saveStockTakeRecord(request, selectedSession.stockTakeId, currentUserId); - onSnackbar(t("Stock take record saved successfully"), "success"); + const gapText = stockTakeQtyGapWarnText( + t, + totalQtyStr ?? "", + stockTakeHiddenOnHand(detail), + qtyGapWarnPercent, + ); + setGapCheckOpen((prev) => ({ ...prev, [`${detail.id}:${isFirstSubmit ? "first" : "second"}`]: true })); + onSnackbar( + gapText + ? `${t("Stock take record saved successfully")} ${gapText}` + : t("Stock take record saved successfully"), + gapText ? "warning" : "success", + ); //await loadDetails(page, pageSize, { silent: true }); setInventoryLotDetails((prev) => @@ -286,6 +305,7 @@ const PickerStockTake: React.FC = ({ t, currentUserId, onSnackbar, + qtyGapWarnPercent, ] ); @@ -540,7 +560,7 @@ const PickerStockTake: React.FC = ({ {t("Warehouse Location")} {t("Item-lotNo-ExpiryDate")} {t("UOM")} - {t("Stock Take Qty(include Bad Qty)= Available Qty")} + {t("Stock Take Qty(include Bad Qty)= Available Qty")} {t("Action")} {/*{t("Remark")}*/} {t("Record Status")} @@ -572,16 +592,19 @@ const PickerStockTake: React.FC = ({ - + {detail.itemCode || "-"} {detail.itemName || "-"} - + {detail.lotNo || "-"} {detail.expiryDate @@ -592,16 +615,23 @@ const PickerStockTake: React.FC = ({ {detail.uom || "-"} {/* Qty + Bad Qty 合并显示/输入 */} - + {/* First */} {!submitDisabled && isFirstSubmit ? ( + {t("First")}: + setGapCheckOpen((prev) => ({ ...prev, [`${detail.id}:first`]: false })) + } + onBlur={() => + setGapCheckOpen((prev) => ({ ...prev, [`${detail.id}:first`]: true })) + } inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }} onKeyDown={blockNonIntegerKeys} onChange={(e) => { @@ -610,9 +640,12 @@ const PickerStockTake: React.FC = ({ if (val.includes("-")) return; setRecordInputs(prev => ({ ...prev, [detail.id]: { ...prev[detail.id], firstQty: val } })); }} + InputProps={{ + endAdornment: stockTakeQtyEndAdornment(detail.uomShortDesc), + }} sx={{ - width: 130, - minWidth: 130, + width: 148, + minWidth: 148, "& .MuiInputBase-input": { height: "1.4375em", padding: "4px 8px", @@ -652,40 +685,39 @@ const PickerStockTake: React.FC = ({ placeholder={t("Bad Qty")} /> */} - - = - {formatNumber( - parseFloat(recordInputs[detail.id]?.firstQty || "0") - - parseFloat(recordInputs[detail.id]?.firstBadQty || "0") - )} - + + ) : detail.firstStockTakeQty != null ? ( {t("First")}:{" "} - {formatNumber( - (detail.firstStockTakeQty ?? 0) + - (detail.firstBadQty ?? 0) - )}{" "} - {/* - ( - {formatNumber( - detail.firstBadQty ?? 0 - )} - */} - ={" "} - {formatNumber(detail.firstStockTakeQty ?? 0)} + ) : null} {/* Second */} {!submitDisabled && isSecondSubmit ? ( + {t("Second")}: + setGapCheckOpen((prev) => ({ ...prev, [`${detail.id}:second`]: false })) + } + onBlur={() => + setGapCheckOpen((prev) => ({ ...prev, [`${detail.id}:second`]: true })) + } inputProps={{ inputMode: "numeric", pattern: "[0-9]*" }} onKeyDown={blockNonIntegerKeys} onChange={(e) => { @@ -694,9 +726,12 @@ const PickerStockTake: React.FC = ({ if (val.includes("-")) return; setRecordInputs(prev => ({ ...prev, [detail.id]: { ...prev[detail.id], secondQty: val } })); }} + InputProps={{ + endAdornment: stockTakeQtyEndAdornment(detail.uomShortDesc), + }} sx={{ - width: 130, - minWidth: 130, + width: 148, + minWidth: 148, "& .MuiInputBase-input": { height: "1.4375em", padding: "4px 8px", @@ -728,29 +763,21 @@ const PickerStockTake: React.FC = ({ placeholder={t("Bad Qty")} /> */} - - = - {formatNumber( - parseFloat(recordInputs[detail.id]?.secondQty || "0") - - parseFloat(recordInputs[detail.id]?.secondBadQty || "0") - )} - + + ) : detail.secondStockTakeQty != null ? ( {t("Second")}:{" "} - {formatNumber( - (detail.secondStockTakeQty ?? 0) + - (detail.secondBadQty ?? 0) - )}{" "} - {/* - ( - {formatNumber( - detail.secondBadQty ?? 0 - )} - */} - ={" "} - {formatNumber(detail.secondStockTakeQty ?? 0)} + ) : null} diff --git a/src/components/StockTakeManagement/StockTakeQtyGapHint.tsx b/src/components/StockTakeManagement/StockTakeQtyGapHint.tsx new file mode 100644 index 00000000..3323d5e1 --- /dev/null +++ b/src/components/StockTakeManagement/StockTakeQtyGapHint.tsx @@ -0,0 +1,40 @@ +"use client"; + +import Typography from "@mui/material/Typography"; +import { useTranslation } from "react-i18next"; +import { STOCK_TAKE_QTY_GAP_WARN_PERCENT, stockTakeQtyGapWarnText } from "./stockTakeQtyGapWarning"; + +/** Shown after the field is left, or flagged on save. Does not show the hidden on-hand quantity. */ +export default function StockTakeQtyGapHint({ + entered, + currentQty, + open, + threshold = STOCK_TAKE_QTY_GAP_WARN_PERCENT, +}: { + entered: string; + currentQty: number | null | undefined; + /** False while the user is still typing. */ + open: boolean; + /** Warn when the count differs from on-hand by at least this percent. */ + threshold?: number; +}) { + const { t } = useTranslation("stockTake"); + if (!open) return null; + const text = stockTakeQtyGapWarnText(t, entered, currentQty, threshold); + if (!text) return null; + return ( + + {text} + + ); +} diff --git a/src/components/StockTakeManagement/StockTakeTab.tsx b/src/components/StockTakeManagement/StockTakeTab.tsx index ad4af356..957e1901 100644 --- a/src/components/StockTakeManagement/StockTakeTab.tsx +++ b/src/components/StockTakeManagement/StockTakeTab.tsx @@ -1,14 +1,23 @@ "use client"; -import { Box, Tab, Tabs, Snackbar, Alert, CircularProgress, Typography } from "@mui/material"; -import { useState, useCallback, useEffect } from "react"; +import { Box, Tab, Tabs, Snackbar, Alert, CircularProgress, Typography, TextField, Button, Stack } from "@mui/material"; +import { useState, useCallback, useEffect, useRef } from "react"; +import { useSession } from "next-auth/react"; import { useTranslation } from "react-i18next"; +import { AUTH } from "@/authorities"; +import { SessionWithTokens } from "@/config/authConfig"; import { AllPickedStockTakeListReponse, getLatestApproverStockTakeHeader } from "@/app/api/stockTake/actions"; import PickerCardList from "./PickerCardList"; import type { PickerCardListFilters } from "./PickerCardList"; import PickerStockTake from "./PickerStockTake"; import PickerReStockTake from "./PickerReStockTake"; import ApproverStockTakeAll from "./ApproverStockTakeAll"; +import { useStockTakeQtyGapWarnPercent } from "./useStockTakeQtyGapWarnPercent"; +import { + parseQtyGapWarnPercent, + saveStockTakeQtyGapWarnPercent, +} from "./qtyGapWarnSettingClient"; +import { STOCK_TAKE_QTY_GAP_WARN_PERCENT } from "./stockTakeQtyGapWarning"; type ViewScope = "picker" | "approver-all"; const DEFAULT_PICKER_CARD_LIST_FILTERS: PickerCardListFilters = { @@ -21,6 +30,14 @@ const DEFAULT_PICKER_CARD_LIST_FILTERS: PickerCardListFilters = { const StockTakeTab: React.FC = () => { const { t } = useTranslation(["stockTake", "common"]); + const { data: session } = useSession() as { data: SessionWithTokens | null }; + const isAdmin = (session?.abilities ?? session?.user?.abilities ?? []).some( + (ability) => String(ability).trim() === AUTH.ADMIN, + ); + const qtyGapWarnPercent = useStockTakeQtyGapWarnPercent(); + const [qtyGapDraft, setQtyGapDraft] = useState(String(STOCK_TAKE_QTY_GAP_WARN_PERCENT)); + const [qtyGapSaving, setQtyGapSaving] = useState(false); + const qtyGapSaveLock = useRef(false); const [tabValue, setTabValue] = useState(0); const [selectedSession, setSelectedSession] = useState(null); const [viewMode, setViewMode] = useState<"details" | "reStockTake">("details"); @@ -66,6 +83,31 @@ const StockTakeTab: React.FC = () => { }); }, []); + useEffect(() => { + setQtyGapDraft(String(qtyGapWarnPercent)); + }, [qtyGapWarnPercent]); + + const saveQtyGapWarnPercent = useCallback(async () => { + if (!isAdmin || qtyGapSaveLock.current) return; + const parsed = Number(qtyGapDraft.trim()); + if (!Number.isInteger(parsed) || parsed < 0 || parsed > 1000) { + handleSnackbar(t("qtyGapWarnPercentInvalid"), "warning"); + return; + } + qtyGapSaveLock.current = true; + setQtyGapSaving(true); + try { + await saveStockTakeQtyGapWarnPercent(parsed); + setQtyGapDraft(String(parseQtyGapWarnPercent(String(parsed)))); + handleSnackbar(t("qtyGapWarnPercentSaved"), "success"); + } catch (e) { + handleSnackbar(e instanceof Error ? e.message : t("qtyGapWarnPercentInvalid"), "error"); + } finally { + qtyGapSaveLock.current = false; + setQtyGapSaving(false); + } + }, [handleSnackbar, isAdmin, qtyGapDraft, t]); + useEffect(() => { if (tabValue !== 1 && tabValue !== 2) return; setApproverLoading(true); @@ -115,6 +157,46 @@ const StockTakeTab: React.FC = () => { return ( + {isAdmin && ( + + + {t("qtyGapWarnPercent")} + + setQtyGapDraft(e.target.value.replace(/[^\d]/g, ""))} + inputProps={{ min: 0, max: 1000, inputMode: "numeric" }} + sx={{ + width: 88, + m: 0, + "& .MuiFilledInput-root": { height: 40 }, + "& .MuiFilledInput-input.MuiInputBase-inputSizeSmall": { + height: 40, + boxSizing: "border-box", + paddingTop: 0, + paddingBottom: 0, + lineHeight: "40px", + }, + }} + /> + + + )} { diff --git a/src/components/StockTakeManagement/qtyGapWarnSettingClient.ts b/src/components/StockTakeManagement/qtyGapWarnSettingClient.ts new file mode 100644 index 00000000..ac6e81ee --- /dev/null +++ b/src/components/StockTakeManagement/qtyGapWarnSettingClient.ts @@ -0,0 +1,49 @@ +"use client"; + +import { clientAuthFetch } from "@/app/utils/clientAuthFetch"; +import { NEXT_PUBLIC_API_URL } from "@/config/api"; +import { STOCK_TAKE_QTY_GAP_WARN_PERCENT } from "./stockTakeQtyGapWarning"; + +export const STOCK_TAKE_QTY_GAP_WARN_SETTING = "STOCK_TAKE.qtyGapWarnPercent"; +export const STOCK_TAKE_QTY_GAP_SETTING_EVENT = "stock-take-qty-gap-warn-percent"; + +type SettingsRow = { name: string; value: string }; + +let cached: number | null = null; + +export function parseQtyGapWarnPercent(raw: string | null | undefined): number { + const text = String(raw ?? "").trim(); + if (!text) return STOCK_TAKE_QTY_GAP_WARN_PERCENT; + const n = Number(text); + if (!Number.isFinite(n) || n < 0 || n > 1000) return STOCK_TAKE_QTY_GAP_WARN_PERCENT; + return Math.round(n); +} + +export async function fetchStockTakeQtyGapWarnPercent(): Promise { + if (cached != null) return cached; + const base = (NEXT_PUBLIC_API_URL ?? "").replace(/\/$/, ""); + const res = await clientAuthFetch(`${base}/settings`, { method: "GET" }); + if (!res.ok) return STOCK_TAKE_QTY_GAP_WARN_PERCENT; + const rows = (await res.json()) as SettingsRow[]; + const value = rows.find((row) => row.name === STOCK_TAKE_QTY_GAP_WARN_SETTING)?.value; + cached = parseQtyGapWarnPercent(value); + return cached; +} + +export async function saveStockTakeQtyGapWarnPercent(percent: number): Promise { + const base = (NEXT_PUBLIC_API_URL ?? "").replace(/\/$/, ""); + const res = await clientAuthFetch( + `${base}/settings/${encodeURIComponent(STOCK_TAKE_QTY_GAP_WARN_SETTING)}`, + { + method: "POST", + headers: { "Content-Type": "application/json" }, + body: JSON.stringify({ value: String(percent) }), + }, + ); + if (!res.ok) { + const text = await res.text().catch(() => ""); + throw new Error(text || `Failed to save setting: ${res.status}`); + } + cached = percent; + window.dispatchEvent(new CustomEvent(STOCK_TAKE_QTY_GAP_SETTING_EVENT, { detail: percent })); +} diff --git a/src/components/StockTakeManagement/stockTakeQtyAdornment.tsx b/src/components/StockTakeManagement/stockTakeQtyAdornment.tsx new file mode 100644 index 00000000..88e7b7c2 --- /dev/null +++ b/src/components/StockTakeManagement/stockTakeQtyAdornment.tsx @@ -0,0 +1,55 @@ +"use client"; + +import InputAdornment from "@mui/material/InputAdornment"; +import Typography from "@mui/material/Typography"; + +/** Large unit reminder inside the count field, same style as PO stock-in qty. */ +export function stockTakeQtyEndAdornment(uomShortDesc?: string | null) { + const label = uomShortDesc?.trim() ?? ""; + if (!label) return undefined; + return ( + + + {label} + + + ); +} + +/** Saved count with the same large unit label, e.g. 140 包. */ +export function StockTakeQtyWithUnit({ + qty, + uomShortDesc, +}: { + qty: string; + uomShortDesc?: string | null; +}) { + const unit = uomShortDesc?.trim() ?? ""; + return ( + <> + {qty} + {unit ? ( + + {unit} + + ) : null} + + ); +} diff --git a/src/components/StockTakeManagement/stockTakeQtyGapWarning.ts b/src/components/StockTakeManagement/stockTakeQtyGapWarning.ts new file mode 100644 index 00000000..5bdb1144 --- /dev/null +++ b/src/components/StockTakeManagement/stockTakeQtyGapWarning.ts @@ -0,0 +1,62 @@ +/** Warn when the typed count is this far from hidden on-hand, either higher or lower. Save stays allowed. */ +export const STOCK_TAKE_QTY_GAP_WARN_PERCENT = 50; + +export type StockTakeQtyGap = + | { kind: "percent"; pct: number } + | { kind: "over" }; + +/** + * On-hand used only for the gap check. Prefer the stock-take book qty (frozen for this count); + * fall back to live available qty. Callers must not render this number. + */ +export function stockTakeHiddenOnHand(detail: { + bookQty?: number | null; + availableQty?: number | null; +}): number | null { + if (detail.bookQty != null && Number.isFinite(Number(detail.bookQty))) { + return Number(detail.bookQty); + } + if (detail.availableQty != null && Number.isFinite(Number(detail.availableQty))) { + return Number(detail.availableQty); + } + return null; +} + +/** Null when the field is empty, or the gap is within the threshold. */ +export function stockTakeQtyGapWarning( + enteredRaw: string, + currentQty: number | null | undefined, + threshold = STOCK_TAKE_QTY_GAP_WARN_PERCENT, +): StockTakeQtyGap | null { + const raw = enteredRaw.trim(); + if (!raw) return null; + const entered = Number(raw); + if (!Number.isFinite(entered)) return null; + if (currentQty == null || !Number.isFinite(Number(currentQty))) return null; + const current = Number(currentQty); + if (current === 0) { + return entered === 0 ? null : { kind: "over" }; + } + const pct = (Math.abs(entered - current) / Math.abs(current)) * 100; + if (pct + 1e-9 < threshold) return null; + return { kind: "percent", pct: Math.round(pct) }; +} + +export function stockTakeQtyGapWarnText( + t: (key: string, options?: Record) => string, + enteredRaw: string, + currentQty: number | null | undefined, + threshold = STOCK_TAKE_QTY_GAP_WARN_PERCENT, +): string | null { + const gap = stockTakeQtyGapWarning(enteredRaw, currentQty, threshold); + if (!gap) return null; + if (gap.kind === "percent") { + return t("stockTakeQtyGapWarn", { + pct: gap.pct, + threshold, + }); + } + return t("stockTakeQtyGapWarnOver", { + threshold, + }); +} diff --git a/src/components/StockTakeManagement/useStockTakeQtyGapWarnPercent.ts b/src/components/StockTakeManagement/useStockTakeQtyGapWarnPercent.ts new file mode 100644 index 00000000..289214b2 --- /dev/null +++ b/src/components/StockTakeManagement/useStockTakeQtyGapWarnPercent.ts @@ -0,0 +1,33 @@ +"use client"; + +import { useEffect, useState } from "react"; +import { STOCK_TAKE_QTY_GAP_WARN_PERCENT } from "./stockTakeQtyGapWarning"; +import { + fetchStockTakeQtyGapWarnPercent, + STOCK_TAKE_QTY_GAP_SETTING_EVENT, +} from "./qtyGapWarnSettingClient"; + +/** Warning threshold from settings (`STOCK_TAKE.qtyGapWarnPercent`), default 50. */ +export function useStockTakeQtyGapWarnPercent(): number { + const [percent, setPercent] = useState(STOCK_TAKE_QTY_GAP_WARN_PERCENT); + + useEffect(() => { + let cancelled = false; + fetchStockTakeQtyGapWarnPercent() + .then((n) => { + if (!cancelled) setPercent(n); + }) + .catch(() => {}); + const onChange = (event: Event) => { + const next = (event as CustomEvent).detail; + if (Number.isFinite(next)) setPercent(next); + }; + window.addEventListener(STOCK_TAKE_QTY_GAP_SETTING_EVENT, onChange); + return () => { + cancelled = true; + window.removeEventListener(STOCK_TAKE_QTY_GAP_SETTING_EVENT, onChange); + }; + }, []); + + return percent; +} diff --git a/src/i18n/en/stockTake.json b/src/i18n/en/stockTake.json index faaef94f..64f04baf 100644 --- a/src/i18n/en/stockTake.json +++ b/src/i18n/en/stockTake.json @@ -116,7 +116,7 @@ "Stock Take Management": "Stock Take Management", "Stock Take Qty": "Stock Take Qty", "Stock Take Qty Data and Variance Analysis": "Stock Take Qty Data and Variance Analysis", - "Stock Take Qty(include Bad Qty)= Available Qty": "Stock Take Qty(include Bad Qty)= Available Qty", + "Stock Take Qty(include Bad Qty)= Available Qty": "Stock Take Qty", "Stock Take Round": "Stock Take Round", "Stock Take Section": "Stock Take Section", "Stock Take Section (can use , to search multiple sections)": "Stock Take Section (can use , to search multiple sections)", @@ -173,6 +173,11 @@ "sections unit": "area(s)", "selected stock take qty": "selected stock take qty", "start time": "start time", + "qtyGapWarnPercent": "Qty variance warning %", + "qtyGapWarnPercentSaved": "Qty gap warning percent saved", + "qtyGapWarnPercentInvalid": "Enter a whole number from 0 to 1000", + "stockTakeQtyGapWarn": "Please check the entry. The count differs from current stock by {{pct}}%.", + "stockTakeQtyGapWarnOver": "Please check the entry. The count differs from current stock by more than {{threshold}}%.", "stockTaking": "Stock taking", "stock_take": "Stock take", "variance Percentage": "variance Percentage" diff --git a/src/i18n/zh/stockTake.json b/src/i18n/zh/stockTake.json index aad4cd7a..53745a40 100644 --- a/src/i18n/zh/stockTake.json +++ b/src/i18n/zh/stockTake.json @@ -53,7 +53,7 @@ "Warehouse Location": "倉庫位置", "Item-lotNo-ExpiryDate": "貨品-批號-到期日", "UOM": "單位", - "Stock Take Qty(include Bad Qty)= Available Qty": "盤點數= 可用數", + "Stock Take Qty(include Bad Qty)= Available Qty": "盤點數", "Record Status": "盤點狀態", "No data": "沒有數據", "Difference": "差異", @@ -61,6 +61,11 @@ "Second": "第二次", "Approver Input": "審核員輸入", "Stock Take Qty": "盤點數", + "qtyGapWarnPercent": "出入差異警告%", + "qtyGapWarnPercentSaved": "出入差異警告%已保存", + "qtyGapWarnPercentInvalid": "請輸入 0 至 1000 的整數", + "stockTakeQtyGapWarn": "請小心輸入查看,盤點數與現時倉存有 {{pct}}% 的出入", + "stockTakeQtyGapWarnOver": "請小心輸入查看,盤點數與現時倉存的出入已超過 {{threshold}}%", "Bad Qty": "不良數量", "selected stock take qty": "已選擇盤點數量", "book qty": "帳面庫存", From a1f430a536175ef20f3d596b6ff7c588a8954111 Mon Sep 17 00:00:00 2001 From: Harry Groves Date: Mon, 28 Sep 2026 15:17:58 +0800 Subject: [PATCH 18/24] [Fix] Item search field: codes that weren't selected through dropdown still take effect --- .../report/AsyncItemCodeAutocomplete.tsx | 61 ++++++++--- .../report/SemiFGProductionAnalysisReport.tsx | 16 ++- src/app/(main)/report/page.tsx | 102 ++++++++++++++---- 3 files changed, 139 insertions(+), 40 deletions(-) diff --git a/src/app/(main)/report/AsyncItemCodeAutocomplete.tsx b/src/app/(main)/report/AsyncItemCodeAutocomplete.tsx index 3e1681a1..a1f68151 100644 --- a/src/app/(main)/report/AsyncItemCodeAutocomplete.tsx +++ b/src/app/(main)/report/AsyncItemCodeAutocomplete.tsx @@ -1,14 +1,17 @@ "use client"; -import { useEffect, useMemo, useState } from "react"; +import { useEffect, useMemo, useRef, useState } from "react"; import { Autocomplete, Chip, CircularProgress, TextField } from "@mui/material"; import { useTranslation } from "react-i18next"; import { searchItemCodes, type ItemCodeSearchHit } from "./itemCodeSearchApi"; +import { parseItemCodeTokens } from "./parseItemCodeTokens"; type Props = { label: string; value: string[]; onChange: (codes: string[]) => void; + /** Live text in the box, including text that has not been picked from the list. */ + onInputValueChange?: (value: string) => void; placeholder?: string; disabled?: boolean; minChars?: number; @@ -17,11 +20,12 @@ type Props = { const hitLabel = (hit: ItemCodeSearchHit) => hit.name ? `${hit.code} ${hit.name}` : hit.code; -/** FP-MTMS Version Checklist | Functions Ref. No. 81 | v1.0.0 | 2026-09-10 */ +/** FP-MTMS Version Checklist | Functions Ref. No. 81 | v1.0.1 | 2026-09-28 */ const AsyncItemCodeAutocomplete: React.FC = ({ label, value, onChange, + onInputValueChange, placeholder, disabled = false, minChars = 2, @@ -73,21 +77,47 @@ const AsyncItemCodeAutocomplete: React.FC = ({ }; }, [trimmedInput, minChars]); + const selectedCodes = useMemo( + () => new Set(value.map((code) => code.toUpperCase())), + [value], + ); + const options = useMemo(() => { const seen = new Set(); const codes: string[] = []; suggestions.forEach((hit) => { - if (seen.has(hit.code)) return; - seen.add(hit.code); + const key = hit.code.toUpperCase(); + if (seen.has(key) || selectedCodes.has(key)) return; + seen.add(key); codes.push(hit.code); }); - value.forEach((code) => { - if (seen.has(code)) return; - seen.add(code); - codes.push(code); - }); return codes; - }, [suggestions, value]); + }, [suggestions, selectedCodes]); + + useEffect(() => { + const trimmed = inputValue.trim(); + if (!trimmed) return; + const hit = suggestions.find((item) => item.code.toUpperCase() === trimmed.toUpperCase()); + if (hit) onInputValueChange?.(hit.code); + }, [suggestions, inputValue, onInputValueChange]); + + const inputValueRef = useRef(inputValue); + inputValueRef.current = inputValue; + const previousValueRef = useRef(value); + useEffect(() => { + const previous = previousValueRef.current; + previousValueRef.current = value; + const tokens = parseItemCodeTokens(inputValueRef.current); + if (tokens.length === 0) return; + const previousKeys = new Set(previous.map((code) => code.toUpperCase())); + const nextKeys = new Set(value.map((code) => code.toUpperCase())); + const justCommitted = tokens.every( + (token) => nextKeys.has(token.toUpperCase()) && !previousKeys.has(token.toUpperCase()), + ); + if (!justCommitted) return; + setInputValue(""); + onInputValueChange?.(""); + }, [value, onInputValueChange]); const noOptionsText = needsMoreChars ? t("typeToSearchItemCode", { min: minChars }) @@ -112,9 +142,11 @@ const AsyncItemCodeAutocomplete: React.FC = ({ filterOptions={(opts) => trimmedInput.length < minChars ? [] - : opts.filter((code) => !value.includes(code)) + : opts.filter((code) => !selectedCodes.has(code.toUpperCase())) + } + isOptionEqualToValue={(option, selected) => + option.toUpperCase() === selected.toUpperCase() } - isOptionEqualToValue={(option, selected) => option === selected} autoHighlight noOptionsText={noOptionsText} sx={{ @@ -160,11 +192,16 @@ const AsyncItemCodeAutocomplete: React.FC = ({ }, }} onInputChange={(_, next, reason) => { + if (reason === "blur") return; if (reason === "reset") { setInputValue(""); + onInputValueChange?.(""); return; } setInputValue(next); + const trimmed = next.trim(); + const hit = suggestions.find((item) => item.code.toUpperCase() === trimmed.toUpperCase()); + onInputValueChange?.(hit?.code ?? next); }} onChange={(_, newValue) => { const codes = (Array.isArray(newValue) ? newValue : []) diff --git a/src/app/(main)/report/SemiFGProductionAnalysisReport.tsx b/src/app/(main)/report/SemiFGProductionAnalysisReport.tsx index f676ba66..9a55d1cf 100644 --- a/src/app/(main)/report/SemiFGProductionAnalysisReport.tsx +++ b/src/app/(main)/report/SemiFGProductionAnalysisReport.tsx @@ -30,6 +30,7 @@ import { parseItemCodeTokens } from './parseItemCodeTokens'; interface SemiFGProductionAnalysisReportProps { criteria: Record; + prepareCriteria?: () => Record; requiredFieldLabels: string[]; loading: boolean; setLoading: (loading: boolean) => void; @@ -39,6 +40,7 @@ interface SemiFGProductionAnalysisReportProps { export default function SemiFGProductionAnalysisReport({ criteria, + prepareCriteria, requiredFieldLabels, loading, setLoading, @@ -70,6 +72,7 @@ export default function SemiFGProductionAnalysisReport({ }, [criteria.stockCategory]); const handleExportClick = async (format: 'pdf' | 'excel') => { + const activeCriteria = prepareCriteria?.() ?? criteria; setExportFormat(format); // Validate required fields if (requiredFieldLabels.length > 0) { @@ -78,10 +81,10 @@ export default function SemiFGProductionAnalysisReport({ } const selectedCodes = parseItemCodeTokens( - [criteria.itemCode, criteria.itemCodePaste].filter(Boolean).join(' '), + [activeCriteria.itemCode, activeCriteria.itemCodePaste].filter(Boolean).join(' '), ); if (selectedCodes.length === 0) { - await executeExport(format); + await executeExport(format, activeCriteria); return; } @@ -97,13 +100,16 @@ export default function SemiFGProductionAnalysisReport({ setShowConfirmDialog(true); }; - const executeExport = async (format: 'pdf' | 'excel' = exportFormat) => { + const executeExport = async ( + format: 'pdf' | 'excel' = exportFormat, + activeCriteria: Record = prepareCriteria?.() ?? criteria, + ) => { setLoading(true); try { if (format === 'excel') { - await generateSemiFGProductionAnalysisReportExcel(criteria, reportTitle); + await generateSemiFGProductionAnalysisReportExcel(activeCriteria, reportTitle); } else { - await generateSemiFGProductionAnalysisReport(criteria, reportTitle); + await generateSemiFGProductionAnalysisReport(activeCriteria, reportTitle); } onExportSuccess?.(format); setShowConfirmDialog(false); diff --git a/src/app/(main)/report/page.tsx b/src/app/(main)/report/page.tsx index 89f442e8..1c69d010 100644 --- a/src/app/(main)/report/page.tsx +++ b/src/app/(main)/report/page.tsx @@ -26,7 +26,7 @@ import { import DownloadIcon from '@mui/icons-material/Download'; import InfoOutlinedIcon from '@mui/icons-material/InfoOutlined'; import { REPORTS } from '@/config/reportConfig'; -import { mergePastedItemCodes, buildItemCodePasteRequestBody } from './parseItemCodeTokens'; +import { mergePastedItemCodes, buildItemCodePasteRequestBody, parseItemCodeTokens } from './parseItemCodeTokens'; import { NEXT_PUBLIC_API_URL } from '@/config/api'; import { clientAuthFetch } from '@/app/utils/clientAuthFetch'; import SemiFGProductionAnalysisReport from './SemiFGProductionAnalysisReport'; @@ -86,8 +86,8 @@ const ITEM_CODE_PASTE_POST_REPORTS = new Set([ /** FP-MTMS Version Checklist | Functions Ref. No. 39 | v1.0.3 | 2026-09-10 */ /** FP-MTMS Version Checklist | Functions Ref. No. 60 | v1.0.1 | 2026-08-11 */ -/** FP-MTMS Version Checklist | Functions Ref. No. 69 | v1.0.2 | 2026-09-10 */ -/** FP-MTMS Version Checklist | Functions Ref. No. 82 | v1.0.0 | 2026-09-10 */ +/** FP-MTMS Version Checklist | Functions Ref. No. 69 | v1.0.3 | 2026-09-28 */ +/** FP-MTMS Version Checklist | Functions Ref. No. 82 | v1.0.1 | 2026-09-28 */ export default function ReportPage() { const { data: session } = useSession() as { data: SessionWithTokens | null }; const { t, i18n, reportTitle, fieldLabel, fieldHint, optionLabel } = useReportLabels(); @@ -98,6 +98,37 @@ export default function ReportPage() { const [selectedReportId, setSelectedReportId] = useState(''); const [criteria, setCriteria] = useState>({}); + const criteriaRef = useRef>({}); + const pendingItemCodeInputRef = useRef>({}); + const updateCriteria = ( + updater: Record | ((prev: Record) => Record), + ) => { + const next = typeof updater === 'function' ? updater(criteriaRef.current) : updater; + criteriaRef.current = next; + setCriteria(next); + }; + /** Typed item codes are not in criteria until a dropdown option is chosen. Merge them in before the request. */ + const flushPendingItemCodeInputs = (): Record => { + const pendingEntries = Object.entries(pendingItemCodeInputRef.current).filter(([, raw]) => raw.trim()); + if (pendingEntries.length === 0) return criteriaRef.current; + + const next = { ...criteriaRef.current }; + let changed = false; + for (const [field, raw] of pendingEntries) { + pendingItemCodeInputRef.current[field] = ''; + const merged = parseItemCodeTokens([next[field], raw].filter(Boolean).join(' ')); + const joined = merged.join(','); + if (joined && joined !== (next[field] || '')) { + next[field] = joined; + changed = true; + } + } + if (changed) { + criteriaRef.current = next; + setCriteria(next); + } + return criteriaRef.current; + }; const [loading, setLoading] = useState(false); const excelInFlightRef = useRef(false); const [dynamicOptions, setDynamicOptions] = useState>({}); @@ -124,14 +155,15 @@ export default function ReportPage() { if (reportId === selectedReportId) return; setSelectedReportId(reportId); setFieldErrors({}); + pendingItemCodeInputRef.current = {}; if (reportId === 'rep-010') { - setCriteria({ qcType: 'all', qcItemScope: 'all' }); + updateCriteria({ qcType: 'all', qcItemScope: 'all' }); } else if (reportId === 'rep-004') { - setCriteria({ storeId: 'All', poPrefix: 'All' }); + updateCriteria({ storeId: 'All', poPrefix: 'All' }); } else if (reportId === 'rep-021') { - setCriteria({ storeId: 'All', stockTakeSectionDescription: 'All', lotOrigin: 'All' }); + updateCriteria({ storeId: 'All', stockTakeSectionDescription: 'All', lotOrigin: 'All' }); } else { - setCriteria({}); + updateCriteria({}); } }; @@ -143,7 +175,7 @@ export default function ReportPage() { delete next[name]; return next; }); - setCriteria((prev) => { + updateCriteria((prev) => { const next = { ...prev, [name]: stringValue }; if (currentReport?.id === 'rep-021' && name === 'warehouse') { const m = stringValue.trim().match(/^w(\d)/i); @@ -252,7 +284,7 @@ export default function ReportPage() { // Default "All" (no filter) for stock take variance report conditions. if (selectedReportId === 'rep-012') { - setCriteria({ + updateCriteria({ store_id: 'All', status: 'All', type: 'All', @@ -264,7 +296,7 @@ export default function ReportPage() { useEffect(() => { if (selectedReportId !== 'rep-012' || !rep012MultiRound) return; if (criteria.status === 'completed') return; - setCriteria((prev) => ({ ...prev, status: 'completed' })); + updateCriteria((prev) => ({ ...prev, status: 'completed' })); }, [selectedReportId, rep012MultiRound, criteria.status]); // React 18 Strict Mode (dev) mounts → unmounts → remounts, so effects with [] run twice. @@ -329,19 +361,20 @@ export default function ReportPage() { /** rep-012:單輪送 status;多輪送 stockTakeRoundId 清單且 status=completed */ const buildRep012QueryString = (): string => { + const active = criteriaRef.current; const p = new URLSearchParams(); p.set('stockTakeRoundId', rep012RoundIds.join(',')); - const code = criteria.itemCode?.trim(); + const code = active.itemCode?.trim(); if (code) p.set('itemCode', code); - const store = criteria.store_id?.trim(); + const store = active.store_id?.trim(); if (store && store !== 'All') p.set('store_id', store); if (rep012MultiRound) { p.set('status', 'completed'); } else { - const status = criteria.status?.trim(); + const status = active.status?.trim(); if (status && status !== 'All') p.set('status', status); } - const lotType = criteria.type?.trim(); + const lotType = active.type?.trim(); if (lotType && lotType !== 'All') p.set('type', lotType); return p.toString(); }; @@ -349,15 +382,16 @@ export default function ReportPage() { /** FP-MTMS Version Checklist | Functions Ref. No. 64 | v1.0.0 | 2026-08-11 */ /** rep-010:qcItemScope → includeMeasurable / includeOther;qcType=all 不傳篩選 */ const buildRep010QueryString = (): string => { + const active = criteriaRef.current; const p = new URLSearchParams(); - Object.entries(criteria).forEach(([key, value]) => { + Object.entries(active).forEach(([key, value]) => { if (key === 'qcItemScope') return; if (key === 'qcType' && String(value).trim().toLowerCase() === 'all') return; if (value != null && String(value).trim() !== '') { p.set(key, String(value)); } }); - const scope = (criteria.qcItemScope || 'all').trim().toLowerCase(); + const scope = (active.qcItemScope || 'all').trim().toLowerCase(); if (scope === 'measurable') { p.set('includeMeasurable', 'true'); p.set('includeOther', 'false'); @@ -380,7 +414,7 @@ export default function ReportPage() { if (!currentReport) return ''; if (currentReport.id === 'rep-012') return buildRep012QueryString(); if (currentReport.id === 'rep-010') return buildRep010QueryString(); - const merged = mergePastedItemCodes(criteria, itemCodeFieldName()); + const merged = mergePastedItemCodes(criteriaRef.current, itemCodeFieldName()); const p = new URLSearchParams(merged); if (currentReport.id === 'rep-016') { const day = (merged.dateStart || '').trim(); @@ -393,6 +427,7 @@ export default function ReportPage() { }; const handlePrint = async () => { + flushPendingItemCodeInputs(); if (!currentReport) return; if (!validateRequiredFields()) return; @@ -409,6 +444,7 @@ export default function ReportPage() { }; const handleExcelPrint = async () => { + flushPendingItemCodeInputs(); if (!currentReport) return; if (!validateRequiredFields()) return; await executeExcelReport(); @@ -420,17 +456,18 @@ export default function ReportPage() { excelInFlightRef.current = true; setLoading(true); try { + const activeCriteria = criteriaRef.current; if (currentReport.id === 'rep-014') { await generateGrnReportExcel( - criteria, + activeCriteria, reportTitle(currentReport), includeGrnFinancialColumns, t, ); } else if (currentReport.id === 'rep-015') { - await generateBomShopSyncReportExcel(criteria, reportTitle(currentReport), t); + await generateBomShopSyncReportExcel(activeCriteria, reportTitle(currentReport), t); } else if (currentReport.id === 'rep-017') { - await generateShopOrderReplenishmentReportExcel(criteria, reportTitle(currentReport), t); + await generateShopOrderReplenishmentReportExcel(activeCriteria, reportTitle(currentReport), t); } else { // Backend returns actual .xlsx bytes for this Excel endpoint. const usesItemCodePastePost = isItemCodePastePostReport(); @@ -445,7 +482,7 @@ export default function ReportPage() { Accept: 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'Content-Type': 'application/json', }, - body: JSON.stringify(buildItemCodePasteRequestBody(criteria, itemCodeFieldName())), + body: JSON.stringify(buildItemCodePasteRequestBody(criteriaRef.current, itemCodeFieldName())), } : { method: 'GET', @@ -514,7 +551,7 @@ export default function ReportPage() { Accept: 'application/pdf', 'Content-Type': 'application/json', }, - body: JSON.stringify(buildItemCodePasteRequestBody(criteria, itemCodeFieldName())), + body: JSON.stringify(buildItemCodePasteRequestBody(criteriaRef.current, itemCodeFieldName())), } : { method: 'GET', @@ -692,7 +729,13 @@ export default function ReportPage() { label={translatedLabel} placeholder={field.placeholder || "e.g. FA0591"} value={selectedCodes} - onChange={(codes) => handleFieldChange(field.name, codes)} + onInputValueChange={(text) => { + pendingItemCodeInputRef.current[field.name] = text; + }} + onChange={(codes) => { + pendingItemCodeInputRef.current[field.name] = ""; + handleFieldChange(field.name, codes); + }} minChars={field.asyncSearchMinChars ?? 2} disabled={disabledByCheckedCheckbox || disabledRep012Status || !!field.disabled} /> @@ -711,8 +754,20 @@ export default function ReportPage() { opt.value)} value={autocompleteValue} + isOptionEqualToValue={(option, selected) => + String(option).toUpperCase() === String(selected).toUpperCase() + } + onInputChange={(_, input, reason) => { + if (reason === "reset" || reason === "clear") { + pendingItemCodeInputRef.current[field.name] = ""; + return; + } + if (reason === "blur") return; + pendingItemCodeInputRef.current[field.name] = input; + }} onChange={(event, newValue, reason) => { if (field.multiple) { // Handle multiple selection - newValue is an array @@ -895,6 +950,7 @@ export default function ReportPage() { {currentReport.id === 'rep-005' ? ( f.required && !criteria[f.name]).map(f => fieldLabel(currentReport.id, f))} loading={loading} setLoading={setLoading} From d908f2378c88c68f5068c29a99d528d5f68be1b7 Mon Sep 17 00:00:00 2001 From: "PC-20260115JRSN\\Administrator" Date: Tue, 29 Sep 2026 22:24:09 +0800 Subject: [PATCH 19/24] added access right LANE for car line --- src/app/(main)/settings/shop/layout.tsx | 27 +++++++++++++++++++ src/authorities.ts | 2 ++ .../NavigationContent/NavigationContent.tsx | 19 ++++++++++++- 3 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/app/(main)/settings/shop/layout.tsx diff --git a/src/app/(main)/settings/shop/layout.tsx b/src/app/(main)/settings/shop/layout.tsx new file mode 100644 index 00000000..357f7952 --- /dev/null +++ b/src/app/(main)/settings/shop/layout.tsx @@ -0,0 +1,27 @@ +import { I18nProvider } from "@/i18n"; +import { authOptions } from "@/config/authConfig"; +import { AUTH, hasAbility } from "@/authorities"; +import { getServerSession } from "next-auth"; +import { redirect } from "next/navigation"; + +/** Route board and shop/truck lane pages: ADMIN or 車線 (TRUCK_LANE). */ +export default async function ShopSettingsLayout({ + children, +}: { + children: React.ReactNode; +}) { + const session = await getServerSession(authOptions); + const abilities = session?.user?.abilities ?? []; + const canAccess = + hasAbility(abilities, AUTH.TRUCK_LANE) || hasAbility(abilities, AUTH.ADMIN); + + if (!canAccess) { + redirect("/dashboard"); + } + + return ( + + {children} + + ); +} diff --git a/src/authorities.ts b/src/authorities.ts index ad4aeb9e..12747b66 100644 --- a/src/authorities.ts +++ b/src/authorities.ts @@ -27,6 +27,8 @@ export const AUTH = { REPORT_MGMT: "REPORT_MGMT", /** FP-MTMS Version Checklist | Functions Ref. No. 67 | v1.0.0 | 2026-08-13 — Manual M18 sync page (/m18Syn): ADMIN or this ability */ M18_SYNC: "M18_SYNC", + /** Route board (/settings/shop/board): ADMIN or this ability (DB name: 車線) */ + TRUCK_LANE: "TRUCK_LANE", } as const; /** diff --git a/src/components/NavigationContent/NavigationContent.tsx b/src/components/NavigationContent/NavigationContent.tsx index 957cb95b..05916740 100644 --- a/src/components/NavigationContent/NavigationContent.tsx +++ b/src/components/NavigationContent/NavigationContent.tsx @@ -303,7 +303,7 @@ const NavigationContent: React.FC = () => { icon: , labelKey: "nav.settings", path: "", - requiredAbility: [AUTH.VIEW_USER, AUTH.ADMIN], + requiredAbility: [AUTH.VIEW_USER, AUTH.ADMIN, AUTH.TRUCK_LANE], children: [ { id: "nav.settings.user", @@ -325,78 +325,91 @@ const NavigationContent: React.FC = () => { icon: , labelKey: "nav.settings.items", path: "/settings/items", + requiredAbility: [AUTH.VIEW_USER, AUTH.ADMIN], }, { id: "nav.settings.itemDefaultShelfLife", icon: , labelKey: "nav.settings.itemDefaultShelfLife", path: "/settings/itemDefaultShelfLife", + requiredAbility: [AUTH.VIEW_USER, AUTH.ADMIN], }, { id: "nav.settings.equipment", icon: , labelKey: "nav.settings.equipment", path: "/settings/equipment", + requiredAbility: [AUTH.VIEW_USER, AUTH.ADMIN], }, { id: "nav.settings.warehouse", icon: , labelKey: "nav.settings.warehouse", path: "/settings/warehouse", + requiredAbility: [AUTH.VIEW_USER, AUTH.ADMIN], }, { id: "nav.settings.printer", icon: , labelKey: "nav.settings.printer", path: "/settings/printer", + requiredAbility: [AUTH.VIEW_USER, AUTH.ADMIN], }, { id: "nav.settings.priceInquiry", icon: , labelKey: "nav.settings.priceInquiry", path: "/settings/itemPrice", + requiredAbility: [AUTH.VIEW_USER, AUTH.ADMIN], }, { id: "nav.settings.qcItem", icon: , labelKey: "nav.settings.qcItem", path: "/settings/qcItem", + requiredAbility: [AUTH.VIEW_USER, AUTH.ADMIN], }, { id: "nav.settings.qcCategory", icon: {/* Remark */} diff --git a/src/components/StockTakeManagement/StockTakeTab.tsx b/src/components/StockTakeManagement/StockTakeTab.tsx index 957e1901..2ef820ba 100644 --- a/src/components/StockTakeManagement/StockTakeTab.tsx +++ b/src/components/StockTakeManagement/StockTakeTab.tsx @@ -145,9 +145,15 @@ const StockTakeTab: React.FC = () => { setSnackbar({ ...snackbar, open: false })} + onClose={(_event, reason) => { + if (reason === "clickaway") return; + setSnackbar((prev) => ({ ...prev, open: false })); + }} > - setSnackbar({ ...snackbar, open: false })} severity={snackbar.severity}> + setSnackbar((prev) => ({ ...prev, open: false }))} + severity={snackbar.severity} + > {snackbar.message} @@ -268,9 +274,15 @@ const StockTakeTab: React.FC = () => { setSnackbar({ ...snackbar, open: false })} + onClose={(_event, reason) => { + if (reason === "clickaway") return; + setSnackbar((prev) => ({ ...prev, open: false })); + }} > - setSnackbar({ ...snackbar, open: false })} severity={snackbar.severity}> + setSnackbar((prev) => ({ ...prev, open: false }))} + severity={snackbar.severity} + > {snackbar.message} diff --git a/src/i18n/en/stockTake.json b/src/i18n/en/stockTake.json index 64f04baf..a866d2bb 100644 --- a/src/i18n/en/stockTake.json +++ b/src/i18n/en/stockTake.json @@ -98,6 +98,8 @@ "Return": "Return", "Rows per page": "Rows per page", "Save": "Save", + "Change": "Change", + "oneChangeLeft": "Only 1 change left", "Search": "Search", "Search Criteria": "Search Criteria", "Search section code or name": "Search code or name (e.g. ST-042 or drinks)", diff --git a/src/i18n/zh/stockTake.json b/src/i18n/zh/stockTake.json index 53745a40..3287df0f 100644 --- a/src/i18n/zh/stockTake.json +++ b/src/i18n/zh/stockTake.json @@ -8,6 +8,8 @@ "Remark": "備註", "Action": "操作", "Save": "保存", + "Change": "更改", + "oneChangeLeft": "只剩 1 次更改機會", "Selected Qty": "選擇數量", "Not Match": "要求重點", "Search Criteria": "搜索條件", From 8af1f2c9a109860e555aaae745ea03c0032bc555 Mon Sep 17 00:00:00 2001 From: "PC-20260115JRSN\\Administrator" Date: Sun, 4 Oct 2026 13:58:43 +0800 Subject: [PATCH 23/24] make the enter box num and print delivery note faster --- .../GoodPickExecutionWorkbenchRecord.tsx | 242 +++++++++++------- 1 file changed, 151 insertions(+), 91 deletions(-) diff --git a/src/components/DoWorkbench/GoodPickExecutionWorkbenchRecord.tsx b/src/components/DoWorkbench/GoodPickExecutionWorkbenchRecord.tsx index d38a07a8..284a017e 100644 --- a/src/components/DoWorkbench/GoodPickExecutionWorkbenchRecord.tsx +++ b/src/components/DoWorkbench/GoodPickExecutionWorkbenchRecord.tsx @@ -67,6 +67,8 @@ const GoodPickExecutionWorkbenchRecord: React.FC = ({ const currentUserId = session?.id ? parseInt(session.id, 10) : undefined; const [loading, setLoading] = useState(false); + const [isPrinting, setIsPrinting] = useState(false); + const printInFlightRef = useRef(false); const [records, setRecords] = useState([]); const initialSearchTargetDate = useMemo( () => resolveWorkbenchRecordTargetDate(initialTargetDate), @@ -183,6 +185,65 @@ const GoodPickExecutionWorkbenchRecord: React.FC = ({ return t("All dates"); }, [searchQuery.targetDate, t]); + const rememberCartonQty = useCallback((recordId: number, cartonQty: number) => { + setRecords((prev) => + prev.map((row) => + row.doPickOrderRecordId === recordId ? { ...row, numberOfCartons: cartonQty } : row, + ), + ); + }, []); + + const submitPrint = useCallback( + async (job: () => Promise<{ success: boolean }>) => { + await new Promise((resolve) => { + void Swal.fire({ + title: t("Printing..."), + allowOutsideClick: false, + allowEscapeKey: false, + showConfirmButton: false, + didOpen: () => { + Swal.showLoading(); + resolve(); + }, + }); + }); + try { + const response = await job(); + Swal.close(); + if (response.success) { + await Swal.fire({ + position: "bottom-end", + icon: "success", + text: t("Printed Successfully."), + showConfirmButton: false, + timer: 1500, + }); + return true; + } + await Swal.fire({ + position: "bottom-end", + icon: "error", + text: t("Print failed"), + showConfirmButton: false, + timer: 2000, + }); + return false; + } catch (error) { + console.error("print error:", error); + Swal.close(); + await Swal.fire({ + position: "bottom-end", + icon: "error", + text: t("Print failed"), + showConfirmButton: false, + timer: 2000, + }); + return false; + } + }, + [t], + ); + const askNumOfCarton = useCallback(async () => { const result = await Swal.fire({ title: t("Enter the number of cartons: "), @@ -210,6 +271,7 @@ const GoodPickExecutionWorkbenchRecord: React.FC = ({ const handlePrintDN = useCallback( async (recordId: number) => { + if (printInFlightRef.current) return; if (!a4Printer) { await Swal.fire({ position: "bottom-end", @@ -220,31 +282,32 @@ const GoodPickExecutionWorkbenchRecord: React.FC = ({ }); return; } - const cartonQty = await askNumOfCarton(); - if (!cartonQty) return; - const response = await printDNWorkbench({ - deliveryOrderPickOrderId: recordId, - printerId: a4Printer.id, - printQty: 1, - isDraft: false, - numOfCarton: cartonQty, - }); - if (response.success) { - await Swal.fire({ - position: "bottom-end", - icon: "success", - text: t("Printed Successfully."), - showConfirmButton: false, - timer: 1500, - }); - await loadData(); + printInFlightRef.current = true; + setIsPrinting(true); + try { + const cartonQty = await askNumOfCarton(); + if (!cartonQty) return; + const ok = await submitPrint(() => + printDNWorkbench({ + deliveryOrderPickOrderId: recordId, + printerId: a4Printer.id, + printQty: 1, + isDraft: false, + numOfCarton: cartonQty, + }), + ); + if (ok) rememberCartonQty(recordId, cartonQty); + } finally { + setIsPrinting(false); + printInFlightRef.current = false; } }, - [a4Printer, askNumOfCarton, loadData, t], + [a4Printer, askNumOfCarton, rememberCartonQty, submitPrint, t], ); const handlePrintLabel = useCallback( async (recordId: number) => { + if (printInFlightRef.current) return; if (!labelPrinter) { await Swal.fire({ position: "bottom-end", @@ -255,30 +318,31 @@ const GoodPickExecutionWorkbenchRecord: React.FC = ({ }); return; } - const cartonQty = await askNumOfCarton(); - if (!cartonQty) return; - const response = await printDNLabelsWorkbench({ - deliveryOrderPickOrderId: recordId, - printerId: labelPrinter.id, - printQty: 1, - numOfCarton: cartonQty, - }); - if (response.success) { - await Swal.fire({ - position: "bottom-end", - icon: "success", - text: t("Printed Successfully."), - showConfirmButton: false, - timer: 1500, - }); - await loadData(); + printInFlightRef.current = true; + setIsPrinting(true); + try { + const cartonQty = await askNumOfCarton(); + if (!cartonQty) return; + const ok = await submitPrint(() => + printDNLabelsWorkbench({ + deliveryOrderPickOrderId: recordId, + printerId: labelPrinter.id, + printQty: 1, + numOfCarton: cartonQty, + }), + ); + if (ok) rememberCartonQty(recordId, cartonQty); + } finally { + setIsPrinting(false); + printInFlightRef.current = false; } }, - [askNumOfCarton, labelPrinter, loadData, t], + [askNumOfCarton, labelPrinter, rememberCartonQty, submitPrint, t], ); const handlePrintBoth = useCallback( async (recordId: number) => { + if (printInFlightRef.current) return; if (!a4Printer || !labelPrinter) { await Swal.fire({ position: "bottom-end", @@ -289,37 +353,39 @@ const GoodPickExecutionWorkbenchRecord: React.FC = ({ }); return; } - const cartonQty = await askNumOfCarton(); - if (!cartonQty) return; - const [labelRes, dnRes] = await Promise.all([ - printDNLabelsWorkbench({ - deliveryOrderPickOrderId: recordId, - printerId: labelPrinter.id, - printQty: 1, - numOfCarton: cartonQty, - }), - printDNWorkbench({ - deliveryOrderPickOrderId: recordId, - printerId: a4Printer.id, - printQty: 1, - isDraft: false, - numOfCarton: cartonQty, - }), - ]); - if (labelRes.success && dnRes.success) { - await Swal.fire({ - position: "bottom-end", - icon: "success", - text: t("Printed Successfully."), - showConfirmButton: false, - timer: 1500, + printInFlightRef.current = true; + setIsPrinting(true); + try { + const cartonQty = await askNumOfCarton(); + if (!cartonQty) return; + const ok = await submitPrint(async () => { + const [labelRes, dnRes] = await Promise.all([ + printDNLabelsWorkbench({ + deliveryOrderPickOrderId: recordId, + printerId: labelPrinter.id, + printQty: 1, + numOfCarton: cartonQty, + }), + printDNWorkbench({ + deliveryOrderPickOrderId: recordId, + printerId: a4Printer.id, + printQty: 1, + isDraft: false, + numOfCarton: cartonQty, + }), + ]); + return { success: labelRes.success && dnRes.success }; }); - await loadData(); + if (ok) rememberCartonQty(recordId, cartonQty); + } finally { + setIsPrinting(false); + printInFlightRef.current = false; } }, - [a4Printer, askNumOfCarton, labelPrinter, loadData, t], + [a4Printer, askNumOfCarton, labelPrinter, rememberCartonQty, submitPrint, t], ); const handleLabelReprint = useCallback(async (doPickOrder: CompletedDoPickOrderResponse) => { + if (printInFlightRef.current) return; if (!labelPrinter) { Swal.fire({ position: "bottom-end", @@ -331,6 +397,9 @@ const GoodPickExecutionWorkbenchRecord: React.FC = ({ return; } + printInFlightRef.current = true; + setIsPrinting(true); + try { const defaultTotalCartons = Math.max(1, doPickOrder.numberOfCartons || 1); const result = await Swal.fire({ title: t("Reprint DN Label"), @@ -390,31 +459,22 @@ const GoodPickExecutionWorkbenchRecord: React.FC = ({ return; } - try { - const response = await printDNLabelsReprintWorkbench({ - deliveryOrderPickOrderId: doPickOrder.doPickOrderRecordId, - printerId: labelPrinter.id, - printQty: 1, - fromCarton: result.value.fromCarton, - toCarton: result.value.toCarton, - totalCartonsOnShipment: result.value.totalCartonsOnShipment, - }); - - if (response.success) { - Swal.fire({ - position: "bottom-end", - icon: "success", - text: t("Printed Successfully."), - showConfirmButton: false, - timer: 1500 - }); - } else { - console.error("Reprint failed:", response.message); - } - } catch (error) { - console.error("reprint error: ", error); + const ok = await submitPrint(() => + printDNLabelsReprintWorkbench({ + deliveryOrderPickOrderId: doPickOrder.doPickOrderRecordId, + printerId: labelPrinter.id, + printQty: 1, + fromCarton: result.value.fromCarton, + toCarton: result.value.toCarton, + totalCartonsOnShipment: result.value.totalCartonsOnShipment, + }), + ); + if (ok) rememberCartonQty(doPickOrder.doPickOrderRecordId, result.value.totalCartonsOnShipment); + } finally { + setIsPrinting(false); + printInFlightRef.current = false; } - }, [labelPrinter, t]); + }, [labelPrinter, rememberCartonQty, submitPrint, t]); const handleDetailClick = useCallback( async (record: CompletedDoPickOrderResponse) => { @@ -735,16 +795,16 @@ const GoodPickExecutionWorkbenchRecord: React.FC = ({ - - - - From d22ef70f7437209ea1165dd6bcfccbff5d71a9cd Mon Sep 17 00:00:00 2001 From: "PC-20260115JRSN\\Administrator" Date: Sun, 4 Oct 2026 14:34:13 +0800 Subject: [PATCH 24/24] =?UTF-8?q?=E7=99=BC=E8=B2=A8=E8=88=87=E9=85=8D?= =?UTF-8?q?=E9=80=81>=E5=93=A1=E5=B7=A5=E7=99=BC=E8=B2=A8=E7=B8=BE?= =?UTF-8?q?=E6=95=88=20added=20a=20new=20access=20right=20=E7=B8=BE?= =?UTF-8?q?=E6=95=88?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/app/(main)/chart/delivery/page.tsx | 19 +++++++++++++++++-- src/authorities.ts | 2 ++ 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/app/(main)/chart/delivery/page.tsx b/src/app/(main)/chart/delivery/page.tsx index bbbf3bb8..4cc04524 100644 --- a/src/app/(main)/chart/delivery/page.tsx +++ b/src/app/(main)/chart/delivery/page.tsx @@ -1,6 +1,8 @@ "use client"; import React, { useCallback, useMemo, useState } from "react"; +import { useSession } from "next-auth/react"; +import { AUTH, hasAbility } from "@/authorities"; import { Box, Typography, @@ -68,6 +70,9 @@ const defaultCriteria: Criteria = { /** FP-MTMS Version Checklist | Functions Ref. No. 61 | v1.0.0 | 2026-08-10 */ export default function DeliveryChartPage() { + const { data: session } = useSession(); + const abilities = session?.abilities ?? session?.user?.abilities ?? []; + const canSeeStaffPerformance = hasAbility(abilities, AUTH.PERFORMANCE); const [criteria, setCriteria] = useState(defaultCriteria); const [topItemsSelected, setTopItemsSelected] = useState([]); const [topItemOptions, setTopItemOptions] = useState([]); @@ -132,6 +137,10 @@ export default function DeliveryChartPage() { }, [criteria.topItems, topItemsSelected, setChartLoading]); React.useEffect(() => { + if (!canSeeStaffPerformance) { + setChartData((prev) => ({ ...prev, staffPerf: [] })); + return; + } const s = criteria.staffPerf.startDate; const e = criteria.staffPerf.endDate; if (!s || !e) { @@ -161,13 +170,17 @@ export default function DeliveryChartPage() { ) .catch((err) => setError(err instanceof Error ? err.message : "Request failed")) .finally(() => setChartLoading("staffPerf", false)); - }, [criteria.staffPerf, staffSelected, setChartLoading]); + }, [canSeeStaffPerformance, criteria.staffPerf, staffSelected, setChartLoading]); React.useEffect(() => { + if (!canSeeStaffPerformance) { + setStaffOptions([]); + return; + } fetchStaffDeliveryPerformanceHandlers() .then(setStaffOptions) .catch(() => setStaffOptions([])); - }, []); + }, [canSeeStaffPerformance]); React.useEffect(() => { const { startDate: s, endDate: e } = toDateRange(criteria.topItems.rangeDays); fetchTopDeliveryItemsItemOptions(s, e).then(setTopItemOptions).catch(() => setTopItemOptions([])); @@ -317,6 +330,7 @@ export default function DeliveryChartPage() { )} + {canSeeStaffPerformance && ( )} + )} ); } diff --git a/src/authorities.ts b/src/authorities.ts index 12747b66..b601e86f 100644 --- a/src/authorities.ts +++ b/src/authorities.ts @@ -29,6 +29,8 @@ export const AUTH = { M18_SYNC: "M18_SYNC", /** Route board (/settings/shop/board): ADMIN or this ability (DB name: 車線) */ TRUCK_LANE: "TRUCK_LANE", + /** 員工發貨績效 on /chart/delivery (DB name: 績效) */ + PERFORMANCE: "PERFORMANCE", } as const; /**