Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.
 
 

81 řádky
2.3 KiB

  1. "use client";
  2. import {
  3. ProjectCompletionReportFilter,
  4. ProjectCompletionReportRequest,
  5. } from "@/app/api/reports";
  6. import React, { useMemo, useState } from "react";
  7. import { useTranslation } from "react-i18next";
  8. import SearchBox, { Criterion } from "../SearchBox";
  9. import dayjs from "dayjs";
  10. import { INPUT_DATE_FORMAT } from "@/app/utils/formatUtil";
  11. import { downloadFile } from "@/app/utils/commonUtil";
  12. import { fetchProjectCompletionReport } from "@/app/api/reports/actions";
  13. interface Props {
  14. teamId: number| null
  15. }
  16. type SearchQuery = Partial<Omit<ProjectCompletionReportFilter, "id">>;
  17. type SearchParamNames = keyof SearchQuery;
  18. const ProjectCompletionReport: React.FC<Props> = (
  19. {
  20. teamId
  21. }
  22. ) => {
  23. const { t } = useTranslation("report");
  24. const [error, setError] = useState("");
  25. const outstandingList = ["Regular", "Outstanding Accounts Receivable"]
  26. const searchCriteria: Criterion<SearchParamNames>[] = useMemo(
  27. () => [
  28. {
  29. label: t("Completion Date From"),
  30. label2: t("Completion Date To"),
  31. paramName: "startDate",
  32. type: "dateRange",
  33. },
  34. {
  35. label: t("Type"),
  36. paramName: "outstanding",
  37. type: "select",
  38. needAll: false,
  39. options: outstandingList
  40. },
  41. ],
  42. [t]
  43. );
  44. return (
  45. <>
  46. <SearchBox
  47. formType={"download"}
  48. criteria={searchCriteria}
  49. onSearch={async (query: any) => {
  50. let postData: ProjectCompletionReportRequest = {
  51. startDate: "1900-01-01",
  52. endDate: dayjs().format(INPUT_DATE_FORMAT).toString(),
  53. outstanding: query.outstanding && query.outstanding === "Outstanding Accounts Receivable"
  54. };
  55. if (query.startDateTo && query.startDateTo.length > 0) {
  56. postData.endDate = query.startDateTo;
  57. }
  58. if (teamId) {
  59. postData.teamId = teamId
  60. }
  61. if (query.startDateFrom && query.startDateFrom.length > 0) {
  62. postData.startDate = query.startDate;
  63. }
  64. console.log(postData)
  65. const response = await fetchProjectCompletionReport(postData);
  66. if (response) {
  67. downloadFile(new Uint8Array(response.blobValue), response.filename!!);
  68. }
  69. }}
  70. />
  71. </>
  72. );
  73. };
  74. export default ProjectCompletionReport;