From 8f92abe49cbaecf76e597600ac58cbda27237d27 Mon Sep 17 00:00:00 2001 From: Joan Sanchez Date: Tue, 31 Dec 2019 14:01:05 +0100 Subject: [PATCH] fixed procedure bug --- .../00-timeControl_calculate.sql | 44 ++++++++ db/dump/fixtures.sql | 2 +- modules/worker/front/time-control/index.js | 102 +++++++++--------- 3 files changed, 96 insertions(+), 52 deletions(-) create mode 100644 db/changes/10130-christmas/00-timeControl_calculate.sql diff --git a/db/changes/10130-christmas/00-timeControl_calculate.sql b/db/changes/10130-christmas/00-timeControl_calculate.sql new file mode 100644 index 000000000..0a6470216 --- /dev/null +++ b/db/changes/10130-christmas/00-timeControl_calculate.sql @@ -0,0 +1,44 @@ +USE `vn`; +DROP procedure IF EXISTS `timeControl_calculate`; + +DELIMITER $$ +USE `vn`$$ +CREATE DEFINER=`root`@`%` PROCEDURE `timeControl_calculate`(vDatedFrom DATETIME, vDatedTo DATETIME) +BEGIN + SET @vIsOdd := TRUE; + SET @vUser := NULL; + SET @vDated := NULL; + + DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate; + + CREATE TEMPORARY TABLE tmp.timeControlCalculate + SELECT userFk, + dated, + IF( timeWork >= 18000, @timeWork:=timeWork + 1200, @timeWork:=timeWork) timeWorkSeconds, + SEC_TO_TIME(@timeWork ) timeWorkSexagesimal, + @timeWork / 3600 timeWorkDecimal + FROM (SELECT SUM(timeWork) timeWork, + userFk, + dated + FROM (SELECT IF(@vUser = wtc.userFk, @vUser :=@vUser, @vUser := wtc.userFk ), + IF(@vIsOdd, @vIsOdd := FALSE, @vIsOdd := TRUE ), + IF(direction='in', @vIsOdd := TRUE, @vIsOdd := @vIsOdd ), + IF(@vIsOdd, @vLastTimed:=UNIX_TIMESTAMP(timed),@vLastTimed:=@vLastTimed), + IF(@vIsOdd, 0, UNIX_TIMESTAMP(timed)-@vLastTimed) timeWork, + IF(direction='in', @vDated := DATE(wtc.timed), @vDated :=@vDated) dated, + wtc.userFk, + wtc.timed timed, + direction + FROM (SELECT * FROM workerTimeControl ORDER BY userFk, timed ASC) wtc + JOIN tmp.`user` w ON w.userFk = wtc.userFk + WHERE wtc.timed BETWEEN vDatedFrom AND vDatedTo + ORDER BY userFk, timed ASC + ) sub + GROUP BY userFk, dated + ORDER BY userFk, dated + )sub2; + +END$$ + +DELIMITER ; + diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index a10b2003c..38516b8f3 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1549,7 +1549,7 @@ INSERT INTO `postgresql`.`profile`(`profile_id`, `person_id`, `profile_type_id`) FROM `postgresql`.`person` `p`; INSERT INTO `postgresql`.`business`(`business_id`, `client_id`, `provider_id`, `date_start`, `date_end`, `workerBusiness`, `reasonEndFk`) - SELECT p.profile_id, p.profile_id, 1000, CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL -1 YEAR)), '-12-31'), CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL +1 YEAR)), '-01-01'), CONCAT('E-46-',RPAD(CONCAT(p.profile_id,9),8,p.profile_id)), NULL + SELECT p.profile_id, p.profile_id, 1000, CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL -1 YEAR)), '-12-31'), CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL +1 YEAR)), '-01-25'), CONCAT('E-46-',RPAD(CONCAT(p.profile_id,9),8,p.profile_id)), NULL FROM `postgresql`.`profile` `p`; INSERT INTO `postgresql`.`business_labour`(`business_id`, `notes`, `department_id`, `professional_category_id`, `incentivo`, `calendar_labour_type_id`, `porhoras`, `labour_agreement_id`, `workcenter_id`) diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index c355138c3..13829e0c5 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -77,16 +77,63 @@ class Controller extends Component { {timed: {lte: this.ended}} ]} }; - this.$.model.applyFilter(filter, params); - - this.getAbsences(); - this.getWorkedHours(this.started, this.ended); + this.$.model.applyFilter(filter, params).then(() => { + this.getWorkedHours(this.started, this.ended); + this.getAbsences(); + }); } hasEvents(day) { return day >= this.started && day < this.ended; } + getAbsences() { + let params = { + workerFk: this.$params.id, + started: this.started, + ended: this.ended + }; + + return this.$http.get(`WorkerCalendars/absences`, {params}) + .then(res => this.onData(res.data)); + } + + onData(data) { + const events = {}; + + let addEvent = (day, event) => { + events[new Date(day).getTime()] = event; + }; + + if (data.holidays) { + data.holidays.forEach(holiday => { + const holidayDetail = holiday.detail && holiday.detail.description; + const holidayType = holiday.type && holiday.type.name; + const holidayName = holidayDetail || holidayType; + + addEvent(holiday.dated, { + name: holidayName, + color: '#ff0' + }); + }); + } + if (data.absences) { + data.absences.forEach(absence => { + const type = absence.absenceType; + addEvent(absence.dated, { + name: type.name, + color: type.rgb + }); + }); + } + + this.weekDays.forEach(day => { + const timestamp = day.dated.getTime(); + if (events[timestamp]) + day.event = events[timestamp]; + }); + } + getWorkedHours(from, to) { this.weekTotalHours = null; let weekTotalHours = 0; @@ -208,53 +255,6 @@ class Controller extends Component { this.vnApp.showSuccess(this.$t('Entry removed')); }); } - - getAbsences() { - let params = { - workerFk: this.$params.id, - started: this.started, - ended: this.ended - }; - - return this.$http.get(`WorkerCalendars/absences`, {params}) - .then(res => this.onData(res.data)); - } - - onData(data) { - const events = {}; - - let addEvent = (day, event) => { - events[new Date(day).getTime()] = event; - }; - - if (data.holidays) { - data.holidays.forEach(holiday => { - const holidayDetail = holiday.detail && holiday.detail.description; - const holidayType = holiday.type && holiday.type.name; - const holidayName = holidayDetail || holidayType; - - addEvent(holiday.dated, { - name: holidayName, - color: '#ff0' - }); - }); - } - if (data.absences) { - data.absences.forEach(absence => { - const type = absence.absenceType; - addEvent(absence.dated, { - name: type.name, - color: type.rgb - }); - }); - } - - this.weekDays.forEach(day => { - const timestamp = day.dated.getTime(); - if (events[timestamp]) - day.event = events[timestamp]; - }); - } } Controller.$inject = ['$element', '$scope', 'vnWeekDays'];