feat(approvals): add functionality to return weekly hours breakdown

This commit is contained in:
Nicolas Drolet 2026-01-09 07:44:15 -05:00
parent 41efccac17
commit c43d7649ca
3 changed files with 12 additions and 3 deletions

View File

@ -27,6 +27,7 @@ export class EmployeePeriodOverviewDto {
holiday_hours: number; holiday_hours: number;
vacation_hours: number; vacation_hours: number;
}; };
weekly_hours: number[];
total_hours: number; total_hours: number;
expenses: number; expenses: number;
mileage: number; mileage: number;

View File

@ -116,6 +116,8 @@ export class GetOverviewService {
); );
for (const timesheet of employee.timesheet) { for (const timesheet of employee.timesheet) {
let total_weekly_hours: number = 0;
//totals by types for shifts //totals by types for shifts
for (const shift of timesheet.shift) { for (const shift of timesheet.shift) {
const hours = computeHours(shift.start_time, shift.end_time); const hours = computeHours(shift.start_time, shift.end_time);
@ -123,24 +125,27 @@ export class GetOverviewService {
switch (type) { switch (type) {
case "EVENING": record.other_hours.evening_hours += hours; case "EVENING": record.other_hours.evening_hours += hours;
record.total_hours += hours; record.total_hours += hours;
total_weekly_hours += hours;
break; break;
case "EMERGENCY": record.other_hours.emergency_hours += hours; case "EMERGENCY": record.other_hours.emergency_hours += hours;
record.total_hours += hours; record.total_hours += hours;
total_weekly_hours += hours;
break; break;
case "OVERTIME": record.other_hours.overtime_hours += hours; case "OVERTIME": record.other_hours.overtime_hours += hours;
record.total_hours += hours; record.total_hours += hours;
total_weekly_hours += hours;
break; break;
case "SICK": record.other_hours.sick_hours += hours; case "SICK": record.other_hours.sick_hours += hours;
record.total_hours += hours;
break; break;
case "HOLIDAY": record.other_hours.holiday_hours += hours; case "HOLIDAY": record.other_hours.holiday_hours += hours;
record.total_hours += hours; record.total_hours += hours;
total_weekly_hours += hours;
break; break;
case "VACATION": record.other_hours.vacation_hours += hours; case "VACATION": record.other_hours.vacation_hours += hours;
record.total_hours += hours;
break; break;
case "REGULAR": record.regular_hours += hours; case "REGULAR": record.regular_hours += hours;
record.total_hours += hours; record.total_hours += hours;
total_weekly_hours += hours;
break; break;
} }
} }
@ -155,6 +160,8 @@ export class GetOverviewService {
record.mileage = Number((record.mileage += Math.round(mileage)).toFixed(2)); record.mileage = Number((record.mileage += Math.round(mileage)).toFixed(2));
} }
} }
record.weekly_hours.push(total_weekly_hours);
} }
} }
@ -214,6 +221,7 @@ export class GetOverviewService {
holiday_hours: 0, holiday_hours: 0,
vacation_hours: 0, vacation_hours: 0,
}, },
weekly_hours: [],
total_hours: 0, total_hours: 0,
expenses: 0, expenses: 0,
mileage: 0, mileage: 0,

View File

@ -64,7 +64,7 @@ export class GetTimesheetsOverviewService {
const has_existing_timesheets = rows.some( const has_existing_timesheets = rows.some(
(row) => toDateFromString(row.start_date).getTime() === week_start.getTime() (row) => toDateFromString(row.start_date).getTime() === week_start.getTime()
); );
if (!has_existing_timesheets) this.ensureTimesheet(employee_id.data, week_start); if (!has_existing_timesheets) await this.ensureTimesheet(employee_id.data, week_start);
} }
rows = await this.loadTimesheets(employee_id.data, period.period_start, period.period_end); rows = await this.loadTimesheets(employee_id.data, period.period_start, period.period_end);