From c43d7649ca7d6c4bd1bd0c9d46df0d2c48f39a2f Mon Sep 17 00:00:00 2001 From: Nicolas Drolet Date: Fri, 9 Jan 2026 07:44:15 -0500 Subject: [PATCH] feat(approvals): add functionality to return weekly hours breakdown --- .../pay-period/dtos/overview-pay-period.dto.ts | 1 + .../services/pay-periods-build-overview.service.ts | 12 ++++++++++-- .../services/timesheet-get-overview.service.ts | 2 +- 3 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/time-and-attendance/pay-period/dtos/overview-pay-period.dto.ts b/src/time-and-attendance/pay-period/dtos/overview-pay-period.dto.ts index 34a1a51..be75a7a 100644 --- a/src/time-and-attendance/pay-period/dtos/overview-pay-period.dto.ts +++ b/src/time-and-attendance/pay-period/dtos/overview-pay-period.dto.ts @@ -27,6 +27,7 @@ export class EmployeePeriodOverviewDto { holiday_hours: number; vacation_hours: number; }; + weekly_hours: number[]; total_hours: number; expenses: number; mileage: number; diff --git a/src/time-and-attendance/pay-period/services/pay-periods-build-overview.service.ts b/src/time-and-attendance/pay-period/services/pay-periods-build-overview.service.ts index fca6fad..0878308 100644 --- a/src/time-and-attendance/pay-period/services/pay-periods-build-overview.service.ts +++ b/src/time-and-attendance/pay-period/services/pay-periods-build-overview.service.ts @@ -116,6 +116,8 @@ export class GetOverviewService { ); for (const timesheet of employee.timesheet) { + let total_weekly_hours: number = 0; + //totals by types for shifts for (const shift of timesheet.shift) { const hours = computeHours(shift.start_time, shift.end_time); @@ -123,24 +125,27 @@ export class GetOverviewService { switch (type) { case "EVENING": record.other_hours.evening_hours += hours; record.total_hours += hours; + total_weekly_hours += hours; break; case "EMERGENCY": record.other_hours.emergency_hours += hours; record.total_hours += hours; + total_weekly_hours += hours; break; case "OVERTIME": record.other_hours.overtime_hours += hours; record.total_hours += hours; + total_weekly_hours += hours; break; case "SICK": record.other_hours.sick_hours += hours; - record.total_hours += hours; break; case "HOLIDAY": record.other_hours.holiday_hours += hours; record.total_hours += hours; + total_weekly_hours += hours; break; case "VACATION": record.other_hours.vacation_hours += hours; - record.total_hours += hours; break; case "REGULAR": record.regular_hours += hours; record.total_hours += hours; + total_weekly_hours += hours; break; } } @@ -155,6 +160,8 @@ export class GetOverviewService { 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, vacation_hours: 0, }, + weekly_hours: [], total_hours: 0, expenses: 0, mileage: 0, diff --git a/src/time-and-attendance/timesheets/services/timesheet-get-overview.service.ts b/src/time-and-attendance/timesheets/services/timesheet-get-overview.service.ts index 1e44393..566d546 100644 --- a/src/time-and-attendance/timesheets/services/timesheet-get-overview.service.ts +++ b/src/time-and-attendance/timesheets/services/timesheet-get-overview.service.ts @@ -64,7 +64,7 @@ export class GetTimesheetsOverviewService { const has_existing_timesheets = rows.some( (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);