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.
 
 
 

235 lines
6.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 { serverFetchJson } from "@/app/utils/fetchUtil";
  7. import { QcItemResult } from "../settings/qcItem";
  8. import { RecordsRes } from "../utils";
  9. import {
  10. ConsoPickOrderResult,
  11. PickOrderLineWithSuggestedLot,
  12. PickOrderResult,
  13. PreReleasePickOrderSummary,
  14. StockOutLine,
  15. } from ".";
  16. import { PurchaseQcResult } from "../po/actions";
  17. // import { BASE_API_URL } from "@/config/api";
  18. export interface PostStockOutLiineResponse<T> {
  19. id: number | null;
  20. name: string;
  21. code: string;
  22. type?: string;
  23. message: string | null;
  24. errorPosition: string | keyof T;
  25. entity: T | T[];
  26. }
  27. export interface ReleasePickOrderInputs {
  28. consoCode: string;
  29. assignTo: number;
  30. }
  31. export interface CreateStockOutLine {
  32. consoCode: string;
  33. pickOrderLineId: number;
  34. inventoryLotLineId: number;
  35. qty: number;
  36. }
  37. export interface UpdateStockOutLine {
  38. id: number;
  39. // consoCode: String,
  40. itemId: number;
  41. qty: number;
  42. pickOrderLineId: number;
  43. inventoryLotLineId?: number;
  44. status: string;
  45. pickTime?: string;
  46. // pickerId: number?
  47. }
  48. export interface PickOrderQcInput {
  49. qty: number;
  50. status: string;
  51. qcResult: PurchaseQcResult[];
  52. }
  53. export interface PickOrderApprovalInput {
  54. allowQty: number;
  55. rejectQty: number;
  56. status: string;
  57. }
  58. export const consolidatePickOrder = async (ids: number[]) => {
  59. const pickOrder = await serverFetchJson<any>(
  60. `${BASE_API_URL}/pickOrder/conso`,
  61. {
  62. method: "POST",
  63. body: JSON.stringify({ ids: ids }),
  64. headers: { "Content-Type": "application/json" },
  65. },
  66. );
  67. // revalidateTag("po");
  68. return pickOrder;
  69. };
  70. export const consolidatePickOrder_revert = async (ids: number[]) => {
  71. const pickOrder = await serverFetchJson<any>(
  72. `${BASE_API_URL}/pickOrder/deconso`,
  73. {
  74. method: "POST",
  75. body: JSON.stringify({ ids: ids }),
  76. headers: { "Content-Type": "application/json" },
  77. },
  78. );
  79. // revalidateTag("po");
  80. return pickOrder;
  81. };
  82. export const fetchPickOrderClient = cache(
  83. async (queryParams?: Record<string, any>) => {
  84. if (queryParams) {
  85. const queryString = new URLSearchParams(queryParams).toString();
  86. return serverFetchJson<RecordsRes<PickOrderResult[]>>(
  87. `${BASE_API_URL}/pickOrder/getRecordByPage?${queryString}`,
  88. {
  89. method: "GET",
  90. next: { tags: ["pickorder"] },
  91. },
  92. );
  93. } else {
  94. return serverFetchJson<RecordsRes<PickOrderResult[]>>(
  95. `${BASE_API_URL}/pickOrder/getRecordByPage`,
  96. {
  97. method: "GET",
  98. next: { tags: ["pickorder"] },
  99. },
  100. );
  101. }
  102. },
  103. );
  104. export const fetchConsoPickOrderClient = cache(
  105. async (queryParams?: Record<string, any>) => {
  106. if (queryParams) {
  107. const queryString = new URLSearchParams(queryParams).toString();
  108. return serverFetchJson<RecordsRes<ConsoPickOrderResult[]>>(
  109. `${BASE_API_URL}/pickOrder/getRecordByPage-conso?${queryString}`,
  110. {
  111. method: "GET",
  112. next: { tags: ["pickorder"] },
  113. },
  114. );
  115. } else {
  116. return serverFetchJson<RecordsRes<ConsoPickOrderResult[]>>(
  117. `${BASE_API_URL}/pickOrder/getRecordByPage-conso`,
  118. {
  119. method: "GET",
  120. next: { tags: ["pickorder"] },
  121. },
  122. );
  123. }
  124. },
  125. );
  126. export const fetchPickOrderLineClient = cache(
  127. async (queryParams?: Record<string, any>) => {
  128. if (queryParams) {
  129. const queryString = new URLSearchParams(queryParams).toString();
  130. return serverFetchJson<RecordsRes<PickOrderLineWithSuggestedLot[]>>(
  131. `${BASE_API_URL}/pickOrder/get-pickorder-line-byPage?${queryString}`,
  132. {
  133. method: "GET",
  134. next: { tags: ["pickorder"] },
  135. },
  136. );
  137. } else {
  138. return serverFetchJson<RecordsRes<PickOrderLineWithSuggestedLot[]>>(
  139. `${BASE_API_URL}/pickOrder/get-pickorder-line-byPage`,
  140. {
  141. method: "GET",
  142. next: { tags: ["pickorder"] },
  143. },
  144. );
  145. }
  146. },
  147. );
  148. export const fetchStockOutLineClient = cache(
  149. async (pickOrderLineId: number) => {
  150. return serverFetchJson<StockOutLine[]>(
  151. `${BASE_API_URL}/stockOutLine/getByPickOrderLineId/${pickOrderLineId}`,
  152. {
  153. method: "GET",
  154. next: { tags: ["pickorder"] },
  155. },
  156. );
  157. },
  158. );
  159. export const fetchConsoDetail = cache(async (consoCode: string) => {
  160. return serverFetchJson<PreReleasePickOrderSummary>(
  161. `${BASE_API_URL}/pickOrder/pre-release-info/${consoCode}`,
  162. {
  163. method: "GET",
  164. next: { tags: ["pickorder"] },
  165. },
  166. );
  167. });
  168. export const releasePickOrder = async (data: ReleasePickOrderInputs) => {
  169. console.log(data);
  170. console.log(JSON.stringify(data));
  171. const po = await serverFetchJson<{ body: any; status: number }>(
  172. `${BASE_API_URL}/pickOrder/releaseConso`,
  173. {
  174. method: "POST",
  175. body: JSON.stringify(data),
  176. headers: { "Content-Type": "application/json" },
  177. },
  178. );
  179. revalidateTag("pickorder");
  180. return po;
  181. };
  182. export const createStockOutLine = async (data: CreateStockOutLine) => {
  183. console.log("triggering");
  184. const po = await serverFetchJson<PostStockOutLiineResponse<StockOutLine>>(
  185. `${BASE_API_URL}/stockOutLine/create`,
  186. {
  187. method: "POST",
  188. body: JSON.stringify(data),
  189. headers: { "Content-Type": "application/json" },
  190. },
  191. );
  192. revalidateTag("pickorder");
  193. return po;
  194. };
  195. export const updateStockOutLine = async (data: UpdateStockOutLine) => {
  196. console.log(data);
  197. const po = await serverFetchJson<PostStockOutLiineResponse<StockOutLine>>(
  198. `${BASE_API_URL}/stockOutLine/update`,
  199. {
  200. method: "POST",
  201. body: JSON.stringify(data),
  202. headers: { "Content-Type": "application/json" },
  203. },
  204. );
  205. revalidateTag("pickorder");
  206. return po;
  207. };
  208. export const completeConsoPickOrder = async (consoCode: string) => {
  209. const po = await serverFetchJson<PostStockOutLiineResponse<StockOutLine>>(
  210. `${BASE_API_URL}/pickOrder/consoPickOrder/complete/${consoCode}`,
  211. {
  212. method: "POST",
  213. headers: { "Content-Type": "application/json" },
  214. },
  215. );
  216. revalidateTag("pickorder");
  217. return po;
  218. };