|
- "use client";
-
- import { NEXT_PUBLIC_API_URL } from "@/config/api";
- import { clientAuthFetch } from "@/app/utils/clientAuthFetch";
-
- export interface JobOrderListItem {
- id: number;
- code: string | null;
- planStart: string | null;
- itemCode: string | null;
- itemName: string | null;
- reqQty: number | null;
- stockInLineId: number | null;
- itemId: number | null;
- lotNo: string | null;
- }
-
- export interface PrinterStatusRequest {
- printerType: "dataflex" | "laser";
- printerIp?: string;
- printerPort?: number;
- }
-
- export interface PrinterStatusResponse {
- connected: boolean;
- message: string;
- }
-
- export interface OnPackQrDownloadRequest {
- jobOrders: {
- jobOrderId: number;
- itemCode: string;
- }[];
- }
-
- /**
- * Fetch job orders by plan date from GET /py/job-orders.
- * Client-side only; uses auth token from localStorage.
- */
- export async function fetchJobOrders(planStart: string): Promise<JobOrderListItem[]> {
- const url = `${NEXT_PUBLIC_API_URL}/py/job-orders?planStart=${encodeURIComponent(planStart)}`;
- const res = await clientAuthFetch(url, { method: "GET" });
- if (!res.ok) {
- throw new Error(`Failed to fetch job orders: ${res.status}`);
- }
- return res.json();
- }
-
- export async function checkPrinterStatus(
- request: PrinterStatusRequest,
- ): Promise<PrinterStatusResponse> {
- const url = `${NEXT_PUBLIC_API_URL}/plastic/check-printer`;
- const res = await clientAuthFetch(url, {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify(request),
- });
-
- const data = (await res.json()) as PrinterStatusResponse;
- if (!res.ok) {
- return data;
- }
-
- return data;
- }
-
- export async function downloadOnPackQrZip(
- request: OnPackQrDownloadRequest,
- ): Promise<Blob> {
- const url = `${NEXT_PUBLIC_API_URL}/plastic/download-onpack-qr`;
- const res = await clientAuthFetch(url, {
- method: "POST",
- headers: { "Content-Type": "application/json" },
- body: JSON.stringify(request),
- });
-
- if (!res.ok) {
- throw new Error((await res.text()) || "Download failed");
- }
-
- return res.blob();
- }
|