FPSMS-frontend
25개 이상의 토픽을 선택하실 수 없습니다. Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

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