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.
This commit is contained in:
@@ -486,18 +486,11 @@ export default class ReportingAllocationController extends ReportingControllerBa
|
|||||||
current.add(1, 'day');
|
current.add(1, 'day');
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get hours_per_day for all selected projects
|
// Get organization working hours
|
||||||
const projectHoursQuery = `SELECT id, hours_per_day FROM projects WHERE id IN (${projectIds})`;
|
const orgWorkingHoursQuery = `SELECT working_hours FROM organizations WHERE id = (SELECT t.organization_id FROM teams t WHERE t.id IN (${teamIds}) LIMIT 1)`;
|
||||||
const projectHoursResult = await db.query(projectHoursQuery, []);
|
const orgWorkingHoursResult = await db.query(orgWorkingHoursQuery, []);
|
||||||
const projectHoursMap: Record<string, number> = {};
|
const orgWorkingHours = orgWorkingHoursResult.rows[0]?.working_hours || 8;
|
||||||
for (const row of projectHoursResult.rows) {
|
let totalWorkingHours = workingDays * orgWorkingHours;
|
||||||
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];
|
|
||||||
}
|
|
||||||
|
|
||||||
const durationClause = this.getDateRangeClause(duration || DATE_RANGES.LAST_WEEK, date_range);
|
const durationClause = this.getDateRangeClause(duration || DATE_RANGES.LAST_WEEK, date_range);
|
||||||
const archivedClause = archived
|
const archivedClause = archived
|
||||||
|
|||||||
Reference in New Issue
Block a user