From c1067d87fe7b5172169b99552578e03c5a787143 Mon Sep 17 00:00:00 2001 From: chamiakJ Date: Tue, 20 May 2025 16:49:07 +0530 Subject: [PATCH] refactor(reporting): update total working hours calculation in allocation controller - Replaced project-specific hours per day with organization-wide working hours for total working hours calculation. - Streamlined the SQL query to fetch organization working hours, ensuring accurate reporting based on organizational settings. --- .../reporting-allocation-controller.ts | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/worklenz-backend/src/controllers/reporting/reporting-allocation-controller.ts b/worklenz-backend/src/controllers/reporting/reporting-allocation-controller.ts index 7d458777..ec348952 100644 --- a/worklenz-backend/src/controllers/reporting/reporting-allocation-controller.ts +++ b/worklenz-backend/src/controllers/reporting/reporting-allocation-controller.ts @@ -486,18 +486,11 @@ export default class ReportingAllocationController extends ReportingControllerBa current.add(1, 'day'); } - // Get hours_per_day for all selected projects - const projectHoursQuery = `SELECT id, hours_per_day FROM projects WHERE id IN (${projectIds})`; - const projectHoursResult = await db.query(projectHoursQuery, []); - const projectHoursMap: Record = {}; - for (const row of projectHoursResult.rows) { - projectHoursMap[row.id] = row.hours_per_day || 8; - } - // Sum total working hours for all selected projects - let totalWorkingHours = 0; - for (const pid of Object.keys(projectHoursMap)) { - totalWorkingHours += workingDays * projectHoursMap[pid]; - } + // Get organization working hours + const orgWorkingHoursQuery = `SELECT working_hours FROM organizations WHERE id = (SELECT t.organization_id FROM teams t WHERE t.id IN (${teamIds}) LIMIT 1)`; + const orgWorkingHoursResult = await db.query(orgWorkingHoursQuery, []); + const orgWorkingHours = orgWorkingHoursResult.rows[0]?.working_hours || 8; + let totalWorkingHours = workingDays * orgWorkingHours; const durationClause = this.getDateRangeClause(duration || DATE_RANGES.LAST_WEEK, date_range); const archivedClause = archived