FPSMS-frontend
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 
 

369 rindas
11 KiB

  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. useEffect(() => {
  89. console.log(uom);
  90. console.log(productionDate);
  91. console.log(expiryDate);
  92. if (expiryDate) clearErrors();
  93. if (productionDate) clearErrors();
  94. }, [productionDate, expiryDate, clearErrors]);
  95. // console.log(itemDetail)
  96. return (
  97. <Grid container justifyContent="flex-start" alignItems="flex-start">
  98. {/* <Grid item xs={12}>
  99. <Typography variant="h6" display="block" marginBlockEnd={1}>
  100. {t("Stock In Detail")}
  101. </Typography>
  102. </Grid> */}
  103. <Grid
  104. container
  105. justifyContent="flex-start"
  106. alignItems="flex-start"
  107. spacing={2}
  108. sx={{ mt: 0.5 }}
  109. >
  110. <Grid item xs={6}>
  111. <TextField
  112. label={t("dnNo")}
  113. fullWidth
  114. {...register("dnNo", {
  115. // required: "productLotNo required!",
  116. })}
  117. disabled={disabled}
  118. // error={Boolean(errors.productLotNo)}
  119. // helperText={errors.productLotNo?.message}
  120. />
  121. </Grid>
  122. <Grid item xs={6}>
  123. <TextField
  124. label={t("itemName")}
  125. fullWidth
  126. {...register("itemName", {
  127. // required: "productLotNo required!",
  128. })}
  129. disabled={true}
  130. // error={Boolean(errors.productLotNo)}
  131. // helperText={errors.productLotNo?.message}
  132. />
  133. </Grid>
  134. <Grid item xs={6}>
  135. <TextField
  136. label={t("PO No.")}
  137. fullWidth
  138. {...register("poCode", {
  139. // required: "productLotNo required!",
  140. })}
  141. disabled={true}
  142. // error={Boolean(errors.productLotNo)}
  143. // helperText={errors.productLotNo?.message}
  144. />
  145. </Grid>
  146. <Grid item xs={6}>
  147. <Controller
  148. control={control}
  149. name="receiptDate"
  150. rules={{ required: true }}
  151. render={({ field }) => {
  152. return (
  153. <LocalizationProvider
  154. dateAdapter={AdapterDayjs}
  155. adapterLocale={`${language}-hk`}
  156. >
  157. <DatePicker
  158. {...field}
  159. sx={{ width: "100%" }}
  160. label={t("receiptDate")}
  161. value={dayjs(watch("receiptDate"))}
  162. disabled={true}
  163. onChange={(date) => {
  164. if (!date) return;
  165. // setValue("receiptDate", date.format(INPUT_DATE_FORMAT));
  166. field.onChange(date);
  167. }}
  168. inputRef={field.ref}
  169. slotProps={{
  170. textField: {
  171. // required: true,
  172. error: Boolean(errors.receiptDate?.message),
  173. helperText: errors.receiptDate?.message,
  174. },
  175. }}
  176. />
  177. </LocalizationProvider>
  178. );
  179. }}
  180. />
  181. </Grid>
  182. <Grid item xs={6}>
  183. <TextField
  184. label={t("Supplier")}
  185. fullWidth
  186. {...register("supplier", {
  187. // required: "productLotNo required!",
  188. })}
  189. disabled={true}
  190. />
  191. </Grid>
  192. <Grid item xs={6}>
  193. <TextField
  194. label={t("productLotNo")}
  195. fullWidth
  196. {...register("productLotNo", {
  197. // required: "productLotNo required!",
  198. })}
  199. disabled={disabled}
  200. error={Boolean(errors.productLotNo)}
  201. helperText={errors.productLotNo?.message}
  202. />
  203. </Grid>
  204. <Grid item xs={6}>
  205. <Controller
  206. control={control}
  207. name="productionDate"
  208. // rules={{ required: !Boolean(expiryDate) }}
  209. render={({ field }) => {
  210. return (
  211. <LocalizationProvider
  212. dateAdapter={AdapterDayjs}
  213. adapterLocale={`${language}-hk`}
  214. >
  215. <DatePicker
  216. {...field}
  217. sx={{ width: "100%" }}
  218. label={t("productionDate")}
  219. value={productionDate ? dayjs(productionDate) : undefined}
  220. disabled={disabled}
  221. onChange={(date) => {
  222. if (!date) return;
  223. setValue(
  224. "productionDate",
  225. date.format(INPUT_DATE_FORMAT),
  226. );
  227. // field.onChange(date);
  228. }}
  229. inputRef={field.ref}
  230. slotProps={{
  231. textField: {
  232. // required: true,
  233. error: Boolean(errors.productionDate?.message),
  234. helperText: errors.productionDate?.message,
  235. },
  236. }}
  237. />
  238. </LocalizationProvider>
  239. );
  240. }}
  241. />
  242. </Grid>
  243. <Grid item xs={6}>
  244. <TextField
  245. label={t("qty")}
  246. fullWidth
  247. {...register("qty", {
  248. required: "qty required!",
  249. })}
  250. disabled={true}
  251. />
  252. </Grid>
  253. <Grid item xs={6}>
  254. <Controller
  255. control={control}
  256. name="expiryDate"
  257. // rules={{ required: !Boolean(productionDate) }}
  258. render={({ field }) => {
  259. return (
  260. <LocalizationProvider
  261. dateAdapter={AdapterDayjs}
  262. adapterLocale={`${language}-hk`}
  263. >
  264. <DatePicker
  265. {...field}
  266. sx={{ width: "100%" }}
  267. label={t("expiryDate")}
  268. value={expiryDate ? dayjs(expiryDate) : undefined}
  269. disabled={disabled}
  270. onChange={(date) => {
  271. console.log(date);
  272. if (!date) return;
  273. console.log(date.format(INPUT_DATE_FORMAT));
  274. setValue("expiryDate", date.format(INPUT_DATE_FORMAT));
  275. // field.onChange(date);
  276. }}
  277. inputRef={field.ref}
  278. slotProps={{
  279. textField: {
  280. // required: true,
  281. error: Boolean(errors.expiryDate?.message),
  282. helperText: errors.expiryDate?.message,
  283. },
  284. }}
  285. />
  286. </LocalizationProvider>
  287. );
  288. }}
  289. />
  290. </Grid>
  291. <Grid item xs={6}>
  292. <TextField
  293. label={t("receivedQty")}
  294. fullWidth
  295. {...register("receivedQty", {
  296. required: "receivedQty required!",
  297. })}
  298. disabled={true}
  299. />
  300. </Grid>
  301. <Grid item xs={6}>
  302. <TextField
  303. label={t("uom")}
  304. fullWidth
  305. {...register("uom.code", {
  306. required: "uom required!",
  307. })}
  308. // value={uom?.code}
  309. disabled={true}
  310. />
  311. </Grid>
  312. <Grid item xs={6}>
  313. <TextField
  314. label={t("acceptedQty")}
  315. fullWidth
  316. disabled={true}
  317. {...register("acceptedQty", {
  318. required: "acceptedQty required!",
  319. })}
  320. // disabled={true}
  321. // disabled={disabled}
  322. // error={Boolean(errors.acceptedQty)}
  323. // helperText={errors.acceptedQty?.message}
  324. />
  325. </Grid>
  326. {/* <Grid item xs={4}>
  327. <TextField
  328. label={t("acceptedWeight")}
  329. fullWidth
  330. // {...register("acceptedWeight", {
  331. // required: "acceptedWeight required!",
  332. // })}
  333. disabled={disabled}
  334. error={Boolean(errors.acceptedWeight)}
  335. helperText={errors.acceptedWeight?.message}
  336. />
  337. </Grid> */}
  338. </Grid>
  339. <Grid
  340. container
  341. justifyContent="flex-start"
  342. alignItems="flex-start"
  343. spacing={2}
  344. sx={{ mt: 0.5 }}
  345. >
  346. {/* <Grid item xs={12}>
  347. <InputDataGrid<PurchaseQCInput, PurchaseQcResult, EntryError>
  348. apiRef={apiRef}
  349. checkboxSelection={false}
  350. _formKey={"qcCheck"}
  351. columns={columns}
  352. validateRow={validationTest}
  353. />
  354. </Grid> */}
  355. </Grid>
  356. </Grid>
  357. );
  358. };
  359. export default StockInFormVer2;