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

actions.ts 21 KiB

5ヶ月前
3ヶ月前
5ヶ月前
5ヶ月前
3ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
3ヶ月前
5ヶ月前
3ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
5ヶ月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809
  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 } from "@/app/utils/fetchUtil";
  7. import { QcItemResult } from "../settings/qcItem";
  8. import { RecordsRes } from "../utils";
  9. import {
  10. ConsoPickOrderResult,
  11. PickOrderLineWithSuggestedLot,
  12. PickOrderResult,
  13. PreReleasePickOrderSummary,
  14. StockOutLine,
  15. } from ".";
  16. import { PurchaseQcResult } from "../po/actions";
  17. // import { BASE_API_URL } from "@/config/api";
  18. export interface SavePickOrderLineRequest {
  19. itemId: number
  20. qty: number
  21. uomId: number
  22. }
  23. export interface SavePickOrderRequest {
  24. type: string
  25. targetDate: string
  26. pickOrderLine: SavePickOrderLineRequest[]
  27. }
  28. export interface PostPickOrderResponse<T = null> {
  29. id: number | null;
  30. name: string;
  31. code: string;
  32. type?: string;
  33. message: string | null;
  34. errorPosition: string
  35. entity?: T | T[];
  36. consoCode?: string;
  37. }
  38. export interface PostStockOutLiineResponse<T> {
  39. id: number | null;
  40. name: string;
  41. code: string;
  42. type?: string;
  43. message: string | null;
  44. errorPosition: string | keyof T;
  45. entity: T | T[] | null;
  46. }
  47. export interface ReleasePickOrderInputs {
  48. consoCode: string;
  49. assignTo: number;
  50. }
  51. export interface CreateStockOutLine {
  52. consoCode: string;
  53. pickOrderLineId: number;
  54. inventoryLotLineId: number;
  55. qty: number;
  56. }
  57. export interface UpdateStockOutLine {
  58. id: number;
  59. // consoCode: String,
  60. itemId: number;
  61. qty: number;
  62. pickOrderLineId: number;
  63. inventoryLotLineId?: number;
  64. status: string;
  65. pickTime?: string;
  66. // pickerId: number?
  67. }
  68. export interface PickOrderQcInput {
  69. qty: number;
  70. status: string;
  71. qcResult: PurchaseQcResult[];
  72. }
  73. export interface PickOrderApprovalInput {
  74. allowQty: number;
  75. rejectQty: number;
  76. status: string;
  77. }
  78. export interface GetPickOrderInfoResponse {
  79. consoCode: string | null;
  80. pickOrders: GetPickOrderInfo[];
  81. items: CurrentInventoryItemInfo[];
  82. }
  83. export interface GetPickOrderInfo {
  84. id: number;
  85. code: string;
  86. consoCode: string | null; // ✅ 添加 consoCode 属性
  87. targetDate: string | number[]; // ✅ Support both formats
  88. type: string;
  89. status: string;
  90. assignTo: number;
  91. groupName: string; // ✅ Add this field
  92. pickOrderLines: GetPickOrderLineInfo[];
  93. }
  94. export interface GetPickOrderLineInfo {
  95. id: number;
  96. itemId: number;
  97. itemCode: string;
  98. itemName: string;
  99. availableQty: number| null;
  100. requiredQty: number;
  101. uomCode: string;
  102. uomDesc: string;
  103. suggestedList: any[];
  104. pickedQty: number;
  105. }
  106. export interface CurrentInventoryItemInfo {
  107. id: number;
  108. code: string;
  109. name: string;
  110. uomDesc: string;
  111. availableQty: number;
  112. requiredQty: number;
  113. }
  114. export interface SavePickOrderGroupRequest {
  115. groupIds?: number[];
  116. names?: string[];
  117. targetDate?: string;
  118. pickOrderId?: number | null;
  119. }
  120. export interface PickOrderGroupInfo {
  121. id: number;
  122. name: string;
  123. targetDate: string | null;
  124. pickOrderId: number | null;
  125. }
  126. export interface AssignPickOrderInputs {
  127. pickOrderIds: number[];
  128. assignTo: number;
  129. }
  130. export interface LotDetailWithStockOutLine {
  131. lotId: number;
  132. lotNo: string;
  133. expiryDate: string;
  134. location: string;
  135. stockUnit: string;
  136. availableQty: number;
  137. requiredQty: number;
  138. actualPickQty: number;
  139. suggestedPickLotId: number;
  140. lotStatus: string;
  141. lotAvailability: string;
  142. stockOutLineId?: number;
  143. stockOutLineStatus?: string;
  144. stockOutLineQty?: number;
  145. }
  146. export interface PickAnotherLotFormData {
  147. pickOrderLineId: number;
  148. lotId: number;
  149. qty: number;
  150. type: string;
  151. handlerId?: number;
  152. category?: string;
  153. releasedBy?: number;
  154. recordDate?: string;
  155. }
  156. export const recordFailLot = async (data: PickAnotherLotFormData) => {
  157. const result = await serverFetchJson<PostPickOrderResponse>(
  158. `${BASE_API_URL}/suggestedPickLot/recordFailLot`,
  159. {
  160. method: "POST",
  161. body: JSON.stringify(data),
  162. headers: { "Content-Type": "application/json" },
  163. },
  164. );
  165. revalidateTag("pickorder");
  166. return result;
  167. };
  168. export interface PickExecutionIssueData {
  169. pickOrderId: number;
  170. pickOrderCode: string;
  171. pickOrderCreateDate: string;
  172. pickExecutionDate: string;
  173. pickOrderLineId: number;
  174. itemId: number;
  175. itemCode: string;
  176. itemDescription: string;
  177. lotId: number;
  178. lotNo: string;
  179. storeLocation: string;
  180. requiredQty: number;
  181. actualPickQty: number;
  182. missQty: number;
  183. badItemQty: number;
  184. issueRemark: string;
  185. pickerName: string;
  186. handledBy?: number;
  187. }
  188. export interface AutoAssignReleaseResponse {
  189. id: number | null;
  190. name: string;
  191. code: string;
  192. type?: string;
  193. message: string | null;
  194. errorPosition: string;
  195. entity?: {
  196. consoCode?: string;
  197. pickOrderIds?: number[];
  198. hasActiveOrders: boolean;
  199. };
  200. }
  201. export interface PickOrderCompletionResponse {
  202. id: number | null;
  203. name: string;
  204. code: string;
  205. type?: string;
  206. message: string | null;
  207. errorPosition: string;
  208. entity?: {
  209. hasCompletedOrders: boolean;
  210. completedOrders: Array<{
  211. pickOrderId: number;
  212. pickOrderCode: string;
  213. consoCode: string;
  214. isCompleted: boolean;
  215. stockOutStatus: string;
  216. totalLines: number;
  217. unfinishedLines: number;
  218. }>;
  219. allOrders: Array<{
  220. pickOrderId: number;
  221. pickOrderCode: string;
  222. consoCode: string;
  223. isCompleted: boolean;
  224. stockOutStatus: string;
  225. totalLines: number;
  226. unfinishedLines: number;
  227. }>;
  228. };
  229. }
  230. export interface UpdateSuggestedLotLineIdRequest {
  231. newLotLineId: number;
  232. }
  233. export const updateSuggestedLotLineId = async (suggestedPickLotId: number, newLotLineId: number) => {
  234. const response = await serverFetchJson<PostPickOrderResponse<UpdateSuggestedLotLineIdRequest>>(
  235. `${BASE_API_URL}/suggestedPickLot/update-suggested-lot/${suggestedPickLotId}`,
  236. {
  237. method: "POST",
  238. body: JSON.stringify({ newLotLineId }),
  239. headers: { "Content-Type": "application/json" },
  240. },
  241. );
  242. revalidateTag("pickorder");
  243. return response;
  244. };
  245. export const autoAssignAndReleasePickOrder = async (userId: number): Promise<AutoAssignReleaseResponse> => {
  246. const response = await serverFetchJson<AutoAssignReleaseResponse>(
  247. `${BASE_API_URL}/pickOrder/auto-assign-release/${userId}`,
  248. {
  249. method: "POST",
  250. headers: { "Content-Type": "application/json" },
  251. },
  252. );
  253. revalidateTag("pickorder");
  254. return response;
  255. };
  256. export const checkPickOrderCompletion = async (userId: number): Promise<PickOrderCompletionResponse> => {
  257. const response = await serverFetchJson<PickOrderCompletionResponse>(
  258. `${BASE_API_URL}/pickOrder/check-pick-completion/${userId}`,
  259. {
  260. method: "GET",
  261. headers: { "Content-Type": "application/json" },
  262. },
  263. );
  264. return response;
  265. };
  266. export const recordPickExecutionIssue = async (data: PickExecutionIssueData) => {
  267. const result = await serverFetchJson<PostPickOrderResponse>(
  268. `${BASE_API_URL}/pickExecution/recordIssue`,
  269. {
  270. method: "POST",
  271. body: JSON.stringify(data),
  272. headers: { "Content-Type": "application/json" },
  273. },
  274. );
  275. revalidateTag("pickorder");
  276. return result;
  277. };
  278. export const resuggestPickOrder = async (pickOrderId: number) => {
  279. console.log("Resuggesting pick order:", pickOrderId);
  280. const result = await serverFetchJson<PostPickOrderResponse>(
  281. `${BASE_API_URL}/suggestedPickLot/resuggest/${pickOrderId}`,
  282. {
  283. method: "POST",
  284. headers: { "Content-Type": "application/json" },
  285. },
  286. );
  287. revalidateTag("pickorder");
  288. return result;
  289. };
  290. export const updateStockOutLineStatus = async (data: {
  291. id: number;
  292. status: string;
  293. qty?: number;
  294. remarks?: string;
  295. }) => {
  296. console.log("Updating stock out line status:", data);
  297. const result = await serverFetchJson<PostStockOutLiineResponse<StockOutLine>>(
  298. `${BASE_API_URL}/stockOutLine/updateStatus`,
  299. {
  300. method: "POST",
  301. body: JSON.stringify(data),
  302. headers: { "Content-Type": "application/json" },
  303. },
  304. );
  305. revalidateTag("pickorder");
  306. return result;
  307. };
  308. // Missing function 1: newassignPickOrder
  309. export const newassignPickOrder = async (data: AssignPickOrderInputs) => {
  310. const response = await serverFetchJson<PostPickOrderResponse>(
  311. `${BASE_API_URL}/pickOrder/assign`,
  312. {
  313. method: "POST",
  314. body: JSON.stringify(data),
  315. headers: { "Content-Type": "application/json" },
  316. },
  317. );
  318. revalidateTag("pickorder");
  319. return response;
  320. };
  321. // Missing function 2: releaseAssignedPickOrders
  322. export const releaseAssignedPickOrders = async (data: AssignPickOrderInputs) => {
  323. const response = await serverFetchJson<PostPickOrderResponse>(
  324. `${BASE_API_URL}/pickOrder/release-assigned`,
  325. {
  326. method: "POST",
  327. body: JSON.stringify(data),
  328. headers: { "Content-Type": "application/json" },
  329. },
  330. );
  331. revalidateTag("pickorder");
  332. return response;
  333. };
  334. // Get latest group name and create it automatically
  335. export const getLatestGroupNameAndCreate = async () => {
  336. return serverFetchJson<PostPickOrderResponse>(
  337. `${BASE_API_URL}/pickOrder/groups/latest`,
  338. {
  339. method: "GET",
  340. next: { tags: ["pickorder"] },
  341. },
  342. );
  343. };
  344. // Get all groups
  345. export const fetchAllGroups = cache(async () => {
  346. return serverFetchJson<PickOrderGroupInfo[]>(
  347. `${BASE_API_URL}/pickOrder/groups/list`,
  348. {
  349. method: "GET",
  350. next: { tags: ["pickorder"] },
  351. },
  352. );
  353. });
  354. // Create or update groups (flexible - can handle both cases)
  355. export const createOrUpdateGroups = async (data: SavePickOrderGroupRequest) => {
  356. const response = await serverFetchJson<PostPickOrderResponse>(
  357. `${BASE_API_URL}/pickOrder/groups/create`,
  358. {
  359. method: "POST",
  360. body: JSON.stringify(data),
  361. headers: { "Content-Type": "application/json" },
  362. },
  363. );
  364. revalidateTag("pickorder");
  365. return response;
  366. };
  367. // Get groups by pick order ID
  368. export const fetchGroupsByPickOrderId = cache(async (pickOrderId: number) => {
  369. return serverFetchJson<PickOrderGroupInfo[]>(
  370. `${BASE_API_URL}/pickOrder/groups/${pickOrderId}`,
  371. {
  372. method: "GET",
  373. next: { tags: ["pickorder"] },
  374. },
  375. );
  376. });
  377. export const fetchPickOrderDetails = cache(async (ids: string) => {
  378. return serverFetchJson<GetPickOrderInfoResponse>(
  379. `${BASE_API_URL}/pickOrder/detail/${ids}`,
  380. {
  381. method: "GET",
  382. next: { tags: ["pickorder"] },
  383. },
  384. );
  385. });
  386. export interface PickOrderLotDetailResponse {
  387. lotId: number;
  388. lotNo: string;
  389. expiryDate: string;
  390. location: string;
  391. stockUnit: string;
  392. inQty: number;
  393. availableQty: number;
  394. requiredQty: number;
  395. actualPickQty: number;
  396. suggestedPickLotId: number;
  397. lotStatus: string;
  398. lotAvailability: 'available' | 'insufficient_stock' | 'expired' | 'status_unavailable'|'rejected';
  399. }
  400. interface ALLPickOrderLotDetailResponse {
  401. // Pick Order Information
  402. pickOrderId: number;
  403. pickOrderCode: string;
  404. pickOrderTargetDate: string;
  405. pickOrderType: string;
  406. pickOrderStatus: string;
  407. pickOrderAssignTo: number;
  408. groupName: string;
  409. // Pick Order Line Information
  410. pickOrderLineId: number;
  411. pickOrderLineRequiredQty: number;
  412. pickOrderLineStatus: string;
  413. // Item Information
  414. itemId: number;
  415. itemCode: string;
  416. itemName: string;
  417. uomCode: string;
  418. uomDesc: string;
  419. // Lot Information
  420. lotId: number;
  421. lotNo: string;
  422. expiryDate: string;
  423. location: string;
  424. outQty: number;
  425. holdQty: number;
  426. stockUnit: string;
  427. availableQty: number;
  428. requiredQty: number;
  429. actualPickQty: number;
  430. totalPickedByAllPickOrders: number;
  431. suggestedPickLotId: number;
  432. lotStatus: string;
  433. stockOutLineId?: number;
  434. stockOutLineStatus?: string;
  435. stockOutLineQty?: number;
  436. lotAvailability: 'available' | 'insufficient_stock' | 'expired' | 'status_unavailable'|'rejected';
  437. processingStatus: string;
  438. }
  439. interface SuggestionWithStatus {
  440. suggestionId: number;
  441. suggestionQty: number;
  442. suggestionCreated: string;
  443. lotLineId: number;
  444. lotNo: string;
  445. expiryDate: string;
  446. location: string;
  447. stockOutLineId?: number;
  448. stockOutLineStatus?: string;
  449. stockOutLineQty?: number;
  450. suggestionStatus: 'active' | 'completed' | 'rejected' | 'in_progress' | 'unknown';
  451. }
  452. export interface CheckCompleteResponse {
  453. id: number | null;
  454. name: string;
  455. code: string;
  456. type?: string;
  457. message: string | null;
  458. errorPosition: string;
  459. }
  460. export const checkAndCompletePickOrderByConsoCode = async (consoCode: string): Promise<CheckCompleteResponse> => {
  461. const response = await serverFetchJson<CheckCompleteResponse>(
  462. `${BASE_API_URL}/pickOrder/check-complete/${consoCode}`,
  463. {
  464. method: "POST",
  465. headers: {
  466. "Content-Type": "application/json",
  467. },
  468. },
  469. );
  470. revalidateTag("pickorder");
  471. return response;
  472. };
  473. export const fetchPickOrderDetailsOptimized = cache(async (userId?: number) => {
  474. const url = userId
  475. ? `${BASE_API_URL}/pickOrder/detail-optimized?userId=${userId}`
  476. : `${BASE_API_URL}/pickOrder/detail-optimized`;
  477. return serverFetchJson<any[]>(
  478. url,
  479. {
  480. method: "GET",
  481. next: { tags: ["pickorder"] },
  482. },
  483. );
  484. });
  485. const fetchSuggestionsWithStatus = async (pickOrderLineId: number) => {
  486. try {
  487. const response = await fetch(`/api/suggestedPickLot/suggestions-with-status/${pickOrderLineId}`);
  488. const suggestions: SuggestionWithStatus[] = await response.json();
  489. return suggestions;
  490. } catch (error) {
  491. console.error('Error fetching suggestions with status:', error);
  492. return [];
  493. }
  494. };
  495. export const fetchALLPickOrderLineLotDetails = cache(async (userId: number): Promise<any[]> => {
  496. try {
  497. console.log("🔍 Fetching all pick order line lot details for userId:", userId);
  498. // ✅ 使用 serverFetchJson 而不是直接的 fetch
  499. const data = await serverFetchJson<any[]>(
  500. `${BASE_API_URL}/pickOrder/all-lots-with-details/${userId}`,
  501. {
  502. method: 'GET',
  503. next: { tags: ["pickorder"] },
  504. }
  505. );
  506. console.log("✅ API Response:", data);
  507. return data;
  508. } catch (error) {
  509. console.error("❌ Error fetching all pick order line lot details:", error);
  510. throw error;
  511. }
  512. });
  513. export const fetchAllPickOrderDetails = cache(async (userId?: number) => {
  514. if (!userId) {
  515. return {
  516. consoCode: null,
  517. pickOrders: [],
  518. items: []
  519. };
  520. }
  521. // ✅ Use the correct endpoint with userId in the path
  522. const url = `${BASE_API_URL}/pickOrder/detail-optimized/${userId}`;
  523. return serverFetchJson<GetPickOrderInfoResponse>(
  524. url,
  525. {
  526. method: "GET",
  527. next: { tags: ["pickorder"] },
  528. },
  529. );
  530. });
  531. export const fetchPickOrderLineLotDetails = cache(async (pickOrderLineId: number) => {
  532. return serverFetchJson<PickOrderLotDetailResponse[]>(
  533. `${BASE_API_URL}/pickOrder/lot-details/${pickOrderLineId}`,
  534. {
  535. method: "GET",
  536. next: { tags: ["pickorder"] },
  537. },
  538. );
  539. });
  540. export const createPickOrder = async (data: SavePickOrderRequest) => {
  541. console.log(data);
  542. const po = await serverFetchJson<PostPickOrderResponse>(
  543. `${BASE_API_URL}/pickOrder/create`,
  544. {
  545. method: "POST",
  546. body: JSON.stringify(data),
  547. headers: { "Content-Type": "application/json" },
  548. },
  549. );
  550. revalidateTag("pickorder");
  551. return po;
  552. }
  553. export const assignPickOrder = async (ids: number[]) => {
  554. const pickOrder = await serverFetchJson<any>(
  555. `${BASE_API_URL}/pickOrder/conso`,
  556. {
  557. method: "POST",
  558. body: JSON.stringify({ ids: ids }),
  559. headers: { "Content-Type": "application/json" },
  560. },
  561. );
  562. // revalidateTag("po");
  563. return pickOrder;
  564. };
  565. export const consolidatePickOrder = async (ids: number[]) => {
  566. const pickOrder = await serverFetchJson<any>(
  567. `${BASE_API_URL}/pickOrder/conso`,
  568. {
  569. method: "POST",
  570. body: JSON.stringify({ ids: ids }),
  571. headers: { "Content-Type": "application/json" },
  572. },
  573. );
  574. return pickOrder;
  575. };
  576. export const consolidatePickOrder_revert = async (ids: number[]) => {
  577. const pickOrder = await serverFetchJson<any>(
  578. `${BASE_API_URL}/pickOrder/deconso`,
  579. {
  580. method: "POST",
  581. body: JSON.stringify({ ids: ids }),
  582. headers: { "Content-Type": "application/json" },
  583. },
  584. );
  585. // revalidateTag("po");
  586. return pickOrder;
  587. };
  588. export const fetchPickOrderClient = cache(
  589. async (queryParams?: Record<string, any>) => {
  590. if (queryParams) {
  591. const queryString = new URLSearchParams(queryParams).toString();
  592. return serverFetchJson<RecordsRes<PickOrderResult[]>>(
  593. `${BASE_API_URL}/pickOrder/getRecordByPage?${queryString}`,
  594. {
  595. method: "GET",
  596. next: { tags: ["pickorder"] },
  597. },
  598. );
  599. } else {
  600. return serverFetchJson<RecordsRes<PickOrderResult[]>>(
  601. `${BASE_API_URL}/pickOrder/getRecordByPage`,
  602. {
  603. method: "GET",
  604. next: { tags: ["pickorder"] },
  605. },
  606. );
  607. }
  608. },
  609. );
  610. export const fetchPickOrderWithStockClient = cache(
  611. async (queryParams?: Record<string, any>) => {
  612. if (queryParams) {
  613. const queryString = new URLSearchParams(queryParams).toString();
  614. return serverFetchJson<RecordsRes<GetPickOrderInfo[]>>(
  615. `${BASE_API_URL}/pickOrder/getRecordByPageWithStock?${queryString}`,
  616. {
  617. method: "GET",
  618. next: { tags: ["pickorder"] },
  619. },
  620. );
  621. } else {
  622. return serverFetchJson<RecordsRes<GetPickOrderInfo[]>>(
  623. `${BASE_API_URL}/pickOrder/getRecordByPageWithStock`,
  624. {
  625. method: "GET",
  626. next: { tags: ["pickorder"] },
  627. },
  628. );
  629. }
  630. },
  631. );
  632. export const fetchConsoPickOrderClient = cache(
  633. async (queryParams?: Record<string, any>) => {
  634. if (queryParams) {
  635. const queryString = new URLSearchParams(queryParams).toString();
  636. return serverFetchJson<RecordsRes<ConsoPickOrderResult[]>>(
  637. `${BASE_API_URL}/pickOrder/getRecordByPage-conso?${queryString}`,
  638. {
  639. method: "GET",
  640. next: { tags: ["pickorder"] },
  641. },
  642. );
  643. } else {
  644. return serverFetchJson<RecordsRes<ConsoPickOrderResult[]>>(
  645. `${BASE_API_URL}/pickOrder/getRecordByPage-conso`,
  646. {
  647. method: "GET",
  648. next: { tags: ["pickorder"] },
  649. },
  650. );
  651. }
  652. },
  653. );
  654. export const fetchPickOrderLineClient = cache(
  655. async (queryParams?: Record<string, any>) => {
  656. if (queryParams) {
  657. const queryString = new URLSearchParams(queryParams).toString();
  658. return serverFetchJson<RecordsRes<PickOrderLineWithSuggestedLot[]>>(
  659. `${BASE_API_URL}/pickOrder/get-pickorder-line-byPage?${queryString}`,
  660. {
  661. method: "GET",
  662. next: { tags: ["pickorder"] },
  663. },
  664. );
  665. } else {
  666. return serverFetchJson<RecordsRes<PickOrderLineWithSuggestedLot[]>>(
  667. `${BASE_API_URL}/pickOrder/get-pickorder-line-byPage`,
  668. {
  669. method: "GET",
  670. next: { tags: ["pickorder"] },
  671. },
  672. );
  673. }
  674. },
  675. );
  676. export const fetchStockOutLineClient = cache(
  677. async (pickOrderLineId: number) => {
  678. return serverFetchJson<StockOutLine[]>(
  679. `${BASE_API_URL}/stockOutLine/getByPickOrderLineId/${pickOrderLineId}`,
  680. {
  681. method: "GET",
  682. next: { tags: ["pickorder"] },
  683. },
  684. );
  685. },
  686. );
  687. export const fetchConsoDetail = cache(async (consoCode: string) => {
  688. return serverFetchJson<PreReleasePickOrderSummary>(
  689. `${BASE_API_URL}/pickOrder/pre-release-info/${consoCode}`,
  690. {
  691. method: "GET",
  692. next: { tags: ["pickorder"] },
  693. },
  694. );
  695. });
  696. export const releasePickOrder = async (data: ReleasePickOrderInputs) => {
  697. console.log(data);
  698. console.log(JSON.stringify(data));
  699. const po = await serverFetchJson<{ consoCode: string }>(
  700. `${BASE_API_URL}/pickOrder/releaseConso`,
  701. {
  702. method: "POST",
  703. body: JSON.stringify(data),
  704. headers: { "Content-Type": "application/json" },
  705. },
  706. );
  707. revalidateTag("pickorder");
  708. return po;
  709. };
  710. export const createStockOutLine = async (data: CreateStockOutLine) => {
  711. console.log("triggering");
  712. const po = await serverFetchJson<PostStockOutLiineResponse<StockOutLine>>(
  713. `${BASE_API_URL}/stockOutLine/create`,
  714. {
  715. method: "POST",
  716. body: JSON.stringify(data),
  717. headers: { "Content-Type": "application/json" },
  718. },
  719. );
  720. revalidateTag("pickorder");
  721. return po;
  722. };
  723. export const updateStockOutLine = async (data: UpdateStockOutLine) => {
  724. console.log(data);
  725. const po = await serverFetchJson<PostStockOutLiineResponse<StockOutLine>>(
  726. `${BASE_API_URL}/stockOutLine/update`,
  727. {
  728. method: "POST",
  729. body: JSON.stringify(data),
  730. headers: { "Content-Type": "application/json" },
  731. },
  732. );
  733. revalidateTag("pickorder");
  734. return po;
  735. };
  736. export const completeConsoPickOrder = async (consoCode: string) => {
  737. const po = await serverFetchJson<PostStockOutLiineResponse<StockOutLine>>(
  738. `${BASE_API_URL}/pickOrder/consoPickOrder/complete/${consoCode}`,
  739. {
  740. method: "POST",
  741. headers: { "Content-Type": "application/json" },
  742. },
  743. );
  744. revalidateTag("pickorder");
  745. return po;
  746. };
  747. export const fetchConsoStatus = cache(async (consoCode: string) => {
  748. return serverFetchJson<{ status: string }>(
  749. `${BASE_API_URL}/stockOut/get-status/${consoCode}`,
  750. {
  751. method: "GET",
  752. next: { tags: ["pickorder"] },
  753. },
  754. );
  755. });