diff --git a/modules/worker/back/methods/worker/getWorkedHours.js b/modules/worker/back/methods/worker/getWorkedHours.js index dfb219c72..9957fca25 100644 --- a/modules/worker/back/methods/worker/getWorkedHours.js +++ b/modules/worker/back/methods/worker/getWorkedHours.js @@ -34,35 +34,45 @@ module.exports = Self => { }); Self.getWorkedHours = async(id, started, ended) => { + const models = Self.app.models; const conn = Self.dataSource.connector; + + const worker = await models.Worker.findById(id); + const userId = worker.userFk; + const stmts = []; + const startedMinusOne = new Date(started); + startedMinusOne.setDate(started.getDate() - 1); + const endedPlusOne = new Date(ended); - let worker = await Self.app.models.Worker.findById(id); - let userId = worker.userFk; + endedPlusOne.setDate(ended.getDate() + 1); stmts.push(` DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate, tmp.timeBusinessCalculate `); - startedMinusOne.setDate(started.getDate() - 1); - endedPlusOne.setDate(ended.getDate() + 1); + stmts.push(new ParameterizedSQL('CALL vn.timeControl_calculateByUser(?, ?, ?)', [userId, startedMinusOne, endedPlusOne])); + stmts.push(new ParameterizedSQL('CALL vn.timeBusiness_calculateByUser(?, ?, ?)', [userId, startedMinusOne, endedPlusOne])); - let resultIndex = stmts.push(new ParameterizedSQL(` + + const resultIndex = stmts.push(new ParameterizedSQL(` SELECT tbc.dated, tbc.timeWorkSeconds expectedHours, tcc.timeWorkSeconds workedHours FROM tmp.timeBusinessCalculate tbc LEFT JOIN tmp.timeControlCalculate tcc ON tcc.dated = tbc.dated WHERE tbc.dated BETWEEN ? AND ? `, [started, ended])) - 1; + stmts.push(` DROP TEMPORARY TABLE IF EXISTS tmp.timeControlCalculate, tmp.timeBusinessCalculate `); - let sql = ParameterizedSQL.join(stmts, ';'); - let result = await conn.executeStmt(sql); + + const sql = ParameterizedSQL.join(stmts, ';'); + const result = await conn.executeStmt(sql); return result[resultIndex]; };