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.
 
 

84 righe
2.0 KiB

  1. import { cache } from "react";
  2. import "server-only";
  3. // import { serverFetchJson } from "@/app/utils/fetchUtil";
  4. // import { BASE_API_URL } from "@/config/api";
  5. import { serverFetchJson } from "../../utils/fetchUtil";
  6. import { BASE_API_URL } from "../../../config/api";
  7. import { Uom } from "../settings/uom";
  8. import { RecordsRes } from "../utils";
  9. export interface PoResult {
  10. id: number;
  11. code: string;
  12. orderDate: string;
  13. supplier: string;
  14. estimatedArrivalDate: string;
  15. completedDate: string;
  16. escalated: boolean;
  17. status: string;
  18. pol?: PurchaseOrderLine[];
  19. }
  20. export interface PurchaseOrderLine {
  21. id: number;
  22. purchaseOrderId: number;
  23. itemId: number;
  24. itemNo: string;
  25. itemName: string;
  26. qty: number;
  27. processed: number;
  28. uom: Uom;
  29. price: number;
  30. status: string;
  31. stockInLine: StockInLine[];
  32. }
  33. export interface StockInLine {
  34. id: number;
  35. stockInId: number;
  36. purchaseOrderId?: number;
  37. purchaseOrderLineId: number;
  38. itemId: number;
  39. itemNo: string;
  40. itemName: string;
  41. itemType: string;
  42. demandQty: number;
  43. acceptedQty: number;
  44. price: number;
  45. priceUnit: string;
  46. shelfLife?: number;
  47. receiptDate?: string;
  48. productionDate?: string;
  49. expiryDate?: string;
  50. status: string;
  51. supplier: string;
  52. lotNo: string;
  53. poCode: string;
  54. uom: Uom;
  55. defaultWarehouseId: number; // id for now
  56. }
  57. export const fetchPoList = cache(async (queryParams?: Record<string, any>) => {
  58. if (queryParams) {
  59. const queryString = new URLSearchParams(queryParams).toString();
  60. return serverFetchJson<RecordsRes<PoResult[]>>(
  61. `${BASE_API_URL}/po/list?${queryString}`,
  62. {
  63. method: "GET",
  64. next: { tags: ["po"] },
  65. },
  66. );
  67. } else {
  68. return serverFetchJson<RecordsRes<PoResult[]>>(`${BASE_API_URL}/po/list`, {
  69. method: "GET",
  70. next: { tags: ["po"] },
  71. });
  72. }
  73. });
  74. export const fetchPoWithStockInLines = cache(async (id: number) => {
  75. return serverFetchJson<PoResult>(`${BASE_API_URL}/po/detail/${id}`, {
  76. next: { tags: ["po"] },
  77. });
  78. });