FPSMS-frontend
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。
 
 
 

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