|
|
@@ -7,7 +7,7 @@ import { ProjectResult } from "@/app/api/projects"; |
|
|
|
import { ProjectCashFlowReportFilter } from "@/app/api/reports"; |
|
|
|
import { fetchProjectCashFlowReport } from "@/app/api/reports/actions"; |
|
|
|
import { downloadFile } from "@/app/utils/commonUtil"; |
|
|
|
import { BASE_API_URL } from "@/config/api"; |
|
|
|
import { dateTypeCombo } from "@/app/utils/comboUtil"; |
|
|
|
|
|
|
|
interface Props { |
|
|
|
projects: ProjectResult[]; |
|
|
@@ -17,12 +17,13 @@ type SearchQuery = Partial<Omit<ProjectCashFlowReportFilter, "id">>; |
|
|
|
type SearchParamNames = keyof SearchQuery; |
|
|
|
|
|
|
|
const GenerateProjectCashFlowReport: React.FC<Props> = ({ projects }) => { |
|
|
|
const { t } = useTranslation(); |
|
|
|
const { t } = useTranslation("report"); |
|
|
|
const projectCombo = projects.map(project => `${project.code} - ${project.name}`) |
|
|
|
|
|
|
|
const searchCriteria: Criterion<SearchParamNames>[] = useMemo( |
|
|
|
() => [ |
|
|
|
{ label: t("Project"), paramName: "project", type: "select", options: projectCombo, needAll: false}, |
|
|
|
{ label: t("Date Type"), paramName: "dateType", type: "select", options: dateTypeCombo, needAll: false}, |
|
|
|
], |
|
|
|
[t], |
|
|
|
); |
|
|
@@ -35,7 +36,7 @@ const GenerateProjectCashFlowReport: React.FC<Props> = ({ projects }) => { |
|
|
|
|
|
|
|
if (query.project.length > 0 && query.project.toLocaleLowerCase() !== "all") { |
|
|
|
const projectIndex = projectCombo.findIndex(project => project === query.project) |
|
|
|
const response = await fetchProjectCashFlowReport({ projectId: projects[projectIndex].id }) |
|
|
|
const response = await fetchProjectCashFlowReport({ projectId: projects[projectIndex].id, dateType: query.dateType }) |
|
|
|
if (response) { |
|
|
|
downloadFile(new Uint8Array(response.blobValue), response.filename!!) |
|
|
|
} |
|
|
|