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.
 
 

121 line
3.2 KiB

  1. "use server";
  2. import { BASE_API_URL } from "@/config/api";
  3. // import { ServerFetchError, serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil";
  4. import { revalidateTag } from "next/cache";
  5. import { cache } from "react";
  6. import { Pageable, serverFetchJson } from "@/app/utils/fetchUtil";
  7. import { QcItemResult } from "../settings/qcItem";
  8. import { RecordsRes } from "../utils";
  9. import { convertObjToURLSearchParams } from "@/app/utils/commonUtil";
  10. import { InventoryLotLineResult, InventoryResult } from ".";
  11. // import { BASE_API_URL } from "@/config/api";
  12. export interface LotLineInfo {
  13. inventoryLotLineId: number;
  14. itemId: number;
  15. itemNo: string;
  16. itemName: string;
  17. lotNo: string;
  18. remainingQty: number;
  19. uom: string;
  20. }
  21. export interface SearchInventoryLotLine extends Pageable {
  22. itemId: number;
  23. }
  24. export interface SearchInventory extends Pageable {
  25. code: string;
  26. name: string;
  27. type: string;
  28. }
  29. export interface InventoryResultByPage {
  30. total: number;
  31. records: InventoryResult[];
  32. }
  33. export interface UpdateInventoryLotLineStatusRequest {
  34. inventoryLotLineId: number;
  35. status: string;
  36. }
  37. export interface InventoryLotLineResultByPage {
  38. total: number;
  39. records: InventoryLotLineResult[];
  40. }
  41. export interface PostInventoryLotLineResponse<T = null> {
  42. id: number | null;
  43. name: string;
  44. code: string;
  45. type?: string;
  46. message: string | null;
  47. errorPosition: string
  48. entity?: T | T[];
  49. consoCode?: string;
  50. }
  51. export const updateInventoryStatus = async (data: {
  52. itemId: number;
  53. lotId: number;
  54. status: string;
  55. qty: number;
  56. }) => {
  57. return serverFetchJson(`${BASE_API_URL}/inventory/update-status`, {
  58. method: 'PUT',
  59. body: JSON.stringify(data)
  60. });
  61. };
  62. export const fetchLotDetail = cache(async (stockInLineId: number) => {
  63. return serverFetchJson<LotLineInfo>(
  64. `${BASE_API_URL}/inventoryLotLine/lot-detail/${stockInLineId}`,
  65. {
  66. method: "GET",
  67. next: { tags: ["inventory"] },
  68. },
  69. );
  70. });
  71. export const updateInventoryLotLineStatus = async (data: {
  72. inventoryLotLineId: number;
  73. status: string;
  74. qty: number;
  75. operation?: string;
  76. }) => {
  77. return serverFetchJson(`${BASE_API_URL}/inventory/lot-line/update-status`, {
  78. method: 'PUT',
  79. body: JSON.stringify(data)
  80. });
  81. };
  82. export const fetchInventories = cache(async (data: SearchInventory) => {
  83. const queryStr = convertObjToURLSearchParams(data)
  84. return serverFetchJson<InventoryResultByPage>(`${BASE_API_URL}/inventory/getRecordByPage?${queryStr}`,
  85. { next: { tags: ["inventories"] } }
  86. )
  87. })
  88. export const fetchInventoryLotLines = cache(async (data: SearchInventoryLotLine) => {
  89. const queryStr = convertObjToURLSearchParams(data)
  90. return serverFetchJson<InventoryLotLineResultByPage>(`${BASE_API_URL}/inventoryLotLine/getRecordByPage?${queryStr}`, {
  91. next: { tags: ["inventoryLotLines"] },
  92. });
  93. });
  94. export const updateInventoryLotLineQuantities = async (data: {
  95. inventoryLotLineId: number;
  96. qty: number;
  97. operation: string;
  98. status: string;
  99. }) => {
  100. const result = await serverFetchJson<any>(
  101. `${BASE_API_URL}/inventoryLotLine/updateQuantities`,
  102. {
  103. method: "POST",
  104. body: JSON.stringify(data),
  105. headers: { "Content-Type": "application/json" },
  106. },
  107. );
  108. revalidateTag("pickorder");
  109. return result;
  110. };