[email protected] 4 дней назад
Родитель
Сommit
1c6368540e
2 измененных файлов: 47 добавлений и 9 удалений
  1. +14
    -4
      src/app/api/scheduling/actions.ts
  2. +33
    -5
      src/components/DetailedSchedule/DetailedScheduleSearchView.tsx

+ 14
- 4
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');
};



+ 33
- 5
src/components/DetailedSchedule/DetailedScheduleSearchView.tsx Просмотреть файл

@@ -78,7 +78,7 @@ const DSOverview: React.FC<Props> = ({ 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<Props> = ({ 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<Props> = ({ 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);


Загрузка…
Отмена
Сохранить