| @@ -0,0 +1,169 @@ | |||
| "use server"; | |||
| import { BASE_API_URL } from "@/config/api"; | |||
| import { serverFetchJson } from "@/app/utils/fetchUtil"; | |||
| import { cache } from "react"; | |||
| import type { MessageResponse } from "@/app/api/shop/actions"; | |||
| // Export types/interfaces (these are safe to import in client components) | |||
| export interface StockIssueResult { | |||
| id: number; | |||
| itemId: number; | |||
| itemCode: string; | |||
| itemDescription: string; | |||
| lotId: number; | |||
| lotNo: string; | |||
| storeLocation: string | null; | |||
| requiredQty: number | null; | |||
| actualPickQty: number | null; | |||
| missQty: number; | |||
| badItemQty: number; | |||
| issueRemark: string | null; | |||
| pickerName: string | null; | |||
| handleStatus: string; | |||
| handleDate: string | null; | |||
| handledBy: number | null; | |||
| } | |||
| export interface ExpiryItemResult { | |||
| id: number; | |||
| itemId: number; | |||
| itemCode: string; | |||
| itemDescription: string | null; | |||
| lotId: number; | |||
| lotNo: string | null; | |||
| storeLocation: string | null; | |||
| expiryDate: string | null; | |||
| remainingQty: number; | |||
| } | |||
| export interface StockIssueLists { | |||
| missItems: StockIssueResult[]; | |||
| badItems: StockIssueResult[]; | |||
| expiryItems: ExpiryItemResult[]; | |||
| } | |||
| // Server actions (these work from both server and client components) | |||
| export const PreloadList = () => { | |||
| fetchList(); | |||
| }; | |||
| export const fetchMissItemList = cache(async (issueCategory: string = "lot_issue") => { | |||
| return serverFetchJson<StockIssueResult[]>( | |||
| `${BASE_API_URL}/pickExecution/issues/missItem?issueCategory=${issueCategory}`, | |||
| { | |||
| next: { tags: ["Miss Item List"] }, | |||
| }, | |||
| ); | |||
| }); | |||
| export const fetchBadItemList = cache(async (issueCategory: string = "lot_issue") => { | |||
| return serverFetchJson<StockIssueResult[]>( | |||
| `${BASE_API_URL}/pickExecution/issues/badItem?issueCategory=${issueCategory}`, | |||
| { | |||
| next: { tags: ["Bad Item List"] }, | |||
| }, | |||
| ); | |||
| }); | |||
| export const fetchExpiryItemList = cache(async () => { | |||
| return serverFetchJson<ExpiryItemResult[]>( | |||
| `${BASE_API_URL}/pickExecution/issues/expiryItem`, | |||
| { | |||
| next: { tags: ["Expiry Item List"] }, | |||
| }, | |||
| ); | |||
| }); | |||
| export const fetchList = cache(async (issueCategory: string = "lot_issue"): Promise<StockIssueLists> => { | |||
| const [missItems, badItems, expiryItems] = await Promise.all([ | |||
| fetchMissItemList(issueCategory), | |||
| fetchBadItemList(issueCategory), | |||
| fetchExpiryItemList(), | |||
| ]); | |||
| return { | |||
| missItems, | |||
| badItems, | |||
| expiryItems, | |||
| }; | |||
| }); | |||
| export async function submitMissItem(issueId: number, handler: number) { | |||
| return serverFetchJson<MessageResponse>( | |||
| `${BASE_API_URL}/pickExecution/submitMissItem`, | |||
| { | |||
| method: "POST", | |||
| headers: { | |||
| "Content-Type": "application/json", | |||
| }, | |||
| body: JSON.stringify({ issueId, handler }), | |||
| }, | |||
| ); | |||
| } | |||
| export async function batchSubmitMissItem(issueIds: number[], handler: number) { | |||
| return serverFetchJson<MessageResponse>( | |||
| `${BASE_API_URL}/pickExecution/batchSubmitMissItem`, | |||
| { | |||
| method: "POST", | |||
| headers: { | |||
| "Content-Type": "application/json", | |||
| }, | |||
| body: JSON.stringify({ issueIds, handler }), | |||
| }, | |||
| ); | |||
| } | |||
| export async function submitBadItem(issueId: number, handler: number) { | |||
| return serverFetchJson<MessageResponse>( | |||
| `${BASE_API_URL}/pickExecution/submitBadItem`, | |||
| { | |||
| method: "POST", | |||
| headers: { | |||
| "Content-Type": "application/json", | |||
| }, | |||
| body: JSON.stringify({ issueId, handler }), | |||
| }, | |||
| ); | |||
| } | |||
| export async function batchSubmitBadItem(issueIds: number[], handler: number) { | |||
| return serverFetchJson<MessageResponse>( | |||
| `${BASE_API_URL}/pickExecution/batchSubmitBadItem`, | |||
| { | |||
| method: "POST", | |||
| headers: { | |||
| "Content-Type": "application/json", | |||
| }, | |||
| body: JSON.stringify({ issueIds, handler }), | |||
| }, | |||
| ); | |||
| } | |||
| export async function submitExpiryItem(lotLineId: number, handler: number) { | |||
| return serverFetchJson<MessageResponse>( | |||
| `${BASE_API_URL}/pickExecution/submitExpiryItem`, | |||
| { | |||
| method: "POST", | |||
| headers: { | |||
| "Content-Type": "application/json", | |||
| }, | |||
| body: JSON.stringify({ lotLineId, handler }), | |||
| }, | |||
| ); | |||
| } | |||
| export async function batchSubmitExpiryItem(lotLineIds: number[], handler: number) { | |||
| return serverFetchJson<MessageResponse>( | |||
| `${BASE_API_URL}/pickExecution/batchSubmitExpiryItem`, | |||
| { | |||
| method: "POST", | |||
| headers: { | |||
| "Content-Type": "application/json", | |||
| }, | |||
| body: JSON.stringify({ lotLineIds, handler }), | |||
| }, | |||
| ); | |||
| } | |||