From 560bb9cc3ce7e09a323839425f034ba2c8d7b241 Mon Sep 17 00:00:00 2001 From: Matthieu Haineault Date: Tue, 13 Jan 2026 14:07:44 -0500 Subject: [PATCH] fix(banking_hours): added modifier of 1.5 to ensure real display and manipulations of banked hours --- .../domains/services/banking-hours.service.ts | 2 +- .../paid-time-off/paid-time-off.service.ts | 15 ++++++++++++--- .../shifts/services/shifts-create.service.ts | 10 +++++++--- .../shifts/services/shifts-update.service.ts | 10 ++++++++-- 4 files changed, 28 insertions(+), 9 deletions(-) diff --git a/src/time-and-attendance/domains/services/banking-hours.service.ts b/src/time-and-attendance/domains/services/banking-hours.service.ts index 851dd5f..1a94b91 100644 --- a/src/time-and-attendance/domains/services/banking-hours.service.ts +++ b/src/time-and-attendance/domains/services/banking-hours.service.ts @@ -40,7 +40,7 @@ export class BankedHoursService { const new_balance = await tx.paidTimeOff.update({ where: { employee_id: employee.id }, data: { - banked_hours: { increment: asked_hours }, + banked_hours: { increment: (asked_hours) }, last_updated: new Date(), }, select: { banked_hours: true }, diff --git a/src/time-and-attendance/paid-time-off/paid-time-off.service.ts b/src/time-and-attendance/paid-time-off/paid-time-off.service.ts index 0f9b5cb..8aacb60 100644 --- a/src/time-and-attendance/paid-time-off/paid-time-off.service.ts +++ b/src/time-and-attendance/paid-time-off/paid-time-off.service.ts @@ -25,8 +25,14 @@ export class PaidTimeOFfBankHoursService { og_start: Date, og_end: Date ): Promise> => { - const original_hours = computeHours(og_start, og_end); - const ajusted_hours = computeHours(start_time, end_time); + let original_hours = computeHours(og_start, og_end); + let ajusted_hours = computeHours(start_time, end_time); + + if (type === 'BANKING') { + original_hours = original_hours * 1.5; + ajusted_hours = ajusted_hours * 1.5; + } + const diff_hours = Math.abs(ajusted_hours - original_hours); if (diff_hours === 0) return { success: true, data: true }; @@ -83,8 +89,11 @@ export class PaidTimeOFfBankHoursService { //called during delete function of Shifts Module updatePaidTimeoffBankHoursWhenShiftDelete = async (start: Date, end: Date, type: string, employee_id: number) => { - const ajusted_hours = computeHours(start, end); + let ajusted_hours = computeHours(start, end); if (!paid_time_off_types.includes(type)) return; + if (type === 'BANKING') { + ajusted_hours = ajusted_hours * 1.5; + } const config = paid_time_off_mapping[type]; await this.prisma.paidTimeOff.update({ diff --git a/src/time-and-attendance/shifts/services/shifts-create.service.ts b/src/time-and-attendance/shifts/services/shifts-create.service.ts index 646e2ee..c4e9c83 100644 --- a/src/time-and-attendance/shifts/services/shifts-create.service.ts +++ b/src/time-and-attendance/shifts/services/shifts-create.service.ts @@ -103,13 +103,17 @@ export class ShiftsCreateService { let adjusted_end_time = normed_shift.data.end_time; - if (paid_time_off_types.includes(dto.type)) { - const amount_hours = computeHours(normed_shift.data.start_time, normed_shift.data.end_time); - const banking_types: string[] = ['BANKING', 'WITHDRAW_BANKED']; + if (paid_time_off_types.includes(dto.type)) { let result: Result; + let amount_hours = computeHours(normed_shift.data.start_time, normed_shift.data.end_time); + const banking_types: string[] = ['BANKING', 'WITHDRAW_BANKED']; + if (banking_types.includes(dto.type)) { + if (dto.type === 'BANKING') { + amount_hours = amount_hours * 1.5; + } result = await this.bankingService.manageBankingHours(employee_id, amount_hours, dto.type); } else { switch (dto.type) { diff --git a/src/time-and-attendance/shifts/services/shifts-update.service.ts b/src/time-and-attendance/shifts/services/shifts-update.service.ts index e81e800..2c9f0fc 100644 --- a/src/time-and-attendance/shifts/services/shifts-update.service.ts +++ b/src/time-and-attendance/shifts/services/shifts-update.service.ts @@ -92,13 +92,19 @@ export class ShiftsUpdateService { //call to ajust paid_time_off hour banks if (paid_time_off_types.includes(original_type) || paid_time_off_types.includes(new_type)) { if (type_changed) { - const original_hours = computeHours(original.start_time, original.end_time); + let original_hours = computeHours(original.start_time, original.end_time); + if (original_type === 'BANKING') { + original_hours = original_hours * 1.5; + } if (paid_time_off_types.includes(original_type)) { const restoration = await this.paidTimeOffService.restorePaidTimeOffHours(employee.data, original_type, original_hours); if (!restoration.success) return { success: false, error: restoration.error }; } if (paid_time_off_types.includes(new_type)) { - const new_hours = computeHours(normed_shift.data.start_time, normed_shift.data.end_time); + let new_hours = computeHours(normed_shift.data.start_time, normed_shift.data.end_time); + if (new_type === 'BANKING') { + new_hours = new_hours * 1.5; + } const validation = await this.paidTimeOffService.validateAndDeductPaidTimeOff(employee.data, new_type, new_hours); if (!validation.success) return { success: false, error: validation.error }; }