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.
 
 
 

162 rivejä
6.1 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, useMemo, useState} from "react";
  12. import { 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. type Props = {
  22. apiRef: MutableRefObject<GridApiCommunity>
  23. };
  24. type EntryError =
  25. | {
  26. [field in keyof QcChecksInputs]?: string;
  27. }
  28. | undefined;
  29. export type FGRecord = {
  30. id: string | number
  31. code: string;
  32. name: string;
  33. inStockQty: number;
  34. purchaseQty: number;
  35. }
  36. const ViewByBomDetails: React.FC<Props> = ({ apiRef, isEdit }) => {
  37. const {
  38. t,
  39. i18n: { language },
  40. } = useTranslation();
  41. const {
  42. formState: { errors, defaultValues, touchedFields },
  43. } = useFormContext<CreateItemInputs>();
  44. // const apiRef = useGridApiRef();
  45. const dayPeriod = [
  46. '2025-05-11',
  47. '2025-05-12',
  48. '2025-05-13',
  49. '2025-05-14',
  50. '2025-05-15',
  51. '2025-05-16',
  52. '2025-05-17',
  53. ];
  54. const fakeRecords = useMemo<FGRecord[][]>(
  55. () => [
  56. [
  57. { id: 1, code: "MH0040", name: "大豆油(1噸/桶)", inStockQty: 54.44 , purchaseQty: 544.4 },
  58. { id: 2, code: "GI3236", name: "清水(煮過牛腩)", inStockQty: 317.52 , purchaseQty: 3175.2 },
  59. { id: 3, code: "MG1700", name: "STERILTOM 意大利茄粒", inStockQty: 9.00 , purchaseQty: 90 },
  60. { id: 4, code: "FA0533", name: "乾蔥茸", inStockQty: 6.04 , purchaseQty: 60.4 },
  61. { id: 5, code: "FA0210", name: "薑茸", inStockQty: 6.04 , purchaseQty: 60.4 },
  62. { id: 6, code: "FA0608", name: "粗蒜茸", inStockQty: 6.04 , purchaseQty: 60.4 },
  63. { id: 7, code: "FA0056", name: "洋蔥肉", inStockQty: 241.98 , purchaseQty: 2419.8 },
  64. { id: 8, code: "PP1188", name: "咖喱膽", inStockQty: 36.00 , purchaseQty: 360 },
  65. { id: 9, code: "PP8001", name: "咖哩汁箱料粉", inStockQty: 77.42 , purchaseQty: 774.2 },
  66. { id: 10, code: "PP1096", name: "白麵撈", inStockQty: 60.00 , purchaseQty: 600 },
  67. { id: 10, code: "NA0476", name: "2磅份量三邊覆合袋 (0.1x225x260mm)個計", inStockQty: 600.00 , purchaseQty: 6000 },
  68. { id: 2, code: "MH0040", name: "大豆油(1噸/桶)", inStockQty: 0, purchaseQty: 20 },
  69. { id: 3, code: "FA0161", name: "洋蔥粒", inStockQty: 0, purchaseQty: 10 }
  70. ],
  71. [
  72. { id: 3, code: "mt3", name: "material 3", inStockQty: 30, purchaseQty: 3 },
  73. { id: 4, code: "mt4", name: "material 4", inStockQty: 40, purchaseQty: 499 },
  74. ],
  75. [
  76. { id: 5, code: "mt5", name: "material 5", inStockQty: 50, purchaseQty: 5 },
  77. { id: 6, code: "mt6", name: "material 6", inStockQty: 60, purchaseQty: 699 },
  78. ],
  79. [
  80. { id: 7, code: "mt7", name: "material 7", inStockQty: 70, purchaseQty: 7 },
  81. { id: 8, code: "mt8", name: "material 8", inStockQty: 80, purchaseQty: 899 },
  82. ],
  83. [
  84. { id: 9, code: "mt9", name: "material 9", inStockQty: 90, purchaseQty: 9 },
  85. { id: 10, code: "mt10", name: "material 10", inStockQty: 100, purchaseQty: 999 },
  86. ],
  87. [
  88. { id: 11, code: "mt11", name: "material 11", inStockQty: 110, purchaseQty: 11 },
  89. { id: 12, code: "mt12", name: "material 12", inStockQty: 120, purchaseQty: 1299 },
  90. ],
  91. [
  92. { id: 13, code: "mt13", name: "material 13", inStockQty: 130, purchaseQty: 13 },
  93. { id: 14, code: "mt14", name: "material 14", inStockQty: 140, purchaseQty: 1499 },
  94. ],
  95. ],
  96. []
  97. );
  98. const [pagingController, setPagingController] = useState({
  99. pageNum: 1,
  100. pageSize: 10,
  101. totalCount: 0,
  102. })
  103. const columns = useMemo<Column<any>[]>(
  104. () => [
  105. {
  106. field: "name",
  107. label: "name",
  108. type: 'read-only',
  109. },
  110. {
  111. field: "code",
  112. label: "code",
  113. type: 'read-only',
  114. // editable: true,
  115. },
  116. {
  117. field: "inStockQty",
  118. label: "In Stock Amount",
  119. type: 'read-only',
  120. // editable: true,
  121. },
  122. {
  123. field: "purchaseQty",
  124. label: "Purchase Qty",
  125. type: 'read-only',
  126. },
  127. ],
  128. []
  129. );
  130. return (
  131. <Grid container spacing={2}>
  132. {dayPeriod.map((date, index) => (
  133. <Grid item xs={12} key={index}>
  134. <Typography variant="overline" display="block" marginBlockEnd={1}>
  135. {date}
  136. </Typography>
  137. <EditableSearchResults<FGRecord>
  138. items={fakeRecords[index]} // Use the corresponding records for the day
  139. columns={columns}
  140. setPagingController={setPagingController}
  141. pagingController={pagingController}
  142. isAutoPaging={false}
  143. isHideButton={true}
  144. isEdit={isEdit}
  145. />
  146. </Grid>
  147. ))}
  148. </Grid>
  149. );
  150. };
  151. export default ViewByBomDetails;