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

PickOrderDetail.tsx 8.8 KiB

7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314
  1. "use client";
  2. import {
  3. Button,
  4. ButtonProps,
  5. Card,
  6. CardContent,
  7. CardHeader,
  8. CircularProgress,
  9. Grid,
  10. Stack,
  11. Typography,
  12. } from "@mui/material";
  13. import { useTranslation } from "react-i18next";
  14. import StyledDataGrid from "../StyledDataGrid";
  15. import { useCallback, useEffect, useMemo, useState } from "react";
  16. import { GridColDef } from "@mui/x-data-grid";
  17. import { PlayArrow } from "@mui/icons-material";
  18. import DoneIcon from "@mui/icons-material/Done";
  19. import { GridRowSelectionModel } from "@mui/x-data-grid";
  20. import { useQcCodeScanner } from "../QrCodeScannerProvider/QrCodeScannerProvider";
  21. import { fetchPickOrderLineClient } from "@/app/api/pickorder/actions";
  22. import { PickOrderLineWithSuggestedLot } from "@/app/api/pickorder";
  23. import { Pageable } from "@/app/utils/fetchUtil";
  24. import { QrCodeInfo } from "@/app/api/qrcode";
  25. import { QrCode } from "../QrCode";
  26. import { fetchLotDetail, LotLineInfo } from "@/app/api/inventory/actions";
  27. import { GridRowModesModel } from "@mui/x-data-grid";
  28. interface Props {
  29. consoCode: string;
  30. }
  31. interface IsLoadingModel {
  32. pickOrderLineTable: boolean;
  33. stockOutLineTable: boolean;
  34. }
  35. const PickOrderDetail: React.FC<Props> = ({ consoCode }) => {
  36. const { t } = useTranslation("pickOrder");
  37. const [selectedRow, setSelectRow] = useState<GridRowSelectionModel>();
  38. const [isLoadingModel, setIsLoadingModel] = useState<IsLoadingModel>({
  39. pickOrderLineTable: false,
  40. stockOutLineTable: false,
  41. });
  42. const [polCriteriaArgs, setPolCriteriaArgs] = useState<Pageable>({
  43. pageNum: 1,
  44. pageSize: 10,
  45. });
  46. const [solCriteriaArgs, setSolCriteriaArgs] = useState<Pageable>({
  47. pageNum: 1,
  48. pageSize: 10,
  49. });
  50. const [polTotalCount, setPolTotalCount] = useState(0);
  51. const [solTotalCount, setSolTotalCount] = useState(0);
  52. const [rowModesModel, setRowModesModel] = useState<GridRowModesModel>({});
  53. const [pickOrderLine, setPickOrderLine] = useState<
  54. PickOrderLineWithSuggestedLot[]
  55. >([]);
  56. const pickOrderLineColumns = useMemo<GridColDef[]>(
  57. () => [
  58. {
  59. field: "id",
  60. headerName: "pickOrderLineId",
  61. flex: 1,
  62. },
  63. {
  64. field: "itemName",
  65. headerName: "itemId",
  66. flex: 1,
  67. },
  68. {
  69. field: "qty",
  70. headerName: "qty",
  71. flex: 1,
  72. },
  73. {
  74. field: "uom",
  75. headerName: "uom",
  76. flex: 1,
  77. },
  78. {
  79. field: "warehouse",
  80. headerName: "location",
  81. flex: 1,
  82. },
  83. {
  84. field: "suggestedLotNo",
  85. headerName: "suggestedLotNo",
  86. flex: 1.2,
  87. },
  88. ],
  89. []
  90. );
  91. const [stockOutLine, setStockOutLine] = useState([]);
  92. const stockOutLineColumns = useMemo<GridColDef[]>(
  93. () => [
  94. {
  95. field: "code",
  96. headerName: "actual lot (out line",
  97. flex: 1,
  98. },
  99. ],
  100. []
  101. );
  102. const handleStartPickOrder = useCallback(async () => {}, []);
  103. const handleCompletePickOrder = useCallback(async () => {}, []);
  104. useEffect(() => {
  105. console.log(selectedRow);
  106. }, [selectedRow]);
  107. const buttonData = useMemo(
  108. () => ({
  109. buttonName: "complete",
  110. title: t("Do you want to complete?"),
  111. confirmButtonText: t("Complete"),
  112. successTitle: t("Complete Success"),
  113. errorTitle: t("Complete Fail"),
  114. buttonText: t("Complete PO"),
  115. buttonIcon: <DoneIcon />,
  116. buttonColor: "info",
  117. disabled: true,
  118. }),
  119. []
  120. );
  121. const [isOpenScanner, setOpenScanner] = useState(false);
  122. const onOpenScanner = useCallback(() => {
  123. setOpenScanner((prev) => !prev);
  124. }, []);
  125. const fetchPickOrderLine = useCallback(
  126. async (params: Record<string, any>) => {
  127. setIsLoadingModel((prev) => ({
  128. ...prev,
  129. pickOrderLineTable: true,
  130. }));
  131. const res = await fetchPickOrderLineClient({
  132. ...params,
  133. consoCode: consoCode,
  134. });
  135. if (res) {
  136. console.log(res);
  137. setPickOrderLine(res.records);
  138. setPolTotalCount(res.total);
  139. } else {
  140. console.log("error");
  141. console.log(res);
  142. }
  143. setIsLoadingModel((prev) => ({
  144. ...prev,
  145. pickOrderLineTable: false,
  146. }));
  147. },
  148. [fetchPickOrderLineClient, consoCode]
  149. );
  150. const fetchStockOutLine = useCallback(
  151. async (params: Record<string, any>) => {},
  152. []
  153. );
  154. useEffect(() => {
  155. fetchPickOrderLine(polCriteriaArgs);
  156. }, [polCriteriaArgs]);
  157. useEffect(() => {
  158. fetchStockOutLine(solCriteriaArgs);
  159. }, [solCriteriaArgs]);
  160. const getLotDetail = useCallback(
  161. async (stockInLineId: number): Promise<LotLineInfo> => {
  162. const res = await fetchLotDetail(stockInLineId);
  163. return res;
  164. },
  165. [fetchLotDetail]
  166. );
  167. const scanner = useQcCodeScanner();
  168. useEffect(() => {
  169. if (isOpenScanner && !scanner.isScanning) {
  170. scanner.startScan();
  171. } else if (!isOpenScanner && scanner.isScanning) {
  172. scanner.stopScan();
  173. }
  174. }, [isOpenScanner]);
  175. useEffect(() => {
  176. if (scanner.values.length > 0) {
  177. console.log(scanner.values[0]);
  178. const data: QrCodeInfo = JSON.parse(scanner.values[0]);
  179. console.log(data);
  180. if (data.stockInLineId) {
  181. console.log("still got in");
  182. console.log(data.stockInLineId);
  183. // fetch
  184. getLotDetail(data.stockInLineId).then((value) => {});
  185. }
  186. scanner.resetScan();
  187. }
  188. }, [scanner.values]);
  189. const homemade_Qrcode = {
  190. stockInLineId: 156,
  191. };
  192. return (
  193. <>
  194. <Stack spacing={2}>
  195. <Grid container xs={12} justifyContent="start">
  196. <Grid item xs={12}>
  197. <Typography variant="h4" marginInlineEnd={2}>
  198. {consoCode}
  199. </Typography>
  200. </Grid>
  201. <Grid item xs={8}>
  202. <Button
  203. // onClick={buttonData.onClick}
  204. disabled={buttonData.disabled}
  205. color={buttonData.buttonColor as ButtonProps["color"]}
  206. startIcon={buttonData.buttonIcon}
  207. >
  208. {buttonData.buttonText}
  209. </Button>
  210. </Grid>
  211. <Grid
  212. item
  213. xs={4}
  214. display="flex"
  215. justifyContent="end"
  216. alignItems="end"
  217. >
  218. <Button onClick={onOpenScanner}>
  219. {isOpenScanner ? t("binding") : t("bind")}
  220. </Button>
  221. </Grid>
  222. {/* homemade qrcode for testing purpose */}
  223. {/* <Grid
  224. item
  225. xs={12}
  226. style={{ display: "flex", justifyContent: "center" }}
  227. >
  228. <QrCode
  229. content={homemade_Qrcode}
  230. sx={{ width: 200, height: 200 }}
  231. />
  232. </Grid> */}
  233. </Grid>
  234. <Grid container xs={12} justifyContent="space-between">
  235. {/* <Grid item xs={12} sx={{ height: 400 }}>
  236. <StyledDataGrid rows={pickOrderLine} columns={columns} />
  237. </Grid> */}
  238. <Grid item xs={12} sx={{ height: 400 }}>
  239. {isLoadingModel.pickOrderLineTable ? (
  240. <CircularProgress size={40} />
  241. ) : (
  242. <StyledDataGrid
  243. rows={pickOrderLine}
  244. columns={pickOrderLineColumns}
  245. rowSelectionModel={selectedRow}
  246. onRowSelectionModelChange={(newRowSelectionModel) => {
  247. setSelectRow(newRowSelectionModel);
  248. }}
  249. initialState={{
  250. pagination: {
  251. paginationModel: { pageSize: 10, page: 0 },
  252. },
  253. }}
  254. pageSizeOptions={[10, 25, 50, 100]}
  255. onPaginationModelChange={async (model, details) => {
  256. setPolCriteriaArgs({
  257. pageNum: model.page + 1,
  258. pageSize: model.pageSize,
  259. });
  260. }}
  261. rowCount={polTotalCount}
  262. />
  263. )}
  264. </Grid>
  265. <Grid item xs={12} sx={{ height: 400 }}>
  266. <StyledDataGrid
  267. rows={stockOutLine}
  268. columns={stockOutLineColumns}
  269. rowModesModel={rowModesModel}
  270. onRowModesModelChange={setRowModesModel}
  271. disableColumnMenu
  272. editMode="row"
  273. // processRowUpdate={processRowUpdate}
  274. // onProcessRowUpdateError={onProcessRowUpdateError}
  275. initialState={{
  276. pagination: {
  277. paginationModel: { pageSize: 10, page: 0 },
  278. },
  279. }}
  280. pageSizeOptions={[10, 25, 50, 100]}
  281. onPaginationModelChange={async (model, details) => {
  282. setSolCriteriaArgs({
  283. pageNum: model.page + 1,
  284. pageSize: model.pageSize,
  285. });
  286. }}
  287. rowCount={solTotalCount}
  288. />
  289. </Grid>
  290. </Grid>
  291. </Stack>
  292. </>
  293. );
  294. };
  295. export default PickOrderDetail;