FPSMS-frontend
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

actions.ts 6.6 KiB

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