Merge pull request '3319-worker_time-control' (#770) from 3319-worker_time-control into dev
gitea/salix/pipeline/head This commit looks good
Details
gitea/salix/pipeline/head This commit looks good
Details
Reviewed-on: #770 Reviewed-by: Carlos Jimenez Ruiz <carlosjr@verdnatura.es>
This commit is contained in:
commit
115b294b3e
|
@ -42,27 +42,21 @@ module.exports = Self => {
|
|||
|
||||
const stmts = [];
|
||||
|
||||
const startedMinusOne = new Date(started);
|
||||
startedMinusOne.setDate(started.getDate() - 1);
|
||||
|
||||
const endedPlusOne = new Date(ended);
|
||||
endedPlusOne.setDate(ended.getDate() + 1);
|
||||
|
||||
stmts.push(`
|
||||
DROP TEMPORARY TABLE IF EXISTS
|
||||
tmp.timeControlCalculate,
|
||||
tmp.timeBusinessCalculate
|
||||
`);
|
||||
|
||||
stmts.push(new ParameterizedSQL('CALL vn.timeControl_calculateByUser(?, ?, ?)', [userId, startedMinusOne, endedPlusOne]));
|
||||
stmts.push(new ParameterizedSQL('CALL vn.timeControl_calculateByUser(?, ?, ?)', [userId, started, ended]));
|
||||
|
||||
stmts.push(new ParameterizedSQL('CALL vn.timeBusiness_calculateByUser(?, ?, ?)', [userId, startedMinusOne, endedPlusOne]));
|
||||
stmts.push(new ParameterizedSQL('CALL vn.timeBusiness_calculateByUser(?, ?, ?)', [userId, started, ended]));
|
||||
|
||||
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 ?
|
||||
SELECT tcc.dated, tbc.timeWorkSeconds expectedHours, tcc.timeWorkSeconds workedHours
|
||||
FROM tmp.timeControlCalculate tcc
|
||||
LEFT JOIN tmp.timeBusinessCalculate tbc ON tcc.dated = tbc.dated
|
||||
WHERE tcc.dated BETWEEN DATE(?) AND DATE(?)
|
||||
`, [started, ended])) - 1;
|
||||
|
||||
stmts.push(`
|
||||
|
|
|
@ -1,17 +1,17 @@
|
|||
const app = require('vn-loopback/server/server');
|
||||
const models = require('vn-loopback/server/server').models;
|
||||
|
||||
describe('Worker getWorkedHours()', () => {
|
||||
it(`should return the expected hours and the worked hours of a given date`, async() => {
|
||||
const workerID = 1106;
|
||||
let started = new Date();
|
||||
const started = new Date();
|
||||
started.setHours(0, 0, 0, 0);
|
||||
|
||||
let ended = new Date();
|
||||
ended.setHours(0, 0, 0, 0);
|
||||
const ended = new Date();
|
||||
ended.setHours(23, 59, 59, 999);
|
||||
|
||||
const [result] = await app.models.Worker.getWorkedHours(workerID, started, ended);
|
||||
const [result] = await models.Worker.getWorkedHours(workerID, started, ended);
|
||||
|
||||
expect(result.expectedHours).toEqual(28800); // 8:00 hours seconds
|
||||
expect(result.expectedHours).toEqual(28800); // 8:00 hours in seconds
|
||||
expect(result.workedHours).toEqual(29400); // 8:10 hours in seconds
|
||||
});
|
||||
});
|
||||
|
|
|
@ -171,7 +171,6 @@ class Controller extends Section {
|
|||
from: from,
|
||||
to: to
|
||||
};
|
||||
|
||||
const query = `Workers/${this.$params.id}/getWorkedHours`;
|
||||
return this.$http.get(query, {params}).then(res => {
|
||||
const workDays = res.data;
|
||||
|
@ -212,7 +211,8 @@ class Controller extends Section {
|
|||
let todayInWeek = this.weekDays.find(day => day.dated.getTime() === today.getTime());
|
||||
|
||||
if (todayInWeek && todayInWeek.hours && todayInWeek.hours.length) {
|
||||
const remainingTime = todayInWeek.workedHours ? ((todayInWeek.expectedHours - todayInWeek.workedHours) * 1000) : null;
|
||||
const remainingTime = todayInWeek.workedHours ?
|
||||
((todayInWeek.expectedHours - todayInWeek.workedHours) * 1000) : null;
|
||||
const lastKnownEntry = todayInWeek.hours[todayInWeek.hours.length - 1];
|
||||
const lastKnownTime = new Date(lastKnownEntry.timed).getTime();
|
||||
const finishTimeStamp = lastKnownTime && remainingTime ? lastKnownTime + remainingTime : null;
|
||||
|
|
Loading…
Reference in New Issue