From 3c8629b3f306d8f969241e3a9cf8fb0b46579a34 Mon Sep 17 00:00:00 2001 From: joan Date: Tue, 8 Jun 2021 16:36:16 +0200 Subject: [PATCH] Added entilementRate effects --- .../worker/back/methods/worker/holidays.js | 39 ++++++++++++++++--- modules/worker/back/models/worker-labour.json | 5 +++ modules/worker/front/calendar/index.js | 4 +- 3 files changed, 40 insertions(+), 8 deletions(-) diff --git a/modules/worker/back/methods/worker/holidays.js b/modules/worker/back/methods/worker/holidays.js index 48c943b58..c6f299a73 100644 --- a/modules/worker/back/methods/worker/holidays.js +++ b/modules/worker/back/methods/worker/holidays.js @@ -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; diff --git a/modules/worker/back/models/worker-labour.json b/modules/worker/back/models/worker-labour.json index eae28cf89..62764961a 100644 --- a/modules/worker/back/models/worker-labour.json +++ b/modules/worker/back/models/worker-labour.json @@ -38,6 +38,11 @@ "type": "belongsTo", "model": "WorkCenterHoliday", "foreignKey": "workCenterFk" + }, + "absences": { + "type": "hasMany", + "model": "Calendar", + "foreignKey": "businessFk" } } } diff --git a/modules/worker/front/calendar/index.js b/modules/worker/front/calendar/index.js index 776f687e4..ab172f597 100644 --- a/modules/worker/front/calendar/index.js +++ b/modules/worker/front/calendar/index.js @@ -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) {