FPSMS-frontend
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 

254 righe
7.1 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, serverFetchWithNoContent } from "@/app/utils/fetchUtil";
  7. import { QcItemResult } from "../settings/qcItem";
  8. import { RecordsRes } from "../utils";
  9. import { DoResult } from ".";
  10. import { GridRowId, GridRowSelectionModel } from "@mui/x-data-grid";
  11. import { GET } from "../auth/[...nextauth]/route";
  12. import { stringify } from "querystring";
  13. export interface CreateConsoDoInput {
  14. ids: GridRowSelectionModel;
  15. }
  16. export interface DoDetail {
  17. id: number;
  18. code: string;
  19. supplierCode: string;
  20. shopCode: string;
  21. shopName: string;
  22. currencyCode: string;
  23. orderDate: string;
  24. estimatedArrivalDate: string;
  25. completeDate: string;
  26. status: string;
  27. deliveryOrderLines: DoDetailLine[];
  28. }
  29. export interface DoDetailLine {
  30. id: number;
  31. itemNo: string;
  32. qty: number;
  33. price: number;
  34. status: string;
  35. itemName?: string;
  36. uomCode?: string;
  37. uom?: string;
  38. shortUom?: string;
  39. }
  40. export interface DoSearchAll {
  41. id: number;
  42. code: string;
  43. status: string;
  44. estimatedArrivalDate: string;
  45. orderDate: string;
  46. supplierName: string;
  47. shopName: string;
  48. deliveryOrderLines: DoDetailLine[];
  49. }
  50. export interface ReleaseDoRequest {
  51. id: number;
  52. }
  53. export interface ReleaseDoResponse {
  54. id: number;
  55. entity: { status: string }
  56. }
  57. export interface AssignByStoreRequest {
  58. storeId: string; // "2/F" or "4/F"
  59. assignTo: number;
  60. }
  61. export interface AssignByStoreResponse {
  62. id: number;
  63. code: string;
  64. name: string;
  65. type: string;
  66. message: string;
  67. errorPosition: string;
  68. entity: any;
  69. }
  70. export interface PrintDeliveryNoteRequest{
  71. doPickOrderId: number;
  72. printerId: number;
  73. printQty: number;
  74. numOfCarton: number;
  75. isDraft: boolean;
  76. }
  77. export interface PrintDeliveryNoteResponse{
  78. success: boolean;
  79. message?: string
  80. }
  81. export interface PrintDNLabelsRequest{
  82. doPickOrderId: number;
  83. printerId: number;
  84. printQty: number;
  85. numOfCarton: number;
  86. }
  87. export interface PrintDNLabelsRespone{
  88. success: boolean;
  89. message?: string
  90. }
  91. export interface BatchReleaseRequest {
  92. ids: number[];
  93. }
  94. export interface BatchReleaseResponse {
  95. success: boolean;
  96. message?: string
  97. }
  98. export interface getTicketReleaseTable {
  99. id: number;
  100. storeId: string | null;
  101. ticketNo: string | null;
  102. pickOrderId: number | null;
  103. doOrderId: number | null;
  104. pickOrderCode: string | null;
  105. deliveryOrderCode: string | null;
  106. loadingSequence: number | null;
  107. ticketStatus: string | null;
  108. truckId: number | null;
  109. truckDepartureTime: string | null;
  110. shopId: number | null;
  111. handledBy: number | null;
  112. ticketReleaseTime: string | null;
  113. ticketCompleteDateTime: string | null;
  114. truckLanceCode: string | null;
  115. shopCode: string | null;
  116. shopName: string | null;
  117. requiredDeliveryDate: string | null;
  118. handlerName: string | null;
  119. }
  120. export const fetchTicketReleaseTable = cache(async ()=> {
  121. return await serverFetchJson<getTicketReleaseTable[]>(
  122. `${BASE_API_URL}/doPickOrder/ticket-release-table`,
  123. {
  124. method: "GET",
  125. }
  126. );
  127. });
  128. export const startBatchReleaseAsync = cache(async (data: { ids: number[]; userId: number }) => {
  129. const { ids, userId } = data;
  130. return await serverFetchJson<{ id: number|null; code: string; entity?: any }>(
  131. `${BASE_API_URL}/doPickOrder/batch-release/async?userId=${userId}`,
  132. {
  133. method: "POST",
  134. body: JSON.stringify(ids),
  135. headers: { "Content-Type": "application/json" },
  136. }
  137. );
  138. });
  139. export const getBatchReleaseProgress = cache(async (jobId: string) => {
  140. return await serverFetchJson<{ id: number|null; code: string; entity?: any }>(
  141. `${BASE_API_URL}/doPickOrder/batch-release/progress/${jobId}`,
  142. { method: "GET" }
  143. );
  144. });
  145. export const assignPickOrderByStore = cache(async (data: AssignByStoreRequest) => {
  146. return await serverFetchJson<AssignByStoreResponse>(`${BASE_API_URL}/doPickOrder/assign-by-store`,
  147. {
  148. method: "POST",
  149. body: JSON.stringify(data),
  150. headers: { "Content-Type": "application/json" },
  151. })
  152. })
  153. export const releaseAssignedPickOrderByStore = cache(async (data: AssignByStoreRequest) => {
  154. return await serverFetchJson<AssignByStoreResponse>(`${BASE_API_URL}/doPickOrder/release-assigned-by-store`,
  155. {
  156. method: "POST",
  157. body: JSON.stringify(data),
  158. headers: { "Content-Type": "application/json" },
  159. })
  160. })
  161. export async function releaseDo(input: ReleaseDoRequest) {
  162. const response = await serverFetchJson<ReleaseDoResponse>(`${BASE_API_URL}/do/release`, {
  163. method: 'POST',
  164. body: JSON.stringify(input),
  165. headers: {
  166. 'Content-Type': 'application/json',
  167. },
  168. });
  169. revalidateTag('do');
  170. return response;
  171. }
  172. export const preloadDo = () => {
  173. fetchDoList();
  174. };
  175. export const fetchDoList = cache(async () => {
  176. return serverFetchJson<DoResult[]>(`${BASE_API_URL}/do/list`, {
  177. next: { tags: ["doList"] },
  178. });
  179. });
  180. export const fetchDoDetail = cache(async (id: number) => {
  181. return serverFetchJson<DoDetail>(`${BASE_API_URL}/do/detail/${id}`, {
  182. method: "GET",
  183. headers: { "Content-Type": "application/json" },
  184. next: {
  185. tags: ["doDetail"]
  186. }
  187. });
  188. });
  189. export const fetchDoSearch = cache(async (code: string, shopName: string, status: string, orderStartDate: string, orderEndDate: string, estArrStartDate: string, estArrEndDate: string)=>{
  190. console.log(`${BASE_API_URL}/do/search-DO/${code}&${shopName}&${status}&${orderStartDate}&${orderEndDate}&${estArrStartDate}&${estArrEndDate}`);
  191. return serverFetchJson<DoSearchAll[]>(`${BASE_API_URL}/do/search-DO/${code}&${shopName}&${status}&${orderStartDate}&${orderEndDate}&${estArrStartDate}&${estArrEndDate}`,{
  192. method: "GET",
  193. next: { tags: ["doSearch"] }
  194. });
  195. });
  196. export async function printDN(request: PrintDeliveryNoteRequest){
  197. const params = new URLSearchParams();
  198. params.append('doPickOrderId', request.doPickOrderId.toString());
  199. params.append('printerId', request.printerId.toString());
  200. if (request.printQty !== null && request.printQty !== undefined) {
  201. params.append('printQty', request.printQty.toString());
  202. }
  203. params.append('numOfCarton', request.numOfCarton.toString());
  204. params.append('isDraft', request.isDraft.toString());
  205. const response = await serverFetchWithNoContent(`${BASE_API_URL}/do/print-DN?${params.toString()}`,{
  206. method: "GET",
  207. });
  208. return { success: true, message: "Print job sent successfully (DN)" } as PrintDeliveryNoteResponse;
  209. }
  210. export async function printDNLabels(request: PrintDNLabelsRequest){
  211. const params = new URLSearchParams();
  212. params.append('doPickOrderId', request.doPickOrderId.toString());
  213. params.append('printerId', request.printerId.toString());
  214. if (request.printQty !== null && request.printQty !== undefined) {
  215. params.append('printQty', request.printQty.toString());
  216. }
  217. params.append('numOfCarton', request.numOfCarton.toString());
  218. const response = await serverFetchWithNoContent(`${BASE_API_URL}/do/print-DNLabels?${params.toString()}`,{
  219. method: "GET"
  220. });
  221. return { success: true, message: "Print job sent successfully (labels)"} as PrintDeliveryNoteResponse
  222. }