From 66e07c5b3eb3d0faec2ce26c07aba053e4fea696 Mon Sep 17 00:00:00 2001 From: "B.E.N.S.O.N" Date: Wed, 15 Apr 2026 18:00:39 +0800 Subject: [PATCH] Truck Routing Summary Update --- .../(main)/report/truckRoutingSummaryApi.ts | 32 +++++++++++++++++++ .../FinishedGoodSearch/FinishedGoodSearch.tsx | 22 +++++++++++++ .../TruckRoutingSummaryTab.tsx | 21 ++++++++++-- 3 files changed, 73 insertions(+), 2 deletions(-) diff --git a/src/app/(main)/report/truckRoutingSummaryApi.ts b/src/app/(main)/report/truckRoutingSummaryApi.ts index c553015..4a92370 100644 --- a/src/app/(main)/report/truckRoutingSummaryApi.ts +++ b/src/app/(main)/report/truckRoutingSummaryApi.ts @@ -8,6 +8,11 @@ export interface ReportOption { value: string; } +export interface TruckRoutingSummaryPrecheck { + unpickedOrderCount: number; + hasUnpickedOrders: boolean; +} + export async function fetchTruckRoutingStoreOptions(): Promise { const response = await clientAuthFetch( `${NEXT_PUBLIC_API_URL}/truck-routing-summary/store-options`, @@ -50,3 +55,30 @@ export async function fetchTruckRoutingLaneOptions(storeId?: string): Promise { + const qs = new URLSearchParams({ + storeId: params.storeId, + truckLanceCode: params.truckLanceCode, + date: params.date, + }).toString(); + const response = await clientAuthFetch( + `${NEXT_PUBLIC_API_URL}/truck-routing-summary/precheck?${qs}`, + { + method: "GET", + headers: { "Content-Type": "application/json" }, + } + ); + if (!response.ok) { + throw new Error(`Failed to precheck routing summary: ${response.status}`); + } + const data = await response.json(); + return { + unpickedOrderCount: Number(data?.unpickedOrderCount ?? 0), + hasUnpickedOrders: Boolean(data?.hasUnpickedOrders), + }; +} diff --git a/src/components/FinishedGoodSearch/FinishedGoodSearch.tsx b/src/components/FinishedGoodSearch/FinishedGoodSearch.tsx index c09548f..8cb2ef4 100644 --- a/src/components/FinishedGoodSearch/FinishedGoodSearch.tsx +++ b/src/components/FinishedGoodSearch/FinishedGoodSearch.tsx @@ -44,6 +44,7 @@ import FGPickOrderTicketReleaseTable from "./FGPickOrderTicketReleaseTable"; import TruckRoutingSummaryTab, { TruckRoutingSummaryFilters } from "./TruckRoutingSummaryTab"; import { clientAuthFetch } from "@/app/utils/clientAuthFetch"; import { NEXT_PUBLIC_API_URL } from "@/config/api"; +import { fetchTruckRoutingSummaryPrecheck } from "@/app/(main)/report/truckRoutingSummaryApi"; interface Props { // pickOrders: PickOrderResult[]; @@ -313,6 +314,27 @@ const [selectedPrinterForDraft, setSelectedPrinterForDraft] = useState = ({ onFiltersChange }) => { const onDownload = async () => { if (!canDownload) return; - setLoading(true); try { + const precheck = await fetchTruckRoutingSummaryPrecheck({ + storeId, + truckLanceCode, + date, + }); + if (precheck.hasUnpickedOrders) { + const confirmed = window.confirm( + `此車線仍有 ${precheck.unpickedOrderCount} 張訂單未執拾。\n是否仍要列印 / 下載送貨路線摘要?` + ); + if (!confirmed) return; + } + + setLoading(true); const qs = new URLSearchParams({ storeId, truckLanceCode,