Added entilementRate effects
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Joan Sanchez 2021-06-08 16:36:16 +02:00
parent 8fa64122f8
commit 3c8629b3f3
3 changed files with 40 additions and 8 deletions

View File

@ -61,6 +61,17 @@ module.exports = Self => {
where: {year}
}
},
{
relation: 'absences',
scope: {
include: {
relation: 'absenceType',
},
where: {
dated: {between: [started, ended]}
}
}
},
{
relation: 'workCenter',
scope: {
@ -112,8 +123,7 @@ module.exports = Self => {
let totalHolidays = 0;
let holidaysEnjoyed = 0;
let entitlementRate = 0;
for (let absence of absences) {
/* for (let absence of absences) {
const absenceType = absence.absenceType();
const isHoliday = absenceType.code === 'holiday';
const isHalfHoliday = absenceType.code === 'halfHoliday';
@ -123,9 +133,7 @@ module.exports = Self => {
entitlementRate += absenceType.holidayEntitlementRate;
absence.dated = new Date(absence.dated); // not needed
absence.dated.setHours(0, 0, 0, 0);
}
} */
// Get number of worked days
// let totalWorkedDays = 0;
@ -138,7 +146,8 @@ module.exports = Self => {
// esta mal, la fecha de inicio puede ser un año anterior...
const startedTime = contractStarted < started ? started.getTime() : contractStarted.getTime();
const endedTime = contractEnded && contractEnded.getTime() || ended.getTime();
const endedTime = !contractEnded || contractEnded && contractEnded > ended ? ended.getTime() : contractEnded.getTime();
// const endedTime = contractEnded && contractEnded.getTime() || ended.getTime();
const dayTimestamp = 1000 * 60 * 60 * 24;
let workedDays = Math.floor((endedTime - startedTime) / dayTimestamp); // debería dar un computo de 366 dias
@ -156,7 +165,25 @@ module.exports = Self => {
holidays.push(day);
}
*/
let entitlementRate = 0;
for (let absence of contract.absences()) {
const absenceType = absence.absenceType();
const isHoliday = absenceType.code === 'holiday';
const isHalfHoliday = absenceType.code === 'halfHoliday';
if (isHoliday) holidaysEnjoyed += 1;
if (isHalfHoliday) holidaysEnjoyed += 0.5;
entitlementRate += absenceType.holidayEntitlementRate;
// absence.dated = new Date(absence.dated); // not needed
// absence.dated.setHours(0, 0, 0, 0);
}
workedDays -= entitlementRate;
// Set max holidays
// const maxHolidays = contract.holidays() && contract.holidays().days;
const maxHolidays = contract.holidays() && contract.holidays().days;

View File

@ -38,6 +38,11 @@
"type": "belongsTo",
"model": "WorkCenterHoliday",
"foreignKey": "workCenterFk"
},
"absences": {
"type": "hasMany",
"model": "Calendar",
"foreignKey": "businessFk"
}
}
}

View File

@ -114,9 +114,9 @@ class Controller extends Section {
}
getYearHolidays() {
this.getHolidays({
/* this.getHolidays({
year: this.year
}, data => this.yearHolidays = data);
}, data => this.yearHolidays = data); */
}
getHolidays(params, cb) {