FPSMS-frontend
Non puoi selezionare più di 25 argomenti Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
 
 
 

160 righe
4.7 KiB

  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<PurchaseQCInput & StockInInput & EscalationInput & PutawayInput>
  67. export const testFetch = cache(async (id: number) => {
  68. return serverFetchJson<PoResult>(`${BASE_API_URL}/po/detail/${id}`, {
  69. next: { tags: ["po"] },
  70. });
  71. });
  72. export const fetchStockInLineInfo = cache(async (stockInLineId: number) => {
  73. return serverFetchJson<StockInLine>(`${BASE_API_URL}/stockInLine/${stockInLineId}`, {
  74. next: { tags: ["stockInLine"] },
  75. });
  76. });
  77. export const createStockInLine = async (data: StockInLineEntry) => {
  78. const stockInLine = await serverFetchJson<PostStockInLiineResponse<StockInLineEntry>>(`${BASE_API_URL}/stockInLine/create`, {
  79. method: "POST",
  80. body: JSON.stringify(data),
  81. headers: { "Content-Type": "application/json" },
  82. });
  83. // revalidateTag("po");
  84. return stockInLine
  85. }
  86. export const updateStockInLine = async (data: StockInLineEntry & ModalFormInput) => {
  87. const stockInLine = await serverFetchJson<PostStockInLiineResponse<StockInLineEntry & ModalFormInput>>(`${BASE_API_URL}/stockInLine/update`, {
  88. method: "POST",
  89. body: JSON.stringify(data),
  90. headers: { "Content-Type": "application/json" },
  91. });
  92. // revalidateTag("po");
  93. return stockInLine
  94. }
  95. export const startPo = async (poId: number) => {
  96. const po = await serverFetchJson<PostStockInLiineResponse<PoResult>>(`${BASE_API_URL}/po/start/${poId}`, {
  97. method: "POST",
  98. body: JSON.stringify({ poId }),
  99. headers: { "Content-Type": "application/json" },
  100. });
  101. revalidateTag("po");
  102. return po
  103. }
  104. export const checkPolAndCompletePo = async (poId: number) => {
  105. const po = await serverFetchJson<PostStockInLiineResponse<PoResult>>(`${BASE_API_URL}/po/check/${poId}`, {
  106. method: "POST",
  107. body: JSON.stringify({ poId }),
  108. headers: { "Content-Type": "application/json" },
  109. });
  110. revalidateTag("po");
  111. return po
  112. }
  113. export const fetchPoInClient = cache(async (id: number) => {
  114. return serverFetchJson<PoResult>(`${BASE_API_URL}/po/detail/${id}`, {
  115. next: { tags: ["po"] },
  116. });
  117. });
  118. export const fetchPoListClient = cache(async (queryParams?: Record<string, any>) => {
  119. if (queryParams) {
  120. const queryString = new URLSearchParams(queryParams).toString();
  121. return serverFetchJson<RecordsRes<PoResult[]>>(`${BASE_API_URL}/po/list?${queryString}`, {
  122. method: 'GET',
  123. next: { tags: ["po"] },
  124. });
  125. } else {
  126. return serverFetchJson<RecordsRes<PoResult[]>>(`${BASE_API_URL}/po/list`, {
  127. method: 'GET',
  128. next: { tags: ["po"] },
  129. });
  130. }
  131. });
  132. export const testing = cache(async (queryParams?: Record<string, any>) => {
  133. if (queryParams) {
  134. const queryString = new URLSearchParams(queryParams).toString();
  135. return serverFetchJson<RecordsRes<PoResult[]>>(`${BASE_API_URL}/po/testing?${queryString}`, {
  136. method: 'GET',
  137. next: { tags: ["po"] },
  138. });
  139. } else {
  140. return serverFetchJson<RecordsRes<PoResult[]>>(`${BASE_API_URL}/po/testing`, {
  141. method: 'GET',
  142. next: { tags: ["po"] },
  143. });
  144. }
  145. });