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

actions.ts 22 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ヶ月前
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ヶ月前
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851
  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 type AutoAssignReleaseResponse = {
  189. id: number | null;
  190. name?: string | null;
  191. code?: string | null;
  192. type?: string | null;
  193. message?: string | null;
  194. errorPosition?: string | null;
  195. entity?: any;
  196. };
  197. export interface PickOrderCompletionResponse {
  198. id: number | null;
  199. name: string;
  200. code: string;
  201. type?: string;
  202. message: string | null;
  203. errorPosition: string;
  204. entity?: {
  205. hasCompletedOrders: boolean;
  206. completedOrders: Array<{
  207. pickOrderId: number;
  208. pickOrderCode: string;
  209. consoCode: string;
  210. isCompleted: boolean;
  211. stockOutStatus: string;
  212. totalLines: number;
  213. unfinishedLines: number;
  214. }>;
  215. allOrders: Array<{
  216. pickOrderId: number;
  217. pickOrderCode: string;
  218. consoCode: string;
  219. isCompleted: boolean;
  220. stockOutStatus: string;
  221. totalLines: number;
  222. unfinishedLines: number;
  223. }>;
  224. };
  225. }
  226. export interface UpdateSuggestedLotLineIdRequest {
  227. newLotLineId: number;
  228. }
  229. export interface FGPickOrderResponse {
  230. pickOrderId: number;
  231. pickOrderCode: string;
  232. pickOrderConsoCode: string;
  233. pickOrderTargetDate: string;
  234. pickOrderStatus: string;
  235. deliveryOrderId: number;
  236. deliveryNo: string;
  237. deliveryDate: string;
  238. shopId: number;
  239. shopCode: string;
  240. shopName: string;
  241. shopAddress: string;
  242. shopPoNo: string;
  243. numberOfCartons: number;
  244. DepartureTime: string;
  245. truckNo: string;
  246. qrCodeData: number;
  247. }
  248. export interface AutoAssignReleaseByStoreRequest {
  249. userId: number;
  250. storeId: string; // "2/F" | "4/F"
  251. }
  252. export const fetchFGPickOrders = async (pickOrderId: number) => {
  253. const response = await serverFetchJson<FGPickOrderResponse>(
  254. `${BASE_API_URL}/pickOrder/fg-pick-orders/${pickOrderId}`,
  255. {
  256. method: "GET",
  257. },
  258. );
  259. return response;
  260. };
  261. export const updateSuggestedLotLineId = async (suggestedPickLotId: number, newLotLineId: number) => {
  262. const response = await serverFetchJson<PostPickOrderResponse<UpdateSuggestedLotLineIdRequest>>(
  263. `${BASE_API_URL}/suggestedPickLot/update-suggested-lot/${suggestedPickLotId}`,
  264. {
  265. method: "POST",
  266. body: JSON.stringify({ newLotLineId }),
  267. headers: { "Content-Type": "application/json" },
  268. },
  269. );
  270. revalidateTag("pickorder");
  271. return response;
  272. };
  273. export const autoAssignAndReleasePickOrder = async (userId: number): Promise<AutoAssignReleaseResponse> => {
  274. const response = await serverFetchJson<AutoAssignReleaseResponse>(
  275. `${BASE_API_URL}/pickOrder/auto-assign-release/${userId}`,
  276. {
  277. method: "POST",
  278. headers: { "Content-Type": "application/json" },
  279. },
  280. );
  281. revalidateTag("pickorder");
  282. return response;
  283. };
  284. export const autoAssignAndReleasePickOrderByStore = async (
  285. userId: number,
  286. storeId: string
  287. ): Promise<AutoAssignReleaseResponse> => {
  288. const url = `${BASE_API_URL}/pickOrder/auto-assign-release-by-store?userId=${userId}&storeId=${encodeURIComponent(storeId)}`;
  289. const response = await serverFetchJson<AutoAssignReleaseResponse>(url, {
  290. method: "POST",
  291. headers: { "Content-Type": "application/json" },
  292. // no body
  293. next: { tags: ["pickorder"] },
  294. });
  295. revalidateTag("pickorder");
  296. return response;
  297. };
  298. export const checkPickOrderCompletion = async (userId: number): Promise<PickOrderCompletionResponse> => {
  299. const response = await serverFetchJson<PickOrderCompletionResponse>(
  300. `${BASE_API_URL}/pickOrder/check-pick-completion/${userId}`,
  301. {
  302. method: "GET",
  303. headers: { "Content-Type": "application/json" },
  304. },
  305. );
  306. return response;
  307. };
  308. export const recordPickExecutionIssue = async (data: PickExecutionIssueData) => {
  309. const result = await serverFetchJson<PostPickOrderResponse>(
  310. `${BASE_API_URL}/pickExecution/recordIssue`,
  311. {
  312. method: "POST",
  313. body: JSON.stringify(data),
  314. headers: { "Content-Type": "application/json" },
  315. },
  316. );
  317. revalidateTag("pickorder");
  318. return result;
  319. };
  320. export const resuggestPickOrder = async (pickOrderId: number) => {
  321. console.log("Resuggesting pick order:", pickOrderId);
  322. const result = await serverFetchJson<PostPickOrderResponse>(
  323. `${BASE_API_URL}/suggestedPickLot/resuggest/${pickOrderId}`,
  324. {
  325. method: "POST",
  326. headers: { "Content-Type": "application/json" },
  327. },
  328. );
  329. revalidateTag("pickorder");
  330. return result;
  331. };
  332. export const updateStockOutLineStatus = async (data: {
  333. id: number;
  334. status: string;
  335. qty?: number;
  336. remarks?: string;
  337. }) => {
  338. console.log("Updating stock out line status:", data);
  339. const result = await serverFetchJson<PostStockOutLiineResponse<StockOutLine>>(
  340. `${BASE_API_URL}/stockOutLine/updateStatus`,
  341. {
  342. method: "POST",
  343. body: JSON.stringify(data),
  344. headers: { "Content-Type": "application/json" },
  345. },
  346. );
  347. revalidateTag("pickorder");
  348. return result;
  349. };
  350. // Missing function 1: newassignPickOrder
  351. export const newassignPickOrder = async (data: AssignPickOrderInputs) => {
  352. const response = await serverFetchJson<PostPickOrderResponse>(
  353. `${BASE_API_URL}/pickOrder/assign`,
  354. {
  355. method: "POST",
  356. body: JSON.stringify(data),
  357. headers: { "Content-Type": "application/json" },
  358. },
  359. );
  360. revalidateTag("pickorder");
  361. return response;
  362. };
  363. // Missing function 2: releaseAssignedPickOrders
  364. export const releaseAssignedPickOrders = async (data: AssignPickOrderInputs) => {
  365. const response = await serverFetchJson<PostPickOrderResponse>(
  366. `${BASE_API_URL}/pickOrder/release-assigned`,
  367. {
  368. method: "POST",
  369. body: JSON.stringify(data),
  370. headers: { "Content-Type": "application/json" },
  371. },
  372. );
  373. revalidateTag("pickorder");
  374. return response;
  375. };
  376. // Get latest group name and create it automatically
  377. export const getLatestGroupNameAndCreate = async () => {
  378. return serverFetchJson<PostPickOrderResponse>(
  379. `${BASE_API_URL}/pickOrder/groups/latest`,
  380. {
  381. method: "GET",
  382. next: { tags: ["pickorder"] },
  383. },
  384. );
  385. };
  386. // Get all groups
  387. export const fetchAllGroups = cache(async () => {
  388. return serverFetchJson<PickOrderGroupInfo[]>(
  389. `${BASE_API_URL}/pickOrder/groups/list`,
  390. {
  391. method: "GET",
  392. next: { tags: ["pickorder"] },
  393. },
  394. );
  395. });
  396. // Create or update groups (flexible - can handle both cases)
  397. export const createOrUpdateGroups = async (data: SavePickOrderGroupRequest) => {
  398. const response = await serverFetchJson<PostPickOrderResponse>(
  399. `${BASE_API_URL}/pickOrder/groups/create`,
  400. {
  401. method: "POST",
  402. body: JSON.stringify(data),
  403. headers: { "Content-Type": "application/json" },
  404. },
  405. );
  406. revalidateTag("pickorder");
  407. return response;
  408. };
  409. // Get groups by pick order ID
  410. export const fetchGroupsByPickOrderId = cache(async (pickOrderId: number) => {
  411. return serverFetchJson<PickOrderGroupInfo[]>(
  412. `${BASE_API_URL}/pickOrder/groups/${pickOrderId}`,
  413. {
  414. method: "GET",
  415. next: { tags: ["pickorder"] },
  416. },
  417. );
  418. });
  419. export const fetchPickOrderDetails = cache(async (ids: string) => {
  420. return serverFetchJson<GetPickOrderInfoResponse>(
  421. `${BASE_API_URL}/pickOrder/detail/${ids}`,
  422. {
  423. method: "GET",
  424. next: { tags: ["pickorder"] },
  425. },
  426. );
  427. });
  428. export interface PickOrderLotDetailResponse {
  429. lotId: number;
  430. lotNo: string;
  431. expiryDate: string;
  432. location: string;
  433. stockUnit: string;
  434. inQty: number;
  435. availableQty: number;
  436. requiredQty: number;
  437. actualPickQty: number;
  438. suggestedPickLotId: number;
  439. lotStatus: string;
  440. lotAvailability: 'available' | 'insufficient_stock' | 'expired' | 'status_unavailable'|'rejected';
  441. }
  442. interface ALLPickOrderLotDetailResponse {
  443. // Pick Order Information
  444. pickOrderId: number;
  445. pickOrderCode: string;
  446. pickOrderTargetDate: string;
  447. pickOrderType: string;
  448. pickOrderStatus: string;
  449. pickOrderAssignTo: number;
  450. groupName: string;
  451. // Pick Order Line Information
  452. pickOrderLineId: number;
  453. pickOrderLineRequiredQty: number;
  454. pickOrderLineStatus: string;
  455. // Item Information
  456. itemId: number;
  457. itemCode: string;
  458. itemName: string;
  459. uomCode: string;
  460. uomDesc: string;
  461. // Lot Information
  462. lotId: number;
  463. lotNo: string;
  464. expiryDate: string;
  465. location: string;
  466. outQty: number;
  467. holdQty: number;
  468. stockUnit: string;
  469. availableQty: number;
  470. requiredQty: number;
  471. actualPickQty: number;
  472. totalPickedByAllPickOrders: number;
  473. suggestedPickLotId: number;
  474. lotStatus: string;
  475. stockOutLineId?: number;
  476. stockOutLineStatus?: string;
  477. stockOutLineQty?: number;
  478. lotAvailability: 'available' | 'insufficient_stock' | 'expired' | 'status_unavailable'|'rejected';
  479. processingStatus: string;
  480. }
  481. interface SuggestionWithStatus {
  482. suggestionId: number;
  483. suggestionQty: number;
  484. suggestionCreated: string;
  485. lotLineId: number;
  486. lotNo: string;
  487. expiryDate: string;
  488. location: string;
  489. stockOutLineId?: number;
  490. stockOutLineStatus?: string;
  491. stockOutLineQty?: number;
  492. suggestionStatus: 'active' | 'completed' | 'rejected' | 'in_progress' | 'unknown';
  493. }
  494. export interface CheckCompleteResponse {
  495. id: number | null;
  496. name: string;
  497. code: string;
  498. type?: string;
  499. message: string | null;
  500. errorPosition: string;
  501. }
  502. export const checkAndCompletePickOrderByConsoCode = async (consoCode: string): Promise<CheckCompleteResponse> => {
  503. const response = await serverFetchJson<CheckCompleteResponse>(
  504. `${BASE_API_URL}/pickOrder/check-complete/${consoCode}`,
  505. {
  506. method: "POST",
  507. headers: {
  508. "Content-Type": "application/json",
  509. },
  510. },
  511. );
  512. revalidateTag("pickorder");
  513. return response;
  514. };
  515. export const fetchPickOrderDetailsOptimized = cache(async (userId?: number) => {
  516. const url = userId
  517. ? `${BASE_API_URL}/pickOrder/detail-optimized?userId=${userId}`
  518. : `${BASE_API_URL}/pickOrder/detail-optimized`;
  519. return serverFetchJson<any[]>(
  520. url,
  521. {
  522. method: "GET",
  523. next: { tags: ["pickorder"] },
  524. },
  525. );
  526. });
  527. const fetchSuggestionsWithStatus = async (pickOrderLineId: number) => {
  528. try {
  529. const response = await fetch(`/api/suggestedPickLot/suggestions-with-status/${pickOrderLineId}`);
  530. const suggestions: SuggestionWithStatus[] = await response.json();
  531. return suggestions;
  532. } catch (error) {
  533. console.error('Error fetching suggestions with status:', error);
  534. return [];
  535. }
  536. };
  537. // Update the existing function to use the non-auto-assign endpoint
  538. export const fetchALLPickOrderLineLotDetails = cache(async (userId: number): Promise<any[]> => {
  539. try {
  540. console.log("🔍 Fetching all pick order line lot details for userId:", userId);
  541. // ✅ Use the non-auto-assign endpoint
  542. const data = await serverFetchJson<any[]>(
  543. `${BASE_API_URL}/pickOrder/all-lots-with-details-no-auto-assign/${userId}`,
  544. {
  545. method: 'GET',
  546. next: { tags: ["pickorder"] },
  547. }
  548. );
  549. console.log("✅ Fetched lot details:", data);
  550. return data;
  551. } catch (error) {
  552. console.error("❌ Error fetching lot details:", error);
  553. return [];
  554. }
  555. });
  556. export const fetchAllPickOrderDetails = cache(async (userId?: number) => {
  557. if (!userId) {
  558. return {
  559. consoCode: null,
  560. pickOrders: [],
  561. items: []
  562. };
  563. }
  564. // ✅ Use the correct endpoint with userId in the path
  565. const url = `${BASE_API_URL}/pickOrder/detail-optimized/${userId}`;
  566. return serverFetchJson<GetPickOrderInfoResponse>(
  567. url,
  568. {
  569. method: "GET",
  570. next: { tags: ["pickorder"] },
  571. },
  572. );
  573. });
  574. export const fetchPickOrderLineLotDetails = cache(async (pickOrderLineId: number) => {
  575. return serverFetchJson<PickOrderLotDetailResponse[]>(
  576. `${BASE_API_URL}/pickOrder/lot-details/${pickOrderLineId}`,
  577. {
  578. method: "GET",
  579. next: { tags: ["pickorder"] },
  580. },
  581. );
  582. });
  583. export const createPickOrder = async (data: SavePickOrderRequest) => {
  584. console.log(data);
  585. const po = await serverFetchJson<PostPickOrderResponse>(
  586. `${BASE_API_URL}/pickOrder/create`,
  587. {
  588. method: "POST",
  589. body: JSON.stringify(data),
  590. headers: { "Content-Type": "application/json" },
  591. },
  592. );
  593. revalidateTag("pickorder");
  594. return po;
  595. }
  596. export const assignPickOrder = async (ids: number[]) => {
  597. const pickOrder = await serverFetchJson<any>(
  598. `${BASE_API_URL}/pickOrder/conso`,
  599. {
  600. method: "POST",
  601. body: JSON.stringify({ ids: ids }),
  602. headers: { "Content-Type": "application/json" },
  603. },
  604. );
  605. // revalidateTag("po");
  606. return pickOrder;
  607. };
  608. export const consolidatePickOrder = async (ids: number[]) => {
  609. const pickOrder = await serverFetchJson<any>(
  610. `${BASE_API_URL}/pickOrder/conso`,
  611. {
  612. method: "POST",
  613. body: JSON.stringify({ ids: ids }),
  614. headers: { "Content-Type": "application/json" },
  615. },
  616. );
  617. return pickOrder;
  618. };
  619. export const consolidatePickOrder_revert = async (ids: number[]) => {
  620. const pickOrder = await serverFetchJson<any>(
  621. `${BASE_API_URL}/pickOrder/deconso`,
  622. {
  623. method: "POST",
  624. body: JSON.stringify({ ids: ids }),
  625. headers: { "Content-Type": "application/json" },
  626. },
  627. );
  628. // revalidateTag("po");
  629. return pickOrder;
  630. };
  631. export const fetchPickOrderClient = cache(
  632. async (queryParams?: Record<string, any>) => {
  633. if (queryParams) {
  634. const queryString = new URLSearchParams(queryParams).toString();
  635. return serverFetchJson<RecordsRes<PickOrderResult[]>>(
  636. `${BASE_API_URL}/pickOrder/getRecordByPage?${queryString}`,
  637. {
  638. method: "GET",
  639. next: { tags: ["pickorder"] },
  640. },
  641. );
  642. } else {
  643. return serverFetchJson<RecordsRes<PickOrderResult[]>>(
  644. `${BASE_API_URL}/pickOrder/getRecordByPage`,
  645. {
  646. method: "GET",
  647. next: { tags: ["pickorder"] },
  648. },
  649. );
  650. }
  651. },
  652. );
  653. export const fetchPickOrderWithStockClient = cache(
  654. async (queryParams?: Record<string, any>) => {
  655. if (queryParams) {
  656. const queryString = new URLSearchParams(queryParams).toString();
  657. return serverFetchJson<RecordsRes<GetPickOrderInfo[]>>(
  658. `${BASE_API_URL}/pickOrder/getRecordByPageWithStock?${queryString}`,
  659. {
  660. method: "GET",
  661. next: { tags: ["pickorder"] },
  662. },
  663. );
  664. } else {
  665. return serverFetchJson<RecordsRes<GetPickOrderInfo[]>>(
  666. `${BASE_API_URL}/pickOrder/getRecordByPageWithStock`,
  667. {
  668. method: "GET",
  669. next: { tags: ["pickorder"] },
  670. },
  671. );
  672. }
  673. },
  674. );
  675. export const fetchConsoPickOrderClient = cache(
  676. async (queryParams?: Record<string, any>) => {
  677. if (queryParams) {
  678. const queryString = new URLSearchParams(queryParams).toString();
  679. return serverFetchJson<RecordsRes<ConsoPickOrderResult[]>>(
  680. `${BASE_API_URL}/pickOrder/getRecordByPage-conso?${queryString}`,
  681. {
  682. method: "GET",
  683. next: { tags: ["pickorder"] },
  684. },
  685. );
  686. } else {
  687. return serverFetchJson<RecordsRes<ConsoPickOrderResult[]>>(
  688. `${BASE_API_URL}/pickOrder/getRecordByPage-conso`,
  689. {
  690. method: "GET",
  691. next: { tags: ["pickorder"] },
  692. },
  693. );
  694. }
  695. },
  696. );
  697. export const fetchPickOrderLineClient = cache(
  698. async (queryParams?: Record<string, any>) => {
  699. if (queryParams) {
  700. const queryString = new URLSearchParams(queryParams).toString();
  701. return serverFetchJson<RecordsRes<PickOrderLineWithSuggestedLot[]>>(
  702. `${BASE_API_URL}/pickOrder/get-pickorder-line-byPage?${queryString}`,
  703. {
  704. method: "GET",
  705. next: { tags: ["pickorder"] },
  706. },
  707. );
  708. } else {
  709. return serverFetchJson<RecordsRes<PickOrderLineWithSuggestedLot[]>>(
  710. `${BASE_API_URL}/pickOrder/get-pickorder-line-byPage`,
  711. {
  712. method: "GET",
  713. next: { tags: ["pickorder"] },
  714. },
  715. );
  716. }
  717. },
  718. );
  719. export const fetchStockOutLineClient = cache(
  720. async (pickOrderLineId: number) => {
  721. return serverFetchJson<StockOutLine[]>(
  722. `${BASE_API_URL}/stockOutLine/getByPickOrderLineId/${pickOrderLineId}`,
  723. {
  724. method: "GET",
  725. next: { tags: ["pickorder"] },
  726. },
  727. );
  728. },
  729. );
  730. export const fetchConsoDetail = cache(async (consoCode: string) => {
  731. return serverFetchJson<PreReleasePickOrderSummary>(
  732. `${BASE_API_URL}/pickOrder/pre-release-info/${consoCode}`,
  733. {
  734. method: "GET",
  735. next: { tags: ["pickorder"] },
  736. },
  737. );
  738. });
  739. export const releasePickOrder = async (data: ReleasePickOrderInputs) => {
  740. console.log(data);
  741. console.log(JSON.stringify(data));
  742. const po = await serverFetchJson<{ consoCode: string }>(
  743. `${BASE_API_URL}/pickOrder/releaseConso`,
  744. {
  745. method: "POST",
  746. body: JSON.stringify(data),
  747. headers: { "Content-Type": "application/json" },
  748. },
  749. );
  750. revalidateTag("pickorder");
  751. return po;
  752. };
  753. export const createStockOutLine = async (data: CreateStockOutLine) => {
  754. console.log("triggering");
  755. const po = await serverFetchJson<PostStockOutLiineResponse<StockOutLine>>(
  756. `${BASE_API_URL}/stockOutLine/create`,
  757. {
  758. method: "POST",
  759. body: JSON.stringify(data),
  760. headers: { "Content-Type": "application/json" },
  761. },
  762. );
  763. revalidateTag("pickorder");
  764. return po;
  765. };
  766. export const updateStockOutLine = async (data: UpdateStockOutLine) => {
  767. console.log(data);
  768. const po = await serverFetchJson<PostStockOutLiineResponse<StockOutLine>>(
  769. `${BASE_API_URL}/stockOutLine/update`,
  770. {
  771. method: "POST",
  772. body: JSON.stringify(data),
  773. headers: { "Content-Type": "application/json" },
  774. },
  775. );
  776. revalidateTag("pickorder");
  777. return po;
  778. };
  779. export const completeConsoPickOrder = async (consoCode: string) => {
  780. const po = await serverFetchJson<PostStockOutLiineResponse<StockOutLine>>(
  781. `${BASE_API_URL}/pickOrder/consoPickOrder/complete/${consoCode}`,
  782. {
  783. method: "POST",
  784. headers: { "Content-Type": "application/json" },
  785. },
  786. );
  787. revalidateTag("pickorder");
  788. return po;
  789. };
  790. export const fetchConsoStatus = cache(async (consoCode: string) => {
  791. return serverFetchJson<{ status: string }>(
  792. `${BASE_API_URL}/stockOut/get-status/${consoCode}`,
  793. {
  794. method: "GET",
  795. next: { tags: ["pickorder"] },
  796. },
  797. );
  798. });