|
|
@@ -20,11 +20,14 @@ type SearchParamNames = keyof SearchQuery; |
|
|
|
|
|
|
|
const GenerateProjectPandLReport: React.FC<Props> = ({ 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<SearchParamNames>[] = 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<Props> = ({ 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!!) |
|
|
|
} |
|
|
|