fix: transaccionado por trabajador y día
gitea/salix/pipeline/head This commit looks good Details

This commit is contained in:
Vicent Llopis 2023-01-18 14:23:05 +01:00
parent 7368b572a0
commit 2c995208d1
1 changed files with 78 additions and 77 deletions

View File

@ -38,15 +38,9 @@ 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();
@ -155,6 +149,9 @@ module.exports = Self => {
`, [args.workerId]);
const index = stmts.push(stmt) - 1;
stmts.push('DROP TEMPORARY TABLE tmp.timeControlCalculate');
stmts.push('DROP TEMPORARY TABLE tmp.timeBusinessCalculate');
const sql = ParameterizedSQL.join(stmts, ';');
const days = await conn.executeStmt(sql, myOptions);
@ -164,7 +161,11 @@ module.exports = Self => {
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();
return true;
} catch (e) {
if (tx) await tx.rollback();
throw e;
}
}
return true;
};
function getStartDateOfWeekNumber(week, year) {