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.
 
 

88 lines
2.1 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. itemDetail?: string;
  17. escalated: boolean;
  18. status: string;
  19. pol?: PurchaseOrderLine[];
  20. }
  21. export interface PurchaseOrderLine {
  22. id: number;
  23. purchaseOrderId: number;
  24. itemId: number;
  25. itemNo: string;
  26. itemName: string;
  27. qty: number;
  28. processed: number;
  29. receivedQty: number;
  30. uom: Uom;
  31. price: number;
  32. status: string;
  33. stockInLine: StockInLine[];
  34. }
  35. export interface StockInLine {
  36. id: number;
  37. stockInId: number;
  38. purchaseOrderId?: number;
  39. purchaseOrderLineId: number;
  40. itemId: number;
  41. itemNo: string;
  42. itemName: string;
  43. itemType: string;
  44. demandQty: number;
  45. acceptedQty: number;
  46. qty: number;
  47. processed: number;
  48. price: number;
  49. priceUnit: string;
  50. shelfLife?: number;
  51. receiptDate?: string;
  52. productionDate?: string;
  53. expiryDate?: string;
  54. status: string;
  55. supplier: string;
  56. lotNo: string;
  57. poCode: string;
  58. uom: Uom;
  59. defaultWarehouseId: number; // id for now
  60. }
  61. export const fetchPoList = cache(async (queryParams?: Record<string, any>) => {
  62. if (queryParams) {
  63. const queryString = new URLSearchParams(queryParams).toString();
  64. return serverFetchJson<RecordsRes<PoResult[]>>(
  65. `${BASE_API_URL}/po/list?${queryString}`,
  66. {
  67. method: "GET",
  68. next: { tags: ["po"] },
  69. },
  70. );
  71. } else {
  72. return serverFetchJson<RecordsRes<PoResult[]>>(`${BASE_API_URL}/po/list`, {
  73. method: "GET",
  74. next: { tags: ["po"] },
  75. });
  76. }
  77. });
  78. export const fetchPoWithStockInLines = cache(async (id: number) => {
  79. return serverFetchJson<PoResult>(`${BASE_API_URL}/po/detail/${id}`, {
  80. next: { tags: ["po"] },
  81. });
  82. });