FPSMS-frontend
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

89 line
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 PurchaseQcCheck {
  27. qcCheckId: number;
  28. qty: 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. sampleRate: number;
  42. sampleWeight: number;
  43. totalWeight: number;
  44. qcCheck: PurchaseQcCheck[];
  45. }
  46. export interface EscalationInput {
  47. status: string
  48. handler: string
  49. stockInLine: StockInLineEntry[]
  50. }
  51. export interface PutawayInput {
  52. status: string
  53. acceptedQty: number
  54. warehouseId: number
  55. // handler: string
  56. // stockInLine: StockInLineEntry[]
  57. }
  58. export type ModalFormInput = Partial<PurchaseQCInput & StockInInput & EscalationInput & PutawayInput>
  59. export const testFetch = cache(async (id: number) => {
  60. return serverFetchJson<PoResult>(`${BASE_API_URL}/po/detail/${id}`, {
  61. next: { tags: ["po"] },
  62. });
  63. });
  64. export const createStockInLine = async (data: StockInLineEntry) => {
  65. const stockInLine = await serverFetchJson<PostStockInLiineResponse<StockInLineEntry>>(`${BASE_API_URL}/stockInLine/create`, {
  66. method: "POST",
  67. body: JSON.stringify(data),
  68. headers: { "Content-Type": "application/json" },
  69. });
  70. return stockInLine
  71. }
  72. export const updateStockInLine = async (data: StockInLineEntry & ModalFormInput) => {
  73. const stockInLine = await serverFetchJson<PostStockInLiineResponse<StockInLineEntry & ModalFormInput>>(`${BASE_API_URL}/stockInLine/update`, {
  74. method: "POST",
  75. body: JSON.stringify(data),
  76. headers: { "Content-Type": "application/json" },
  77. });
  78. return stockInLine
  79. }