Entitlement rate
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Joan Sanchez 2020-06-19 09:58:09 +02:00
parent fcec710d7c
commit 41eeaeef0b
2 changed files with 26 additions and 4 deletions

View File

@ -56,15 +56,19 @@ module.exports = Self => {
} }
}); });
let entitlementRate = 0;
absences.forEach(absence => { absences.forEach(absence => {
const isHoliday = absence.absenceType().code === 'holiday'; const absenceType = absence.absenceType();
const isHalfHoliday = absence.absenceType().code === 'halfHoliday'; const isHoliday = absenceType.code === 'holiday';
const isHalfHoliday = absenceType.code === 'halfHoliday';
if (isHoliday) if (isHoliday)
calendar.holidaysEnjoyed += 1; calendar.holidaysEnjoyed += 1;
if (isHalfHoliday) if (isHalfHoliday)
calendar.holidaysEnjoyed += 0.5; calendar.holidaysEnjoyed += 0.5;
entitlementRate += absenceType.holidayEntitlementRate;
absence.dated = new Date(absence.dated); absence.dated = new Date(absence.dated);
absence.dated.setHours(0, 0, 0, 0); absence.dated.setHours(0, 0, 0, 0);
}); });
@ -119,6 +123,9 @@ module.exports = Self => {
workedDays += Math.floor((endedTime - startedTime) / dayTimestamp); workedDays += Math.floor((endedTime - startedTime) / dayTimestamp);
if (workedDays > daysInYear())
workedDays = daysInYear();
// Workcenter holidays // Workcenter holidays
let holidayList = contract.workCenter().holidays(); let holidayList = contract.workCenter().holidays();
for (let day of holidayList) { for (let day of holidayList) {
@ -137,10 +144,22 @@ module.exports = Self => {
const maxHolidays = currentContract.holidays().days; const maxHolidays = currentContract.holidays().days;
calendar.totalHolidays = maxHolidays; calendar.totalHolidays = maxHolidays;
if (workedDays < 365) workedDays -= entitlementRate;
calendar.totalHolidays = Math.round(2 * maxHolidays * (workedDays) / 365) / 2;
if (workedDays < daysInYear())
calendar.totalHolidays = Math.round(2 * maxHolidays * (workedDays) / daysInYear()) / 2;
}
function daysInYear() {
const year = yearStarted.getFullYear();
return isLeapYear(year) ? 366 : 365;
} }
return [calendar, absences, holidays]; return [calendar, absences, holidays];
}; };
function isLeapYear(year) {
return year % 400 === 0 || (year % 100 !== 0 && year % 4 === 0);
}
}; };

View File

@ -19,6 +19,9 @@
}, },
"code": { "code": {
"type": "String" "type": "String"
},
"holidayEntitlementRate": {
"type": "Number"
} }
}, },
"acls": [ "acls": [