diff --git a/src/app/api/scheduling/actions.ts b/src/app/api/scheduling/actions.ts index e7d2ebb..d230ec0 100644 --- a/src/app/api/scheduling/actions.ts +++ b/src/app/api/scheduling/actions.ts @@ -4,13 +4,14 @@ import { convertObjToURLSearchParams } from "@/app/utils/commonUtil"; import { serverFetchJson } from "@/app/utils/fetchUtil" import { BASE_API_URL } from "@/config/api" import { cache } from "react" +import { ScheduleType } from "."; export interface SearchProdSchedule { scheduleAt?: string; schedulePeriod?: string; schedulePeriodTo?: string; totalEstProdCount?: number; - type?: "manual" | "detailed" | "rough"; + types?: ScheduleType[]; pageSize?: number; pageNum?: number; } @@ -40,4 +41,24 @@ export const fetchProdSchedules = cache(async (data: SearchProdSchedule | null) tags: ["prodSchedules"] } }) +}) + +export const testRoughSchedule = cache(async () => { + return serverFetchJson(`${BASE_API_URL}/productionSchedule/testRoughSchedule`, { + method: "GET", + headers: { "Content-Type": "application/json" }, + next: { + tags: ["prodSchedules"] + } + }) +}) + +export const testDetailSchedule = cache(async () => { + return serverFetchJson(`${BASE_API_URL}/productionSchedule/testDetailSchedule`, { + method: "GET", + headers: { "Content-Type": "application/json" }, + next: { + tags: ["prodSchedules"] + } + }) }) \ No newline at end of file diff --git a/src/app/api/scheduling/index.ts b/src/app/api/scheduling/index.ts index d64b5b3..0d24edc 100644 --- a/src/app/api/scheduling/index.ts +++ b/src/app/api/scheduling/index.ts @@ -3,9 +3,9 @@ import { BASE_API_URL } from "@/config/api" import { cache } from "react" import "server-only" -export type ScheduleType = "rough" | "detail"; +export type ScheduleType = "all" | "rough" | "detailed" | "manual"; -export interface ProdScheduleResult { +export interface RoughProdScheduleResult { id: number; scheduleAt: number[]; schedulePeriod: number[]; @@ -13,13 +13,13 @@ export interface ProdScheduleResult { totalEstProdCount: number; totalFGType: number; type: string; - prodScheduleLinesByFg: ProdScheduleLineResultByFg[]; - prodScheduleLinesByFgByDate: { [assignDate: number]: ProdScheduleLineResultByFg[] }; - prodScheduleLinesByBom: ProdScheduleLineResultByBom[]; - prodScheduleLinesByBomByDate: { [assignDate: number]: ProdScheduleLineResultByBomByDate[] }; + prodScheduleLinesByFg: RoughProdScheduleLineResultByFg[]; + prodScheduleLinesByFgByDate: { [assignDate: number]: RoughProdScheduleLineResultByFg[] }; + prodScheduleLinesByBom: RoughProdScheduleLineResultByBom[]; + prodScheduleLinesByBomByDate: { [assignDate: number]: RoughProdScheduleLineResultByBomByDate[] }; } -export interface ProdScheduleLineResultByFg { +export interface RoughProdScheduleLineResultByFg { id: number; code: string; name: string; @@ -30,10 +30,10 @@ export interface ProdScheduleLineResultByFg { estCloseBal: number; priority: number; assignDate: number; - bomMaterials: ProdScheduleLineBomMaterialResult[]; + bomMaterials: RoughProdScheduleLineBomMaterialResult[]; } -export interface ProdScheduleLineBomMaterialResult { +export interface RoughProdScheduleLineBomMaterialResult { id: number; code: string; name: string; @@ -43,7 +43,7 @@ export interface ProdScheduleLineBomMaterialResult { uomName: string; } -export interface ProdScheduleLineResultByBom { +export interface RoughProdScheduleLineResultByBom { id: number, code: string, name: string, @@ -60,7 +60,7 @@ export interface ProdScheduleLineResultByBom { uomName: string, } -export interface ProdScheduleLineResultByBomByDate { +export interface RoughProdScheduleLineResultByBomByDate { id: number, code: string, name: string, @@ -72,7 +72,7 @@ export interface ProdScheduleLineResultByBomByDate { } export const fetchProdScheduleDetail = cache(async (id: number) => { - return serverFetchJson(`${BASE_API_URL}/productionSchedule/detail/${id}`, { + return serverFetchJson(`${BASE_API_URL}/productionSchedule/detail/${id}`, { method: "GET", headers: { "Content-Type": "application/json" }, next: { diff --git a/src/components/RoughScheduleDetail/DetailInfoCard.tsx b/src/components/RoughScheduleDetail/DetailInfoCard.tsx index 9dfb6f4..5cefcff 100644 --- a/src/components/RoughScheduleDetail/DetailInfoCard.tsx +++ b/src/components/RoughScheduleDetail/DetailInfoCard.tsx @@ -18,7 +18,7 @@ import { InputDataGridProps, TableRow } from "../InputDataGrid/InputDataGrid"; import { TypeEnum } from "@/app/utils/typeEnum"; import { NumberInputProps } from "@/components/CreateItem/NumberInputProps"; import { arrayToDateString, integerFormatter } from "@/app/utils/formatUtil"; -import { ProdScheduleResult } from "@/app/api/scheduling"; +import { RoughProdScheduleResult } from "@/app/api/scheduling"; import { DatePicker, LocalizationProvider } from "@mui/x-date-pickers"; import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs"; @@ -38,12 +38,12 @@ const DetailInfoCard: React.FC = ({ isEditing }) => { getValues, watch, formState: { errors, defaultValues, touchedFields }, - } = useFormContext(); + } = useFormContext(); // const [details, setDetails] = useState(null); useEffect(() => { - console.log("[debug] record details", getValues) + console.log("[debug] record details", getValues()) // setDetails(recordDetails); }, [getValues]) diff --git a/src/components/RoughScheduleDetail/RoughScheduleDetailWrapper.tsx b/src/components/RoughScheduleDetail/RoughScheduleDetailWrapper.tsx index 1c0d399..694a3c3 100644 --- a/src/components/RoughScheduleDetail/RoughScheduleDetailWrapper.tsx +++ b/src/components/RoughScheduleDetail/RoughScheduleDetailWrapper.tsx @@ -15,7 +15,7 @@ type Props = { const RoughScheduleDetailWrapper: React.FC & SubComponents = async ({ id, type }) => { const prodSchedule = id ? await fetchProdScheduleDetail(id) : undefined - + return ( | undefined; + defaultValues: Partial | undefined; // qcChecks: ItemQc[] }; @@ -42,7 +42,6 @@ const RoughScheduleDetailView: React.FC = ({ // console.log(type) const apiRef = useGridApiRef(); const params = useSearchParams() - console.log(params.get("id")) const [serverError, setServerError] = useState(""); const [tabIndex, setTabIndex] = useState(0); const { t } = useTranslation("schedule") @@ -51,7 +50,7 @@ const RoughScheduleDetailView: React.FC = ({ //const title = "Demand Forecast Detail" // console.log(typeId) - const formProps = useForm({ + const formProps = useForm({ defaultValues: defaultValues ? defaultValues : { }, }); @@ -88,7 +87,7 @@ const RoughScheduleDetailView: React.FC = ({ router.replace(`/scheduling/rough`); }; - const onSubmit = useCallback>( + const onSubmit = useCallback>( async (data, event) => { let hasErrors = false; console.log(errors) @@ -109,7 +108,7 @@ const RoughScheduleDetailView: React.FC = ({ ); // multiple tabs - const onSubmitError = useCallback>( + const onSubmitError = useCallback>( (errors) => { }, [] ); diff --git a/src/components/RoughScheduleDetail/ViewByBomDetails.tsx b/src/components/RoughScheduleDetail/ViewByBomDetails.tsx index 8e8b814..d02661e 100644 --- a/src/components/RoughScheduleDetail/ViewByBomDetails.tsx +++ b/src/components/RoughScheduleDetail/ViewByBomDetails.tsx @@ -21,7 +21,7 @@ import { RiceBowl } from "@mui/icons-material"; // import EditableSearchResults, { Column } from "@/components/SearchResults/EditableSearchResults"; import { decimalFormatter } from "@/app/utils/formatUtil"; import { GridRenderCellParams } from "@mui/x-data-grid"; -import { ProdScheduleLineResultByBom, ProdScheduleLineResultByBomByDate, ProdScheduleResult, ScheduleType } from "@/app/api/scheduling"; +import { RoughProdScheduleLineResultByBom, RoughProdScheduleLineResultByBomByDate, RoughProdScheduleResult, ScheduleType } from "@/app/api/scheduling"; import ScheduleTable from "@/components/ScheduleTable"; import { Column } from "@/components/ScheduleTable/ScheduleTable"; @@ -63,7 +63,7 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) control, getValues, formState: { errors, defaultValues, touchedFields }, - } = useFormContext(); + } = useFormContext(); // const apiRef = useGridApiRef(); const { fields } = useFieldArray({ @@ -165,7 +165,7 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) style: { textAlign: "right", }, - renderCell: (row: ProdScheduleLineResultByBom) => { + renderCell: (row: RoughProdScheduleLineResultByBom) => { if (typeof (row.availableQty) == "number") { return decimalFormatter.format(row.availableQty) } @@ -180,7 +180,7 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) style: { textAlign: "right", }, - renderCell: (row: ProdScheduleLineResultByBom) => { + renderCell: (row: RoughProdScheduleLineResultByBom) => { if (typeof (row.totalDemandQty) == "number") { return decimalFormatter.format(row.totalDemandQty) } @@ -194,7 +194,7 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) style: { textAlign: "right", }, - renderCell: (row: ProdScheduleLineResultByBom) => { + renderCell: (row: RoughProdScheduleLineResultByBom) => { if (typeof (row.demandQty1) == "number") { return decimalFormatter.format(row.demandQty1) } @@ -208,7 +208,7 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) style: { textAlign: "right", }, - renderCell: (row: ProdScheduleLineResultByBom) => { + renderCell: (row: RoughProdScheduleLineResultByBom) => { if (typeof (row.demandQty2) == "number") { return decimalFormatter.format(row.demandQty2) } @@ -222,7 +222,7 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) style: { textAlign: "right", }, - renderCell: (row: ProdScheduleLineResultByBom) => { + renderCell: (row: RoughProdScheduleLineResultByBom) => { if (typeof (row.demandQty3) == "number") { return decimalFormatter.format(row.demandQty3) } @@ -236,7 +236,7 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) style: { textAlign: "right", }, - renderCell: (row: ProdScheduleLineResultByBom) => { + renderCell: (row: RoughProdScheduleLineResultByBom) => { if (typeof (row.demandQty4) == "number") { return decimalFormatter.format(row.demandQty4) } @@ -249,7 +249,7 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) style: { textAlign: "right", }, - renderCell: (row: ProdScheduleLineResultByBom) => { + renderCell: (row: RoughProdScheduleLineResultByBom) => { if (typeof (row.demandQty5) == "number") { return decimalFormatter.format(row.demandQty5) } @@ -263,7 +263,7 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) style: { textAlign: "right", }, - renderCell: (row: ProdScheduleLineResultByBom) => { + renderCell: (row: RoughProdScheduleLineResultByBom) => { if (typeof (row.demandQty6) == "number") { return decimalFormatter.format(row.demandQty6) } @@ -277,7 +277,7 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) style: { textAlign: "right", }, - renderCell: (row: ProdScheduleLineResultByBom) => { + renderCell: (row: RoughProdScheduleLineResultByBom) => { if (typeof (row.demandQty7) == "number") { return decimalFormatter.format(row.demandQty7) } @@ -288,7 +288,7 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) [t] ); - const columns = useMemo[]>( + const columns = useMemo[]>( () => [ { field: "code", @@ -317,7 +317,7 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) style: { textAlign: "right", }, - renderCell: (row: ProdScheduleLineResultByBomByDate) => { + renderCell: (row: RoughProdScheduleLineResultByBomByDate) => { if (typeof (row.availableQty) == "number") { return decimalFormatter.format(row.availableQty) } @@ -331,7 +331,7 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) style: { textAlign: "right", }, - renderCell: (row: ProdScheduleLineResultByBomByDate) => { + renderCell: (row: RoughProdScheduleLineResultByBomByDate) => { if (typeof (row.demandQty) == "number") { return decimalFormatter.format(row.demandQty) } @@ -342,15 +342,13 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) [] ); - console.log(getValues("prodScheduleLinesByBom")) - return ( {t("Material Demand List (7 Days)")} - + // index={7} type={type} items={getValues("prodScheduleLinesByBom")} @@ -368,7 +366,7 @@ const ViewByBomDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) {`${t("Material Demand Date")}: ${date}`} - + // index={index} type={type} items={getValues("prodScheduleLinesByBomByDate")[index + 1]} // Use the corresponding records for the day diff --git a/src/components/RoughScheduleDetail/ViewByFGDetails.tsx b/src/components/RoughScheduleDetail/ViewByFGDetails.tsx index bd31a71..22d27e5 100644 --- a/src/components/RoughScheduleDetail/ViewByFGDetails.tsx +++ b/src/components/RoughScheduleDetail/ViewByFGDetails.tsx @@ -21,7 +21,7 @@ import { RiceBowl } from "@mui/icons-material"; import ScheduleTable from "@/components/ScheduleTable"; import { Column } from "@/components/ScheduleTable/ScheduleTable"; import { arrayToDayjs, dayjsToDateString, decimalFormatter, integerFormatter } from "@/app/utils/formatUtil"; -import { ProdScheduleLineResultByFg, ProdScheduleResult, ScheduleType } from "@/app/api/scheduling"; +import { RoughProdScheduleLineResultByFg, RoughProdScheduleResult, ScheduleType } from "@/app/api/scheduling"; type Props = { apiRef: MutableRefObject @@ -50,7 +50,7 @@ const ViewByFGDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) = control, getValues, formState: { errors, defaultValues, touchedFields }, - } = useFormContext(); + } = useFormContext(); const { fields } = useFieldArray({ control, @@ -125,7 +125,7 @@ const ViewByFGDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) = }); }; - const columns = useMemo[]>( + const columns = useMemo[]>( () => [ { field: "code", @@ -177,7 +177,7 @@ const ViewByFGDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) = [] ); - const overallColumns = useMemo[]>( + const overallColumns = useMemo[]>( () => [ { field: "code", @@ -270,7 +270,7 @@ const ViewByFGDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) = {t("FG Demand List (7 Days)")} - + // index={7} type={type} items={getValues("prodScheduleLinesByFg")} @@ -288,9 +288,9 @@ const ViewByFGDetails: React.FC = ({ apiRef, isEdit, type, dayPeriod }) = {`${t("FG Demand Date")}: ${date}`} - + type={type} - items={getValues("prodScheduleLinesByFgByDate")[index + 1]} // Use the corresponding records for the day + items={getValues("prodScheduleLinesByFgByDate") && Object.entries(getValues("prodScheduleLinesByFgByDate")).length > 0 ? getValues("prodScheduleLinesByFgByDate")[index + 1] : []} // Use the corresponding records for the day columns={columns} setPagingController={updatePagingController} pagingController={pagingController[index]}