Merge pull request '4903-workerTimeControl_sendMail' (!1261) from 4903-workerTimeControl_sendMail into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #1261 Reviewed-by: Joan Sanchez <joan@verdnatura.es>
This commit is contained in:
commit
9072f3696d
|
@ -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;
|
|
@ -2667,9 +2667,9 @@ INSERT INTO `vn`.`sectorCollectionSaleGroup` (`sectorCollectionFk`, `saleGroupFk
|
||||||
VALUES
|
VALUES
|
||||||
(1, 1);
|
(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
|
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`)
|
INSERT INTO `vn`.`host` (`id`, `code`, `description`, `warehouseFk`, `bankFk`)
|
||||||
VALUES
|
VALUES
|
||||||
|
|
|
@ -32,94 +32,87 @@ module.exports = Self => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
const conn = Self.dataSource.connector;
|
const conn = Self.dataSource.connector;
|
||||||
const args = ctx.args;
|
const args = ctx.args;
|
||||||
const $t = ctx.req.__; // $translate
|
|
||||||
let tx;
|
let tx;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
if (!myOptions.transaction) {
|
|
||||||
tx = await Self.beginTransaction({});
|
|
||||||
myOptions.transaction = tx;
|
|
||||||
}
|
|
||||||
|
|
||||||
const stmts = [];
|
const stmts = [];
|
||||||
let stmt;
|
let stmt;
|
||||||
|
|
||||||
try {
|
if (!args.week || !args.year) {
|
||||||
if (!args.week || !args.year) {
|
const from = new Date();
|
||||||
const from = new Date();
|
const to = new Date();
|
||||||
const to = new Date();
|
|
||||||
|
|
||||||
const time = await models.Time.findOne({
|
const time = await models.Time.findOne({
|
||||||
where: {
|
where: {
|
||||||
dated: {between: [from.setDate(from.getDate() - 10), to.setDate(to.getDate() - 4)]}
|
dated: {between: [from.setDate(from.getDate() - 10), to.setDate(to.getDate() - 4)]}
|
||||||
},
|
},
|
||||||
order: 'week ASC'
|
order: 'week ASC'
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
args.week = time.week;
|
args.week = time.week;
|
||||||
args.year = time.year;
|
args.year = time.year;
|
||||||
}
|
}
|
||||||
|
|
||||||
const started = getStartDateOfWeekNumber(args.week, args.year);
|
const started = getStartDateOfWeekNumber(args.week, args.year);
|
||||||
started.setHours(0, 0, 0, 0);
|
started.setHours(0, 0, 0, 0);
|
||||||
|
|
||||||
const ended = new Date(started);
|
const ended = new Date(started);
|
||||||
ended.setDate(started.getDate() + 6);
|
ended.setDate(started.getDate() + 6);
|
||||||
ended.setHours(23, 59, 59, 999);
|
ended.setHours(23, 59, 59, 999);
|
||||||
|
|
||||||
stmts.push('DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate');
|
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.timeBusinessCalculate');
|
||||||
|
|
||||||
if (args.workerId) {
|
if (args.workerId) {
|
||||||
await models.WorkerTimeControl.destroyAll({
|
await models.WorkerTimeControl.destroyAll({
|
||||||
userFk: args.workerId,
|
userFk: args.workerId,
|
||||||
timed: {between: [started, ended]},
|
timed: {between: [started, ended]},
|
||||||
isSendMail: true
|
isSendMail: true
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
const where = {
|
const where = {
|
||||||
workerFk: args.workerId,
|
workerFk: args.workerId,
|
||||||
year: args.year,
|
year: args.year,
|
||||||
week: args.week
|
week: args.week
|
||||||
};
|
};
|
||||||
await models.WorkerTimeControlMail.updateAll(where, {
|
await models.WorkerTimeControlMail.updateAll(where, {
|
||||||
updated: new Date(), state: 'SENDED'
|
updated: new Date(), state: 'SENDED'
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(
|
stmt = new ParameterizedSQL(
|
||||||
`CALL vn.timeControl_calculateByUser(?, ?, ?)
|
`CALL vn.timeControl_calculateByUser(?, ?, ?)
|
||||||
`, [args.workerId, started, ended]);
|
`, [args.workerId, started, ended]);
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(
|
stmt = new ParameterizedSQL(
|
||||||
`CALL vn.timeBusiness_calculateByUser(?, ?, ?)
|
`CALL vn.timeBusiness_calculateByUser(?, ?, ?)
|
||||||
`, [args.workerId, started, ended]);
|
`, [args.workerId, started, ended]);
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
} else {
|
} else {
|
||||||
await models.WorkerTimeControl.destroyAll({
|
await models.WorkerTimeControl.destroyAll({
|
||||||
timed: {between: [started, ended]},
|
timed: {between: [started, ended]},
|
||||||
isSendMail: true
|
isSendMail: true
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
const where = {
|
const where = {
|
||||||
year: args.year,
|
year: args.year,
|
||||||
week: args.week
|
week: args.week
|
||||||
};
|
};
|
||||||
await models.WorkerTimeControlMail.updateAll(where, {
|
await models.WorkerTimeControlMail.updateAll(where, {
|
||||||
updated: new Date(), state: 'SENDED'
|
updated: new Date(), state: 'SENDED'
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(`CALL vn.timeControl_calculateAll(?, ?)`, [started, ended]);
|
stmt = new ParameterizedSQL(`CALL vn.timeControl_calculateAll(?, ?)`, [started, ended]);
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(`CALL vn.timeBusiness_calculateAll(?, ?)`, [started, ended]);
|
stmt = new ParameterizedSQL(`CALL vn.timeBusiness_calculateAll(?, ?)`, [started, ended]);
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(`
|
stmt = new ParameterizedSQL(`
|
||||||
SELECT CONCAT(u.name, '@verdnatura.es') receiver,
|
SELECT CONCAT(u.name, '@verdnatura.es') receiver,
|
||||||
u.id workerFk,
|
u.id workerFk,
|
||||||
tb.dated,
|
tb.dated,
|
||||||
|
@ -154,25 +147,33 @@ module.exports = Self => {
|
||||||
AND w.businessFk
|
AND w.businessFk
|
||||||
ORDER BY u.id, tb.dated
|
ORDER BY u.id, tb.dated
|
||||||
`, [args.workerId]);
|
`, [args.workerId]);
|
||||||
const index = stmts.push(stmt) - 1;
|
const index = stmts.push(stmt) - 1;
|
||||||
|
|
||||||
const sql = ParameterizedSQL.join(stmts, ';');
|
stmts.push('DROP TEMPORARY TABLE tmp.timeControlCalculate');
|
||||||
const days = await conn.executeStmt(sql, myOptions);
|
stmts.push('DROP TEMPORARY TABLE tmp.timeBusinessCalculate');
|
||||||
|
|
||||||
let previousWorkerFk = days[index][0].workerFk;
|
const sql = ParameterizedSQL.join(stmts, ';');
|
||||||
let previousReceiver = days[index][0].receiver;
|
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]) {
|
||||||
|
if (!myOptions.transaction) {
|
||||||
|
tx = await Self.beginTransaction({});
|
||||||
|
myOptions.transaction = tx;
|
||||||
|
}
|
||||||
|
try {
|
||||||
workerFk = day.workerFk;
|
workerFk = day.workerFk;
|
||||||
if (day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null
|
if (day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null
|
||||||
&& (day.permissionRate ? day.permissionRate : true)) {
|
&& (day.permissionRate == null ? true : day.permissionRate)) {
|
||||||
if (day.timeTable == null) {
|
if (day.timeTable == null) {
|
||||||
const timed = new Date(day.dated);
|
const timed = new Date(day.dated);
|
||||||
await models.WorkerTimeControl.create({
|
await models.WorkerTimeControl.create({
|
||||||
userFk: day.workerFk,
|
userFk: day.workerFk,
|
||||||
timed: timed.setHours(8),
|
timed: timed.setHours(workerTimeControlConfig.teleworkingStart / 3600),
|
||||||
manual: true,
|
manual: true,
|
||||||
direction: 'in',
|
direction: 'in',
|
||||||
isSendMail: true
|
isSendMail: true
|
||||||
|
@ -181,7 +182,7 @@ module.exports = Self => {
|
||||||
if (day.timeWorkDecimal >= workerTimeControlConfig.timeToBreakTime / 3600) {
|
if (day.timeWorkDecimal >= workerTimeControlConfig.timeToBreakTime / 3600) {
|
||||||
await models.WorkerTimeControl.create({
|
await models.WorkerTimeControl.create({
|
||||||
userFk: day.workerFk,
|
userFk: day.workerFk,
|
||||||
timed: timed.setHours(9),
|
timed: timed.setHours(workerTimeControlConfig.teleworkingStartBreakTime / 3600),
|
||||||
manual: true,
|
manual: true,
|
||||||
direction: 'middle',
|
direction: 'middle',
|
||||||
isSendMail: true
|
isSendMail: true
|
||||||
|
@ -189,7 +190,10 @@ module.exports = Self => {
|
||||||
|
|
||||||
await models.WorkerTimeControl.create({
|
await models.WorkerTimeControl.create({
|
||||||
userFk: day.workerFk,
|
userFk: day.workerFk,
|
||||||
timed: timed.setHours(9, 20),
|
timed: timed.setHours(
|
||||||
|
workerTimeControlConfig.teleworkingStartBreakTime / 3600,
|
||||||
|
workerTimeControlConfig.breakTime / 60
|
||||||
|
),
|
||||||
manual: true,
|
manual: true,
|
||||||
direction: 'middle',
|
direction: 'middle',
|
||||||
isSendMail: true
|
isSendMail: true
|
||||||
|
@ -199,7 +203,11 @@ module.exports = Self => {
|
||||||
const [hoursWork, minutesWork, secondsWork] = getTime(day.timeWorkSexagesimal);
|
const [hoursWork, minutesWork, secondsWork] = getTime(day.timeWorkSexagesimal);
|
||||||
await models.WorkerTimeControl.create({
|
await models.WorkerTimeControl.create({
|
||||||
userFk: day.workerFk,
|
userFk: day.workerFk,
|
||||||
timed: timed.setHours(8 + hoursWork, minutesWork, secondsWork),
|
timed: timed.setHours(
|
||||||
|
workerTimeControlConfig.teleworkingStart / 3600 + hoursWork,
|
||||||
|
minutesWork,
|
||||||
|
secondsWork
|
||||||
|
),
|
||||||
manual: true,
|
manual: true,
|
||||||
direction: 'out',
|
direction: 'out',
|
||||||
isSendMail: true
|
isSendMail: true
|
||||||
|
@ -307,7 +315,7 @@ module.exports = Self => {
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
if (firstWorkerTimeControl)
|
if (firstWorkerTimeControl)
|
||||||
firstWorkerTimeControl.updateAttribute('direction', 'in', myOptions);
|
await firstWorkerTimeControl.updateAttribute('direction', 'in', myOptions);
|
||||||
|
|
||||||
const lastWorkerTimeControl = await models.WorkerTimeControl.findOne({
|
const lastWorkerTimeControl = await models.WorkerTimeControl.findOne({
|
||||||
where: {
|
where: {
|
||||||
|
@ -318,7 +326,7 @@ module.exports = Self => {
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
if (lastWorkerTimeControl)
|
if (lastWorkerTimeControl)
|
||||||
lastWorkerTimeControl.updateAttribute('direction', 'out', myOptions);
|
await lastWorkerTimeControl.updateAttribute('direction', 'out', myOptions);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -339,15 +347,18 @@ module.exports = Self => {
|
||||||
previousWorkerFk = day.workerFk;
|
previousWorkerFk = day.workerFk;
|
||||||
previousReceiver = day.receiver;
|
previousReceiver = day.receiver;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tx) {
|
||||||
|
await tx.commit();
|
||||||
|
delete myOptions.transaction;
|
||||||
|
}
|
||||||
|
} 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) {
|
function getStartDateOfWeekNumber(week, year) {
|
||||||
|
|
|
@ -10,7 +10,6 @@ describe('workerTimeControl sendMail()', () => {
|
||||||
const ctx = {req: activeCtx, args: {}};
|
const ctx = {req: activeCtx, args: {}};
|
||||||
|
|
||||||
it('should fill time control of a worker without records in Journey and with rest', async() => {
|
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({});
|
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -35,7 +34,6 @@ describe('workerTimeControl sendMail()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fill time control of a worker without records in Journey and without rest', async() => {
|
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 workdayOf20Hours = 3;
|
||||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
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() => {
|
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({});
|
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
@ -95,7 +92,6 @@ describe('workerTimeControl sendMail()', () => {
|
||||||
});
|
});
|
||||||
|
|
||||||
it('should fill time control of a worker with records in Journey and without rest', async() => {
|
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({});
|
const tx = await models.WorkerTimeControl.beginTransaction({});
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
|
|
@ -2,7 +2,7 @@ const {Email} = require('vn-print');
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('weeklyHourRecordEmail', {
|
Self.remoteMethodCtx('weeklyHourRecordEmail', {
|
||||||
description: 'Sends the buyer waste email',
|
description: 'Sends the weekly hour record',
|
||||||
accessType: 'WRITE',
|
accessType: 'WRITE',
|
||||||
accepts: [
|
accepts: [
|
||||||
{
|
{
|
||||||
|
|
|
@ -11,8 +11,17 @@
|
||||||
"id": true,
|
"id": true,
|
||||||
"type": "number"
|
"type": "number"
|
||||||
},
|
},
|
||||||
|
"breakTime": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
"timeToBreakTime": {
|
"timeToBreakTime": {
|
||||||
"type": "number"
|
"type": "number"
|
||||||
|
},
|
||||||
|
"teleworkingStart": {
|
||||||
|
"type": "number"
|
||||||
|
},
|
||||||
|
"teleworkingStartBreakTime": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue