FPSMS-frontend
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

427 regels
11 KiB

  1. "use client";
  2. import { CreateItemInputs } from "@/app/api/settings/item/actions";
  3. import {
  4. GridColDef,
  5. GridRowModel,
  6. GridRenderEditCellParams,
  7. GridEditInputCell,
  8. GridRowSelectionModel,
  9. useGridApiRef,
  10. } from "@mui/x-data-grid";
  11. import {
  12. MutableRefObject,
  13. useCallback,
  14. useEffect,
  15. useMemo,
  16. useState,
  17. } from "react";
  18. import { useFieldArray, useFormContext } from "react-hook-form";
  19. import { useTranslation } from "react-i18next";
  20. import InputDataGrid, { TableRow } from "../InputDataGrid/InputDataGrid";
  21. import { Box, Grid, Tooltip, Typography } from "@mui/material";
  22. import { ItemQc } from "@/app/api/settings/item";
  23. import { QcChecksInputs } from "@/app/api/settings/qcCheck/actions";
  24. import { GridApiCommunity } from "@mui/x-data-grid/internals";
  25. import { RiceBowl } from "@mui/icons-material";
  26. // import EditableSearchResults, { Column } from "@/components/SearchResults/EditableSearchResults";
  27. import { decimalFormatter } from "@/app/utils/formatUtil";
  28. import { GridRenderCellParams } from "@mui/x-data-grid";
  29. import {
  30. RoughProdScheduleLineResultByBom,
  31. RoughProdScheduleLineResultByBomByDate,
  32. RoughProdScheduleResult,
  33. ScheduleType,
  34. } from "@/app/api/scheduling";
  35. import ScheduleTable from "@/components/ScheduleTable";
  36. import { Column } from "@/components/ScheduleTable/ScheduleTable";
  37. type Props = {
  38. apiRef: MutableRefObject<GridApiCommunity>;
  39. isEdit: boolean;
  40. type: ScheduleType;
  41. dayPeriod: string[];
  42. };
  43. // export type FGRecord = {
  44. // id: string | number
  45. // code: string;
  46. // name: string;
  47. // inStockQty: number;
  48. // purchaseQty: number;
  49. // }
  50. // export type FGOverallRecord = {
  51. // id: string | number
  52. // code: string;
  53. // name: string;
  54. // type: string;
  55. // inStockQty: number;
  56. // purchaseQty: number;
  57. // purchaseQty1: number;
  58. // purchaseQty2: number;
  59. // purchaseQty3: number;
  60. // purchaseQty4: number;
  61. // purchaseQty5: number;
  62. // purchaseQty6: number;
  63. // purchaseQty7: number;
  64. // overallPurchaseQty: number;
  65. // }
  66. const ViewByBomDetails: React.FC<Props> = ({
  67. apiRef,
  68. isEdit,
  69. type,
  70. dayPeriod,
  71. }) => {
  72. const {
  73. t,
  74. i18n: { language },
  75. } = useTranslation("schedule");
  76. const {
  77. control,
  78. getValues,
  79. formState: { errors, defaultValues, touchedFields },
  80. } = useFormContext<RoughProdScheduleResult>();
  81. // const apiRef = useGridApiRef();
  82. const { fields } = useFieldArray({
  83. control,
  84. name: "prodScheduleLinesByBom",
  85. });
  86. const [pagingController, setPagingController] = useState([
  87. {
  88. pageNum: 1,
  89. pageSize: 10,
  90. totalCount: 0,
  91. },
  92. {
  93. pageNum: 1,
  94. pageSize: 10,
  95. totalCount: 0,
  96. },
  97. {
  98. pageNum: 1,
  99. pageSize: 10,
  100. totalCount: 0,
  101. },
  102. {
  103. pageNum: 1,
  104. pageSize: 10,
  105. totalCount: 0,
  106. },
  107. {
  108. pageNum: 1,
  109. pageSize: 10,
  110. totalCount: 0,
  111. },
  112. {
  113. pageNum: 1,
  114. pageSize: 10,
  115. totalCount: 0,
  116. },
  117. {
  118. pageNum: 1,
  119. pageSize: 10,
  120. totalCount: 0,
  121. },
  122. {
  123. pageNum: 1,
  124. pageSize: 10,
  125. totalCount: 0,
  126. },
  127. ]);
  128. const updatePagingController = (updatedObj: {
  129. pageNum: number;
  130. pageSize: number;
  131. totalCount: number;
  132. index?: number | undefined;
  133. }) => {
  134. setPagingController((prevState) => {
  135. return prevState.map((item, index) => {
  136. if (index === updatedObj?.index) {
  137. return {
  138. ...item,
  139. pageNum: item.pageNum,
  140. pageSize: item.pageSize,
  141. totalCount: item.totalCount,
  142. };
  143. } else return item;
  144. });
  145. });
  146. };
  147. const overallColumns = useMemo<Column<any>[]>(
  148. () => [
  149. {
  150. field: "code",
  151. label: t("code"),
  152. type: "read-only",
  153. // editable: true,
  154. },
  155. {
  156. field: "name",
  157. label: t("name"),
  158. type: "read-only",
  159. },
  160. {
  161. field: "type",
  162. label: t("type"),
  163. type: "read-only",
  164. renderCell: (params) => {
  165. return t(params.type);
  166. },
  167. // editable: true,
  168. },
  169. {
  170. field: "availableQty",
  171. label: t("Available Qty"),
  172. type: "read-only",
  173. style: {
  174. textAlign: "right",
  175. },
  176. renderCell: (row: RoughProdScheduleLineResultByBom) => {
  177. if (typeof row.availableQty == "number") {
  178. return decimalFormatter.format(row.availableQty);
  179. }
  180. return row.availableQty;
  181. },
  182. // editable: true,
  183. },
  184. {
  185. field: "totalDemandQty",
  186. label: t("Total Demand Qty"),
  187. type: "read-only",
  188. style: {
  189. textAlign: "right",
  190. },
  191. renderCell: (row: RoughProdScheduleLineResultByBom) => {
  192. if (typeof row.totalDemandQty == "number") {
  193. return decimalFormatter.format(row.totalDemandQty);
  194. }
  195. return row.totalDemandQty;
  196. },
  197. },
  198. {
  199. field: "demandQty1",
  200. label: t("Demand Qty (Day1)"),
  201. type: "read-only",
  202. style: {
  203. textAlign: "right",
  204. },
  205. renderCell: (row: RoughProdScheduleLineResultByBom) => {
  206. if (typeof row.demandQty1 == "number") {
  207. return decimalFormatter.format(row.demandQty1);
  208. }
  209. return row.demandQty1;
  210. },
  211. },
  212. {
  213. field: "demandQty2",
  214. label: t("Demand Qty (Day2)"),
  215. type: "read-only",
  216. style: {
  217. textAlign: "right",
  218. },
  219. renderCell: (row: RoughProdScheduleLineResultByBom) => {
  220. if (typeof row.demandQty2 == "number") {
  221. return decimalFormatter.format(row.demandQty2);
  222. }
  223. return row.demandQty2;
  224. },
  225. },
  226. {
  227. field: "demandQty3",
  228. label: t("Demand Qty (Day3)"),
  229. type: "read-only",
  230. style: {
  231. textAlign: "right",
  232. },
  233. renderCell: (row: RoughProdScheduleLineResultByBom) => {
  234. if (typeof row.demandQty3 == "number") {
  235. return decimalFormatter.format(row.demandQty3);
  236. }
  237. return row.demandQty3;
  238. },
  239. },
  240. {
  241. field: "demandQty4",
  242. label: t("Demand Qty (Day4)"),
  243. type: "read-only",
  244. style: {
  245. textAlign: "right",
  246. },
  247. renderCell: (row: RoughProdScheduleLineResultByBom) => {
  248. if (typeof row.demandQty4 == "number") {
  249. return decimalFormatter.format(row.demandQty4);
  250. }
  251. return row.demandQty4;
  252. },
  253. },
  254. {
  255. field: "demandQty5",
  256. label: t("Demand Qty (Day5)"),
  257. type: "read-only",
  258. style: {
  259. textAlign: "right",
  260. },
  261. renderCell: (row: RoughProdScheduleLineResultByBom) => {
  262. if (typeof row.demandQty5 == "number") {
  263. return decimalFormatter.format(row.demandQty5);
  264. }
  265. return row.demandQty5;
  266. },
  267. },
  268. {
  269. field: "demandQty6",
  270. label: t("Demand Qty (Day6)"),
  271. type: "read-only",
  272. style: {
  273. textAlign: "right",
  274. },
  275. renderCell: (row: RoughProdScheduleLineResultByBom) => {
  276. if (typeof row.demandQty6 == "number") {
  277. return decimalFormatter.format(row.demandQty6);
  278. }
  279. return row.demandQty6;
  280. },
  281. },
  282. {
  283. field: "demandQty7",
  284. label: t("Demand Qty (Day7)"),
  285. type: "read-only",
  286. style: {
  287. textAlign: "right",
  288. },
  289. renderCell: (row: RoughProdScheduleLineResultByBom) => {
  290. if (typeof row.demandQty7 == "number") {
  291. return decimalFormatter.format(row.demandQty7);
  292. }
  293. return row.demandQty7;
  294. },
  295. },
  296. {
  297. field: "uomName",
  298. label: t("UoM"),
  299. type: "read-only",
  300. style: {
  301. textAlign: "left",
  302. },
  303. renderCell: (row) => {
  304. return row.uomName;
  305. },
  306. },
  307. ],
  308. [t],
  309. );
  310. const columns = useMemo<Column<RoughProdScheduleLineResultByBomByDate>[]>(
  311. () => [
  312. {
  313. field: "code",
  314. label: t("code"),
  315. type: "read-only",
  316. // editable: true,
  317. },
  318. {
  319. field: "name",
  320. label: t("name"),
  321. type: "read-only",
  322. },
  323. {
  324. field: "type",
  325. label: t("type"),
  326. type: "read-only",
  327. renderCell: (params) => {
  328. return t(params.type);
  329. },
  330. },
  331. {
  332. field: "availableQty",
  333. label: t("Available Qty"),
  334. type: "read-only",
  335. // editable: true,
  336. style: {
  337. textAlign: "right",
  338. },
  339. renderCell: (row: RoughProdScheduleLineResultByBomByDate) => {
  340. if (typeof row.availableQty == "number") {
  341. return decimalFormatter.format(row.availableQty);
  342. }
  343. return row.availableQty;
  344. },
  345. },
  346. {
  347. field: "demandQty",
  348. label: t("Demand Qty"),
  349. type: "read-only",
  350. style: {
  351. textAlign: "right",
  352. },
  353. renderCell: (row: RoughProdScheduleLineResultByBomByDate) => {
  354. if (typeof row.demandQty == "number") {
  355. return decimalFormatter.format(row.demandQty);
  356. }
  357. return row.demandQty;
  358. },
  359. },
  360. {
  361. field: "uomName",
  362. label: t("UoM"),
  363. type: "read-only",
  364. style: {
  365. textAlign: "left",
  366. },
  367. renderCell: (row) => {
  368. return row.uomName;
  369. },
  370. },
  371. ],
  372. [],
  373. );
  374. return (
  375. <Grid container spacing={2}>
  376. <Grid item xs={12} key={"all"}>
  377. <Typography variant="overline" display="block" marginBlockEnd={1}>
  378. {t("Material Demand List (7 Days)")}
  379. </Typography>
  380. <ScheduleTable<RoughProdScheduleLineResultByBom>
  381. // index={7}
  382. type={type}
  383. items={getValues("prodScheduleLinesByBom")}
  384. columns={overallColumns}
  385. setPagingController={updatePagingController}
  386. pagingController={pagingController[7]}
  387. isAutoPaging={true}
  388. isEditable={false}
  389. isEdit={false}
  390. hasCollapse={false}
  391. />
  392. </Grid>
  393. {dayPeriod.map((date, index) => (
  394. <Grid item xs={12} key={index}>
  395. <Typography variant="overline" display="block" marginBlockEnd={1}>
  396. {`${t("Material Demand Date")}: ${date}`}
  397. </Typography>
  398. <ScheduleTable<RoughProdScheduleLineResultByBomByDate>
  399. // index={index}
  400. type={type}
  401. items={getValues("prodScheduleLinesByBomByDate")[index + 1]} // Use the corresponding records for the day
  402. columns={columns}
  403. setPagingController={updatePagingController}
  404. pagingController={pagingController[index]}
  405. isAutoPaging={true}
  406. isEditable={false}
  407. isEdit={isEdit}
  408. hasCollapse={false}
  409. />
  410. </Grid>
  411. ))}
  412. </Grid>
  413. );
  414. };
  415. export default ViewByBomDetails;