FPSMS-frontend
您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 

222 行
6.4 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. deliveryOrderId: number;
  72. printerId: number;
  73. printQty: number;
  74. numOfCarton: number;
  75. isDraft: boolean;
  76. pickOrderId: number;
  77. }
  78. export interface PrintDeliveryNoteResponse{
  79. success: boolean;
  80. message?: string
  81. }
  82. export interface PrintDNLabelsRequest{
  83. deliveryOrderId: number,
  84. printerId: number,
  85. printQty: number,
  86. numOfCarton: number
  87. }
  88. export interface PrintDNLabelsRespone{
  89. success: boolean;
  90. message?: string
  91. }
  92. export interface BatchReleaseRequest {
  93. ids: number[];
  94. }
  95. export interface BatchReleaseResponse {
  96. success: boolean;
  97. message?: string
  98. }
  99. export const startBatchReleaseAsync = cache(async (data: { ids: number[]; userId: number }) => {
  100. const { ids, userId } = data;
  101. return await serverFetchJson<{ id: number|null; code: string; entity?: any }>(
  102. `${BASE_API_URL}/doPickOrder/batch-release/async?userId=${userId}`,
  103. {
  104. method: "POST",
  105. body: JSON.stringify(ids),
  106. headers: { "Content-Type": "application/json" },
  107. }
  108. );
  109. });
  110. export const getBatchReleaseProgress = cache(async (jobId: string) => {
  111. return await serverFetchJson<{ id: number|null; code: string; entity?: any }>(
  112. `${BASE_API_URL}/doPickOrder/batch-release/progress/${jobId}`,
  113. { method: "GET" }
  114. );
  115. });
  116. export const assignPickOrderByStore = cache(async (data: AssignByStoreRequest) => {
  117. return await serverFetchJson<AssignByStoreResponse>(`${BASE_API_URL}/doPickOrder/assign-by-store`,
  118. {
  119. method: "POST",
  120. body: JSON.stringify(data),
  121. headers: { "Content-Type": "application/json" },
  122. })
  123. })
  124. export const releaseAssignedPickOrderByStore = cache(async (data: AssignByStoreRequest) => {
  125. return await serverFetchJson<AssignByStoreResponse>(`${BASE_API_URL}/doPickOrder/release-assigned-by-store`,
  126. {
  127. method: "POST",
  128. body: JSON.stringify(data),
  129. headers: { "Content-Type": "application/json" },
  130. })
  131. })
  132. export async function releaseDo(input: ReleaseDoRequest) {
  133. const response = await serverFetchJson<ReleaseDoResponse>(`${BASE_API_URL}/do/release`, {
  134. method: 'POST',
  135. body: JSON.stringify(input),
  136. headers: {
  137. 'Content-Type': 'application/json',
  138. },
  139. });
  140. revalidateTag('do');
  141. return response;
  142. }
  143. export const preloadDo = () => {
  144. fetchDoList();
  145. };
  146. export const fetchDoList = cache(async () => {
  147. return serverFetchJson<DoResult[]>(`${BASE_API_URL}/do/list`, {
  148. next: { tags: ["doList"] },
  149. });
  150. });
  151. export const fetchDoDetail = cache(async (id: number) => {
  152. return serverFetchJson<DoDetail>(`${BASE_API_URL}/do/detail/${id}`, {
  153. method: "GET",
  154. headers: { "Content-Type": "application/json" },
  155. next: {
  156. tags: ["doDetail"]
  157. }
  158. });
  159. });
  160. export const fetchDoSearch = cache(async (code: string, shopName: string, status: string, orderStartDate: string, orderEndDate: string, estArrStartDate: string, estArrEndDate: string)=>{
  161. console.log(`${BASE_API_URL}/do/search-DO/${code}&${shopName}&${status}&${orderStartDate}&${orderEndDate}&${estArrStartDate}&${estArrEndDate}`);
  162. return serverFetchJson<DoSearchAll[]>(`${BASE_API_URL}/do/search-DO/${code}&${shopName}&${status}&${orderStartDate}&${orderEndDate}&${estArrStartDate}&${estArrEndDate}`,{
  163. method: "GET",
  164. next: { tags: ["doSearch"] }
  165. });
  166. });
  167. export async function printDN(request: PrintDeliveryNoteRequest){
  168. const params = new URLSearchParams();
  169. params.append('deliveryOrderId', request.deliveryOrderId.toString());
  170. params.append('printerId', request.printerId.toString());
  171. if (request.printQty !== null && request.printQty !== undefined) {
  172. params.append('printQty', request.printQty.toString());
  173. }
  174. params.append('numOfCarton', request.numOfCarton.toString());
  175. params.append('isDraft', request.isDraft.toString());
  176. params.append('pickOrderId', request.pickOrderId.toString());
  177. const response = await serverFetchWithNoContent(`${BASE_API_URL}/do/print-DN?${params.toString()}`,{
  178. method: "GET",
  179. });
  180. return { success: true, message: "Print job sent successfully (DN)" } as PrintDeliveryNoteResponse;
  181. }
  182. export async function printDNLabels(request: PrintDNLabelsRequest){
  183. const params = new URLSearchParams();
  184. params.append('deliveryOrderId', request.deliveryOrderId.toString());
  185. params.append('printerId', request.printerId.toString());
  186. if (request.printQty !== null && request.printQty !== undefined) {
  187. params.append('printQty', request.printQty.toString());
  188. }
  189. params.append('numOfCarton', request.numOfCarton.toString());
  190. const response = await serverFetchWithNoContent(`${BASE_API_URL}/do/print-DNLabels?${params.toString()}`,{
  191. method: "GET"
  192. });
  193. return { success: true, message: "Print job sent successfully (labels)"} as PrintDeliveryNoteResponse
  194. }