|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426 |
- "use client";
-
- import { CreateItemInputs } from "@/app/api/settings/item/actions";
- import {
- GridColDef,
- GridRowModel,
- GridRenderEditCellParams,
- GridEditInputCell,
- GridRowSelectionModel,
- useGridApiRef,
- } from "@mui/x-data-grid";
- import {
- MutableRefObject,
- useCallback,
- useEffect,
- useMemo,
- useState,
- } from "react";
- import { useFieldArray, useFormContext } from "react-hook-form";
- import { useTranslation } from "react-i18next";
- import InputDataGrid, { TableRow } from "../InputDataGrid/InputDataGrid";
- import { Box, Grid, Tooltip, Typography } from "@mui/material";
- import { ItemQc } from "@/app/api/settings/item";
- import { QcChecksInputs } from "@/app/api/settings/qcCheck/actions";
- import { GridApiCommunity } from "@mui/x-data-grid/internals";
- 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 {
- RoughProdScheduleLineResultByBom,
- RoughProdScheduleLineResultByBomByDate,
- RoughProdScheduleResult,
- ScheduleType,
- } from "@/app/api/scheduling";
- import ScheduleTable from "@/components/ScheduleTable";
- import { Column } from "@/components/ScheduleTable/ScheduleTable";
-
- type Props = {
- apiRef: MutableRefObject<GridApiCommunity>;
- isEdit: boolean;
- type: ScheduleType;
- dayPeriod: string[];
- };
-
- // export type FGRecord = {
- // id: string | number
- // code: string;
- // name: string;
- // inStockQty: number;
- // purchaseQty: number;
- // }
-
- // export type FGOverallRecord = {
- // id: string | number
- // code: string;
- // name: string;
- // type: string;
- // inStockQty: number;
- // purchaseQty: number;
- // purchaseQty1: number;
- // purchaseQty2: number;
- // purchaseQty3: number;
- // purchaseQty4: number;
- // purchaseQty5: number;
- // purchaseQty6: number;
- // purchaseQty7: number;
- // overallPurchaseQty: number;
- // }
-
- const ViewByBomDetails: React.FC<Props> = ({
- apiRef,
- isEdit,
- type,
- dayPeriod,
- }) => {
- const {
- t,
- i18n: { language },
- } = useTranslation("schedule");
- const {
- control,
- getValues,
- formState: { errors, defaultValues, touchedFields },
- } = useFormContext<RoughProdScheduleResult>();
- // const apiRef = useGridApiRef();
-
- const { fields } = useFieldArray({
- control,
- name: "prodScheduleLinesByBom",
- });
-
- const [pagingController, setPagingController] = useState([
- {
- pageNum: 1,
- pageSize: 10,
- totalCount: 0,
- },
- {
- pageNum: 1,
- pageSize: 10,
- totalCount: 0,
- },
- {
- pageNum: 1,
- pageSize: 10,
- totalCount: 0,
- },
- {
- pageNum: 1,
- pageSize: 10,
- totalCount: 0,
- },
- {
- pageNum: 1,
- pageSize: 10,
- totalCount: 0,
- },
- {
- pageNum: 1,
- pageSize: 10,
- totalCount: 0,
- },
- {
- pageNum: 1,
- pageSize: 10,
- totalCount: 0,
- },
- {
- pageNum: 1,
- pageSize: 10,
- totalCount: 0,
- },
- ]);
-
- const updatePagingController = (updatedObj: {
- pageNum: number;
- pageSize: number;
- totalCount: number;
- index?: number | undefined;
- }) => {
- setPagingController((prevState) => {
- return prevState.map((item, index) => {
- if (index === updatedObj?.index) {
- return {
- ...item,
- pageNum: item.pageNum,
- pageSize: item.pageSize,
- totalCount: item.totalCount,
- };
- } else return item;
- });
- });
- };
-
- const overallColumns = useMemo<Column<any>[]>(
- () => [
- {
- field: "code",
- label: t("code"),
- type: "read-only",
- // editable: true,
- },
- {
- field: "name",
- label: t("name"),
- type: "read-only",
- },
- {
- field: "type",
- label: t("type"),
- type: "read-only",
- renderCell: (params) => {
- return t(params.type);
- },
- // editable: true,
- },
- {
- field: "availableQty",
- label: t("Available Qty"),
- type: "read-only",
- style: {
- textAlign: "right",
- },
- renderCell: (row: RoughProdScheduleLineResultByBom) => {
- if (typeof row.availableQty == "number") {
- return decimalFormatter.format(row.availableQty);
- }
- return row.availableQty;
- },
- // editable: true,
- },
- {
- field: "totalDemandQty",
- label: t("Total Demand Qty"),
- type: "read-only",
- style: {
- textAlign: "right",
- },
- renderCell: (row: RoughProdScheduleLineResultByBom) => {
- if (typeof row.totalDemandQty == "number") {
- return decimalFormatter.format(row.totalDemandQty);
- }
- return row.totalDemandQty;
- },
- },
- {
- field: "demandQty1",
- label: t("Demand Qty (Day1)"),
- type: "read-only",
- style: {
- textAlign: "right",
- },
- renderCell: (row: RoughProdScheduleLineResultByBom) => {
- if (typeof row.demandQty1 == "number") {
- return decimalFormatter.format(row.demandQty1);
- }
- return row.demandQty1;
- },
- },
- {
- field: "demandQty2",
- label: t("Demand Qty (Day2)"),
- type: "read-only",
- style: {
- textAlign: "right",
- },
- renderCell: (row: RoughProdScheduleLineResultByBom) => {
- if (typeof row.demandQty2 == "number") {
- return decimalFormatter.format(row.demandQty2);
- }
- return row.demandQty2;
- },
- },
- {
- field: "demandQty3",
- label: t("Demand Qty (Day3)"),
- type: "read-only",
- style: {
- textAlign: "right",
- },
- renderCell: (row: RoughProdScheduleLineResultByBom) => {
- if (typeof row.demandQty3 == "number") {
- return decimalFormatter.format(row.demandQty3);
- }
- return row.demandQty3;
- },
- },
- {
- field: "demandQty4",
- label: t("Demand Qty (Day4)"),
- type: "read-only",
- style: {
- textAlign: "right",
- },
- renderCell: (row: RoughProdScheduleLineResultByBom) => {
- if (typeof row.demandQty4 == "number") {
- return decimalFormatter.format(row.demandQty4);
- }
- return row.demandQty4;
- },
- },
- {
- field: "demandQty5",
- label: t("Demand Qty (Day5)"),
- type: "read-only",
- style: {
- textAlign: "right",
- },
- renderCell: (row: RoughProdScheduleLineResultByBom) => {
- if (typeof row.demandQty5 == "number") {
- return decimalFormatter.format(row.demandQty5);
- }
- return row.demandQty5;
- },
- },
- {
- field: "demandQty6",
- label: t("Demand Qty (Day6)"),
- type: "read-only",
- style: {
- textAlign: "right",
- },
- renderCell: (row: RoughProdScheduleLineResultByBom) => {
- if (typeof row.demandQty6 == "number") {
- return decimalFormatter.format(row.demandQty6);
- }
- return row.demandQty6;
- },
- },
- {
- field: "demandQty7",
- label: t("Demand Qty (Day7)"),
- type: "read-only",
- style: {
- textAlign: "right",
- },
- renderCell: (row: RoughProdScheduleLineResultByBom) => {
- if (typeof row.demandQty7 == "number") {
- return decimalFormatter.format(row.demandQty7);
- }
- return row.demandQty7;
- },
- },
- {
- field: "uomName",
- label: t("UoM"),
- type: "read-only",
- style: {
- textAlign: "left",
- },
- renderCell: (row) => {
- return row.uomName;
- },
- },
- ],
- [t],
- );
-
- const columns = useMemo<Column<RoughProdScheduleLineResultByBomByDate>[]>(
- () => [
- {
- field: "code",
- label: t("code"),
- type: "read-only",
- // editable: true,
- },
- {
- field: "name",
- label: t("name"),
- type: "read-only",
- },
- {
- field: "type",
- label: t("type"),
- type: "read-only",
- renderCell: (params) => {
- return t(params.type);
- },
- },
- {
- field: "availableQty",
- label: t("Available Qty"),
- type: "read-only",
- // editable: true,
- style: {
- textAlign: "right",
- },
- renderCell: (row: RoughProdScheduleLineResultByBomByDate) => {
- if (typeof row.availableQty == "number") {
- return decimalFormatter.format(row.availableQty);
- }
- return row.availableQty;
- },
- },
- {
- field: "demandQty",
- label: t("Demand Qty"),
- type: "read-only",
- style: {
- textAlign: "right",
- },
- renderCell: (row: RoughProdScheduleLineResultByBomByDate) => {
- if (typeof row.demandQty == "number") {
- return decimalFormatter.format(row.demandQty);
- }
- return row.demandQty;
- },
- },
- {
- field: "uomName",
- label: t("UoM"),
- type: "read-only",
- style: {
- textAlign: "left",
- },
- renderCell: (row) => {
- return row.uomName;
- },
- },
- ],
- [],
- );
-
- return (
- <Grid container spacing={2}>
- <Grid item xs={12} key={"all"}>
- <Typography variant="overline" display="block" marginBlockEnd={1}>
- {t("Material Demand List (7 Days)")}
- </Typography>
- <ScheduleTable<RoughProdScheduleLineResultByBom>
- // index={7}
- type={type}
- items={getValues("prodScheduleLinesByBom")}
- columns={overallColumns}
- setPagingController={updatePagingController}
- pagingController={pagingController[7]}
- isAutoPaging={true}
- isEditable={false}
- isEdit={false}
- hasCollapse={false}
- />
- </Grid>
- {dayPeriod.map((date, index) => (
- <Grid item xs={12} key={index}>
- <Typography variant="overline" display="block" marginBlockEnd={1}>
- {`${t("Material Demand Date")}: ${date}`}
- </Typography>
- <ScheduleTable<RoughProdScheduleLineResultByBomByDate>
- // index={index}
- type={type}
- items={getValues("prodScheduleLinesByBomByDate")[index + 1]} // Use the corresponding records for the day
- columns={columns}
- setPagingController={updatePagingController}
- pagingController={pagingController[index]}
- isAutoPaging={true}
- isEditable={false}
- isEdit={isEdit}
- hasCollapse={false}
- />
- </Grid>
- ))}
- </Grid>
- );
- };
- export default ViewByBomDetails;
|