"use server"; import { serverFetchBlob, serverFetchJson } from "@/app/utils/fetchUtil"; import { MonthlyWorkHoursReportRequest, ProjectCashFlowReportRequest,LateStartReportRequest, ProjectPandLReportRequest } from "."; import { BASE_API_URL } from "@/config/api"; export interface FileResponse { filename: string; blobValue: Uint8Array; } export const fetchProjectCashFlowReport = async (data: ProjectCashFlowReportRequest) => { const reportBlob = await serverFetchBlob( `${BASE_API_URL}/reports/ProjectCashFlowReport`, { method: "POST", body: JSON.stringify(data), headers: { "Content-Type": "application/json" }, }, ); return reportBlob }; export const fetchMonthlyWorkHoursReport = async (data: MonthlyWorkHoursReportRequest) => { const reportBlob = await serverFetchBlob( `${BASE_API_URL}/reports/StaffMonthlyWorkHourAnalysisReport`, { method: "POST", body: JSON.stringify(data), headers: { "Content-Type": "application/json" }, }, ); return reportBlob }; // export const fetchLateStartReport = async (data: LateStartReportRequest) => { // const response = await serverFetchBlob( // `${BASE_API_URL}/reports/downloadLateStartReport`, // { // method: "POST", // body: JSON.stringify(data), // headers: { "Content-Type": "application/json" }, // }, // ); // return response; // }; export const fetchLateStartReport = async (data: LateStartReportRequest) => { const response = await serverFetchBlob(`${BASE_API_URL}/reports/downloadLateStartReport`, { method: "POST", body: JSON.stringify(data), headers: { "Content-Type": "application/json" }, }); // if (!response.ok) { // const errorText = await response.text(); // Attempt to read the response text // throw new Error(`Network response was not ok: ${response.status} - ${errorText}`); // } // const blob = await response.blob(); // return { fileBlob: blob, fileName: 'Late_Start_Report.xlsx' }; return response }; export const fetchProjectPandLReport = async (data: ProjectPandLReportRequest) => { const reportBlob = await serverFetchBlob( `${BASE_API_URL}/reports/projectpandlreport`, { method: "POST", body: JSON.stringify(data), headers: { "Content-Type": "application/json" }, }, ); return reportBlob };