From d85a8e78412be081ae180006fc82792aa59fc7d7 Mon Sep 17 00:00:00 2001 From: "cyril.tsui" Date: Wed, 29 May 2024 14:56:32 +0800 Subject: [PATCH] update P&L report --- src/app/api/reports/index.ts | 2 +- .../GenerateProjectPandLReport.tsx | 17 ++++++++++------- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/src/app/api/reports/index.ts b/src/app/api/reports/index.ts index 950ee73..bf39c0f 100644 --- a/src/app/api/reports/index.ts +++ b/src/app/api/reports/index.ts @@ -6,7 +6,7 @@ export interface FinancialStatusReportFilter { // - Project P&L Report export interface ProjectPandLReportFilter { - project: string[]; + project: AutocompleteOptions[]; startMonth: string; startMonthTo: string; } diff --git a/src/components/GenerateProjectPandLReport/GenerateProjectPandLReport.tsx b/src/components/GenerateProjectPandLReport/GenerateProjectPandLReport.tsx index 2fb5d63..eb56fcd 100644 --- a/src/components/GenerateProjectPandLReport/GenerateProjectPandLReport.tsx +++ b/src/components/GenerateProjectPandLReport/GenerateProjectPandLReport.tsx @@ -20,11 +20,14 @@ type SearchParamNames = keyof SearchQuery; const GenerateProjectPandLReport: React.FC = ({ projects }) => { const { t } = useTranslation("report"); - const projectCombo = projects.map(project => `${project.code} - ${project.name}`) + const projectCombo = projects.map(project => ({ + label: `${project.code} - ${project.name}`, + value: project.id + })) const searchCriteria: Criterion[] = useMemo( () => [ - { label: t("Project *"), paramName: "project", type: "select", options: projectCombo, needAll: false}, + { label: t("Project *"), paramName: "project", type: "autocomplete", options: projectCombo, needAll: false}, { label: t("Start Month *"), label2: t("End Month *"), paramName: "startMonth", type: "dateRange", needMonth: true }, ], @@ -37,11 +40,11 @@ const GenerateProjectPandLReport: React.FC = ({ projects }) => { criteria={searchCriteria} onSearch={async (query) => { - if (query.project.length > 0 && query.project.toLocaleLowerCase() !== "all") { - const projectIndex = projectCombo.findIndex(project => project === query.project) - console.log(projects[projectIndex].id, query.startMonth, query.startMonthTo) - if(projects[projectIndex].id != null && query.startMonth != "" && query.startMonthTo != undefined){ - const response = await fetchProjectPandLReport({ projectId: projects[projectIndex].id, startMonth: query.startMonth, endMonth: query.startMonthTo }) + if (Boolean(query.project) && query.project !== "All") { + // const projectIndex = projectCombo.findIndex(project => project === query.project) + // console.log(projects[projectIndex].id, query.startMonth, query.startMonthTo) + if(query.project != null && query.startMonth != "" && query.startMonthTo != undefined){ + const response = await fetchProjectPandLReport({ projectId: parseFloat(query.project), startMonth: query.startMonth, endMonth: query.startMonthTo }) if (response) { downloadFile(new Uint8Array(response.blobValue), response.filename!!) }