dev #1731

Merged
jgallego merged 105 commits from dev into test 2023-08-31 09:13:29 +00:00
1 changed files with 37 additions and 10 deletions
Showing only changes of commit 0054f2d82f - Show all commits

View File

@ -121,15 +121,18 @@ module.exports = Self => {
`, [started, ended]); `, [started, ended]);
stmts.push(stmt); stmts.push(stmt);
stmt = new ParameterizedSQL(`INSERT INTO mail (receiver, subject, body) stmt = new ParameterizedSQL(`
SELECT CONCAT(u.name, '@verdnatura.es'), INSERT INTO mail (receiver, subject, body)
CONCAT('Error registro de horas semana ', ?, ' año ', ?) , SELECT CONCAT(u.name, '@verdnatura.es'),
CONCAT('No se ha podido enviar el registro de horas al empleado/s: ', GROUP_CONCAT(DISTINCT CONCAT('<br>', w.id, ' ', w.firstName, ' ', w.lastName))) CONCAT('Error registro de horas semana ', ?, ' año ', ?) ,
FROM tmp.timeControlError tce CONCAT('No se ha podido enviar el registro de horas al empleado/s: ',
JOIN vn.workerTimeControl wtc ON wtc.id = tce.id GROUP_CONCAT(DISTINCT CONCAT('<br>', w.id, ' ', w.firstName, ' ', w.lastName)))
JOIN worker w ON w.id = wtc.userFK FROM tmp.timeControlError tce
JOIN account.user u ON u.id = w.bossFk JOIN vn.workerTimeControl wtc ON wtc.id = tce.id
GROUP BY w.bossFk`, [args.week, args.year]); JOIN worker w ON w.id = wtc.userFK
JOIN account.user u ON u.id = w.bossFk
GROUP BY w.bossFk
`, [args.week, args.year]);
stmts.push(stmt); stmts.push(stmt);
stmt = new ParameterizedSQL(` stmt = new ParameterizedSQL(`
@ -176,6 +179,7 @@ module.exports = Self => {
const workerTimeControlConfig = await models.WorkerTimeControlConfig.findOne(null, myOptions); const workerTimeControlConfig = await models.WorkerTimeControlConfig.findOne(null, myOptions);
console.log(days[index]);
for (let day of days[index]) { for (let day of days[index]) {
if (!myOptions.transaction) { if (!myOptions.transaction) {
tx = await Self.beginTransaction({}); tx = await Self.beginTransaction({});
@ -371,7 +375,30 @@ module.exports = Self => {
} }
} catch (e) { } catch (e) {
if (tx) await tx.rollback(); if (tx) await tx.rollback();
throw e; delete myOptions.transaction;
const stmts = [];
let stmt;
stmt = new ParameterizedSQL(`
INSERT INTO mail (receiver, subject, body)
SELECT CONCAT(u.name, '@verdnatura.es'),
CONCAT('Error registro de horas semana ', ?, ' año ', ?) ,
CONCAT('No se ha podido enviar el registro de horas al empleado/s: ',
GROUP_CONCAT(DISTINCT CONCAT('<br>', w.id, ' ', w.firstName, ' ', w.lastName)))
FROM worker w
JOIN account.user u ON u.id = w.bossFk
WHERE w.id = ?
GROUP BY w.bossFk
`, [args.week, args.year, day.workerFk]);
stmts.push(stmt);
const sql = ParameterizedSQL.join(stmts, ';');
await conn.executeStmt(sql);
previousWorkerFk = day.workerFk;
previousReceiver = day.receiver;
continue;
} }
} }