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

actions.ts 5.8 KiB

9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
2ヶ月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216
  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, StockInLine } from ".";
  8. //import { serverFetchJson } from "@/app/utils/fetchUtil";
  9. import { serverFetchJson } from "../../utils/fetchUtil";
  10. import { QcItemResult } from "../settings/qcItem";
  11. import { RecordsRes } from "../utils";
  12. // import { BASE_API_URL } from "@/config/api";
  13. export interface PostStockInLineResponse<T> {
  14. id: number | null;
  15. name: string;
  16. code: string;
  17. type?: string;
  18. message: string | null;
  19. errorPosition: string | keyof T;
  20. entity: T | T[];
  21. // entity: StockInLine | StockInLine[]
  22. }
  23. export interface StockInLineEntry {
  24. id?: number;
  25. itemId: number;
  26. purchaseOrderId: number;
  27. purchaseOrderLineId: number;
  28. acceptedQty: number;
  29. status?: string;
  30. expiryDate?: string;
  31. }
  32. export interface PurchaseQcResult {
  33. qcItemId: number;
  34. failQty: number;
  35. isPassed: boolean;
  36. }
  37. export interface StockInInput {
  38. status: string;
  39. productLotNo?: string;
  40. receiptDate: string;
  41. acceptedQty: number;
  42. acceptedWeight?: number;
  43. productionDate?: string;
  44. expiryDate: string;
  45. }
  46. export interface PurchaseQCInput {
  47. status?: string;
  48. qcAccept: boolean;
  49. acceptQty: number;
  50. sampleRate?: number;
  51. sampleWeight?: number;
  52. totalWeight?: number;
  53. qcResult: PurchaseQcResult[];
  54. }
  55. export interface EscalationInput {
  56. status: string;
  57. handler: string;
  58. acceptedQty: number; // this is the qty to be escalated
  59. // escalationQty: number
  60. }
  61. export interface PutawayInput {
  62. status: string;
  63. acceptedQty: number;
  64. warehouseId: number;
  65. // handler: string
  66. // stockInLine: StockInLineEntry[]
  67. }
  68. export type ModalFormInput = Partial<
  69. PurchaseQCInput & StockInInput & EscalationInput & PutawayInput
  70. >;
  71. export const testFetch = cache(async (id: number) => {
  72. return serverFetchJson<PoResult>(`${BASE_API_URL}/po/detail/${id}`, {
  73. next: { tags: ["po"] },
  74. });
  75. });
  76. export const fetchStockInLineInfo = cache(async (stockInLineId: number) => {
  77. return serverFetchJson<StockInLine>(
  78. `${BASE_API_URL}/stockInLine/${stockInLineId}`,
  79. {
  80. next: { tags: ["stockInLine"] },
  81. },
  82. );
  83. });
  84. export const createStockInLine = async (data: StockInLineEntry) => {
  85. console.log(data)
  86. const stockInLine = await serverFetchJson<
  87. PostStockInLineResponse<StockInLineEntry>
  88. >(`${BASE_API_URL}/stockInLine/create`, {
  89. method: "POST",
  90. body: JSON.stringify(data),
  91. headers: { "Content-Type": "application/json" },
  92. });
  93. // revalidateTag("po");
  94. return stockInLine;
  95. };
  96. export const updateStockInLine = async (
  97. data: StockInLineEntry & ModalFormInput,
  98. ) => {
  99. const stockInLine = await serverFetchJson<
  100. PostStockInLineResponse<StockInLineEntry & ModalFormInput>
  101. >(`${BASE_API_URL}/stockInLine/update`, {
  102. method: "POST",
  103. body: JSON.stringify(data),
  104. headers: { "Content-Type": "application/json" },
  105. });
  106. // revalidateTag("po");
  107. return stockInLine;
  108. };
  109. export const startPo = async (poId: number) => {
  110. const po = await serverFetchJson<PostStockInLineResponse<PoResult>>(
  111. `${BASE_API_URL}/po/start/${poId}`,
  112. {
  113. method: "POST",
  114. body: JSON.stringify({ poId }),
  115. headers: { "Content-Type": "application/json" },
  116. },
  117. );
  118. revalidateTag("po");
  119. return po;
  120. };
  121. export const checkPolAndCompletePo = async (poId: number) => {
  122. const po = await serverFetchJson<PostStockInLineResponse<PoResult>>(
  123. `${BASE_API_URL}/po/check/${poId}`,
  124. {
  125. method: "POST",
  126. body: JSON.stringify({ poId }),
  127. headers: { "Content-Type": "application/json" },
  128. },
  129. );
  130. revalidateTag("po");
  131. return po;
  132. };
  133. export const fetchPoInClient = cache(async (id: number) => {
  134. return serverFetchJson<PoResult>(`${BASE_API_URL}/po/detail/${id}`, {
  135. next: { tags: ["po"] },
  136. });
  137. });
  138. export const fetchPoListClient = cache(
  139. async (queryParams?: Record<string, any>) => {
  140. if (queryParams) {
  141. const queryString = new URLSearchParams(queryParams).toString();
  142. return serverFetchJson<RecordsRes<PoResult[]>>(
  143. `${BASE_API_URL}/po/list?${queryString}`,
  144. {
  145. method: "GET",
  146. next: { tags: ["po"] },
  147. },
  148. );
  149. } else {
  150. return serverFetchJson<RecordsRes<PoResult[]>>(
  151. `${BASE_API_URL}/po/list`,
  152. {
  153. method: "GET",
  154. next: { tags: ["po"] },
  155. },
  156. );
  157. }
  158. },
  159. );
  160. export const testing = cache(async (queryParams?: Record<string, any>) => {
  161. if (queryParams) {
  162. const queryString = new URLSearchParams(queryParams).toString();
  163. return serverFetchJson<RecordsRes<PoResult[]>>(
  164. `${BASE_API_URL}/po/testing?${queryString}`,
  165. {
  166. method: "GET",
  167. next: { tags: ["po"] },
  168. },
  169. );
  170. } else {
  171. return serverFetchJson<RecordsRes<PoResult[]>>(
  172. `${BASE_API_URL}/po/testing`,
  173. {
  174. method: "GET",
  175. next: { tags: ["po"] },
  176. },
  177. );
  178. }
  179. });
  180. export interface GoodsReceiptStatusRow {
  181. supplierId: number | null;
  182. supplierCode: string | null;
  183. supplierName: string;
  184. purchaseOrderCode: string | null;
  185. statistics: string;
  186. expectedNoOfDelivery: number;
  187. noOfOrdersReceivedAtDock: number;
  188. noOfItemsInspected: number;
  189. noOfItemsWithIqcIssue: number;
  190. noOfItemsCompletedPutAwayAtStore: number;
  191. // When true, this PO should be hidden from the dashboard table,
  192. // but still counted in the overall statistics (訂單已處理).
  193. hideFromDashboard?: boolean;
  194. }
  195. export const fetchGoodsReceiptStatus = cache(async (date?: string) => {
  196. const url = date
  197. ? `${BASE_API_URL}/dashboard/goods-receipt-status?date=${date}`
  198. : `${BASE_API_URL}/dashboard/goods-receipt-status`;
  199. return await serverFetchJson<GoodsReceiptStatusRow[]>(url, { method: "GET" });
  200. });