From cd3cb79061493f75d20f367074a8a560cf262159 Mon Sep 17 00:00:00 2001 From: kelvinsuen Date: Tue, 26 Aug 2025 17:10:17 +0800 Subject: [PATCH] update escalation --- src/app/(main)/po/edit/page.tsx | 2 +- src/app/api/escalation/actions.ts | 21 +++ src/app/api/escalation/index.ts | 13 -- src/app/api/po/actions.ts | 18 ++- src/app/api/po/index.ts | 1 + src/app/utils/formatUtil.ts | 6 + .../escalation/EscalationLogTable.tsx | 37 +++-- .../PoDetail/EscalationComponent.tsx | 36 ++++- src/components/PoDetail/PoInputGrid.tsx | 44 ++++-- src/components/PoDetail/QcFormVer2.tsx | 137 ++++++++++++------ .../PoDetail/QcStockInModalVer2.tsx | 137 ++++++++++++------ src/components/PoDetail/StockInFormVer2.tsx | 14 +- src/components/PoSearch/PoSearch.tsx | 2 +- src/i18n/zh/dashboard.json | 3 +- src/i18n/zh/purchaseOrder.json | 6 +- 15 files changed, 327 insertions(+), 150 deletions(-) create mode 100644 src/app/api/escalation/actions.ts diff --git a/src/app/(main)/po/edit/page.tsx b/src/app/(main)/po/edit/page.tsx index 04ea01a..c9b0b72 100644 --- a/src/app/(main)/po/edit/page.tsx +++ b/src/app/(main)/po/edit/page.tsx @@ -29,7 +29,7 @@ const PoEdit: React.FC = async ({ searchParams }) => { return ( <> {/* {t("Create Material")} */} - + }> diff --git a/src/app/api/escalation/actions.ts b/src/app/api/escalation/actions.ts new file mode 100644 index 0000000..3b50e23 --- /dev/null +++ b/src/app/api/escalation/actions.ts @@ -0,0 +1,21 @@ +"use server" + +import { convertObjToURLSearchParams } from "@/app/utils/commonUtil"; +import { serverFetchJson } from "@/app/utils/fetchUtil"; +import { BASE_API_URL } from "@/config/api"; +import { cache } from "react"; +import { EscalationResult } from "."; + + +export const fetchEscalationLogsByStockInLines = cache(async(stockInLineIds: number[]) => { + const searchParams = convertObjToURLSearchParams({stockInLineIds: stockInLineIds}) + return serverFetchJson(`${BASE_API_URL}/escalationLog/stockInLines?${searchParams}`, + { + method: "GET", + headers: { "Content-Type": "application/json" }, + next: { + tags: ["escalationLogs"], + }, + }, + ); +}); diff --git a/src/app/api/escalation/index.ts b/src/app/api/escalation/index.ts index 5c0e7d4..086fab6 100644 --- a/src/app/api/escalation/index.ts +++ b/src/app/api/escalation/index.ts @@ -32,19 +32,6 @@ export interface EscalationResult { dnNo?: string; } -export const fetchEscalationLogsByStockInLines = cache(async(stockInLineIds: number[]) => { - const searchParams = convertObjToURLSearchParams({stockInLineIds: stockInLineIds}) - return serverFetchJson(`${BASE_API_URL}/escalationLog/stockInLines?${searchParams}`, - { - method: "GET", - headers: { "Content-Type": "application/json" }, - next: { - tags: ["escalationLogs"], - }, - }, - ); -}); - export const fetchEscalationLogsByUser = cache(async() => { return serverFetchJson(`${BASE_API_URL}/escalationLog/user`, { diff --git a/src/app/api/po/actions.ts b/src/app/api/po/actions.ts index a013ab4..5956b2b 100644 --- a/src/app/api/po/actions.ts +++ b/src/app/api/po/actions.ts @@ -38,8 +38,8 @@ export interface StockInLineEntry { export interface PurchaseQcResult{ qcItemId: number; - qcPassed: boolean; - failQty: number; + qcPassed?: boolean; + failQty?: number; remarks?: string; } @@ -69,14 +69,16 @@ export interface PurchaseQCInput { sampleWeight: number; totalWeight: number; qcAccept: boolean; + qcDecision?: number; qcResult: PurchaseQcResult[]; } export interface EscalationInput { status: string; remarks?: string; - handler: string; - productLotNo: string; - acceptedQty: number; // this is the qty to be escalated + reason?: string; + handlerId: number; + productLotNo?: string; + acceptedQty?: number; // this is the qty to be escalated // escalationQty: number } export interface PutawayLine { @@ -94,8 +96,10 @@ export interface PutawayInput { } export type ModalFormInput = Partial< - PurchaseQCInput & StockInInput & EscalationInput & PutawayInput ->; + PurchaseQCInput & StockInInput & PutawayInput +> & { + escalationLog? : Partial +}; export const testFetch = cache(async (id: number) => { return serverFetchJson(`${BASE_API_URL}/po/detail/${id}`, { diff --git a/src/app/api/po/index.ts b/src/app/api/po/index.ts index 8cff8fc..e56aff8 100644 --- a/src/app/api/po/index.ts +++ b/src/app/api/po/index.ts @@ -81,6 +81,7 @@ export interface StockInLine { dnNo?: string; dnDate?: number[]; stockQty?: number; + handlerId?: number; } export const fetchPoList = cache(async (queryParams?: Record) => { diff --git a/src/app/utils/formatUtil.ts b/src/app/utils/formatUtil.ts index e791833..ef354a6 100644 --- a/src/app/utils/formatUtil.ts +++ b/src/app/utils/formatUtil.ts @@ -32,6 +32,8 @@ export const INPUT_DATE_FORMAT = "YYYY-MM-DD"; export const OUTPUT_DATE_FORMAT = "YYYY/MM/DD"; +export const INPUT_TIME_FORMAT = "HH:mm:ss"; + export const OUTPUT_TIME_FORMAT = "HH:mm:ss"; export const arrayToDayjs = (arr: ConfigType | (number | undefined)[]) => { @@ -73,6 +75,10 @@ export const dayjsToDateString = (date: Dayjs) => { }; export const dayjsToInputDateString = (date: Dayjs) => { + return date.format(INPUT_DATE_FORMAT + "T" + INPUT_TIME_FORMAT); +}; + +export const dayjsToInputDatetimeString = (date: Dayjs) => { return date.format(INPUT_DATE_FORMAT); }; diff --git a/src/components/DashboardPage/escalation/EscalationLogTable.tsx b/src/components/DashboardPage/escalation/EscalationLogTable.tsx index 62f1040..2aedeb3 100644 --- a/src/components/DashboardPage/escalation/EscalationLogTable.tsx +++ b/src/components/DashboardPage/escalation/EscalationLogTable.tsx @@ -62,40 +62,57 @@ const EscalationLogTable: React.FC = ({ () => [ { name: "handler", - label: t("Responsible for handling colleagues") + label: t("Responsible for handling colleagues"), + sx: { width: "20%", minWidth: 200, maxWidth: 500 }, }, { name: "acceptedQty", label: t("Received Qty"), align: "right", - headerAlign: "right" + headerAlign: "right", + sx: { width: "10%", minWidth: 100 }, }, { name: "purchaseUomDesc", - label: t("Purchase UoM") + label: t("Purchase UoM"), + sx: { width: "15%", minWidth: 120 }, }, { name: "dnDate", label: t("DN Date"), + sx: { width: "10%", minWidth: 120 }, renderCell: (params) => { return params.dnDate ? arrayToDateString(params.dnDate) : "N/A" } }, - { - name: "qcTotalCount", - label: t("QC Completed Count"), - align: "right", - headerAlign: "right" - }, { name: "qcFailCount", label: t("QC Fail Count"), align: "right", - headerAlign: "right" + headerAlign: "right", + sx: { width: "15%", minWidth: 120 }, + renderCell: (params) => { + return `${params.qcFailCount} / ${params.qcTotalCount}` + } }, + // { + // name: "qcTotalCount", + // label: t("QC Completed Count"), + // align: "right", + // headerAlign: "right" + // flex: 1, + // }, + // { + // name: "qcFailCount", + // label: t("QC Fail Count"), + // align: "right", + // headerAlign: "right" + // flex: 1, + // }, { name: "reason", label: t("Reason"), + sx: { width: "30%", minWidth: 150 }, }, ], []) diff --git a/src/components/PoDetail/EscalationComponent.tsx b/src/components/PoDetail/EscalationComponent.tsx index 5337eab..02bb163 100644 --- a/src/components/PoDetail/EscalationComponent.tsx +++ b/src/components/PoDetail/EscalationComponent.tsx @@ -21,6 +21,8 @@ import { SelectChangeEvent } from '@mui/material/Select'; import ExpandMoreIcon from '@mui/icons-material/ExpandMore'; import ExpandLessIcon from '@mui/icons-material/ExpandLess'; import { useTranslation } from 'react-i18next'; +import { useFormContext } from 'react-hook-form'; +import { EscalationInput, ModalFormInput } from '@/app/api/po/actions'; interface NameOption { value: string; @@ -38,6 +40,7 @@ interface Props { isCollapsed: boolean setIsCollapsed: Dispatch> } + const EscalationComponent: React.FC = ({ forSupervisor, isCollapsed, @@ -60,6 +63,19 @@ const EscalationComponent: React.FC = ({ { value: 'david', label: '林建國' }, ]; + const { + register, + formState: { errors, defaultValues, touchedFields }, + watch, + control, + setValue, + getValues, + reset, + resetField, + setError, + clearErrors, + } = useFormContext(); + const handleInputChange = ( event: ChangeEvent | SelectChangeEvent ): void => { @@ -70,7 +86,7 @@ const EscalationComponent: React.FC = ({ })); }; - const handleSubmit = (e: FormEvent): void => { + const handleSubmit = (e: FormEvent): void => {console.log("called this?"); e.preventDefault(); console.log('表單已提交:', formData); // 處理表單提交 @@ -118,9 +134,12 @@ const EscalationComponent: React.FC = ({