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 7c45858764
commit 2930b60adc
2 changed files with 26 additions and 4 deletions

View File

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

View File

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