| @@ -52,6 +52,7 @@ export interface StockInInput { | |||||
| export interface PurchaseQCInput { | export interface PurchaseQCInput { | ||||
| status: string; | status: string; | ||||
| acceptedQty: number; | acceptedQty: number; | ||||
| passingQty: number; | |||||
| sampleRate: number; | sampleRate: number; | ||||
| sampleWeight: number; | sampleWeight: number; | ||||
| totalWeight: number; | totalWeight: number; | ||||
| @@ -1,4 +1,4 @@ | |||||
| import React, { useState, ChangeEvent, FormEvent } from 'react'; | |||||
| import React, { useState, ChangeEvent, FormEvent, Dispatch } from 'react'; | |||||
| import { | import { | ||||
| Box, | Box, | ||||
| Button, | Button, | ||||
| @@ -35,14 +35,16 @@ interface FormData { | |||||
| interface Props { | interface Props { | ||||
| forSupervisor: boolean | forSupervisor: boolean | ||||
| isCollapsed: boolean | |||||
| setIsCollapsed: Dispatch<React.SetStateAction<boolean>> | |||||
| } | } | ||||
| const EscalationComponent: React.FC<Props> = ({ | const EscalationComponent: React.FC<Props> = ({ | ||||
| forSupervisor | |||||
| forSupervisor, | |||||
| isCollapsed, | |||||
| setIsCollapsed | |||||
| }) => { | }) => { | ||||
| const { t } = useTranslation("purchaseOrder"); | const { t } = useTranslation("purchaseOrder"); | ||||
| const [isCollapsed, setIsCollapsed] = useState<boolean>(false); | |||||
| const [formData, setFormData] = useState<FormData>({ | const [formData, setFormData] = useState<FormData>({ | ||||
| name: '', | name: '', | ||||
| quantity: '', | quantity: '', | ||||
| @@ -249,7 +249,7 @@ const QcFormVer2: React.FC<Props> = ({ qc, itemDetail, disabled, qcItems, setQcI | |||||
| headerName: t("qcItem"), | headerName: t("qcItem"), | ||||
| flex: 1, | flex: 1, | ||||
| }, | }, | ||||
| { | |||||
| { | |||||
| field: 'isPassed', | field: 'isPassed', | ||||
| headerName: t("passed"), | headerName: t("passed"), | ||||
| flex: 1, | flex: 1, | ||||
| @@ -261,7 +261,11 @@ const QcFormVer2: React.FC<Props> = ({ qc, itemDetail, disabled, qcItems, setQcI | |||||
| onChange={(e) => { | onChange={(e) => { | ||||
| const checked = e.target.checked; | const checked = e.target.checked; | ||||
| setQcItems((prev) => | setQcItems((prev) => | ||||
| prev.map((r) => (r.id === params.id ? { ...r, isPassed: checked } : r)) | |||||
| prev.map((r) => | |||||
| r.id === params.id | |||||
| ? { ...r, isPassed: checked, isFailed: !checked ? r.isFailed : false } | |||||
| : r | |||||
| ) | |||||
| ); | ); | ||||
| }} | }} | ||||
| size="small" | size="small" | ||||
| @@ -282,7 +286,11 @@ const QcFormVer2: React.FC<Props> = ({ qc, itemDetail, disabled, qcItems, setQcI | |||||
| onChange={(e) => { | onChange={(e) => { | ||||
| const checked = e.target.checked; | const checked = e.target.checked; | ||||
| setQcItems((prev) => | setQcItems((prev) => | ||||
| prev.map((r) => (r.id === params.id ? { ...r, isFailed: checked } : r)) | |||||
| prev.map((r) => | |||||
| r.id === params.id | |||||
| ? { ...r, isFailed: checked, isPassed: !checked ? r.isPassed : false } | |||||
| : r | |||||
| ) | |||||
| ); | ); | ||||
| }} | }} | ||||
| size="small" | size="small" | ||||
| @@ -343,15 +351,31 @@ const QcFormVer2: React.FC<Props> = ({ qc, itemDetail, disabled, qcItems, setQcI | |||||
| useEffect(() => { | useEffect(() => { | ||||
| console.log(itemDetail); | console.log(itemDetail); | ||||
| const status = "receiving"; | |||||
| // switch (itemDetail.status) { | |||||
| // case 'pending': | |||||
| // status = "receiving" | |||||
| // break; | |||||
| // } | |||||
| setValue("status", status); | |||||
| }, [itemDetail]); | |||||
| // const [openCollapse, setOpenCollapse] = useState(false) | |||||
| const [isCollapsed, setIsCollapsed] = useState<boolean>(false); | |||||
| const onFailedOpenCollapse = useCallback((qcItems: QcData[]) => { | |||||
| const isFailed = qcItems.some((qc) => qc.isFailed) | |||||
| console.log(isFailed) | |||||
| if (isFailed) { | |||||
| setIsCollapsed(true) | |||||
| } else { | |||||
| setIsCollapsed(false) | |||||
| } | |||||
| }, []) | |||||
| useEffect(() => { | |||||
| console.log(itemDetail); | |||||
| }, [itemDetail]); | }, [itemDetail]); | ||||
| useEffect(() => { | |||||
| onFailedOpenCollapse(qcItems) | |||||
| }, [qcItems, onFailedOpenCollapse]); | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| <Grid container justifyContent="flex-start" alignItems="flex-start"> | <Grid container justifyContent="flex-start" alignItems="flex-start"> | ||||
| @@ -392,10 +416,18 @@ const QcFormVer2: React.FC<Props> = ({ qc, itemDetail, disabled, qcItems, setQcI | |||||
| type="number" | type="number" | ||||
| label={t("acceptedQty")} | label={t("acceptedQty")} | ||||
| fullWidth | fullWidth | ||||
| defaultValue={watch("passingQty")} | |||||
| {...register("passingQty", { | |||||
| required: "passingQty required!", | |||||
| })} | |||||
| /> | /> | ||||
| </Grid> | </Grid> | ||||
| <Grid item xs={12}> | <Grid item xs={12}> | ||||
| <EscalationComponent forSupervisor={false}/> | |||||
| <EscalationComponent | |||||
| forSupervisor={false} | |||||
| isCollapsed={isCollapsed} | |||||
| setIsCollapsed={setIsCollapsed} | |||||
| /> | |||||
| </Grid> | </Grid> | ||||
| </> | </> | ||||
| )} | )} | ||||
| @@ -429,6 +461,8 @@ const QcFormVer2: React.FC<Props> = ({ qc, itemDetail, disabled, qcItems, setQcI | |||||
| <Grid item xs={12}> | <Grid item xs={12}> | ||||
| <EscalationComponent | <EscalationComponent | ||||
| forSupervisor={true} | forSupervisor={true} | ||||
| isCollapsed={isCollapsed} | |||||
| setIsCollapsed={setIsCollapsed} | |||||
| /> | /> | ||||
| </Grid> | </Grid> | ||||
| </> | </> | ||||
| @@ -11,7 +11,7 @@ import { | |||||
| Stack, | Stack, | ||||
| Typography, | Typography, | ||||
| } from "@mui/material"; | } from "@mui/material"; | ||||
| import { Dispatch, SetStateAction, useCallback, useState } from "react"; | |||||
| import { Dispatch, SetStateAction, useCallback, useEffect, useState } from "react"; | |||||
| import { FormProvider, SubmitHandler, useForm } from "react-hook-form"; | import { FormProvider, SubmitHandler, useForm } from "react-hook-form"; | ||||
| import { StockInLineRow } from "./PoInputGrid"; | import { StockInLineRow } from "./PoInputGrid"; | ||||
| import { useTranslation } from "react-i18next"; | import { useTranslation } from "react-i18next"; | ||||
| @@ -19,7 +19,7 @@ import StockInForm from "./StockInForm"; | |||||
| import StockInFormVer2 from "./StockInFormVer2"; | import StockInFormVer2 from "./StockInFormVer2"; | ||||
| import QcFormVer2 from "./QcFormVer2"; | import QcFormVer2 from "./QcFormVer2"; | ||||
| import PutawayForm from "./PutawayForm"; | import PutawayForm from "./PutawayForm"; | ||||
| import { dummyPutawayLine, dummyQCData } from "./dummyQcTemplate"; | |||||
| import { dummyPutawayLine, dummyQCData, QcData } from "./dummyQcTemplate"; | |||||
| import { useGridApiRef } from "@mui/x-data-grid"; | import { useGridApiRef } from "@mui/x-data-grid"; | ||||
| const style = { | const style = { | ||||
| position: "absolute", | position: "absolute", | ||||
| @@ -189,6 +189,25 @@ const [qcItems, setQcItems] = useState(dummyQCData) | |||||
| // Handle print logic here | // Handle print logic here | ||||
| window.print(); | window.print(); | ||||
| }, []); | }, []); | ||||
| const acceptQty = formProps.watch("acceptedQty") | |||||
| const checkQcIsPassed = useCallback((qcItems: QcData[]) => { | |||||
| const isPassed = qcItems.every((qc) => qc.isPassed); | |||||
| console.log(isPassed) | |||||
| if (isPassed) { | |||||
| formProps.setValue("passingQty", acceptQty) | |||||
| } else { | |||||
| formProps.setValue("passingQty", 0) | |||||
| } | |||||
| return isPassed | |||||
| }, [acceptQty, formProps]) | |||||
| useEffect(() => { | |||||
| // maybe check if submitted before | |||||
| console.log(qcItems) | |||||
| checkQcIsPassed(qcItems) | |||||
| }, [qcItems, checkQcIsPassed]) | |||||
| return ( | return ( | ||||
| <> | <> | ||||
| <FormProvider {...formProps}> | <FormProvider {...formProps}> | ||||