You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 

79 rivejä
2.5 KiB

  1. "use server";
  2. import { serverFetchBlob, serverFetchJson } from "@/app/utils/fetchUtil";
  3. import { MonthlyWorkHoursReportRequest, ProjectCashFlowReportRequest,LateStartReportRequest, ProjectPandLReportRequest } from ".";
  4. import { BASE_API_URL } from "@/config/api";
  5. export interface FileResponse {
  6. filename: string;
  7. blobValue: Uint8Array;
  8. }
  9. export const fetchProjectCashFlowReport = async (data: ProjectCashFlowReportRequest) => {
  10. const reportBlob = await serverFetchBlob<FileResponse>(
  11. `${BASE_API_URL}/reports/ProjectCashFlowReport`,
  12. {
  13. method: "POST",
  14. body: JSON.stringify(data),
  15. headers: { "Content-Type": "application/json" },
  16. },
  17. );
  18. return reportBlob
  19. };
  20. export const fetchMonthlyWorkHoursReport = async (data: MonthlyWorkHoursReportRequest) => {
  21. const reportBlob = await serverFetchBlob<FileResponse>(
  22. `${BASE_API_URL}/reports/StaffMonthlyWorkHourAnalysisReport`,
  23. {
  24. method: "POST",
  25. body: JSON.stringify(data),
  26. headers: { "Content-Type": "application/json" },
  27. },
  28. );
  29. return reportBlob
  30. };
  31. // export const fetchLateStartReport = async (data: LateStartReportRequest) => {
  32. // const response = await serverFetchBlob<FileResponse>(
  33. // `${BASE_API_URL}/reports/downloadLateStartReport`,
  34. // {
  35. // method: "POST",
  36. // body: JSON.stringify(data),
  37. // headers: { "Content-Type": "application/json" },
  38. // },
  39. // );
  40. // return response;
  41. // };
  42. export const fetchLateStartReport = async (data: LateStartReportRequest) => {
  43. const response = await serverFetchBlob<FileResponse>(`${BASE_API_URL}/reports/downloadLateStartReport`, {
  44. method: "POST",
  45. body: JSON.stringify(data),
  46. headers: { "Content-Type": "application/json" },
  47. });
  48. // if (!response.ok) {
  49. // const errorText = await response.text(); // Attempt to read the response text
  50. // throw new Error(`Network response was not ok: ${response.status} - ${errorText}`);
  51. // }
  52. // const blob = await response.blob();
  53. // return { fileBlob: blob, fileName: 'Late_Start_Report.xlsx' };
  54. return response
  55. };
  56. export const fetchProjectPandLReport = async (data: ProjectPandLReportRequest) => {
  57. const reportBlob = await serverFetchBlob<FileResponse>(
  58. `${BASE_API_URL}/reports/projectpandlreport`,
  59. {
  60. method: "POST",
  61. body: JSON.stringify(data),
  62. headers: { "Content-Type": "application/json" },
  63. },
  64. );
  65. return reportBlob
  66. };