FPSMS-frontend
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.

actions.ts 6.4 KiB

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