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

actions.ts 6.9 KiB

9ヶ月前
9ヶ月前
7ヶ月前
10ヶ月前
9ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
8ヶ月前
10ヶ月前
7ヶ月前
8ヶ月前
7ヶ月前
8ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
10ヶ月前
10ヶ月前
10ヶ月前
10ヶ月前
10ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
9ヶ月前
7ヶ月前
7ヶ月前
7ヶ月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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 } from ".";
  8. //import { serverFetchJson } from "@/app/utils/fetchUtil";
  9. import { serverFetchJson, serverFetchWithNoContent } from "../../utils/fetchUtil";
  10. import { QcItemResult } from "../settings/qcItem";
  11. import { RecordsRes } from "../utils";
  12. import { Uom } from "../settings/uom";
  13. import { convertObjToURLSearchParams } from "@/app/utils/commonUtil";
  14. import { StockInLine } from "../stockIn";
  15. // import { BASE_API_URL } from "@/config/api";
  16. export interface PostStockInLineResponse<T> {
  17. id: number | null;
  18. name: string;
  19. code: string;
  20. type?: string;
  21. message: string | null;
  22. errorPosition: string | keyof T;
  23. entity: T | T[];
  24. // entity: StockInLine | StockInLine[]
  25. }
  26. // DEPRECIATED
  27. export interface StockInLineEntry {
  28. id?: number;
  29. itemId: number;
  30. purchaseOrderId?: number;
  31. purchaseOrderLineId?: number;
  32. acceptedQty: number;
  33. status?: string;
  34. expiryDate?: string;
  35. productLotNo?: string;
  36. receiptDate?: string;
  37. dnDate?: string;
  38. dnNo?: string;
  39. }
  40. // DEPRECIATED
  41. export interface PurchaseQcResult{
  42. id?: number;
  43. qcItemId: number;
  44. qcPassed?: boolean;
  45. failQty?: number;
  46. remarks?: string;
  47. escalationLogId?: number;
  48. }
  49. // DEPRECIATED
  50. export interface StockInInput {
  51. status: string;
  52. poCode: string;
  53. productLotNo?: string;
  54. dnNo?: string;
  55. dnDate?: string;
  56. itemName: string;
  57. lotNo?: string;
  58. invoiceNo?: string;
  59. receiptDate: string;
  60. supplier: string;
  61. acceptedQty: number;
  62. qty: number;
  63. receivedQty: number;
  64. acceptedWeight?: number;
  65. productionDate?: string;
  66. expiryDate: string;
  67. uom: Uom;
  68. }
  69. // DEPRECIATED
  70. export interface PurchaseQCInput {
  71. status: string;
  72. acceptQty: number;
  73. passingQty: number;
  74. sampleRate?: number;
  75. sampleWeight?: number;
  76. totalWeight?: number;
  77. qcAccept: boolean;
  78. qcDecision?: number;
  79. qcResult: PurchaseQcResult[];
  80. }
  81. // DEPRECIATED
  82. export interface EscalationInput {
  83. status: string;
  84. remarks?: string;
  85. reason?: string;
  86. handlerId: number;
  87. productLotNo?: string;
  88. acceptedQty?: number; // this is the qty to be escalated
  89. // escalationQty: number
  90. }
  91. // DEPRECIATED
  92. export interface PutAwayLine {
  93. id?: number
  94. qty: number
  95. warehouseId: number;
  96. warehouse: string;
  97. printQty: number;
  98. _isNew?: boolean;
  99. }
  100. // DEPRECIATED
  101. export interface PutAwayInput {
  102. status: string;
  103. acceptedQty: number;
  104. warehouseId: number;
  105. putAwayLines: PutAwayLine[]
  106. }
  107. // DEPRECIATED
  108. export type ModalFormInput = Partial<
  109. PurchaseQCInput & StockInInput & PutAwayInput
  110. > & {
  111. escalationLog? : Partial<EscalationInput>
  112. };
  113. // DEPRECIATED
  114. export interface PrintQrCodeForSilRequest {
  115. stockInLineId: number;
  116. printerId: number;
  117. printQty?: number;
  118. }
  119. export const testFetch = cache(async (id: number) => {
  120. return serverFetchJson<PoResult>(`${BASE_API_URL}/po/detail/${id}`, {
  121. next: { tags: ["po"] },
  122. });
  123. });
  124. // DEPRECIATED
  125. export const fetchStockInLineInfo = cache(async (stockInLineId: number) => {
  126. return serverFetchJson<StockInLine>(
  127. `${BASE_API_URL}/stockInLine/${stockInLineId}`,
  128. {
  129. next: { tags: ["stockInLine"] },
  130. },
  131. );
  132. });
  133. // DEPRECIATED
  134. export const createStockInLine = async (data: StockInLineEntry) => {
  135. const stockInLine = await serverFetchJson<
  136. PostStockInLineResponse<StockInLine>
  137. >(`${BASE_API_URL}/stockInLine/create`, {
  138. method: "POST",
  139. body: JSON.stringify(data),
  140. headers: { "Content-Type": "application/json" },
  141. });
  142. // revalidateTag("po");
  143. return stockInLine;
  144. };
  145. // DEPRECIATED
  146. export const updateStockInLine = async (
  147. data: StockInLineEntry & ModalFormInput,
  148. ) => {
  149. const stockInLine = await serverFetchJson<
  150. PostStockInLineResponse<StockInLine & ModalFormInput>
  151. >(`${BASE_API_URL}/stockInLine/update`, {
  152. method: "POST",
  153. body: JSON.stringify(data),
  154. headers: { "Content-Type": "application/json" },
  155. });
  156. // revalidateTag("po");
  157. return stockInLine;
  158. };
  159. export const startPo = async (poId: number) => {
  160. const po = await serverFetchJson<PostStockInLineResponse<PoResult>>(
  161. `${BASE_API_URL}/po/start/${poId}`,
  162. {
  163. method: "POST",
  164. body: JSON.stringify({ poId }),
  165. headers: { "Content-Type": "application/json" },
  166. },
  167. );
  168. revalidateTag("po");
  169. return po;
  170. };
  171. export const checkPolAndCompletePo = async (poId: number) => {
  172. const po = await serverFetchJson<PostStockInLineResponse<PoResult>>(
  173. `${BASE_API_URL}/po/check/${poId}`,
  174. {
  175. method: "POST",
  176. body: JSON.stringify({ poId }),
  177. headers: { "Content-Type": "application/json" },
  178. },
  179. );
  180. revalidateTag("po");
  181. return po;
  182. };
  183. export const fetchPoInClient = cache(async (id: number) => {
  184. return serverFetchJson<PoResult>(`${BASE_API_URL}/po/detail/${id}`, {
  185. next: { tags: ["po"] },
  186. });
  187. });
  188. export interface PurchaseOrderSummary {
  189. id: number;
  190. code: string;
  191. status: string;
  192. orderDate: string;
  193. estimatedArrivalDate: string;
  194. supplierName: string;
  195. escalated: boolean;
  196. }
  197. export const fetchPoSummariesClient = cache(async (ids: number[]) => {
  198. return serverFetchJson<PurchaseOrderSummary[]>(`${BASE_API_URL}/po/summary`, {
  199. next: { tags: ["po"] },
  200. });
  201. });
  202. export const fetchPoListClient = cache(
  203. async (queryParams?: Record<string, any>) => {
  204. if (queryParams) {
  205. const queryString = new URLSearchParams(queryParams).toString();
  206. const fullUrl = `${BASE_API_URL}/po/list?${queryString}`;
  207. console.log("fetchPoListClient full URL:", fullUrl);
  208. console.log("fetchPoListClient BASE_API_URL:", BASE_API_URL);
  209. return serverFetchJson<RecordsRes<PoResult[]>>(
  210. `${BASE_API_URL}/po/list?${queryString}`,
  211. {
  212. method: "GET",
  213. next: { tags: ["po"] },
  214. },
  215. );
  216. } else {
  217. return serverFetchJson<RecordsRes<PoResult[]>>(
  218. `${BASE_API_URL}/po/list`,
  219. {
  220. method: "GET",
  221. next: { tags: ["po"] },
  222. },
  223. );
  224. }
  225. },
  226. );
  227. export const testing = cache(async (queryParams?: Record<string, any>) => {
  228. if (queryParams) {
  229. const queryString = new URLSearchParams(queryParams).toString();
  230. return serverFetchJson<RecordsRes<PoResult[]>>(
  231. `${BASE_API_URL}/po/testing?${queryString}`,
  232. {
  233. method: "GET",
  234. next: { tags: ["po"] },
  235. },
  236. );
  237. } else {
  238. return serverFetchJson<RecordsRes<PoResult[]>>(
  239. `${BASE_API_URL}/po/testing`,
  240. {
  241. method: "GET",
  242. next: { tags: ["po"] },
  243. },
  244. );
  245. }
  246. });
  247. // DEPRECIATED
  248. export const printQrCodeForSil = cache(async(data: PrintQrCodeForSilRequest) => {
  249. const params = convertObjToURLSearchParams(data)
  250. return serverFetchWithNoContent(`${BASE_API_URL}/stockInLine/print-label?${params}`,
  251. {
  252. method: "GET",
  253. headers: { "Content-Type": "application/json" },
  254. next: {
  255. tags: ["printQrCodeForSil"],
  256. },
  257. },
  258. )
  259. })