From 4b60aacbbecf92bf2948d03b281760c65b8479b0 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 12 Jan 2023 08:50:03 +0100 Subject: [PATCH 1/6] =?UTF-8?q?refactor:=20a=C3=B1adidos=20valores=20a=20p?= =?UTF-8?q?i=C3=B1on=20a=20la=20tabla=20workerTimeControlConfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../230201/00-workerTimeControlConfig.sql | 6 ++++++ db/dump/fixtures.sql | 4 ++-- .../methods/worker-time-control/sendMail.js | 17 ++++++++++++----- .../back/models/worker-time-control-config.json | 11 ++++++++++- 4 files changed, 30 insertions(+), 8 deletions(-) create mode 100644 db/changes/230201/00-workerTimeControlConfig.sql diff --git a/db/changes/230201/00-workerTimeControlConfig.sql b/db/changes/230201/00-workerTimeControlConfig.sql new file mode 100644 index 000000000..c04acd936 --- /dev/null +++ b/db/changes/230201/00-workerTimeControlConfig.sql @@ -0,0 +1,6 @@ +ALTER TABLE `vn`.`workerTimeControlConfig` ADD teleworkingStart INT NULL COMMENT 'Hora comienzo jornada de los teletrabajdores expresada en segundos'; +ALTER TABLE `vn`.`workerTimeControlConfig` ADD teleworkingStartBreakTime INT NULL COMMENT 'Hora comienzo descanso de los teletrabjadores expresada en segundos'; + +UPDATE `vn`.`workerTimeControlConfig` + SET `teleworkingStart`=28800, `teleworkingStartBreakTime`=32400 +WHERE `id`=1; diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index f1c9df51f..b192d4751 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -2671,9 +2671,9 @@ INSERT INTO `vn`.`sectorCollectionSaleGroup` (`sectorCollectionFk`, `saleGroupFk VALUES (1, 1); -INSERT INTO `vn`.`workerTimeControlConfig` (`id`, `dayBreak`, `dayBreakDriver`, `shortWeekBreak`, `longWeekBreak`, `weekScope`, `mailPass`, `mailHost`, `mailSuccessFolder`, `mailErrorFolder`, `mailUser`, `minHoursToBreak`, `breakHours`, `hoursCompleteWeek`, `startNightlyHours`, `endNightlyHours`, `maxTimePerDay`, `breakTime`, `timeToBreakTime`, `dayMaxTime`, `shortWeekDays`, `longWeekDays`) +INSERT INTO `vn`.`workerTimeControlConfig` (`id`, `dayBreak`, `dayBreakDriver`, `shortWeekBreak`, `longWeekBreak`, `weekScope`, `mailPass`, `mailHost`, `mailSuccessFolder`, `mailErrorFolder`, `mailUser`, `minHoursToBreak`, `breakHours`, `hoursCompleteWeek`, `startNightlyHours`, `endNightlyHours`, `maxTimePerDay`, `breakTime`, `timeToBreakTime`, `dayMaxTime`, `shortWeekDays`, `longWeekDays`, `teleworkingStart`, `teleworkingStartBreakTime`) VALUES - (1, 43200, 32400, 129600, 259200, 604800, '', '', 'Leidos.exito', 'Leidos.error', 'timeControl', 5.33, 0.33, 40, '22:00:00', '06:00:00', 57600, 1200, 18000, 57600, 6, 13); + (1, 43200, 32400, 129600, 259200, 604800, '', '', 'Leidos.exito', 'Leidos.error', 'timeControl', 5.33, 0.33, 40, '22:00:00', '06:00:00', 57600, 1200, 18000, 57600, 6, 13, 28800, 32400); INSERT INTO `vn`.`host` (`id`, `code`, `description`, `warehouseFk`, `bankFk`) VALUES diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index b38405c1d..793a8b4d9 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -32,7 +32,6 @@ module.exports = Self => { const models = Self.app.models; const conn = Self.dataSource.connector; const args = ctx.args; - const $t = ctx.req.__; // $translate let tx; const myOptions = {}; @@ -166,13 +165,14 @@ module.exports = Self => { for (let day of days[index]) { workerFk = day.workerFk; + console.log(day); if (day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null && (day.permissionRate ? day.permissionRate : true)) { if (day.timeTable == null) { const timed = new Date(day.dated); await models.WorkerTimeControl.create({ userFk: day.workerFk, - timed: timed.setHours(8), + timed: timed.setHours(workerTimeControlConfig.teleworkingStart / 3600), manual: true, direction: 'in', isSendMail: true @@ -181,7 +181,7 @@ module.exports = Self => { if (day.timeWorkDecimal >= workerTimeControlConfig.timeToBreakTime / 3600) { await models.WorkerTimeControl.create({ userFk: day.workerFk, - timed: timed.setHours(9), + timed: timed.setHours(workerTimeControlConfig.teleworkingStartBreakTime / 3600), manual: true, direction: 'middle', isSendMail: true @@ -189,7 +189,10 @@ module.exports = Self => { await models.WorkerTimeControl.create({ userFk: day.workerFk, - timed: timed.setHours(9, 20), + timed: timed.setHours( + workerTimeControlConfig.teleworkingStartBreakTime / 3600, + workerTimeControlConfig.breakTime / 60 + ), manual: true, direction: 'middle', isSendMail: true @@ -199,7 +202,11 @@ module.exports = Self => { const [hoursWork, minutesWork, secondsWork] = getTime(day.timeWorkSexagesimal); await models.WorkerTimeControl.create({ userFk: day.workerFk, - timed: timed.setHours(8 + hoursWork, minutesWork, secondsWork), + timed: timed.setHours( + workerTimeControlConfig.teleworkingStart / 3600 + hoursWork, + minutesWork, + secondsWork + ), manual: true, direction: 'out', isSendMail: true diff --git a/modules/worker/back/models/worker-time-control-config.json b/modules/worker/back/models/worker-time-control-config.json index 4c12ce5d7..b96e2ae3b 100644 --- a/modules/worker/back/models/worker-time-control-config.json +++ b/modules/worker/back/models/worker-time-control-config.json @@ -11,8 +11,17 @@ "id": true, "type": "number" }, + "breakTime": { + "type": "number" + }, "timeToBreakTime": { "type": "number" + }, + "teleworkingStart": { + "type": "number" + }, + "teleworkingStartBreakTime": { + "type": "number" } } -} \ No newline at end of file +} From 7368b572a05131fa80ff13024d4d9cec6d463864 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 18 Jan 2023 13:05:02 +0100 Subject: [PATCH 2/6] =?UTF-8?q?fix:=20a=C3=B1adidos=20await=20y=20actualiz?= =?UTF-8?q?ado=20condicional=20permissionRate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../worker/back/methods/worker-time-control/sendMail.js | 7 +++---- .../methods/worker-time-control/weeklyHourRecordEmail.js | 2 +- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 793a8b4d9..51f6a7cf3 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -165,9 +165,8 @@ module.exports = Self => { for (let day of days[index]) { workerFk = day.workerFk; - console.log(day); if (day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null - && (day.permissionRate ? day.permissionRate : true)) { + && (day.permissionRate == null ? true : day.permissionRate)) { if (day.timeTable == null) { const timed = new Date(day.dated); await models.WorkerTimeControl.create({ @@ -314,7 +313,7 @@ module.exports = Self => { }, myOptions); if (firstWorkerTimeControl) - firstWorkerTimeControl.updateAttribute('direction', 'in', myOptions); + await firstWorkerTimeControl.updateAttribute('direction', 'in', myOptions); const lastWorkerTimeControl = await models.WorkerTimeControl.findOne({ where: { @@ -325,7 +324,7 @@ module.exports = Self => { }, myOptions); if (lastWorkerTimeControl) - lastWorkerTimeControl.updateAttribute('direction', 'out', myOptions); + await lastWorkerTimeControl.updateAttribute('direction', 'out', myOptions); } } diff --git a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js index 0cf614e57..6feadb936 100644 --- a/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js +++ b/modules/worker/back/methods/worker-time-control/weeklyHourRecordEmail.js @@ -2,7 +2,7 @@ const {Email} = require('vn-print'); module.exports = Self => { Self.remoteMethodCtx('weeklyHourRecordEmail', { - description: 'Sends the buyer waste email', + description: 'Sends the weekly hour record', accessType: 'WRITE', accepts: [ { From 2c995208d1f12ebf21d10fe866b2611638e12729 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 18 Jan 2023 14:23:05 +0100 Subject: [PATCH 3/6] =?UTF-8?q?fix:=20transaccionado=20por=20trabajador=20?= =?UTF-8?q?y=20d=C3=ADa?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../methods/worker-time-control/sendMail.js | 155 +++++++++--------- 1 file changed, 78 insertions(+), 77 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 51f6a7cf3..9c2f65dd6 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -38,87 +38,81 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - if (!myOptions.transaction) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; - } - const stmts = []; let stmt; - try { - if (!args.week || !args.year) { - const from = new Date(); - const to = new Date(); + if (!args.week || !args.year) { + const from = new Date(); + const to = new Date(); - const time = await models.Time.findOne({ - where: { - dated: {between: [from.setDate(from.getDate() - 10), to.setDate(to.getDate() - 4)]} - }, - order: 'week ASC' - }, myOptions); + const time = await models.Time.findOne({ + where: { + dated: {between: [from.setDate(from.getDate() - 10), to.setDate(to.getDate() - 4)]} + }, + order: 'week ASC' + }, myOptions); - args.week = time.week; - args.year = time.year; - } + args.week = time.week; + args.year = time.year; + } - const started = getStartDateOfWeekNumber(args.week, args.year); - started.setHours(0, 0, 0, 0); + const started = getStartDateOfWeekNumber(args.week, args.year); + started.setHours(0, 0, 0, 0); - const ended = new Date(started); - ended.setDate(started.getDate() + 6); - ended.setHours(23, 59, 59, 999); + const ended = new Date(started); + ended.setDate(started.getDate() + 6); + ended.setHours(23, 59, 59, 999); - stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate'); - stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.timeBusinessCalculate'); + stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate'); + stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.timeBusinessCalculate'); - if (args.workerId) { - await models.WorkerTimeControl.destroyAll({ - userFk: args.workerId, - timed: {between: [started, ended]}, - isSendMail: true - }, myOptions); + if (args.workerId) { + await models.WorkerTimeControl.destroyAll({ + userFk: args.workerId, + timed: {between: [started, ended]}, + isSendMail: true + }, myOptions); - const where = { - workerFk: args.workerId, - year: args.year, - week: args.week - }; - await models.WorkerTimeControlMail.updateAll(where, { - updated: new Date(), state: 'SENDED' - }, myOptions); + const where = { + workerFk: args.workerId, + year: args.year, + week: args.week + }; + await models.WorkerTimeControlMail.updateAll(where, { + updated: new Date(), state: 'SENDED' + }, myOptions); - stmt = new ParameterizedSQL( - `CALL vn.timeControl_calculateByUser(?, ?, ?) + stmt = new ParameterizedSQL( + `CALL vn.timeControl_calculateByUser(?, ?, ?) `, [args.workerId, started, ended]); - stmts.push(stmt); + stmts.push(stmt); - stmt = new ParameterizedSQL( - `CALL vn.timeBusiness_calculateByUser(?, ?, ?) + stmt = new ParameterizedSQL( + `CALL vn.timeBusiness_calculateByUser(?, ?, ?) `, [args.workerId, started, ended]); - stmts.push(stmt); - } else { - await models.WorkerTimeControl.destroyAll({ - timed: {between: [started, ended]}, - isSendMail: true - }, myOptions); + stmts.push(stmt); + } else { + await models.WorkerTimeControl.destroyAll({ + timed: {between: [started, ended]}, + isSendMail: true + }, myOptions); - const where = { - year: args.year, - week: args.week - }; - await models.WorkerTimeControlMail.updateAll(where, { - updated: new Date(), state: 'SENDED' - }, myOptions); + const where = { + year: args.year, + week: args.week + }; + await models.WorkerTimeControlMail.updateAll(where, { + updated: new Date(), state: 'SENDED' + }, myOptions); - stmt = new ParameterizedSQL(`CALL vn.timeControl_calculateAll(?, ?)`, [started, ended]); - stmts.push(stmt); + stmt = new ParameterizedSQL(`CALL vn.timeControl_calculateAll(?, ?)`, [started, ended]); + stmts.push(stmt); - stmt = new ParameterizedSQL(`CALL vn.timeBusiness_calculateAll(?, ?)`, [started, ended]); - stmts.push(stmt); - } + stmt = new ParameterizedSQL(`CALL vn.timeBusiness_calculateAll(?, ?)`, [started, ended]); + stmts.push(stmt); + } - stmt = new ParameterizedSQL(` + stmt = new ParameterizedSQL(` SELECT CONCAT(u.name, '@verdnatura.es') receiver, u.id workerFk, tb.dated, @@ -153,18 +147,25 @@ module.exports = Self => { AND w.businessFk ORDER BY u.id, tb.dated `, [args.workerId]); - const index = stmts.push(stmt) - 1; + const index = stmts.push(stmt) - 1; - const sql = ParameterizedSQL.join(stmts, ';'); - const days = await conn.executeStmt(sql, myOptions); + stmts.push('DROP TEMPORARY TABLE tmp.timeControlCalculate'); + stmts.push('DROP TEMPORARY TABLE tmp.timeBusinessCalculate'); - let previousWorkerFk = days[index][0].workerFk; - let previousReceiver = days[index][0].receiver; + const sql = ParameterizedSQL.join(stmts, ';'); + const days = await conn.executeStmt(sql, myOptions); - const workerTimeControlConfig = await models.WorkerTimeControlConfig.findOne(null, myOptions); + let previousWorkerFk = days[index][0].workerFk; + let previousReceiver = days[index][0].receiver; - for (let day of days[index]) { + const workerTimeControlConfig = await models.WorkerTimeControlConfig.findOne(null, myOptions); + + for (let day of days[index]) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + try { workerFk = day.workerFk; + if (workerFk == 418) throw new Error('Test'); if (day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null && (day.permissionRate == null ? true : day.permissionRate)) { if (day.timeTable == null) { @@ -345,15 +346,15 @@ module.exports = Self => { previousWorkerFk = day.workerFk; previousReceiver = day.receiver; } + + if (tx) await tx.commit(); + } catch (e) { + if (tx) await tx.rollback(); + throw e; } - - if (tx) await tx.commit(); - - return true; - } catch (e) { - if (tx) await tx.rollback(); - throw e; } + + return true; }; function getStartDateOfWeekNumber(week, year) { From 38e4349e17e9c070a8dcf891074526bd5dc2ff24 Mon Sep 17 00:00:00 2001 From: vicent Date: Wed, 18 Jan 2023 14:25:24 +0100 Subject: [PATCH 4/6] borrado comentario --- modules/worker/back/methods/worker-time-control/sendMail.js | 1 - 1 file changed, 1 deletion(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index 9c2f65dd6..f86f61746 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -165,7 +165,6 @@ module.exports = Self => { myOptions.transaction = tx; try { workerFk = day.workerFk; - if (workerFk == 418) throw new Error('Test'); if (day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null && (day.permissionRate == null ? true : day.permissionRate)) { if (day.timeTable == null) { From 92a9004d98a09caa8987f2ac658e63d5afb02c6b Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 19 Jan 2023 08:54:26 +0100 Subject: [PATCH 5/6] fix: borrada propiedad transaction cuando se hace commit --- .../back/methods/worker-time-control/sendMail.js | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js index f86f61746..78c212e9b 100644 --- a/modules/worker/back/methods/worker-time-control/sendMail.js +++ b/modules/worker/back/methods/worker-time-control/sendMail.js @@ -161,8 +161,10 @@ module.exports = Self => { const workerTimeControlConfig = await models.WorkerTimeControlConfig.findOne(null, myOptions); for (let day of days[index]) { - tx = await Self.beginTransaction({}); - myOptions.transaction = tx; + if (!myOptions.transaction) { + tx = await Self.beginTransaction({}); + myOptions.transaction = tx; + } try { workerFk = day.workerFk; if (day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null @@ -346,7 +348,10 @@ module.exports = Self => { previousReceiver = day.receiver; } - if (tx) await tx.commit(); + if (tx) { + await tx.commit(); + delete myOptions.transaction; + } } catch (e) { if (tx) await tx.rollback(); throw e; From 921b5cf3fb487c0331bb92abc1409d5439d83a21 Mon Sep 17 00:00:00 2001 From: vicent Date: Thu, 19 Jan 2023 08:54:36 +0100 Subject: [PATCH 6/6] add excluded test --- .../back/methods/worker-time-control/specs/sendMail.spec.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/modules/worker/back/methods/worker-time-control/specs/sendMail.spec.js b/modules/worker/back/methods/worker-time-control/specs/sendMail.spec.js index 5b2436be9..24bfd6904 100644 --- a/modules/worker/back/methods/worker-time-control/specs/sendMail.spec.js +++ b/modules/worker/back/methods/worker-time-control/specs/sendMail.spec.js @@ -10,7 +10,6 @@ describe('workerTimeControl sendMail()', () => { const ctx = {req: activeCtx, args: {}}; it('should fill time control of a worker without records in Journey and with rest', async() => { - pending('https://redmine.verdnatura.es/issues/4903'); const tx = await models.WorkerTimeControl.beginTransaction({}); try { @@ -35,7 +34,6 @@ describe('workerTimeControl sendMail()', () => { }); it('should fill time control of a worker without records in Journey and without rest', async() => { - pending('https://redmine.verdnatura.es/issues/4903'); const workdayOf20Hours = 3; const tx = await models.WorkerTimeControl.beginTransaction({}); @@ -63,7 +61,6 @@ describe('workerTimeControl sendMail()', () => { }); it('should fill time control of a worker with records in Journey and with rest', async() => { - pending('https://redmine.verdnatura.es/issues/4903'); const tx = await models.WorkerTimeControl.beginTransaction({}); try { @@ -95,7 +92,6 @@ describe('workerTimeControl sendMail()', () => { }); it('should fill time control of a worker with records in Journey and without rest', async() => { - pending('https://redmine.verdnatura.es/issues/4903'); const tx = await models.WorkerTimeControl.beginTransaction({}); try {