From 2b04c3151ddc548664eadf1d7f3dd8898dc46358 Mon Sep 17 00:00:00 2001 From: Matthieu Haineault Date: Tue, 17 Mar 2026 15:17:24 -0400 Subject: [PATCH] fix(csv): small fix on the shift type checking --- .../exports/csv-exports.utils.ts | 49 ++++++++++--------- 1 file changed, 27 insertions(+), 22 deletions(-) diff --git a/src/time-and-attendance/exports/csv-exports.utils.ts b/src/time-and-attendance/exports/csv-exports.utils.ts index f48b6f4..0319ed2 100644 --- a/src/time-and-attendance/exports/csv-exports.utils.ts +++ b/src/time-and-attendance/exports/csv-exports.utils.ts @@ -83,36 +83,39 @@ export const applyOvertimeRequalifications = ( const vacation_hours = rows.find(r => r.code === VACATION); // if no regular hours row, push as is - if ( - !regular_hours?.quantite_hre - || !evening_hours?.quantite_hre - || !emergency_hours?.quantite_hre - || !holiday_hours?.quantite_hre - || !vacation_hours?.quantite_hre - ) { result.push(...rows); continue; } + if (!regular_hours?.quantite_hre) { result.push(...rows); continue; } const total_hours = ( regular_hours.quantite_hre - + evening_hours.quantite_hre - + emergency_hours.quantite_hre - + holiday_hours.quantite_hre - + vacation_hours.quantite_hre + + (evening_hours?.quantite_hre ?? 0) + + (emergency_hours?.quantite_hre ?? 0) + + (holiday_hours?.quantite_hre ?? 0) + + (vacation_hours?.quantite_hre ?? 0) ) - // calculate overtime directly from consolidated regular hours + // calculate overtime directly from consolidated hours const overtime_hours = Math.max(0, total_hours - WEEKLY_LIMIT_HOURS); // if no overtime, push as is if (overtime_hours <= 0) { result.push(...rows); continue; } - // ensures that its not possible to deduct more hours than the amount of regular hours - const deducted = Math.min(overtime_hours, regular_hours.quantite_hre); - const remaining = regular_hours.quantite_hre - deducted; + // ensures that its not possible to deduct more hours than the amount of regular or evening hours + const deducted_regular = Math.min(overtime_hours, regular_hours.quantite_hre); + const remaining_overtime = overtime_hours - deducted_regular; + const deducted_evening = Math.min(remaining_overtime, evening_hours?.quantite_hre ?? 0); + + const remaining_regular = (regular_hours.quantite_hre ?? 0) - deducted_regular; + const remaining_evening = (evening_hours?.quantite_hre ?? 0) - deducted_evening; for (const row of rows) { if (row === regular_hours) { // pushes the regular row with subtracted overtime hours, if enough hours remaining - if (remaining > 0) { - result.push({ ...regular_hours, quantite_hre: remaining }); + if (remaining_regular > 0) { + result.push({ ...regular_hours, quantite_hre: remaining_regular }); + } + } else if (row === evening_hours) { + // pushes the evening row with subtracted overtime hours, if enough not enough regular hours remaining + if (remaining_evening > 0) { + result.push({ ...evening_hours, quantite_hre: remaining_evening }); } } else { // other rows are left unchanged @@ -120,11 +123,13 @@ export const applyOvertimeRequalifications = ( } } //adds a new row with overtime hours deducted from the regular hours - result.push({ - ...regular_hours, - code: OVERTIME, - quantite_hre: deducted, - }); + if (deducted_regular + deducted_evening > 0) { + result.push({ + ...regular_hours, + code: OVERTIME, + quantite_hre: deducted_regular + deducted_evening, + }); + } } return result; }