FPSMS-frontend
25'ten fazla konu seçemezsiniz Konular bir harf veya rakamla başlamalı, kısa çizgiler ('-') içerebilir ve en fazla 35 karakter uzunluğunda olabilir.
 
 

184 satır
5.0 KiB

  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 { Pageable, serverFetchJson } from "@/app/utils/fetchUtil";
  7. import { QcItemResult } from "../settings/qcItem";
  8. import { RecordsRes } from "../utils";
  9. import { convertObjToURLSearchParams } from "@/app/utils/commonUtil";
  10. import { InventoryLotLineResult, InventoryResult } from ".";
  11. // import { BASE_API_URL } from "@/config/api";
  12. export interface LotLineInfo {
  13. inventoryLotLineId: number;
  14. itemId: number;
  15. itemNo: string;
  16. itemName: string;
  17. lotNo: string;
  18. remainingQty: number;
  19. uom: string;
  20. }
  21. export interface SearchInventoryLotLine extends Pageable {
  22. itemId: number;
  23. }
  24. export interface SearchInventory extends Pageable {
  25. code: string;
  26. name: string;
  27. type: string;
  28. }
  29. export interface InventoryResultByPage {
  30. total: number;
  31. records: InventoryResult[];
  32. }
  33. export interface UpdateInventoryLotLineStatusRequest {
  34. inventoryLotLineId: number;
  35. status: string;
  36. }
  37. export interface InventoryLotLineResultByPage {
  38. total: number;
  39. records: InventoryLotLineResult[];
  40. }
  41. export interface PostInventoryLotLineResponse<T = null> {
  42. id: number | null;
  43. name: string;
  44. code: string;
  45. type?: string;
  46. message: string | null;
  47. errorPosition: string
  48. entity?: T | T[];
  49. consoCode?: string;
  50. }
  51. export interface QrCodeAnalysisResponse {
  52. itemId: number;
  53. itemCode: string;
  54. itemName: string;
  55. scanned: ScannedLotInfo;
  56. sameItemLots: SameItemLotInfo[];
  57. }
  58. export interface ScannedLotInfo {
  59. stockInLineId: number;
  60. lotNo: string;
  61. inventoryLotLineId: number;
  62. }
  63. export interface SameItemLotInfo {
  64. lotNo: string;
  65. inventoryLotLineId: number;
  66. availableQty: number;
  67. uom: string;
  68. }
  69. export const analyzeQrCode = async (data: {
  70. itemId: number;
  71. stockInLineId: number;
  72. }) => {
  73. return serverFetchJson<QrCodeAnalysisResponse>(`${BASE_API_URL}/inventoryLotLine/analyze-qr-code`, {
  74. method: 'POST',
  75. body: JSON.stringify(data),
  76. headers: { "Content-Type": "application/json" },
  77. });
  78. };
  79. export const updateInventoryStatus = async (data: {
  80. itemId: number;
  81. lotId: number;
  82. status: string;
  83. qty: number;
  84. }) => {
  85. return serverFetchJson(`${BASE_API_URL}/inventory/update-status`, {
  86. method: 'PUT',
  87. body: JSON.stringify(data)
  88. });
  89. };
  90. export const fetchLotDetail = cache(async (stockInLineId: number) => {
  91. return serverFetchJson<LotLineInfo>(
  92. `${BASE_API_URL}/inventoryLotLine/lot-detail/${stockInLineId}`,
  93. {
  94. method: "GET",
  95. next: { tags: ["inventory"] },
  96. },
  97. );
  98. });
  99. export const updateInventoryLotLineStatus = async (data: {
  100. inventoryLotLineId: number;
  101. status: string;
  102. //qty: number;
  103. //operation?: string;
  104. }) => {
  105. // return await serverFetchJson(`${BASE_API_URL}/inventoryLotLine/updateStatus`, {
  106. // next: { tags: ["inventoryLotLine"] },
  107. // method: 'POST',
  108. // body: JSON.stringify(data)
  109. // });
  110. return await serverFetchJson<PostInventoryLotLineResponse<InventoryLotLineResult>>(`${BASE_API_URL}/inventoryLotLine/updateStatus`, {
  111. next: { tags: ["inventoryLotLine"] },
  112. method: 'POST',
  113. body: JSON.stringify(data),
  114. headers: { "Content-Type": "application/json" },
  115. });
  116. // revalidateTag("po");
  117. };
  118. export const fetchInventories = cache(async (data: SearchInventory) => {
  119. const queryStr = convertObjToURLSearchParams(data)
  120. return serverFetchJson<InventoryResultByPage>(`${BASE_API_URL}/inventory/getRecordByPage?${queryStr}`,
  121. { next: { tags: ["inventories"] } }
  122. )
  123. })
  124. export const fetchInventoryLotLines = cache(async (data: SearchInventoryLotLine) => {
  125. const queryStr = convertObjToURLSearchParams(data)
  126. return serverFetchJson<InventoryLotLineResultByPage>(`${BASE_API_URL}/inventoryLotLine/getRecordByPage?${queryStr}`, {
  127. next: { tags: ["inventoryLotLines"] },
  128. });
  129. });
  130. export const updateInventoryLotLineQuantities = async (data: {
  131. inventoryLotLineId: number;
  132. qty: number;
  133. operation: string;
  134. status: string;
  135. }) => {
  136. const result = await serverFetchJson<any>(
  137. `${BASE_API_URL}/inventoryLotLine/updateQuantities`,
  138. {
  139. method: "POST",
  140. body: JSON.stringify(data),
  141. headers: { "Content-Type": "application/json" },
  142. },
  143. );
  144. revalidateTag("pickorder");
  145. return result;
  146. };
  147. //STOCK TRANSFER
  148. export interface CreateStockTransferRequest {
  149. inventoryLotLineId: number;
  150. transferredQty: number;
  151. warehouseId: number;
  152. }
  153. export interface MessageResponse {
  154. id: number | null;
  155. name: string;
  156. code: string;
  157. type: string;
  158. message: string | null;
  159. errorPosition: string | null;
  160. }
  161. export const createStockTransfer = async (data: CreateStockTransferRequest) => {
  162. const result = await serverFetchJson<MessageResponse>(
  163. `${BASE_API_URL}/stockTransferRecord/create`,
  164. {
  165. method: "POST",
  166. body: JSON.stringify(data),
  167. headers: { "Content-Type": "application/json" },
  168. },
  169. );
  170. revalidateTag("inventoryLotLines");
  171. revalidateTag("inventories");
  172. return result;
  173. };