FPSMS-frontend
Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.
 
 
 

209 строки
5.3 KiB

  1. "use server";
  2. // import { BASE_API_URL } from "@/config/api";
  3. import { BASE_API_URL } from "../../../config/api";
  4. // import { ServerFetchError, serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil";
  5. import { revalidateTag } from "next/cache";
  6. import { cache } from "react";
  7. import { PoResult, StockInLine } from ".";
  8. //import { serverFetchJson } from "@/app/utils/fetchUtil";
  9. import { serverFetchJson } from "../../utils/fetchUtil";
  10. import { QcItemResult } from "../settings/qcItem";
  11. import { RecordsRes } from "../utils";
  12. import { Uom } from "../settings/uom";
  13. // import { BASE_API_URL } from "@/config/api";
  14. export interface PostStockInLiineResponse<T> {
  15. id: number | null;
  16. name: string;
  17. code: string;
  18. type?: string;
  19. message: string | null;
  20. errorPosition: string | keyof T;
  21. entity: T | T[];
  22. // entity: StockInLine | StockInLine[]
  23. }
  24. export interface StockInLineEntry {
  25. id?: number;
  26. itemId: number;
  27. purchaseOrderId: number;
  28. purchaseOrderLineId: number;
  29. acceptedQty: number;
  30. status?: string;
  31. expiryDate?: string;
  32. }
  33. export interface PurchaseQcResult {
  34. qcItemId: number;
  35. failQty: number;
  36. }
  37. export interface StockInInput {
  38. status: string;
  39. poCode: string;
  40. productLotNo?: string;
  41. dnNo?: string;
  42. itemName: string;
  43. invoiceNo?: string;
  44. receiptDate: string;
  45. supplier: string;
  46. acceptedQty: number;
  47. qty: number;
  48. receivedQty: number;
  49. acceptedWeight?: number;
  50. productionDate?: string;
  51. expiryDate: string;
  52. uom: Uom;
  53. }
  54. export interface PurchaseQCInput {
  55. status: string;
  56. acceptQty: number;
  57. passingQty: number;
  58. sampleRate: number;
  59. sampleWeight: number;
  60. totalWeight: number;
  61. qcAccept: boolean;
  62. qcResult: PurchaseQcResult[];
  63. }
  64. export interface EscalationInput {
  65. status: string;
  66. remarks?: string;
  67. handler: string;
  68. productLotNo: string;
  69. acceptedQty: number; // this is the qty to be escalated
  70. // escalationQty: number
  71. }
  72. export interface PutawayLine {
  73. id?: number
  74. qty: number
  75. warehouseId: number;
  76. warehouse: string;
  77. printQty: number
  78. }
  79. export interface PutawayInput {
  80. status: string;
  81. acceptedQty: number;
  82. warehouseId: number;
  83. putawayLine: PutawayLine[]
  84. }
  85. export type ModalFormInput = Partial<
  86. PurchaseQCInput & StockInInput & EscalationInput & PutawayInput
  87. >;
  88. export const testFetch = cache(async (id: number) => {
  89. return serverFetchJson<PoResult>(`${BASE_API_URL}/po/detail/${id}`, {
  90. next: { tags: ["po"] },
  91. });
  92. });
  93. export const fetchStockInLineInfo = cache(async (stockInLineId: number) => {
  94. return serverFetchJson<StockInLine>(
  95. `${BASE_API_URL}/stockInLine/${stockInLineId}`,
  96. {
  97. next: { tags: ["stockInLine"] },
  98. },
  99. );
  100. });
  101. export const createStockInLine = async (data: StockInLineEntry) => {
  102. const stockInLine = await serverFetchJson<
  103. PostStockInLiineResponse<StockInLineEntry>
  104. >(`${BASE_API_URL}/stockInLine/create`, {
  105. method: "POST",
  106. body: JSON.stringify(data),
  107. headers: { "Content-Type": "application/json" },
  108. });
  109. // revalidateTag("po");
  110. return stockInLine;
  111. };
  112. export const updateStockInLine = async (
  113. data: StockInLineEntry & ModalFormInput,
  114. ) => {
  115. const stockInLine = await serverFetchJson<
  116. PostStockInLiineResponse<StockInLineEntry & ModalFormInput>
  117. >(`${BASE_API_URL}/stockInLine/update`, {
  118. method: "POST",
  119. body: JSON.stringify(data),
  120. headers: { "Content-Type": "application/json" },
  121. });
  122. // revalidateTag("po");
  123. return stockInLine;
  124. };
  125. export const startPo = async (poId: number) => {
  126. const po = await serverFetchJson<PostStockInLiineResponse<PoResult>>(
  127. `${BASE_API_URL}/po/start/${poId}`,
  128. {
  129. method: "POST",
  130. body: JSON.stringify({ poId }),
  131. headers: { "Content-Type": "application/json" },
  132. },
  133. );
  134. revalidateTag("po");
  135. return po;
  136. };
  137. export const checkPolAndCompletePo = async (poId: number) => {
  138. const po = await serverFetchJson<PostStockInLiineResponse<PoResult>>(
  139. `${BASE_API_URL}/po/check/${poId}`,
  140. {
  141. method: "POST",
  142. body: JSON.stringify({ poId }),
  143. headers: { "Content-Type": "application/json" },
  144. },
  145. );
  146. revalidateTag("po");
  147. return po;
  148. };
  149. export const fetchPoInClient = cache(async (id: number) => {
  150. return serverFetchJson<PoResult>(`${BASE_API_URL}/po/detail/${id}`, {
  151. next: { tags: ["po"] },
  152. });
  153. });
  154. export const fetchPoListClient = cache(
  155. async (queryParams?: Record<string, any>) => {
  156. if (queryParams) {
  157. const queryString = new URLSearchParams(queryParams).toString();
  158. return serverFetchJson<RecordsRes<PoResult[]>>(
  159. `${BASE_API_URL}/po/list?${queryString}`,
  160. {
  161. method: "GET",
  162. next: { tags: ["po"] },
  163. },
  164. );
  165. } else {
  166. return serverFetchJson<RecordsRes<PoResult[]>>(
  167. `${BASE_API_URL}/po/list`,
  168. {
  169. method: "GET",
  170. next: { tags: ["po"] },
  171. },
  172. );
  173. }
  174. },
  175. );
  176. export const testing = cache(async (queryParams?: Record<string, any>) => {
  177. if (queryParams) {
  178. const queryString = new URLSearchParams(queryParams).toString();
  179. return serverFetchJson<RecordsRes<PoResult[]>>(
  180. `${BASE_API_URL}/po/testing?${queryString}`,
  181. {
  182. method: "GET",
  183. next: { tags: ["po"] },
  184. },
  185. );
  186. } else {
  187. return serverFetchJson<RecordsRes<PoResult[]>>(
  188. `${BASE_API_URL}/po/testing`,
  189. {
  190. method: "GET",
  191. next: { tags: ["po"] },
  192. },
  193. );
  194. }
  195. });