fix(csv): small fix on the shift type checking
This commit is contained in:
parent
b1069c0add
commit
2b04c3151d
|
|
@ -83,36 +83,39 @@ export const applyOvertimeRequalifications = (
|
||||||
const vacation_hours = rows.find(r => r.code === VACATION);
|
const vacation_hours = rows.find(r => r.code === VACATION);
|
||||||
|
|
||||||
// if no regular hours row, push as is
|
// if no regular hours row, push as is
|
||||||
if (
|
if (!regular_hours?.quantite_hre) { result.push(...rows); continue; }
|
||||||
!regular_hours?.quantite_hre
|
|
||||||
|| !evening_hours?.quantite_hre
|
|
||||||
|| !emergency_hours?.quantite_hre
|
|
||||||
|| !holiday_hours?.quantite_hre
|
|
||||||
|| !vacation_hours?.quantite_hre
|
|
||||||
) { result.push(...rows); continue; }
|
|
||||||
|
|
||||||
const total_hours = (
|
const total_hours = (
|
||||||
regular_hours.quantite_hre
|
regular_hours.quantite_hre
|
||||||
+ evening_hours.quantite_hre
|
+ (evening_hours?.quantite_hre ?? 0)
|
||||||
+ emergency_hours.quantite_hre
|
+ (emergency_hours?.quantite_hre ?? 0)
|
||||||
+ holiday_hours.quantite_hre
|
+ (holiday_hours?.quantite_hre ?? 0)
|
||||||
+ vacation_hours.quantite_hre
|
+ (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);
|
const overtime_hours = Math.max(0, total_hours - WEEKLY_LIMIT_HOURS);
|
||||||
|
|
||||||
// if no overtime, push as is
|
// if no overtime, push as is
|
||||||
if (overtime_hours <= 0) { result.push(...rows); continue; }
|
if (overtime_hours <= 0) { result.push(...rows); continue; }
|
||||||
|
|
||||||
// ensures that its not possible to deduct more hours than the amount of regular hours
|
// ensures that its not possible to deduct more hours than the amount of regular or evening hours
|
||||||
const deducted = Math.min(overtime_hours, regular_hours.quantite_hre);
|
const deducted_regular = Math.min(overtime_hours, regular_hours.quantite_hre);
|
||||||
const remaining = regular_hours.quantite_hre - deducted;
|
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) {
|
for (const row of rows) {
|
||||||
if (row === regular_hours) {
|
if (row === regular_hours) {
|
||||||
// pushes the regular row with subtracted overtime hours, if enough hours remaining
|
// pushes the regular row with subtracted overtime hours, if enough hours remaining
|
||||||
if (remaining > 0) {
|
if (remaining_regular > 0) {
|
||||||
result.push({ ...regular_hours, quantite_hre: remaining });
|
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 {
|
} else {
|
||||||
// other rows are left unchanged
|
// other rows are left unchanged
|
||||||
|
|
@ -120,12 +123,14 @@ export const applyOvertimeRequalifications = (
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//adds a new row with overtime hours deducted from the regular hours
|
//adds a new row with overtime hours deducted from the regular hours
|
||||||
|
if (deducted_regular + deducted_evening > 0) {
|
||||||
result.push({
|
result.push({
|
||||||
...regular_hours,
|
...regular_hours,
|
||||||
code: OVERTIME,
|
code: OVERTIME,
|
||||||
quantite_hre: deducted,
|
quantite_hre: deducted_regular + deducted_evening,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user