|
- "use server";
- 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 { BASE_API_URL } from "@/config/api";
-
- export interface PostStockInLiineResponse<T> {
- id: number | null;
- name: string;
- code: string;
- message: string | null;
- errorPosition: string | keyof T;
- entity: StockInLine | StockInLine[]
- }
-
- export interface StockInLineEntry {
- id?: number
- itemId: number
- purchaseOrderId: number
- purchaseOrderLineId: number
- acceptedQty: number
- status?: string
- expiryDate?: string
- }
-
- export interface PurchaseQcCheck {
- qcCheckId: number;
- qty: number;
- }
- export interface StockInInput {
- status: string
- productLotNo?: string,
- receiptDate: string
- acceptedQty: number
- acceptedWeight?: number
- productionDate?: string
- expiryDate: string
- }
- export interface PurchaseQCInput {
- status: string
- sampleRate: number;
- sampleWeight: number;
- totalWeight: number;
- qcCheck: PurchaseQcCheck[];
- }
- export interface EscalationInput {
- status: string
- handler: string
- stockInLine: StockInLineEntry[]
- }
- export interface PutawayInput {
- status: string
- acceptedQty: number
- warehouseId: number
- // handler: string
- // stockInLine: StockInLineEntry[]
- }
-
- export type ModalFormInput = Partial<PurchaseQCInput & StockInInput & EscalationInput & PutawayInput>
-
- export const testFetch = cache(async (id: number) => {
- return serverFetchJson<PoResult>(`${BASE_API_URL}/po/detail/${id}`, {
- next: { tags: ["po"] },
- });
- });
-
- export const createStockInLine = async (data: StockInLineEntry) => {
- const stockInLine = await serverFetchJson<PostStockInLiineResponse<StockInLineEntry>>(`${BASE_API_URL}/stockInLine/create`, {
- method: "POST",
- body: JSON.stringify(data),
- headers: { "Content-Type": "application/json" },
- });
- return stockInLine
- }
-
- export const updateStockInLine = async (data: StockInLineEntry & ModalFormInput) => {
- const stockInLine = await serverFetchJson<PostStockInLiineResponse<StockInLineEntry & ModalFormInput>>(`${BASE_API_URL}/stockInLine/update`, {
- method: "POST",
- body: JSON.stringify(data),
- headers: { "Content-Type": "application/json" },
- });
- return stockInLine
- }
-
|