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

actions.ts 6.1 KiB

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