FPSMS-frontend
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

StockInFormVer2.tsx 11 KiB

11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
10 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
11 meses atrás
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378
  1. "use client";
  2. import {
  3. PurchaseQcResult,
  4. PurchaseQCInput,
  5. StockInInput,
  6. } from "@/app/api/po/actions";
  7. import {
  8. Box,
  9. Card,
  10. CardContent,
  11. Grid,
  12. Stack,
  13. TextField,
  14. Tooltip,
  15. Typography,
  16. } from "@mui/material";
  17. import { Controller, useFormContext } from "react-hook-form";
  18. import { useTranslation } from "react-i18next";
  19. import StyledDataGrid from "../StyledDataGrid";
  20. import { useCallback, useEffect, useMemo } from "react";
  21. import {
  22. GridColDef,
  23. GridRowIdGetter,
  24. GridRowModel,
  25. useGridApiContext,
  26. GridRenderCellParams,
  27. GridRenderEditCellParams,
  28. useGridApiRef,
  29. } from "@mui/x-data-grid";
  30. import InputDataGrid from "../InputDataGrid";
  31. import { TableRow } from "../InputDataGrid/InputDataGrid";
  32. import TwoLineCell from "./TwoLineCell";
  33. import QcSelect from "./QcSelect";
  34. import { QcItemWithChecks } from "@/app/api/qc";
  35. import { GridEditInputCell } from "@mui/x-data-grid";
  36. import { StockInLine } from "@/app/api/po";
  37. import { DatePicker, LocalizationProvider } from "@mui/x-date-pickers";
  38. import { AdapterDayjs } from "@mui/x-date-pickers/AdapterDayjs";
  39. import { INPUT_DATE_FORMAT } from "@/app/utils/formatUtil";
  40. import dayjs from "dayjs";
  41. // change PurchaseQcResult to stock in entry props
  42. interface Props {
  43. itemDetail: StockInLine;
  44. // qc: QcItemWithChecks[];
  45. disabled: boolean;
  46. }
  47. type EntryError =
  48. | {
  49. [field in keyof StockInInput]?: string;
  50. }
  51. | undefined;
  52. // type PoQcRow = TableRow<Partial<PurchaseQcResult>, EntryError>;
  53. const StockInFormVer2: React.FC<Props> = ({
  54. // qc,
  55. itemDetail,
  56. disabled,
  57. }) => {
  58. const {
  59. t,
  60. i18n: { language },
  61. } = useTranslation("purchaseOrder");
  62. const apiRef = useGridApiRef();
  63. const {
  64. register,
  65. formState: { errors, defaultValues, touchedFields },
  66. watch,
  67. control,
  68. setValue,
  69. getValues,
  70. reset,
  71. resetField,
  72. setError,
  73. clearErrors,
  74. } = useFormContext<StockInInput>();
  75. // console.log(itemDetail);
  76. useEffect(() => {
  77. // console.log("triggered");
  78. // // receiptDate default tdy
  79. // setValue("receiptDate", dayjs().add(0, "month").format(INPUT_DATE_FORMAT));
  80. // setValue("status", "received");
  81. }, [setValue]);
  82. useEffect(() => {
  83. console.log(errors);
  84. }, [errors]);
  85. const productionDate = watch("productionDate");
  86. const expiryDate = watch("expiryDate");
  87. const uom = watch("uom");
  88. //// TODO : Add Checking ////
  89. // Check if dates are input
  90. // if (data.productionDate === undefined || data.productionDate == null) {
  91. // validationErrors.push("請輸入生產日期!");
  92. // }
  93. // if (data.expiryDate === undefined || data.expiryDate == null) {
  94. // validationErrors.push("請輸入到期日!");
  95. // }
  96. useEffect(() => {
  97. // console.log(uom);
  98. // console.log(productionDate);
  99. // console.log(expiryDate);
  100. if (expiryDate) clearErrors();
  101. if (productionDate) clearErrors();
  102. }, [productionDate, expiryDate, clearErrors]);
  103. useEffect(() => {
  104. console.log("%c StockInForm itemDetail update: ", "color: brown", itemDetail);
  105. }, [itemDetail]);
  106. return (
  107. <Grid container justifyContent="flex-start" alignItems="flex-start">
  108. {/* <Grid item xs={12}>
  109. <Typography variant="h6" display="block" marginBlockEnd={1}>
  110. {t("Stock In Detail")}
  111. </Typography>
  112. </Grid> */}
  113. <Grid
  114. container
  115. justifyContent="flex-start"
  116. alignItems="flex-start"
  117. spacing={2}
  118. sx={{ mt: 0.5 }}
  119. >
  120. <Grid item xs={6}>
  121. <TextField
  122. label={t("dnNo")}
  123. fullWidth
  124. {...register("dnNo", {
  125. // required: "productLotNo required!",
  126. })}
  127. disabled={disabled}
  128. // error={Boolean(errors.productLotNo)}
  129. // helperText={errors.productLotNo?.message}
  130. />
  131. </Grid>
  132. <Grid item xs={6}>
  133. <TextField
  134. label={t("itemName")}
  135. fullWidth
  136. {...register("itemName", {
  137. // required: "productLotNo required!",
  138. })}
  139. disabled={true}
  140. // error={Boolean(errors.productLotNo)}
  141. // helperText={errors.productLotNo?.message}
  142. />
  143. </Grid>
  144. <Grid item xs={6}>
  145. <TextField
  146. label={t("PO No.")}
  147. fullWidth
  148. {...register("poCode", {
  149. // required: "productLotNo required!",
  150. })}
  151. disabled={true}
  152. // error={Boolean(errors.productLotNo)}
  153. // helperText={errors.productLotNo?.message}
  154. />
  155. </Grid>
  156. <Grid item xs={6}>
  157. <Controller
  158. control={control}
  159. name="receiptDate"
  160. rules={{ required: true }}
  161. render={({ field }) => {
  162. return (
  163. <LocalizationProvider
  164. dateAdapter={AdapterDayjs}
  165. adapterLocale={`${language}-hk`}
  166. >
  167. <DatePicker
  168. {...field}
  169. sx={{ width: "100%" }}
  170. label={t("receiptDate")}
  171. value={dayjs(watch("receiptDate"))}
  172. disabled={true}
  173. onChange={(date) => {
  174. if (!date) return;
  175. // setValue("receiptDate", date.format(INPUT_DATE_FORMAT));
  176. field.onChange(date);
  177. }}
  178. inputRef={field.ref}
  179. slotProps={{
  180. textField: {
  181. // required: true,
  182. error: Boolean(errors.receiptDate?.message),
  183. helperText: errors.receiptDate?.message,
  184. },
  185. }}
  186. />
  187. </LocalizationProvider>
  188. );
  189. }}
  190. />
  191. </Grid>
  192. <Grid item xs={6}>
  193. <TextField
  194. label={t("Supplier")}
  195. fullWidth
  196. {...register("supplier", {
  197. // required: "productLotNo required!",
  198. })}
  199. disabled={true}
  200. />
  201. </Grid>
  202. <Grid item xs={6}>
  203. <TextField
  204. label={t("productLotNo")}
  205. fullWidth
  206. {...register("productLotNo", {
  207. // required: "productLotNo required!",
  208. })}
  209. disabled={disabled}
  210. error={Boolean(errors.productLotNo)}
  211. helperText={errors.productLotNo?.message}
  212. />
  213. </Grid>
  214. <Grid item xs={6}>
  215. <Controller
  216. control={control}
  217. name="productionDate"
  218. // rules={{ required: !Boolean(expiryDate) }}
  219. render={({ field }) => {
  220. return (
  221. <LocalizationProvider
  222. dateAdapter={AdapterDayjs}
  223. adapterLocale={`${language}-hk`}
  224. >
  225. <DatePicker
  226. {...field}
  227. sx={{ width: "100%" }}
  228. label={t("productionDate")}
  229. value={productionDate ? dayjs(productionDate) : undefined}
  230. disabled={disabled}
  231. onChange={(date) => {
  232. if (!date) return;
  233. setValue(
  234. "productionDate",
  235. date.format(INPUT_DATE_FORMAT),
  236. );
  237. // field.onChange(date);
  238. }}
  239. inputRef={field.ref}
  240. slotProps={{
  241. textField: {
  242. // required: true,
  243. error: Boolean(errors.productionDate?.message),
  244. helperText: errors.productionDate?.message,
  245. },
  246. }}
  247. />
  248. </LocalizationProvider>
  249. );
  250. }}
  251. />
  252. </Grid>
  253. <Grid item xs={6}>
  254. <TextField
  255. label={t("qty")}
  256. fullWidth
  257. {...register("qty", {
  258. required: "qty required!",
  259. })}
  260. disabled={true}
  261. />
  262. </Grid>
  263. <Grid item xs={6}>
  264. <Controller
  265. control={control}
  266. name="expiryDate"
  267. // rules={{ required: !Boolean(productionDate) }}
  268. render={({ field }) => {
  269. return (
  270. <LocalizationProvider
  271. dateAdapter={AdapterDayjs}
  272. adapterLocale={`${language}-hk`}
  273. >
  274. <DatePicker
  275. {...field}
  276. sx={{ width: "100%" }}
  277. label={t("expiryDate")}
  278. value={expiryDate ? dayjs(expiryDate) : undefined}
  279. disabled={disabled}
  280. onChange={(date) => {
  281. if (!date) return;
  282. console.log(date.format(INPUT_DATE_FORMAT));
  283. setValue("expiryDate", date.format(INPUT_DATE_FORMAT));
  284. // field.onChange(date);
  285. }}
  286. inputRef={field.ref}
  287. slotProps={{
  288. textField: {
  289. // required: true,
  290. error: Boolean(errors.expiryDate?.message),
  291. helperText: errors.expiryDate?.message,
  292. },
  293. }}
  294. />
  295. </LocalizationProvider>
  296. );
  297. }}
  298. />
  299. </Grid>
  300. <Grid item xs={6}>
  301. <TextField
  302. label={t("receivedQty")}
  303. fullWidth
  304. {...register("receivedQty", {
  305. required: "receivedQty required!",
  306. })}
  307. disabled={true}
  308. />
  309. </Grid>
  310. <Grid item xs={6}>
  311. <TextField
  312. label={t("uom")}
  313. fullWidth
  314. {...register("uom.udfudesc", {
  315. required: "uom required!",
  316. })}
  317. // value={uom?.code}
  318. disabled={true}
  319. />
  320. </Grid>
  321. <Grid item xs={6}>
  322. <TextField
  323. label={t("acceptedQty")}
  324. fullWidth
  325. disabled={true}
  326. {...register("acceptedQty", {
  327. required: "acceptedQty required!",
  328. })}
  329. // disabled={true}
  330. // disabled={disabled}
  331. // error={Boolean(errors.acceptedQty)}
  332. // helperText={errors.acceptedQty?.message}
  333. />
  334. </Grid>
  335. {/* <Grid item xs={4}>
  336. <TextField
  337. label={t("acceptedWeight")}
  338. fullWidth
  339. // {...register("acceptedWeight", {
  340. // required: "acceptedWeight required!",
  341. // })}
  342. disabled={disabled}
  343. error={Boolean(errors.acceptedWeight)}
  344. helperText={errors.acceptedWeight?.message}
  345. />
  346. </Grid> */}
  347. </Grid>
  348. <Grid
  349. container
  350. justifyContent="flex-start"
  351. alignItems="flex-start"
  352. spacing={2}
  353. sx={{ mt: 0.5 }}
  354. >
  355. {/* <Grid item xs={12}>
  356. <InputDataGrid<PurchaseQCInput, PurchaseQcResult, EntryError>
  357. apiRef={apiRef}
  358. checkboxSelection={false}
  359. _formKey={"qcCheck"}
  360. columns={columns}
  361. validateRow={validationTest}
  362. />
  363. </Grid> */}
  364. </Grid>
  365. </Grid>
  366. );
  367. };
  368. export default StockInFormVer2;