"use server"; // import { BASE_API_URL } from "@/config/api"; 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 { PoResult, StockInLine } from "."; //import { serverFetchJson } from "@/app/utils/fetchUtil"; import { serverFetchJson } from "../../utils/fetchUtil"; import { QcItemResult } from "../settings/qcItem"; import { RecordsRes } from "../utils"; // import { BASE_API_URL } from "@/config/api"; export interface PostStockInLiineResponse { id: number | null; name: string; code: string; type?: string message: string | null; errorPosition: string | keyof T; entity: T | T[] // entity: StockInLine | StockInLine[] } export interface StockInLineEntry { id?: number itemId: number purchaseOrderId: number purchaseOrderLineId: number acceptedQty: number status?: string expiryDate?: string } export interface PurchaseQcResult { qcItemId: number; failQty: number; } export interface StockInInput { status: string productLotNo?: string, receiptDate: string acceptedQty: number acceptedWeight?: number productionDate?: string expiryDate: string } export interface PurchaseQCInput { status: string acceptedQty: number sampleRate: number; sampleWeight: number; totalWeight: number; qcResult: PurchaseQcResult[]; } export interface EscalationInput { status: string handler: string acceptedQty: number // this is the qty to be escalated // escalationQty: number } export interface PutawayInput { status: string acceptedQty: number warehouseId: number // handler: string // stockInLine: StockInLineEntry[] } export type ModalFormInput = Partial export const testFetch = cache(async (id: number) => { return serverFetchJson(`${BASE_API_URL}/po/detail/${id}`, { next: { tags: ["po"] }, }); }); export const fetchStockInLineInfo = cache(async (stockInLineId: number) => { return serverFetchJson(`${BASE_API_URL}/stockInLine/${stockInLineId}`, { next: { tags: ["stockInLine"] }, }); }); export const createStockInLine = async (data: StockInLineEntry) => { const stockInLine = await serverFetchJson>(`${BASE_API_URL}/stockInLine/create`, { method: "POST", body: JSON.stringify(data), headers: { "Content-Type": "application/json" }, }); // revalidateTag("po"); return stockInLine } export const updateStockInLine = async (data: StockInLineEntry & ModalFormInput) => { const stockInLine = await serverFetchJson>(`${BASE_API_URL}/stockInLine/update`, { method: "POST", body: JSON.stringify(data), headers: { "Content-Type": "application/json" }, }); // revalidateTag("po"); return stockInLine } export const startPo = async (poId: number) => { const po = await serverFetchJson>(`${BASE_API_URL}/po/start/${poId}`, { method: "POST", body: JSON.stringify({ poId }), headers: { "Content-Type": "application/json" }, }); revalidateTag("po"); return po } export const checkPolAndCompletePo = async (poId: number) => { const po = await serverFetchJson>(`${BASE_API_URL}/po/check/${poId}`, { method: "POST", body: JSON.stringify({ poId }), headers: { "Content-Type": "application/json" }, }); revalidateTag("po"); return po } export const fetchPoInClient = cache(async (id: number) => { return serverFetchJson(`${BASE_API_URL}/po/detail/${id}`, { next: { tags: ["po"] }, }); }); export const fetchPoListClient = cache(async (queryParams?: Record) => { if (queryParams) { const queryString = new URLSearchParams(queryParams).toString(); return serverFetchJson>(`${BASE_API_URL}/po/list?${queryString}`, { method: 'GET', next: { tags: ["po"] }, }); } else { return serverFetchJson>(`${BASE_API_URL}/po/list`, { method: 'GET', next: { tags: ["po"] }, }); } }); export const testing = cache(async (queryParams?: Record) => { if (queryParams) { const queryString = new URLSearchParams(queryParams).toString(); return serverFetchJson>(`${BASE_API_URL}/po/testing?${queryString}`, { method: 'GET', next: { tags: ["po"] }, }); } else { return serverFetchJson>(`${BASE_API_URL}/po/testing`, { method: 'GET', next: { tags: ["po"] }, }); } });