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.
 
 

70 lines
1.9 KiB

  1. "use client";
  2. import React, { useMemo } from "react";
  3. import SearchBox, { Criterion } from "../SearchBox";
  4. import { useTranslation } from "react-i18next";
  5. import { ProjectResult } from "@/app/api/projects";
  6. import {
  7. fetchMonthlyWorkHoursReport,
  8. fetchProjectCashFlowReport,
  9. } from "@/app/api/reports/actions";
  10. import { downloadFile } from "@/app/utils/commonUtil";
  11. import { BASE_API_URL } from "@/config/api";
  12. import { MonthlyWorkHoursReportFilter } from "@/app/api/reports";
  13. import { records } from "@/app/api/staff/actions";
  14. import { StaffResult } from "@/app/api/staff";
  15. import dayjs from "dayjs";
  16. interface Props {
  17. staffs: StaffResult[];
  18. }
  19. type SearchQuery = Partial<Omit<MonthlyWorkHoursReportFilter, "id">>;
  20. type SearchParamNames = keyof SearchQuery;
  21. const GenerateMonthlyWorkHoursReport: React.FC<Props> = ({ staffs }) => {
  22. const { t } = useTranslation("report");
  23. const staffCombo = staffs.map((staff) => `${staff.name} - ${staff.staffId}`);
  24. const searchCriteria: Criterion<SearchParamNames>[] = useMemo(
  25. () => [
  26. {
  27. label: t("Staff"),
  28. paramName: "staff",
  29. type: "select",
  30. options: staffCombo,
  31. needAll: false,
  32. },
  33. {
  34. label: t("Date"),
  35. paramName: "date",
  36. type: "monthYear",
  37. },
  38. ],
  39. [t]
  40. );
  41. return (
  42. <>
  43. <SearchBox
  44. formType={"download"}
  45. criteria={searchCriteria}
  46. onSearch={async (query: any) => {
  47. const index = staffCombo.findIndex((staff) => staff === query.staff);
  48. const response = await fetchMonthlyWorkHoursReport({
  49. id: staffs[index].id,
  50. yearMonth: query.date,
  51. });
  52. if (response) {
  53. downloadFile(
  54. new Uint8Array(response.blobValue),
  55. response.filename!!
  56. );
  57. }
  58. }}
  59. />
  60. </>
  61. );
  62. };
  63. export default GenerateMonthlyWorkHoursReport;