FPSMS-frontend
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

actions.tsx 6.3 KiB

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