FPSMS-frontend
No puede seleccionar más de 25 temas Los temas deben comenzar con una letra o número, pueden incluir guiones ('-') y pueden tener hasta 35 caracteres de largo.
 
 
 

143 líneas
4.9 KiB

  1. import { InventoryLotLineResult, InventoryResult } from "@/app/api/inventory";
  2. import { Dispatch, SetStateAction, useCallback, useMemo } from "react";
  3. import { useTranslation } from "react-i18next";
  4. import { Column } from "../SearchResults";
  5. import SearchResults, { defaultPagingController, defaultSetPagingController } from "../SearchResults/SearchResults";
  6. import { CheckCircleOutline, DoDisturb, EditNote } from "@mui/icons-material";
  7. import { arrayToDateString } from "@/app/utils/formatUtil";
  8. import { Typography } from "@mui/material";
  9. import { isFinite } from "lodash";
  10. import useUploadContext from "../UploadProvider/useUploadContext";
  11. import { downloadFile } from "@/app/utils/commonUtil";
  12. import { fetchQrCodeByLotLineId, LotLineToQrcode } from "@/app/api/pdf/actions";
  13. import QrCodeIcon from "@mui/icons-material/QrCode";
  14. interface Props {
  15. inventoryLotLines: InventoryLotLineResult[] | null;
  16. setPagingController: defaultSetPagingController;
  17. pagingController: typeof defaultPagingController;
  18. totalCount: number;
  19. item: InventoryResult | null;
  20. }
  21. const InventoryLotLineTable: React.FC<Props> = ({ inventoryLotLines, pagingController, setPagingController, totalCount, item }) => {
  22. const { t } = useTranslation(["inventory"]);
  23. const { setIsUploading } = useUploadContext();
  24. const printQrcode = useCallback(async (lotLineId: number) => {
  25. setIsUploading(true);
  26. // const postData = { stockInLineIds: [42,43,44] };
  27. const postData: LotLineToQrcode = {
  28. inventoryLotLineId: lotLineId
  29. }
  30. const response = await fetchQrCodeByLotLineId(postData);
  31. if (response) {
  32. console.log(response);
  33. downloadFile(new Uint8Array(response.blobValue), response.filename!);
  34. }
  35. setIsUploading(false);
  36. }, [setIsUploading]);
  37. const onDetailClick = useCallback(
  38. (lotLine: InventoryLotLineResult) => {
  39. console.log(lotLine)
  40. printQrcode(lotLine.id)
  41. // lot line id to find stock in line
  42. },
  43. [printQrcode],
  44. );
  45. const columns = useMemo<Column<InventoryLotLineResult>[]>(
  46. () => [
  47. // {
  48. // name: "item",
  49. // label: t("Code"),
  50. // renderCell: (params) => {
  51. // return params.item.code;
  52. // },
  53. // },
  54. // {
  55. // name: "item",
  56. // label: t("Name"),
  57. // renderCell: (params) => {
  58. // return params.item.name;
  59. // },
  60. // },
  61. {
  62. name: "lotNo",
  63. label: t("Lot No"),
  64. },
  65. // {
  66. // name: "item",
  67. // label: t("Type"),
  68. // renderCell: (params) => {
  69. // return t(params.item.type);
  70. // },
  71. // },
  72. {
  73. name: "availableQty",
  74. label: t("Available Qty"),
  75. align: "right",
  76. headerAlign: "right",
  77. type: "integer",
  78. },
  79. {
  80. name: "uom",
  81. label: t("Sales UoM"),
  82. align: "left",
  83. headerAlign: "left",
  84. },
  85. {
  86. name: "qtyPerSmallestUnit",
  87. label: t("Available Qty Per Smallest Unit"),
  88. align: "right",
  89. headerAlign: "right",
  90. type: "integer",
  91. },
  92. {
  93. name: "baseUom",
  94. label: t("Base UoM"),
  95. align: "left",
  96. headerAlign: "left",
  97. },
  98. {
  99. name: "expiryDate",
  100. label: t("Expiry Date"),
  101. renderCell: (params) => {
  102. return arrayToDateString(params.expiryDate)
  103. },
  104. },
  105. {
  106. name: "id",
  107. label: t("qrcode"),
  108. onClick: onDetailClick,
  109. buttonIcon: <QrCodeIcon />,
  110. },
  111. // {
  112. // name: "status",
  113. // label: t("Status"),
  114. // type: "icon",
  115. // icons: {
  116. // available: <CheckCircleOutline fontSize="small"/>,
  117. // unavailable: <DoDisturb fontSize="small"/>,
  118. // },
  119. // colors: {
  120. // available: "success",
  121. // unavailable: "error",
  122. // }
  123. // },
  124. ],
  125. [t],
  126. );
  127. return <>
  128. <Typography variant="h6">{item ? `${t("Item selected")}: ${item.itemCode} | ${item.itemName} (${t(item.itemType)})` : t("No items are selected yet.")}</Typography>
  129. <SearchResults<InventoryLotLineResult>
  130. items={inventoryLotLines ?? []}
  131. columns={columns}
  132. pagingController={pagingController}
  133. setPagingController={setPagingController}
  134. totalCount={totalCount}
  135. />
  136. </>
  137. }
  138. export default InventoryLotLineTable;