diff --git a/src/app/api/inventory/actions.ts b/src/app/api/inventory/actions.ts index 216a3c2..e2bab86 100644 --- a/src/app/api/inventory/actions.ts +++ b/src/app/api/inventory/actions.ts @@ -3,9 +3,11 @@ import { BASE_API_URL } from "@/config/api"; // import { ServerFetchError, serverFetchJson, serverFetchWithNoContent } from "@/app/utils/fetchUtil"; import { revalidateTag } from "next/cache"; import { cache } from "react"; -import { serverFetchJson } from "@/app/utils/fetchUtil"; +import { Pageable, serverFetchJson } from "@/app/utils/fetchUtil"; import { QcItemResult } from "../settings/qcItem"; import { RecordsRes } from "../utils"; +import { convertObjToURLSearchParams } from "@/app/utils/commonUtil"; +import { InventoryLotLineResult, InventoryResult } from "."; // import { BASE_API_URL } from "@/config/api"; export interface LotLineInfo { @@ -18,6 +20,26 @@ export interface LotLineInfo { uom: string; } +export interface SearchInventoryLotLine extends Pageable { + itemId: number; +} + +export interface SearchInventory extends Pageable { + code: string; + name: string; + type: string; +} + +export interface InventoryResultByPage { + total: number; + records: InventoryResult[]; +} + +export interface InventoryLotLineResultByPage { + total: number; + records: InventoryLotLineResult[]; +} + export const fetchLotDetail = cache(async (stockInLineId: number) => { return serverFetchJson( `${BASE_API_URL}/inventoryLotLine/lot-detail/${stockInLineId}`, @@ -27,3 +49,19 @@ export const fetchLotDetail = cache(async (stockInLineId: number) => { }, ); }); + +export const fetchInventories = cache(async (data: SearchInventory) => { + const queryStr = convertObjToURLSearchParams(data) + + return serverFetchJson(`${BASE_API_URL}/inventory/getRecordByPage?${queryStr}`, + { next: { tags: ["inventories"] } } + ) +}) + + +export const fetchInventoryLotLines = cache(async (data: SearchInventoryLotLine) => { + const queryStr = convertObjToURLSearchParams(data) + return serverFetchJson(`${BASE_API_URL}/inventoryLotLine/getRecordByPage?${queryStr}`, { + next: { tags: ["inventoryLotLines"] }, + }); +}); diff --git a/src/app/api/inventory/index.ts b/src/app/api/inventory/index.ts index b4bf7c9..cdb9294 100644 --- a/src/app/api/inventory/index.ts +++ b/src/app/api/inventory/index.ts @@ -1,3 +1,4 @@ +import { convertObjToURLSearchParams } from "@/app/utils/commonUtil"; import { serverFetchJson } from "@/app/utils/fetchUtil"; import { BASE_API_URL } from "@/config/api"; import { cache } from "react"; @@ -5,20 +6,54 @@ import "server-only"; export interface InventoryResult { id: number; + itemId: number; itemCode: string; itemName: string; itemType: string; + onHandQty: number; + onHoldQty: number; + unavailableQty: number; availableQty: number; uomCode: string; uomUdfudesc: string; // germPerSmallestUnit: number; - // qtyPerSmallestUnit: number; + qtyPerSmallestUnit: number; + baseUom: string; // smallestUnit: string; price: number; currencyName: string; status: string; } +export interface InventoryLotLineResult { + id: number; + lotNo: string; + item: InventoryLotLineItem; + warehouse: InventoryLotLineWarehouse; + inQty: number; + outQty: number; + holdQty: number; + expiryDate: number[]; + status: string; + availableQty: number; + uom: string; + qtyPerSmallestUnit: number; + baseUom: string; +} + +export interface InventoryLotLineItem { + id: number; + code: string; + name: string; + type: string; +} + +export interface InventoryLotLineWarehouse { + id: number; + code: string; + name: string; +} + export const preloadInventory = () => { fetchInventories(); };