Skip to content

Commit cf7775d

Browse files
committed
#3951 duplicate project budget fix
1 parent ad90ff3 commit cf7775d

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

src/backend/src/services/finance.services.ts

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -817,10 +817,16 @@ export default class FinanceServices {
817817
}
818818
});
819819

820-
const allTotalBudget = teams.reduce((teamAcc, team) => {
821-
const teamBudget = team.projects.reduce((projAcc, project) => projAcc + project.budget, 0);
822-
return teamAcc + teamBudget;
823-
}, 0);
820+
// project budgets no longer double counted if in multiple teams
821+
const projectsById = new Map<string, { budget: number }>();
822+
for (const team of teams) {
823+
for (const project of team.projects) {
824+
if (!projectsById.has(project.projectId)) {
825+
projectsById.set(project.projectId, { budget: project.budget });
826+
}
827+
}
828+
}
829+
const allTotalBudget = [...projectsById.values()].reduce((acc, p) => acc + p.budget, 0);
824830

825831
const cashTotalBudget =
826832
cashReimbursementRequests.reduce((reqAcc, rr) => {

0 commit comments

Comments
 (0)