FPSMS-frontend
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 

1320 行
31 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 { 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, {
  27. Column,
  28. } from "@/components/SearchResults/EditableSearchResults";
  29. import { decimalFormatter } from "@/app/utils/formatUtil";
  30. import { GridRenderCellParams } from "@mui/x-data-grid";
  31. type Props = {
  32. apiRef: MutableRefObject<GridApiCommunity>
  33. isEdit: boolean
  34. };
  35. type EntryError =
  36. | {
  37. [field in keyof QcChecksInputs]?: string;
  38. }
  39. | undefined;
  40. export type FGRecord = {
  41. id: string | number;
  42. code: string;
  43. name: string;
  44. inStockQty: number;
  45. purchaseQty: number;
  46. };
  47. export type FGOverallRecord = {
  48. id: string | number;
  49. code: string;
  50. name: string;
  51. type: string;
  52. inStockQty: number;
  53. purchaseQty: number;
  54. purchaseQty1: number;
  55. purchaseQty2: number;
  56. purchaseQty3: number;
  57. purchaseQty4: number;
  58. purchaseQty5: number;
  59. purchaseQty6: number;
  60. purchaseQty7: number;
  61. overallPurchaseQty: number;
  62. };
  63. const ViewByBomDetails: React.FC<Props> = ({ apiRef, isEdit }) => {
  64. const {
  65. t,
  66. i18n: { language },
  67. } = useTranslation("schedule");
  68. const {
  69. formState: { errors, defaultValues, touchedFields },
  70. } = useFormContext<CreateItemInputs>();
  71. // const apiRef = useGridApiRef();
  72. const dayPeriod = [
  73. "2025-05-11",
  74. "2025-05-12",
  75. "2025-05-13",
  76. "2025-05-14",
  77. "2025-05-15",
  78. "2025-05-16",
  79. "2025-05-17",
  80. ];
  81. const fakeRecords = useMemo<FGRecord[][]>(
  82. () => [
  83. [
  84. {
  85. id: 1,
  86. code: "MH0040",
  87. type: "Material",
  88. name: "大豆油(1噸/桶)",
  89. inStockQty: 54.44,
  90. purchaseQty: 972.12,
  91. },
  92. {
  93. id: 2,
  94. code: "GI3236",
  95. type: "Material",
  96. name: "清水(煮過牛腩)",
  97. inStockQty: 317.52,
  98. purchaseQty: 3175.2,
  99. },
  100. {
  101. id: 3,
  102. code: "MG1700",
  103. type: "Material",
  104. name: "STERILTOM 意大利茄粒",
  105. inStockQty: 9.0,
  106. purchaseQty: 90,
  107. },
  108. {
  109. id: 4,
  110. code: "FA0533",
  111. type: "Material",
  112. name: "乾蔥茸",
  113. inStockQty: 6.04,
  114. purchaseQty: 60.4,
  115. },
  116. {
  117. id: 5,
  118. code: "FA0210",
  119. type: "Material",
  120. name: "薑茸",
  121. inStockQty: 6.04,
  122. purchaseQty: 66.45,
  123. },
  124. {
  125. id: 6,
  126. code: "FA0608",
  127. type: "Material",
  128. name: "粗蒜茸",
  129. inStockQty: 6.04,
  130. purchaseQty: 78.55,
  131. },
  132. {
  133. id: 7,
  134. code: "FA0056",
  135. type: "Material",
  136. name: "洋蔥肉",
  137. inStockQty: 241.98,
  138. purchaseQty: 2419.8,
  139. },
  140. {
  141. id: 8,
  142. code: "PP1188",
  143. type: "Material",
  144. name: "咖喱膽",
  145. inStockQty: 36.0,
  146. purchaseQty: 0,
  147. },
  148. {
  149. id: 9,
  150. code: "PP8001",
  151. type: "Material",
  152. name: "咖哩汁箱料粉",
  153. inStockQty: 77.42,
  154. purchaseQty: 774.2,
  155. },
  156. {
  157. id: 10,
  158. code: "PP1096",
  159. type: "Material",
  160. name: "白麵撈",
  161. inStockQty: 60.0,
  162. purchaseQty: 0,
  163. },
  164. {
  165. id: 11,
  166. code: "NA0476",
  167. type: "Material",
  168. name: "2磅份量三邊覆合袋 (0.1x225x260mm)個計",
  169. inStockQty: 600.0,
  170. purchaseQty: 6000,
  171. },
  172. {
  173. id: 12,
  174. code: "MH0040",
  175. type: "Material",
  176. name: "大豆油(1噸/桶)",
  177. inStockQty: 0,
  178. purchaseQty: 972.12,
  179. },
  180. {
  181. id: 13,
  182. code: "FA0161",
  183. type: "Material",
  184. name: "洋蔥粒",
  185. inStockQty: 0,
  186. purchaseQty: 28.15,
  187. },
  188. {
  189. id: 14,
  190. code: "MG1288",
  191. type: "Material",
  192. name: "炸紅蔥頭",
  193. inStockQty: 0,
  194. purchaseQty: 6.05,
  195. },
  196. {
  197. id: 15,
  198. code: "MG0066",
  199. type: "Material",
  200. name: "咖哩料(5斤x16包+2斤/包)",
  201. inStockQty: 0,
  202. purchaseQty: 241.98,
  203. },
  204. {
  205. id: 16,
  206. code: "MH0040",
  207. type: "Material",
  208. name: "星加坡綠富貴花牌幼白麵粉 (50磅/包)",
  209. inStockQty: 0,
  210. purchaseQty: 250.0,
  211. },
  212. ],
  213. [
  214. {
  215. id: 1,
  216. code: "MH0040",
  217. type: "Material",
  218. name: "大豆油(1噸/桶)",
  219. inStockQty: 54.44,
  220. purchaseQty: 972.12,
  221. },
  222. {
  223. id: 2,
  224. code: "GI3236",
  225. type: "Material",
  226. name: "清水(煮過牛腩)",
  227. inStockQty: 317.52,
  228. purchaseQty: 3175.2,
  229. },
  230. {
  231. id: 3,
  232. code: "MG1700",
  233. type: "Material",
  234. name: "STERILTOM 意大利茄粒",
  235. inStockQty: 9.0,
  236. purchaseQty: 90,
  237. },
  238. {
  239. id: 4,
  240. code: "FA0533",
  241. type: "Material",
  242. name: "乾蔥茸",
  243. inStockQty: 6.04,
  244. purchaseQty: 60.4,
  245. },
  246. {
  247. id: 5,
  248. code: "FA0210",
  249. type: "Material",
  250. name: "薑茸",
  251. inStockQty: 6.04,
  252. purchaseQty: 66.45,
  253. },
  254. {
  255. id: 6,
  256. code: "FA0608",
  257. type: "Material",
  258. name: "粗蒜茸",
  259. inStockQty: 6.04,
  260. purchaseQty: 78.55,
  261. },
  262. {
  263. id: 7,
  264. code: "FA0056",
  265. type: "Material",
  266. name: "洋蔥肉",
  267. inStockQty: 241.98,
  268. purchaseQty: 2419.8,
  269. },
  270. {
  271. id: 8,
  272. code: "PP1188",
  273. type: "Material",
  274. name: "咖喱膽",
  275. inStockQty: 36.0,
  276. purchaseQty: 0,
  277. },
  278. {
  279. id: 9,
  280. code: "PP8001",
  281. type: "Material",
  282. name: "咖哩汁箱料粉",
  283. inStockQty: 77.42,
  284. purchaseQty: 774.2,
  285. },
  286. {
  287. id: 10,
  288. code: "PP1096",
  289. type: "Material",
  290. name: "白麵撈",
  291. inStockQty: 60.0,
  292. purchaseQty: 0,
  293. },
  294. {
  295. id: 11,
  296. code: "NA0476",
  297. type: "Material",
  298. name: "2磅份量三邊覆合袋 (0.1x225x260mm)個計",
  299. inStockQty: 600.0,
  300. purchaseQty: 6000,
  301. },
  302. {
  303. id: 12,
  304. code: "MH0040",
  305. type: "Material",
  306. name: "大豆油(1噸/桶)",
  307. inStockQty: 0,
  308. purchaseQty: 972.12,
  309. },
  310. {
  311. id: 13,
  312. code: "FA0161",
  313. type: "Material",
  314. name: "洋蔥粒",
  315. inStockQty: 0,
  316. purchaseQty: 28.15,
  317. },
  318. {
  319. id: 14,
  320. code: "MG1288",
  321. type: "Material",
  322. name: "炸紅蔥頭",
  323. inStockQty: 0,
  324. purchaseQty: 6.05,
  325. },
  326. {
  327. id: 15,
  328. code: "MG0066",
  329. type: "Material",
  330. name: "咖哩料(5斤x16包+2斤/包)",
  331. inStockQty: 0,
  332. purchaseQty: 241.98,
  333. },
  334. {
  335. id: 16,
  336. code: "MH0040",
  337. type: "Material",
  338. name: "星加坡綠富貴花牌幼白麵粉 (50磅/包)",
  339. inStockQty: 0,
  340. purchaseQty: 250.0,
  341. },
  342. ],
  343. [
  344. {
  345. id: 1,
  346. code: "MH0040",
  347. type: "Material",
  348. name: "大豆油(1噸/桶)",
  349. inStockQty: 54.44,
  350. purchaseQty: 972.12,
  351. },
  352. {
  353. id: 2,
  354. code: "GI3236",
  355. type: "Material",
  356. name: "清水(煮過牛腩)",
  357. inStockQty: 317.52,
  358. purchaseQty: 3175.2,
  359. },
  360. {
  361. id: 3,
  362. code: "MG1700",
  363. type: "Material",
  364. name: "STERILTOM 意大利茄粒",
  365. inStockQty: 9.0,
  366. purchaseQty: 90,
  367. },
  368. {
  369. id: 4,
  370. code: "FA0533",
  371. type: "Material",
  372. name: "乾蔥茸",
  373. inStockQty: 6.04,
  374. purchaseQty: 60.4,
  375. },
  376. {
  377. id: 5,
  378. code: "FA0210",
  379. type: "Material",
  380. name: "薑茸",
  381. inStockQty: 6.04,
  382. purchaseQty: 66.45,
  383. },
  384. {
  385. id: 6,
  386. code: "FA0608",
  387. type: "Material",
  388. name: "粗蒜茸",
  389. inStockQty: 6.04,
  390. purchaseQty: 78.55,
  391. },
  392. {
  393. id: 7,
  394. code: "FA0056",
  395. type: "Material",
  396. name: "洋蔥肉",
  397. inStockQty: 241.98,
  398. purchaseQty: 2419.8,
  399. },
  400. {
  401. id: 8,
  402. code: "PP1188",
  403. type: "Material",
  404. name: "咖喱膽",
  405. inStockQty: 36.0,
  406. purchaseQty: 0,
  407. },
  408. {
  409. id: 9,
  410. code: "PP8001",
  411. type: "Material",
  412. name: "咖哩汁箱料粉",
  413. inStockQty: 77.42,
  414. purchaseQty: 774.2,
  415. },
  416. {
  417. id: 10,
  418. code: "PP1096",
  419. type: "Material",
  420. name: "白麵撈",
  421. inStockQty: 60.0,
  422. purchaseQty: 0,
  423. },
  424. {
  425. id: 11,
  426. code: "NA0476",
  427. type: "Material",
  428. name: "2磅份量三邊覆合袋 (0.1x225x260mm)個計",
  429. inStockQty: 600.0,
  430. purchaseQty: 6000,
  431. },
  432. {
  433. id: 12,
  434. code: "MH0040",
  435. type: "Material",
  436. name: "大豆油(1噸/桶)",
  437. inStockQty: 0,
  438. purchaseQty: 972.12,
  439. },
  440. {
  441. id: 13,
  442. code: "FA0161",
  443. type: "Material",
  444. name: "洋蔥粒",
  445. inStockQty: 0,
  446. purchaseQty: 28.15,
  447. },
  448. {
  449. id: 14,
  450. code: "MG1288",
  451. type: "Material",
  452. name: "炸紅蔥頭",
  453. inStockQty: 0,
  454. purchaseQty: 6.05,
  455. },
  456. {
  457. id: 15,
  458. code: "MG0066",
  459. type: "Material",
  460. name: "咖哩料(5斤x16包+2斤/包)",
  461. inStockQty: 0,
  462. purchaseQty: 241.98,
  463. },
  464. {
  465. id: 16,
  466. code: "MH0040",
  467. type: "Material",
  468. name: "星加坡綠富貴花牌幼白麵粉 (50磅/包)",
  469. inStockQty: 0,
  470. purchaseQty: 250.0,
  471. },
  472. ],
  473. [
  474. {
  475. id: 1,
  476. code: "MH0040",
  477. type: "Material",
  478. name: "大豆油(1噸/桶)",
  479. inStockQty: 54.44,
  480. purchaseQty: 972.12,
  481. },
  482. {
  483. id: 2,
  484. code: "GI3236",
  485. type: "Material",
  486. name: "清水(煮過牛腩)",
  487. inStockQty: 317.52,
  488. purchaseQty: 3175.2,
  489. },
  490. {
  491. id: 3,
  492. code: "MG1700",
  493. type: "Material",
  494. name: "STERILTOM 意大利茄粒",
  495. inStockQty: 9.0,
  496. purchaseQty: 90,
  497. },
  498. {
  499. id: 4,
  500. code: "FA0533",
  501. type: "Material",
  502. name: "乾蔥茸",
  503. inStockQty: 6.04,
  504. purchaseQty: 60.4,
  505. },
  506. {
  507. id: 5,
  508. code: "FA0210",
  509. type: "Material",
  510. name: "薑茸",
  511. inStockQty: 6.04,
  512. purchaseQty: 66.45,
  513. },
  514. {
  515. id: 6,
  516. code: "FA0608",
  517. type: "Material",
  518. name: "粗蒜茸",
  519. inStockQty: 6.04,
  520. purchaseQty: 78.55,
  521. },
  522. {
  523. id: 7,
  524. code: "FA0056",
  525. type: "Material",
  526. name: "洋蔥肉",
  527. inStockQty: 241.98,
  528. purchaseQty: 2419.8,
  529. },
  530. {
  531. id: 8,
  532. code: "PP1188",
  533. type: "Material",
  534. name: "咖喱膽",
  535. inStockQty: 36.0,
  536. purchaseQty: 0,
  537. },
  538. {
  539. id: 9,
  540. code: "PP8001",
  541. type: "Material",
  542. name: "咖哩汁箱料粉",
  543. inStockQty: 77.42,
  544. purchaseQty: 774.2,
  545. },
  546. {
  547. id: 10,
  548. code: "PP1096",
  549. type: "Material",
  550. name: "白麵撈",
  551. inStockQty: 60.0,
  552. purchaseQty: 0,
  553. },
  554. {
  555. id: 11,
  556. code: "NA0476",
  557. type: "Material",
  558. name: "2磅份量三邊覆合袋 (0.1x225x260mm)個計",
  559. inStockQty: 600.0,
  560. purchaseQty: 6000,
  561. },
  562. {
  563. id: 12,
  564. code: "MH0040",
  565. type: "Material",
  566. name: "大豆油(1噸/桶)",
  567. inStockQty: 0,
  568. purchaseQty: 972.12,
  569. },
  570. {
  571. id: 13,
  572. code: "FA0161",
  573. type: "Material",
  574. name: "洋蔥粒",
  575. inStockQty: 0,
  576. purchaseQty: 28.15,
  577. },
  578. {
  579. id: 14,
  580. code: "MG1288",
  581. type: "Material",
  582. name: "炸紅蔥頭",
  583. inStockQty: 0,
  584. purchaseQty: 6.05,
  585. },
  586. {
  587. id: 15,
  588. code: "MG0066",
  589. type: "Material",
  590. name: "咖哩料(5斤x16包+2斤/包)",
  591. inStockQty: 0,
  592. purchaseQty: 241.98,
  593. },
  594. {
  595. id: 16,
  596. code: "MH0040",
  597. type: "Material",
  598. name: "星加坡綠富貴花牌幼白麵粉 (50磅/包)",
  599. inStockQty: 0,
  600. purchaseQty: 250.0,
  601. },
  602. ],
  603. [
  604. {
  605. id: 1,
  606. code: "MH0040",
  607. type: "Material",
  608. name: "大豆油(1噸/桶)",
  609. inStockQty: 54.44,
  610. purchaseQty: 972.12,
  611. },
  612. {
  613. id: 2,
  614. code: "GI3236",
  615. type: "Material",
  616. name: "清水(煮過牛腩)",
  617. inStockQty: 317.52,
  618. purchaseQty: 3175.2,
  619. },
  620. {
  621. id: 3,
  622. code: "MG1700",
  623. type: "Material",
  624. name: "STERILTOM 意大利茄粒",
  625. inStockQty: 9.0,
  626. purchaseQty: 90,
  627. },
  628. {
  629. id: 4,
  630. code: "FA0533",
  631. type: "Material",
  632. name: "乾蔥茸",
  633. inStockQty: 6.04,
  634. purchaseQty: 60.4,
  635. },
  636. {
  637. id: 5,
  638. code: "FA0210",
  639. type: "Material",
  640. name: "薑茸",
  641. inStockQty: 6.04,
  642. purchaseQty: 66.45,
  643. },
  644. {
  645. id: 6,
  646. code: "FA0608",
  647. type: "Material",
  648. name: "粗蒜茸",
  649. inStockQty: 6.04,
  650. purchaseQty: 78.55,
  651. },
  652. {
  653. id: 7,
  654. code: "FA0056",
  655. type: "Material",
  656. name: "洋蔥肉",
  657. inStockQty: 241.98,
  658. purchaseQty: 2419.8,
  659. },
  660. {
  661. id: 8,
  662. code: "PP1188",
  663. type: "Material",
  664. name: "咖喱膽",
  665. inStockQty: 36.0,
  666. purchaseQty: 0,
  667. },
  668. {
  669. id: 9,
  670. code: "PP8001",
  671. type: "Material",
  672. name: "咖哩汁箱料粉",
  673. inStockQty: 77.42,
  674. purchaseQty: 774.2,
  675. },
  676. {
  677. id: 10,
  678. code: "PP1096",
  679. type: "Material",
  680. name: "白麵撈",
  681. inStockQty: 60.0,
  682. purchaseQty: 0,
  683. },
  684. {
  685. id: 11,
  686. code: "NA0476",
  687. type: "Material",
  688. name: "2磅份量三邊覆合袋 (0.1x225x260mm)個計",
  689. inStockQty: 600.0,
  690. purchaseQty: 6000,
  691. },
  692. {
  693. id: 12,
  694. code: "MH0040",
  695. type: "Material",
  696. name: "大豆油(1噸/桶)",
  697. inStockQty: 0,
  698. purchaseQty: 972.12,
  699. },
  700. {
  701. id: 13,
  702. code: "FA0161",
  703. type: "Material",
  704. name: "洋蔥粒",
  705. inStockQty: 0,
  706. purchaseQty: 28.15,
  707. },
  708. {
  709. id: 14,
  710. code: "MG1288",
  711. type: "Material",
  712. name: "炸紅蔥頭",
  713. inStockQty: 0,
  714. purchaseQty: 6.05,
  715. },
  716. {
  717. id: 15,
  718. code: "MG0066",
  719. type: "Material",
  720. name: "咖哩料(5斤x16包+2斤/包)",
  721. inStockQty: 0,
  722. purchaseQty: 241.98,
  723. },
  724. {
  725. id: 16,
  726. code: "MH0040",
  727. type: "Material",
  728. name: "星加坡綠富貴花牌幼白麵粉 (50磅/包)",
  729. inStockQty: 0,
  730. purchaseQty: 250.0,
  731. },
  732. ],
  733. [
  734. {
  735. id: 1,
  736. code: "MH0040",
  737. type: "Material",
  738. name: "大豆油(1噸/桶)",
  739. inStockQty: 54.44,
  740. purchaseQty: 972.12,
  741. },
  742. {
  743. id: 2,
  744. code: "GI3236",
  745. type: "Material",
  746. name: "清水(煮過牛腩)",
  747. inStockQty: 317.52,
  748. purchaseQty: 3175.2,
  749. },
  750. {
  751. id: 3,
  752. code: "MG1700",
  753. type: "Material",
  754. name: "STERILTOM 意大利茄粒",
  755. inStockQty: 9.0,
  756. purchaseQty: 90,
  757. },
  758. {
  759. id: 4,
  760. code: "FA0533",
  761. type: "Material",
  762. name: "乾蔥茸",
  763. inStockQty: 6.04,
  764. purchaseQty: 60.4,
  765. },
  766. {
  767. id: 5,
  768. code: "FA0210",
  769. type: "Material",
  770. name: "薑茸",
  771. inStockQty: 6.04,
  772. purchaseQty: 66.45,
  773. },
  774. {
  775. id: 6,
  776. code: "FA0608",
  777. type: "Material",
  778. name: "粗蒜茸",
  779. inStockQty: 6.04,
  780. purchaseQty: 78.55,
  781. },
  782. {
  783. id: 7,
  784. code: "FA0056",
  785. type: "Material",
  786. name: "洋蔥肉",
  787. inStockQty: 241.98,
  788. purchaseQty: 2419.8,
  789. },
  790. {
  791. id: 8,
  792. code: "PP1188",
  793. type: "Material",
  794. name: "咖喱膽",
  795. inStockQty: 36.0,
  796. purchaseQty: 0,
  797. },
  798. {
  799. id: 9,
  800. code: "PP8001",
  801. type: "Material",
  802. name: "咖哩汁箱料粉",
  803. inStockQty: 77.42,
  804. purchaseQty: 774.2,
  805. },
  806. {
  807. id: 10,
  808. code: "PP1096",
  809. type: "Material",
  810. name: "白麵撈",
  811. inStockQty: 60.0,
  812. purchaseQty: 0,
  813. },
  814. {
  815. id: 11,
  816. code: "NA0476",
  817. type: "Material",
  818. name: "2磅份量三邊覆合袋 (0.1x225x260mm)個計",
  819. inStockQty: 600.0,
  820. purchaseQty: 6000,
  821. },
  822. {
  823. id: 12,
  824. code: "MH0040",
  825. type: "Material",
  826. name: "大豆油(1噸/桶)",
  827. inStockQty: 0,
  828. purchaseQty: 972.12,
  829. },
  830. {
  831. id: 13,
  832. code: "FA0161",
  833. type: "Material",
  834. name: "洋蔥粒",
  835. inStockQty: 0,
  836. purchaseQty: 28.15,
  837. },
  838. {
  839. id: 14,
  840. code: "MG1288",
  841. type: "Material",
  842. name: "炸紅蔥頭",
  843. inStockQty: 0,
  844. purchaseQty: 6.05,
  845. },
  846. {
  847. id: 15,
  848. code: "MG0066",
  849. type: "Material",
  850. name: "咖哩料(5斤x16包+2斤/包)",
  851. inStockQty: 0,
  852. purchaseQty: 241.98,
  853. },
  854. {
  855. id: 16,
  856. code: "MH0040",
  857. type: "Material",
  858. name: "星加坡綠富貴花牌幼白麵粉 (50磅/包)",
  859. inStockQty: 0,
  860. purchaseQty: 250.0,
  861. },
  862. ],
  863. [
  864. {
  865. id: 1,
  866. code: "MH0040",
  867. type: "Material",
  868. name: "大豆油(1噸/桶)",
  869. inStockQty: 54.44,
  870. purchaseQty: 972.12,
  871. },
  872. {
  873. id: 2,
  874. code: "GI3236",
  875. type: "Material",
  876. name: "清水(煮過牛腩)",
  877. inStockQty: 317.52,
  878. purchaseQty: 3175.2,
  879. },
  880. {
  881. id: 3,
  882. code: "MG1700",
  883. type: "Material",
  884. name: "STERILTOM 意大利茄粒",
  885. inStockQty: 9.0,
  886. purchaseQty: 90,
  887. },
  888. {
  889. id: 4,
  890. code: "FA0533",
  891. type: "Material",
  892. name: "乾蔥茸",
  893. inStockQty: 6.04,
  894. purchaseQty: 60.4,
  895. },
  896. {
  897. id: 5,
  898. code: "FA0210",
  899. type: "Material",
  900. name: "薑茸",
  901. inStockQty: 6.04,
  902. purchaseQty: 66.45,
  903. },
  904. {
  905. id: 6,
  906. code: "FA0608",
  907. type: "Material",
  908. name: "粗蒜茸",
  909. inStockQty: 6.04,
  910. purchaseQty: 78.55,
  911. },
  912. {
  913. id: 7,
  914. code: "FA0056",
  915. type: "Material",
  916. name: "洋蔥肉",
  917. inStockQty: 241.98,
  918. purchaseQty: 2419.8,
  919. },
  920. {
  921. id: 8,
  922. code: "PP1188",
  923. type: "Material",
  924. name: "咖喱膽",
  925. inStockQty: 36.0,
  926. purchaseQty: 0,
  927. },
  928. {
  929. id: 9,
  930. code: "PP8001",
  931. type: "Material",
  932. name: "咖哩汁箱料粉",
  933. inStockQty: 77.42,
  934. purchaseQty: 774.2,
  935. },
  936. {
  937. id: 10,
  938. code: "PP1096",
  939. type: "Material",
  940. name: "白麵撈",
  941. inStockQty: 60.0,
  942. purchaseQty: 0,
  943. },
  944. {
  945. id: 11,
  946. code: "NA0476",
  947. type: "Material",
  948. name: "2磅份量三邊覆合袋 (0.1x225x260mm)個計",
  949. inStockQty: 600.0,
  950. purchaseQty: 6000,
  951. },
  952. {
  953. id: 12,
  954. code: "MH0040",
  955. type: "Material",
  956. name: "大豆油(1噸/桶)",
  957. inStockQty: 0,
  958. purchaseQty: 972.12,
  959. },
  960. {
  961. id: 13,
  962. code: "FA0161",
  963. type: "Material",
  964. name: "洋蔥粒",
  965. inStockQty: 0,
  966. purchaseQty: 28.15,
  967. },
  968. {
  969. id: 14,
  970. code: "MG1288",
  971. type: "Material",
  972. name: "炸紅蔥頭",
  973. inStockQty: 0,
  974. purchaseQty: 6.05,
  975. },
  976. {
  977. id: 15,
  978. code: "MG0066",
  979. type: "Material",
  980. name: "咖哩料(5斤x16包+2斤/包)",
  981. inStockQty: 0,
  982. purchaseQty: 241.98,
  983. },
  984. {
  985. id: 16,
  986. code: "MH0040",
  987. type: "Material",
  988. name: "星加坡綠富貴花牌幼白麵粉 (50磅/包)",
  989. inStockQty: 0,
  990. purchaseQty: 250.0,
  991. },
  992. ],
  993. ],
  994. [],
  995. );
  996. const updatePagingController = (updatedObj: { index: number, pageNum: number, pageSize: number, totalCount: number }) => {
  997. setPagingController((prevState) => {
  998. return prevState.map((item, index) => {
  999. if (index === updatedObj?.index){
  1000. return {
  1001. ...item,
  1002. pageNum: item.pageNum,
  1003. pageSize: item.pageSize,
  1004. totalCount: item.totalCount,
  1005. };
  1006. }
  1007. else
  1008. return item
  1009. });
  1010. });
  1011. };
  1012. const [pagingController, setPagingController] = useState([
  1013. {
  1014. pageNum: 1,
  1015. pageSize: 10,
  1016. totalCount: 0,
  1017. },
  1018. {
  1019. pageNum: 1,
  1020. pageSize: 10,
  1021. totalCount: 0,
  1022. },
  1023. {
  1024. pageNum: 1,
  1025. pageSize: 10,
  1026. totalCount: 0,
  1027. },
  1028. {
  1029. pageNum: 1,
  1030. pageSize: 10,
  1031. totalCount: 0,
  1032. },
  1033. {
  1034. pageNum: 1,
  1035. pageSize: 10,
  1036. totalCount: 0,
  1037. },
  1038. {
  1039. pageNum: 1,
  1040. pageSize: 10,
  1041. totalCount: 0,
  1042. },
  1043. {
  1044. pageNum: 1,
  1045. pageSize: 10,
  1046. totalCount: 0,
  1047. },
  1048. {
  1049. pageNum: 1,
  1050. pageSize: 10,
  1051. totalCount: 0,
  1052. },
  1053. ]);
  1054. const updatePagingController = (updatedObj) => {
  1055. setPagingController((prevState) => {
  1056. return prevState.map((item, index) => {
  1057. if (index === updatedObj?.index) {
  1058. return {
  1059. ...item,
  1060. pageNum: item.pageNum,
  1061. pageSize: item.pageSize,
  1062. totalCount: item.totalCount,
  1063. };
  1064. } else return item;
  1065. });
  1066. });
  1067. };
  1068. const overallColumns = useMemo<Column<any>[]>(
  1069. () => [
  1070. {
  1071. field: "code",
  1072. label: t("code"),
  1073. type: "read-only",
  1074. // editable: true,
  1075. },
  1076. {
  1077. field: "name",
  1078. label: t("name"),
  1079. type: "read-only",
  1080. },
  1081. {
  1082. field: "type",
  1083. label: t("type"),
  1084. type: "read-only",
  1085. // editable: true,
  1086. },
  1087. {
  1088. field: "inStockQty",
  1089. label: t("Available Qty"),
  1090. type: "read-only",
  1091. style: {
  1092. textAlign: "right",
  1093. },
  1094. renderCell: (row: FGOverallRecord) => {
  1095. if (typeof row.inStockQty == "number") {
  1096. return decimalFormatter.format(row.inStockQty);
  1097. }
  1098. return row.inStockQty;
  1099. },
  1100. // editable: true,
  1101. },
  1102. {
  1103. field: "overallPurchaseQty",
  1104. label: t("Total Demand Qty"),
  1105. type: "read-only",
  1106. style: {
  1107. textAlign: "right",
  1108. },
  1109. renderCell: (row: FGOverallRecord) => {
  1110. if (typeof row.overallPurchaseQty == "number") {
  1111. return decimalFormatter.format(row.overallPurchaseQty);
  1112. }
  1113. return row.overallPurchaseQty;
  1114. },
  1115. },
  1116. {
  1117. field: "purchaseQty1",
  1118. label: t("Demand Qty (Day1)"),
  1119. type: "read-only",
  1120. style: {
  1121. textAlign: "right",
  1122. },
  1123. renderCell: (row: FGOverallRecord) => {
  1124. if (typeof row.purchaseQty1 == "number") {
  1125. return decimalFormatter.format(row.purchaseQty1);
  1126. }
  1127. return row.purchaseQty1;
  1128. },
  1129. },
  1130. {
  1131. field: "purchaseQty2",
  1132. label: t("Demand Qty (Day2)"),
  1133. type: "read-only",
  1134. style: {
  1135. textAlign: "right",
  1136. },
  1137. renderCell: (row: FGOverallRecord) => {
  1138. if (typeof row.purchaseQty2 == "number") {
  1139. return decimalFormatter.format(row.purchaseQty2);
  1140. }
  1141. return row.purchaseQty2;
  1142. },
  1143. },
  1144. {
  1145. field: "purchaseQty3",
  1146. label: t("Demand Qty (Day3)"),
  1147. type: "read-only",
  1148. style: {
  1149. textAlign: "right",
  1150. },
  1151. renderCell: (row: FGOverallRecord) => {
  1152. if (typeof row.purchaseQty3 == "number") {
  1153. return decimalFormatter.format(row.purchaseQty3);
  1154. }
  1155. return row.purchaseQty3;
  1156. },
  1157. },
  1158. {
  1159. field: "purchaseQty4",
  1160. label: t("Demand Qty (Day4)"),
  1161. type: "read-only",
  1162. style: {
  1163. textAlign: "right",
  1164. },
  1165. renderCell: (row: FGOverallRecord) => {
  1166. if (typeof row.purchaseQty4 == "number") {
  1167. return decimalFormatter.format(row.purchaseQty4);
  1168. }
  1169. return row.purchaseQty4;
  1170. },
  1171. },
  1172. {
  1173. field: "purchaseQty5",
  1174. label: t("Demand Qty (Day5)"),
  1175. type: "read-only",
  1176. style: {
  1177. textAlign: "right",
  1178. },
  1179. renderCell: (row: FGOverallRecord) => {
  1180. if (typeof row.purchaseQty5 == "number") {
  1181. return decimalFormatter.format(row.purchaseQty5);
  1182. }
  1183. return row.purchaseQty5;
  1184. },
  1185. },
  1186. {
  1187. field: "purchaseQty6",
  1188. label: t("Demand Qty (Day6)"),
  1189. type: "read-only",
  1190. style: {
  1191. textAlign: "right",
  1192. },
  1193. renderCell: (row: FGOverallRecord) => {
  1194. if (typeof row.purchaseQty6 == "number") {
  1195. return decimalFormatter.format(row.purchaseQty6);
  1196. }
  1197. return row.purchaseQty6;
  1198. },
  1199. },
  1200. {
  1201. field: "purchaseQty7",
  1202. label: t("Demand Qty (Day7)"),
  1203. type: "read-only",
  1204. style: {
  1205. textAlign: "right",
  1206. },
  1207. renderCell: (row: FGOverallRecord) => {
  1208. if (typeof row.purchaseQty7 == "number") {
  1209. return decimalFormatter.format(row.purchaseQty7);
  1210. }
  1211. return row.purchaseQty7;
  1212. },
  1213. },
  1214. ],
  1215. [],
  1216. );
  1217. const columns = useMemo<Column<any>[]>(
  1218. () => [
  1219. {
  1220. field: "code",
  1221. label: t("code"),
  1222. type: "read-only",
  1223. // editable: true,
  1224. },
  1225. {
  1226. field: "name",
  1227. label: t("name"),
  1228. type: "read-only",
  1229. },
  1230. {
  1231. field: "type",
  1232. label: t("type"),
  1233. type: "read-only",
  1234. },
  1235. {
  1236. field: "inStockQty",
  1237. label: t("Available Qty"),
  1238. type: "read-only",
  1239. // editable: true,
  1240. style: {
  1241. textAlign: "right",
  1242. },
  1243. renderCell: (row: FGRecord) => {
  1244. if (typeof row.inStockQty == "number") {
  1245. return decimalFormatter.format(row.inStockQty);
  1246. }
  1247. return row.inStockQty;
  1248. },
  1249. },
  1250. {
  1251. field: "purchaseQty",
  1252. label: t("Demand Qty"),
  1253. type: "read-only",
  1254. style: {
  1255. textAlign: "right",
  1256. },
  1257. renderCell: (row: FGRecord) => {
  1258. if (typeof row.purchaseQty == "number") {
  1259. return decimalFormatter.format(row.purchaseQty);
  1260. }
  1261. return row.purchaseQty;
  1262. },
  1263. },
  1264. ],
  1265. [],
  1266. );
  1267. return (
  1268. <Grid container spacing={2}>
  1269. <Grid item xs={12} key={"all"}>
  1270. <Typography variant="overline" display="block" marginBlockEnd={1}>
  1271. {t("Material Demand List (7 Days)")}
  1272. </Typography>
  1273. <EditableSearchResults<FGRecord>
  1274. index={7}
  1275. items={fakeOverallRecords}
  1276. isMockUp={true}
  1277. columns={overallColumns}
  1278. setPagingController={updatePagingController}
  1279. pagingController={pagingController[7]}
  1280. isAutoPaging={true}
  1281. isEditable={false}
  1282. isEdit={false}
  1283. />
  1284. </Grid>
  1285. {dayPeriod.map((date, index) => (
  1286. <Grid item xs={12} key={index}>
  1287. <Typography variant="overline" display="block" marginBlockEnd={1}>
  1288. {`${t("Material Demand Date")}: ${date}`}
  1289. </Typography>
  1290. <EditableSearchResults<FGRecord>
  1291. index={index}
  1292. items={fakeRecords[index]} // Use the corresponding records for the day
  1293. columns={columns}
  1294. setPagingController={updatePagingController}
  1295. pagingController={pagingController[index]}
  1296. isAutoPaging={true}
  1297. isEditable={false}
  1298. isEdit={isEdit}
  1299. />
  1300. </Grid>
  1301. ))}
  1302. </Grid>
  1303. );
  1304. };
  1305. export default ViewByBomDetails;