diff --git a/src/app/api/scheduling/actions.ts b/src/app/api/scheduling/actions.ts index 14c891d..0ed01bb 100644 --- a/src/app/api/scheduling/actions.ts +++ b/src/app/api/scheduling/actions.ts @@ -177,22 +177,32 @@ export const releaseProdSchedule = cache(async (data: ReleaseProdScheduleReq) => return response; }) -export const exportProdSchedule = async (token: string | null) => { +export const exportProdSchedule = async ( + token: string | null, + inputs: any, + prodHeaders: string[], + matHeaders: string[] +) => { if (!token) throw new Error("No access token found"); const response = await fetch(`${BASE_API_URL}/productionSchedule/export-prod-schedule`, { method: "POST", headers: { + "Content-Type": "application/json", // Critical for @RequestBody "Accept": "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet", "Authorization": `Bearer ${token}` - } + }, + // Send everything in one object + body: JSON.stringify({ + ...inputs, + prodHeaders, + matHeaders + }) }); if (!response.ok) throw new Error(`Backend error: ${response.status}`); const arrayBuffer = await response.arrayBuffer(); - - // Convert to Base64 so Next.js can send it safely over the wire return Buffer.from(arrayBuffer).toString('base64'); }; diff --git a/src/components/DetailedSchedule/DetailedScheduleSearchView.tsx b/src/components/DetailedSchedule/DetailedScheduleSearchView.tsx index 12e17c3..79832fd 100644 --- a/src/components/DetailedSchedule/DetailedScheduleSearchView.tsx +++ b/src/components/DetailedSchedule/DetailedScheduleSearchView.tsx @@ -78,7 +78,7 @@ const DSOverview: React.FC = ({ type, defaultInputs }) => { // paramName: "schedulePeriod", // type: "dateRange", // }, - { label: t("Production Date"), paramName: "scheduleAt", type: "date" }, + { label: t("Production Date"), paramName: "produceAt", type: "date" }, //{ // label: t("Product Count"), // paramName: "totalEstProdCount", @@ -179,9 +179,9 @@ const DSOverview: React.FC = ({ type, defaultInputs }) => { ) as ScheduleType[]; const params: SearchProdSchedule = { - //scheduleAt: dayjs(query?.scheduleAt).isValid() - // ? query?.scheduleAt - // : undefined, + produceAt: dayjs(query?.produceAt).isValid() + ? query?.produceAt + : undefined, //schedulePeriod: dayjs(query?.schedulePeriod).isValid() // ? query?.schedulePeriod // : undefined, @@ -304,7 +304,35 @@ const DSOverview: React.FC = ({ type, defaultInputs }) => { try { const token = localStorage.getItem("accessToken"); // 1. Get Base64 string from server - const base64String = await exportProdSchedule(token); + // 1. Prepare translated headers using the t() function + + const prodHeaders = [ + t("Item Name"), + t("Avg Qty Last Month"), + t("Stock Qty"), + t("Days Left"), + t("Output Qty"), + t("Batch Need"), + t("Priority") + ]; + + const matHeaders = [ + t("Mat Code"), + t("Mat Name"), + t("Required Qty"), + t("Total Qty Need"), + t("UoM"), + t("Purchased Qty"), + t("On Hand Qty"), + t("Unavailable Qty"), + t("Related Item Code"), + t("Related Item Name"), + t("Material Summary") // The last one can be used as the Sheet Name + ]; + + // 2. Pass these arrays to your server action + // 'inputs' contains your filters (scheduleAt, types, etc.) + const base64String = await exportProdSchedule(token, inputs, prodHeaders, matHeaders); // 2. Convert Base64 back to Blob const byteCharacters = atob(base64String);