FPSMS-frontend
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.
 
 

91 rinda
2.4 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 { PoResult, StockInLine } from ".";
  7. import { serverFetchJson } from "@/app/utils/fetchUtil";
  8. // import { BASE_API_URL } from "@/config/api";
  9. export interface PostStockInLiineResponse<T> {
  10. id: number | null;
  11. name: string;
  12. code: string;
  13. message: string | null;
  14. errorPosition: string | keyof T;
  15. entity: StockInLine | StockInLine[]
  16. }
  17. export interface StockInLineEntry {
  18. id?: number
  19. itemId: number
  20. purchaseOrderId: number
  21. purchaseOrderLineId: number
  22. acceptedQty: number
  23. status?: string
  24. expiryDate?: string
  25. }
  26. export interface PurchaseQcResult {
  27. qcItemId: number;
  28. failQty: number;
  29. }
  30. export interface StockInInput {
  31. status: string
  32. productLotNo?: string,
  33. receiptDate: string
  34. acceptedQty: number
  35. acceptedWeight?: number
  36. productionDate?: string
  37. expiryDate: string
  38. }
  39. export interface PurchaseQCInput {
  40. status: string
  41. acceptedQty: number
  42. sampleRate: number;
  43. sampleWeight: number;
  44. totalWeight: number;
  45. qcResult: PurchaseQcResult[];
  46. }
  47. export interface EscalationInput {
  48. status: string
  49. handler: string
  50. acceptedQty: number // this is the qty to be escalated
  51. // escalationQty: number
  52. }
  53. export interface PutawayInput {
  54. status: string
  55. acceptedQty: number
  56. warehouseId: number
  57. // handler: string
  58. // stockInLine: StockInLineEntry[]
  59. }
  60. export type ModalFormInput = Partial<PurchaseQCInput & StockInInput & EscalationInput & PutawayInput>
  61. export const testFetch = cache(async (id: number) => {
  62. return serverFetchJson<PoResult>(`${BASE_API_URL}/po/detail/${id}`, {
  63. next: { tags: ["po"] },
  64. });
  65. });
  66. export const createStockInLine = async (data: StockInLineEntry) => {
  67. const stockInLine = await serverFetchJson<PostStockInLiineResponse<StockInLineEntry>>(`${BASE_API_URL}/stockInLine/create`, {
  68. method: "POST",
  69. body: JSON.stringify(data),
  70. headers: { "Content-Type": "application/json" },
  71. });
  72. return stockInLine
  73. }
  74. export const updateStockInLine = async (data: StockInLineEntry & ModalFormInput) => {
  75. const stockInLine = await serverFetchJson<PostStockInLiineResponse<StockInLineEntry & ModalFormInput>>(`${BASE_API_URL}/stockInLine/update`, {
  76. method: "POST",
  77. body: JSON.stringify(data),
  78. headers: { "Content-Type": "application/json" },
  79. });
  80. return stockInLine
  81. }