fix(csv): small fix on the shift type checking

This commit is contained in:
Matthieu Haineault 2026-03-17 15:17:24 -04:00
parent b1069c0add
commit 2b04c3151d

View File

@ -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,12 +123,14 @@ export const applyOvertimeRequalifications = (
}
}
//adds a new row with overtime hours deducted from the regular hours
if (deducted_regular + deducted_evening > 0) {
result.push({
...regular_hours,
code: OVERTIME,
quantite_hre: deducted,
quantite_hre: deducted_regular + deducted_evening,
});
}
}
return result;
}