From e7c273ba0e8ea6216f6b1cead8dfe99bfdd71b71 Mon Sep 17 00:00:00 2001 From: "B.E.N.S.O.N" Date: Sat, 7 Feb 2026 19:59:21 +0800 Subject: [PATCH] Stock Item Consumption Trend Report --- src/app/(main)/report/page.tsx | 9 ++- src/config/reportConfig.ts | 117 ++++++++++++++++++++------------- 2 files changed, 79 insertions(+), 47 deletions(-) diff --git a/src/app/(main)/report/page.tsx b/src/app/(main)/report/page.tsx index 18774af..6e6450e 100644 --- a/src/app/(main)/report/page.tsx +++ b/src/app/(main)/report/page.tsx @@ -33,7 +33,8 @@ export default function ReportPage() { const [criteria, setCriteria] = useState>({}); const [loading, setLoading] = useState(false); const [dynamicOptions, setDynamicOptions] = useState>({}); - + const [showConfirmDialog, setShowConfirmDialog] = useState(false); + // Find the configuration for the currently selected report const currentReport = useMemo(() => REPORTS.find((r) => r.id === selectedReportId), @@ -175,7 +176,11 @@ export default function ReportPage() { }, }); - if (!response.ok) throw new Error(`HTTP error! status: ${response.status}`); + if (!response.ok) { + const errorText = await response.text(); + console.error("Response error:", errorText); + throw new Error(`HTTP error! status: ${response.status}, message: ${errorText}`); + } const blob = await response.blob(); const downloadUrl = window.URL.createObjectURL(blob); diff --git a/src/config/reportConfig.ts b/src/config/reportConfig.ts index 67fc206..41a842e 100644 --- a/src/config/reportConfig.ts +++ b/src/config/reportConfig.ts @@ -24,49 +24,49 @@ export interface ReportDefinition { } export const REPORTS: ReportDefinition[] = [ - { - id: "rep-001", - title: "報告 1", - apiEndpoint: `${NEXT_PUBLIC_API_URL}/report/print-report1`, - fields: [ - { label: "From Date", name: "fromDate", type: "date", required: true }, // Mandatory - { label: "To Date", name: "toDate", type: "date", required: true }, // Mandatory - { label: "Item Code", name: "itemCode", type: "text", required: false, placeholder: "e.g. FG"}, - { label: "Item Type", name: "itemType", type: "select", required: false, - options: [ - { label: "FG", value: "FG" }, - { label: "Material", value: "Mat" } - ] }, - ] - }, - { - id: "rep-002", - title: "報告 2", - apiEndpoint: `${NEXT_PUBLIC_API_URL}/report/print-report2`, - fields: [ - { label: "Target Date", name: "targetDate", type: "date", required: false }, - { label: "Item Code", name: "itemCode", type: "text", required: false }, - { label: "Shift", name: "shift", type: "select", options: [ - { label: "Day", value: "D" }, - { label: "Night", value: "N" } - ], required: false} - ] - }, - { - id: "rep-003", - title: "報告 3", - apiEndpoint: `${NEXT_PUBLIC_API_URL}/report/print-report3`, - fields: [ - { label: "From Date", name: "fromDate", type: "date", required: true }, // Mandatory - { label: "To Date", name: "toDate", type: "date", required: true }, // Mandatory - { label: "Item Code", name: "itemCode", type: "text", required: false, placeholder: "e.g. FG"}, - { label: "Item Type", name: "itemType", type: "select", required: false, - options: [ - { label: "FG", value: "FG" }, - { label: "Material", value: "Mat" } - ] }, - ] - }, + //{ + // id: "rep-001", + // title: "報告 1", + // apiEndpoint: `${NEXT_PUBLIC_API_URL}/report/print-report1`, + // fields: [ + // { label: "From Date", name: "fromDate", type: "date", required: true }, // Mandatory + // { label: "To Date", name: "toDate", type: "date", required: true }, // Mandatory + // { label: "Item Code", name: "itemCode", type: "text", required: false, placeholder: "e.g. FG"}, + // { label: "Item Type", name: "itemType", type: "select", required: false, + // options: [ + // { label: "FG", value: "FG" }, + // { label: "Material", value: "Mat" } + // ] }, + // ] + //}, + //{ + // id: "rep-002", + // title: "報告 2", + // apiEndpoint: `${NEXT_PUBLIC_API_URL}/report/print-report2`, + // fields: [ + // { label: "Target Date", name: "targetDate", type: "date", required: false }, + // { label: "Item Code", name: "itemCode", type: "text", required: false }, + // { label: "Shift", name: "shift", type: "select", options: [ + // { label: "Day", value: "D" }, + // { label: "Night", value: "N" } + // ], required: false} + // ] + //}, + //{ + // id: "rep-003", + // title: "報告 3", + // apiEndpoint: `${NEXT_PUBLIC_API_URL}/report/print-report3`, + // fields: [ + // { label: "From Date", name: "fromDate", type: "date", required: true }, // Mandatory + // { label: "To Date", name: "toDate", type: "date", required: true }, // Mandatory + // { label: "Item Code", name: "itemCode", type: "text", required: false, placeholder: "e.g. FG"}, + // { label: "Item Type", name: "itemType", type: "select", required: false, + // options: [ + // { label: "FG", value: "FG" }, + // { label: "Material", value: "Mat" } + // ] }, + // ] + //}, { id: "rep-004", title: "入倉記錄報告", @@ -94,14 +94,41 @@ export const REPORTS: ReportDefinition[] = [ ] }, { label: "物料編號 Item Code", name: "itemCode", type: "select", required: false, multiple: true, - allowInput: true, // Allow user to input custom item codes + allowInput: true, dynamicOptions: true, dynamicOptionsEndpoint: `${NEXT_PUBLIC_API_URL}/report/semi-fg-item-codes`, dynamicOptionsParam: "stockCategory", - options: [] }, // Options will be loaded dynamically + options: [] }, { label: "年份 Year", name: "year", type: "text", required: false, placeholder: "e.g. 2026" }, { label: "完成生產日期:由 Last Out Date Start", name: "lastOutDateStart", type: "date", required: false, placeholder: "dd/mm/yyyy" }, { label: "完成生產日期:至 Last Out Date End", name: "lastOutDateEnd", type: "date", required: false, placeholder: "dd/mm/yyyy" }, ] + }, + { + id: "rep-006", + title: "庫存商品消費趨勢報告", + apiEndpoint: `${NEXT_PUBLIC_API_URL}/report/print-stock-item-consumption-trend`, + fields: [ + { label: "倉存類別 Stock Category", name: "stockCategory", type: "select", required: false, + multiple: true, + options: [ + { label: "All", value: "All" }, + { label: "MAT", value: "MAT" }, + { label: "WIP", value: "WIP" }, + { label: "NM", value: "NM" }, + { label: "FG", value: "FG" }, + { label: "CMB", value: "CMB" } + ] }, + { label: "物料編號 Item Code", name: "itemCode", type: "select", required: false, + multiple: true, + allowInput: true, + dynamicOptions: true, + dynamicOptionsEndpoint: `${NEXT_PUBLIC_API_URL}/report/stock-item-code-prefixes`, + dynamicOptionsParam: "stockCategory", + options: [] }, + { label: "年份 Year", name: "year", type: "text", required: false, placeholder: "e.g. 2026" }, + { label: "完成生產日期:由 Last Out Date Start", name: "lastOutDateStart", type: "date", required: false }, + { label: "完成生產日期:至 Last Out Date End", name: "lastOutDateEnd", type: "date", required: false }, + ] } ]; \ No newline at end of file