FPSMS-frontend
Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
před 5 měsíci
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  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 } from "../../utils/fetchUtil";
  10. import { QcItemResult } from "../settings/qcItem";
  11. import { RecordsRes } from "../utils";
  12. // import { BASE_API_URL } from "@/config/api";
  13. export interface PostStockInLiineResponse<T> {
  14. id: number | null;
  15. name: string;
  16. code: string;
  17. type?: string;
  18. message: string | null;
  19. errorPosition: string | keyof T;
  20. entity: T | T[];
  21. // entity: StockInLine | StockInLine[]
  22. }
  23. export interface StockInLineEntry {
  24. id?: number;
  25. itemId: number;
  26. purchaseOrderId: number;
  27. purchaseOrderLineId: number;
  28. acceptedQty: number;
  29. status?: string;
  30. expiryDate?: string;
  31. }
  32. export interface PurchaseQcResult {
  33. qcItemId: number;
  34. failQty: number;
  35. }
  36. export interface StockInInput {
  37. status: string;
  38. productLotNo?: string;
  39. receiptDate: string;
  40. acceptedQty: number;
  41. acceptedWeight?: number;
  42. productionDate?: string;
  43. expiryDate: string;
  44. }
  45. export interface PurchaseQCInput {
  46. status: string;
  47. acceptedQty: number;
  48. sampleRate: number;
  49. sampleWeight: number;
  50. totalWeight: number;
  51. qcResult: PurchaseQcResult[];
  52. }
  53. export interface EscalationInput {
  54. status: string;
  55. handler: string;
  56. acceptedQty: number; // this is the qty to be escalated
  57. // escalationQty: number
  58. }
  59. export interface PutawayInput {
  60. status: string;
  61. acceptedQty: number;
  62. warehouseId: number;
  63. // handler: string
  64. // stockInLine: StockInLineEntry[]
  65. }
  66. export type ModalFormInput = Partial<
  67. PurchaseQCInput & StockInInput & EscalationInput & PutawayInput
  68. >;
  69. export const testFetch = cache(async (id: number) => {
  70. return serverFetchJson<PoResult>(`${BASE_API_URL}/po/detail/${id}`, {
  71. next: { tags: ["po"] },
  72. });
  73. });
  74. export const fetchStockInLineInfo = cache(async (stockInLineId: number) => {
  75. return serverFetchJson<StockInLine>(
  76. `${BASE_API_URL}/stockInLine/${stockInLineId}`,
  77. {
  78. next: { tags: ["stockInLine"] },
  79. },
  80. );
  81. });
  82. export const createStockInLine = async (data: StockInLineEntry) => {
  83. const stockInLine = await serverFetchJson<
  84. PostStockInLiineResponse<StockInLineEntry>
  85. >(`${BASE_API_URL}/stockInLine/create`, {
  86. method: "POST",
  87. body: JSON.stringify(data),
  88. headers: { "Content-Type": "application/json" },
  89. });
  90. // revalidateTag("po");
  91. return stockInLine;
  92. };
  93. export const updateStockInLine = async (
  94. data: StockInLineEntry & ModalFormInput,
  95. ) => {
  96. const stockInLine = await serverFetchJson<
  97. PostStockInLiineResponse<StockInLineEntry & ModalFormInput>
  98. >(`${BASE_API_URL}/stockInLine/update`, {
  99. method: "POST",
  100. body: JSON.stringify(data),
  101. headers: { "Content-Type": "application/json" },
  102. });
  103. // revalidateTag("po");
  104. return stockInLine;
  105. };
  106. export const startPo = async (poId: number) => {
  107. const po = await serverFetchJson<PostStockInLiineResponse<PoResult>>(
  108. `${BASE_API_URL}/po/start/${poId}`,
  109. {
  110. method: "POST",
  111. body: JSON.stringify({ poId }),
  112. headers: { "Content-Type": "application/json" },
  113. },
  114. );
  115. revalidateTag("po");
  116. return po;
  117. };
  118. export const checkPolAndCompletePo = async (poId: number) => {
  119. const po = await serverFetchJson<PostStockInLiineResponse<PoResult>>(
  120. `${BASE_API_URL}/po/check/${poId}`,
  121. {
  122. method: "POST",
  123. body: JSON.stringify({ poId }),
  124. headers: { "Content-Type": "application/json" },
  125. },
  126. );
  127. revalidateTag("po");
  128. return po;
  129. };
  130. export const fetchPoInClient = cache(async (id: number) => {
  131. return serverFetchJson<PoResult>(`${BASE_API_URL}/po/detail/${id}`, {
  132. next: { tags: ["po"] },
  133. });
  134. });
  135. export const fetchPoListClient = cache(
  136. async (queryParams?: Record<string, any>) => {
  137. if (queryParams) {
  138. const queryString = new URLSearchParams(queryParams).toString();
  139. return serverFetchJson<RecordsRes<PoResult[]>>(
  140. `${BASE_API_URL}/po/list?${queryString}`,
  141. {
  142. method: "GET",
  143. next: { tags: ["po"] },
  144. },
  145. );
  146. } else {
  147. return serverFetchJson<RecordsRes<PoResult[]>>(
  148. `${BASE_API_URL}/po/list`,
  149. {
  150. method: "GET",
  151. next: { tags: ["po"] },
  152. },
  153. );
  154. }
  155. },
  156. );
  157. export const testing = cache(async (queryParams?: Record<string, any>) => {
  158. if (queryParams) {
  159. const queryString = new URLSearchParams(queryParams).toString();
  160. return serverFetchJson<RecordsRes<PoResult[]>>(
  161. `${BASE_API_URL}/po/testing?${queryString}`,
  162. {
  163. method: "GET",
  164. next: { tags: ["po"] },
  165. },
  166. );
  167. } else {
  168. return serverFetchJson<RecordsRes<PoResult[]>>(
  169. `${BASE_API_URL}/po/testing`,
  170. {
  171. method: "GET",
  172. next: { tags: ["po"] },
  173. },
  174. );
  175. }
  176. });