231801_test_to_master #1519
|
@ -51,6 +51,8 @@ module.exports = Self => {
|
||||||
if (response[0] && response[0].error)
|
if (response[0] && response[0].error)
|
||||||
throw new UserError(response[0].error);
|
throw new UserError(response[0].error);
|
||||||
|
|
||||||
|
await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, workerId, args.timed, myOptions);
|
||||||
|
|
||||||
return response;
|
return response;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -38,7 +38,11 @@ module.exports = Self => {
|
||||||
if (isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss))
|
if (isSubordinate === false || (isSubordinate && isHimself && !isTeamBoss))
|
||||||
throw new UserError(`You don't have enough privileges`);
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
return Self.rawSql('CALL vn.workerTimeControl_remove(?, ?)', [
|
const response = await Self.rawSql('CALL vn.workerTimeControl_remove(?, ?)', [
|
||||||
targetTimeEntry.userFk, targetTimeEntry.timed], myOptions);
|
targetTimeEntry.userFk, targetTimeEntry.timed], myOptions);
|
||||||
|
|
||||||
|
await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, targetTimeEntry.userFk, targetTimeEntry.timed, myOptions);
|
||||||
|
|
||||||
|
return response;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -0,0 +1,68 @@
|
||||||
|
module.exports = Self => {
|
||||||
|
Self.remoteMethodCtx('resendWeeklyHourEmail', {
|
||||||
|
description: 'Adds a new hour registry',
|
||||||
|
accessType: 'WRITE',
|
||||||
|
accepts: [{
|
||||||
|
arg: 'id',
|
||||||
|
type: 'number',
|
||||||
|
description: 'The worker id',
|
||||||
|
http: {source: 'path'}
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'dated',
|
||||||
|
type: 'date',
|
||||||
|
required: true
|
||||||
|
}],
|
||||||
|
returns: [{
|
||||||
|
type: 'Object',
|
||||||
|
root: true
|
||||||
|
}],
|
||||||
|
http: {
|
||||||
|
path: `/:id/resendWeeklyHourEmail`,
|
||||||
|
verb: 'POST'
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
Self.resendWeeklyHourEmail = async(ctx, workerId, dated, options) => {
|
||||||
|
const models = Self.app.models;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
const yearNumber = dated.getFullYear();
|
||||||
|
const weekNumber = getWeekNumber(dated);
|
||||||
|
const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({
|
||||||
|
where: {
|
||||||
|
workerFk: workerId,
|
||||||
|
year: yearNumber,
|
||||||
|
week: weekNumber
|
||||||
|
}
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
if (workerTimeControlMail && workerTimeControlMail.state != 'SENDED') {
|
||||||
|
const worker = await models.EmailUser.findById(workerId, null, myOptions);
|
||||||
|
ctx.args = {
|
||||||
|
recipient: worker.email,
|
||||||
|
year: yearNumber,
|
||||||
|
week: weekNumber,
|
||||||
|
workerId: workerId,
|
||||||
|
state: 'SENDED'
|
||||||
|
};
|
||||||
|
return models.WorkerTimeControl.weeklyHourRecordEmail(ctx, myOptions);
|
||||||
|
}
|
||||||
|
|
||||||
|
return false;
|
||||||
|
};
|
||||||
|
|
||||||
|
function getWeekNumber(date) {
|
||||||
|
const tempDate = new Date(date);
|
||||||
|
let dayOfWeek = tempDate.getDay();
|
||||||
|
dayOfWeek = (dayOfWeek === 0) ? 7 : dayOfWeek;
|
||||||
|
const firstDayOfWeek = new Date(tempDate.getFullYear(), tempDate.getMonth(), tempDate.getDate() - (dayOfWeek - 1));
|
||||||
|
const firstDayOfYear = new Date(tempDate.getFullYear(), 0, 1);
|
||||||
|
const differenceInMilliseconds = firstDayOfWeek.getTime() - firstDayOfYear.getTime();
|
||||||
|
const weekNumber = Math.floor(differenceInMilliseconds / (1000 * 60 * 60 * 24 * 7)) + 1;
|
||||||
|
return weekNumber;
|
||||||
|
}
|
||||||
|
};
|
|
@ -82,14 +82,9 @@ module.exports = Self => {
|
||||||
updated: Date.vnNew(), state: 'SENDED'
|
updated: Date.vnNew(), state: 'SENDED'
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(
|
stmt = new ParameterizedSQL('DROP TEMPORARY TABLE IF EXISTS tmp.`user`');
|
||||||
`CALL vn.timeControl_calculateByUser(?, ?, ?)
|
|
||||||
`, [args.workerId, started, ended]);
|
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
|
stmt = new ParameterizedSQL('CREATE TEMPORARY TABLE tmp.`user` SELECT id userFk FROM account.user WHERE id = ?', [args.workerId]);
|
||||||
stmt = new ParameterizedSQL(
|
|
||||||
`CALL vn.timeBusiness_calculateByUser(?, ?, ?)
|
|
||||||
`, [args.workerId, started, ended]);
|
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
} else {
|
} else {
|
||||||
await models.WorkerTimeControl.destroyAll({
|
await models.WorkerTimeControl.destroyAll({
|
||||||
|
@ -105,13 +100,38 @@ module.exports = Self => {
|
||||||
updated: Date.vnNew(), state: 'SENDED'
|
updated: Date.vnNew(), state: 'SENDED'
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
stmt = new ParameterizedSQL(`CALL vn.timeControl_calculateAll(?, ?)`, [started, ended]);
|
stmt = new ParameterizedSQL('DROP TEMPORARY TABLE IF EXISTS tmp.`user`');
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
|
stmt = new ParameterizedSQL('CREATE TEMPORARY TABLE IF NOT EXISTS tmp.`user` SELECT userFk FROM vn.worker w JOIN account.`user` u ON u.id = w.userFk WHERE userFk IS NOT NULL');
|
||||||
stmt = new ParameterizedSQL(`CALL vn.timeBusiness_calculateAll(?, ?)`, [started, ended]);
|
|
||||||
stmts.push(stmt);
|
stmts.push(stmt);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
stmt = new ParameterizedSQL(
|
||||||
|
`CALL vn.timeControl_calculate(?, ?)
|
||||||
|
`, [started, ended]);
|
||||||
|
stmts.push(stmt);
|
||||||
|
|
||||||
|
stmt = new ParameterizedSQL(
|
||||||
|
`CALL vn.timeBusiness_calculate(?, ?)
|
||||||
|
`, [started, ended]);
|
||||||
|
stmts.push(stmt);
|
||||||
|
|
||||||
|
stmt = new ParameterizedSQL(
|
||||||
|
`CALL vn.timeControl_getError(?, ?)
|
||||||
|
`, [started, ended]);
|
||||||
|
stmts.push(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 tmp.timeControlError tce
|
||||||
|
JOIN vn.workerTimeControl wtc ON wtc.id = tce.id
|
||||||
|
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);
|
||||||
|
|
||||||
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,
|
||||||
|
@ -131,20 +151,16 @@ module.exports = Self => {
|
||||||
JOIN business b ON b.id = tb.businessFk
|
JOIN business b ON b.id = tb.businessFk
|
||||||
LEFT JOIN tmp.timeControlCalculate tc ON tc.userFk = tb.userFk AND tc.dated = tb.dated
|
LEFT JOIN tmp.timeControlCalculate tc ON tc.userFk = tb.userFk AND tc.dated = tb.dated
|
||||||
LEFT JOIN worker w ON w.id = u.id
|
LEFT JOIN worker w ON w.id = u.id
|
||||||
JOIN (SELECT tb.userFk,
|
LEFT JOIN (
|
||||||
SUM(IF(tb.type IS NULL,
|
SELECT DISTINCT wtc.userFk
|
||||||
IF(tc.timeWorkDecimal > 0, FALSE, IF(tb.timeWorkDecimal > 0, TRUE, FALSE)),
|
FROM tmp.timeControlError tce
|
||||||
TRUE))isTeleworkingWeek
|
JOIN vn.workerTimeControl wtc ON wtc.id = tce.id
|
||||||
FROM tmp.timeBusinessCalculate tb
|
)sub ON sub.userFk = tb.userFk
|
||||||
LEFT JOIN tmp.timeControlCalculate tc ON tc.userFk = tb.userFk
|
WHERE sub.userFK IS NULL
|
||||||
AND tc.dated = tb.dated
|
|
||||||
GROUP BY tb.userFk
|
|
||||||
HAVING isTeleworkingWeek > 0
|
|
||||||
)sub ON sub.userFk = u.id
|
|
||||||
WHERE d.hasToRefill
|
|
||||||
AND IFNULL(?, u.id) = u.id
|
AND IFNULL(?, u.id) = u.id
|
||||||
AND b.companyCodeFk = 'VNL'
|
AND b.companyCodeFk = 'VNL'
|
||||||
AND w.businessFk
|
AND w.businessFk
|
||||||
|
AND d.isTeleworking
|
||||||
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;
|
||||||
|
@ -332,17 +348,18 @@ module.exports = Self => {
|
||||||
|
|
||||||
const lastDay = days[index][days[index].length - 1];
|
const lastDay = days[index][days[index].length - 1];
|
||||||
if (day.workerFk != previousWorkerFk || day == lastDay) {
|
if (day.workerFk != previousWorkerFk || day == lastDay) {
|
||||||
const salix = await models.Url.findOne({
|
const query = `INSERT IGNORE INTO workerTimeControlMail (workerFk, year, week)
|
||||||
where: {
|
VALUES(?, ?, ?);`;
|
||||||
appName: 'salix',
|
await Self.rawSql(query, [previousWorkerFk, args.year, args.week]);
|
||||||
environment: process.env.NODE_ENV || 'dev'
|
|
||||||
}
|
|
||||||
}, myOptions);
|
|
||||||
|
|
||||||
const timestamp = started.getTime() / 1000;
|
ctx.args = {
|
||||||
const url = `${salix.url}worker/${previousWorkerFk}/time-control?timestamp=${timestamp}`;
|
recipient: previousReceiver,
|
||||||
|
year: args.year,
|
||||||
await models.WorkerTimeControl.weeklyHourRecordEmail(ctx, previousReceiver, args.week, args.year, url);
|
week: args.week,
|
||||||
|
workerId: previousWorkerFk,
|
||||||
|
state: 'SENDED'
|
||||||
|
};
|
||||||
|
await models.WorkerTimeControl.weeklyHourRecordEmail(ctx, myOptions);
|
||||||
|
|
||||||
previousWorkerFk = day.workerFk;
|
previousWorkerFk = day.workerFk;
|
||||||
previousReceiver = day.receiver;
|
previousReceiver = day.receiver;
|
||||||
|
|
|
@ -1,120 +0,0 @@
|
||||||
const models = require('vn-loopback/server/server').models;
|
|
||||||
|
|
||||||
describe('workerTimeControl sendMail()', () => {
|
|
||||||
const workerId = 18;
|
|
||||||
const activeCtx = {
|
|
||||||
getLocale: () => {
|
|
||||||
return 'en';
|
|
||||||
}
|
|
||||||
};
|
|
||||||
const ctx = {req: activeCtx, args: {}};
|
|
||||||
|
|
||||||
it('should fill time control of a worker without records in Journey and with rest', async() => {
|
|
||||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
|
|
||||||
await models.WorkerTimeControl.sendMail(ctx, options);
|
|
||||||
|
|
||||||
const workerTimeControl = await models.WorkerTimeControl.find({
|
|
||||||
where: {userFk: workerId}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
expect(workerTimeControl[0].timed.getHours()).toEqual(8);
|
|
||||||
expect(workerTimeControl[1].timed.getHours()).toEqual(9);
|
|
||||||
expect(`${workerTimeControl[2].timed.getHours()}:${workerTimeControl[2].timed.getMinutes()}`).toEqual('9:20');
|
|
||||||
expect(workerTimeControl[3].timed.getHours()).toEqual(16);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fill time control of a worker without records in Journey and without rest', async() => {
|
|
||||||
const workdayOf20Hours = 3;
|
|
||||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
query = `UPDATE business b
|
|
||||||
SET b.calendarTypeFk = ?
|
|
||||||
WHERE b.workerFk = ?; `;
|
|
||||||
await models.WorkerTimeControl.rawSql(query, [workdayOf20Hours, workerId], options);
|
|
||||||
|
|
||||||
await models.WorkerTimeControl.sendMail(ctx, options);
|
|
||||||
|
|
||||||
const workerTimeControl = await models.WorkerTimeControl.find({
|
|
||||||
where: {userFk: workerId}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
expect(workerTimeControl[0].timed.getHours()).toEqual(8);
|
|
||||||
expect(workerTimeControl[1].timed.getHours()).toEqual(12);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fill time control of a worker with records in Journey and with rest', async() => {
|
|
||||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
query = `INSERT INTO postgresql.journey(journey_id, day_id, start, end, business_id)
|
|
||||||
VALUES
|
|
||||||
(1, 1, '09:00:00', '13:00:00', ?),
|
|
||||||
(2, 1, '14:00:00', '19:00:00', ?);`;
|
|
||||||
await models.WorkerTimeControl.rawSql(query, [workerId, workerId, workerId], options);
|
|
||||||
|
|
||||||
await models.WorkerTimeControl.sendMail(ctx, options);
|
|
||||||
|
|
||||||
const workerTimeControl = await models.WorkerTimeControl.find({
|
|
||||||
where: {userFk: workerId}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
expect(workerTimeControl[0].timed.getHours()).toEqual(9);
|
|
||||||
expect(workerTimeControl[2].timed.getHours()).toEqual(10);
|
|
||||||
expect(`${workerTimeControl[3].timed.getHours()}:${workerTimeControl[3].timed.getMinutes()}`).toEqual('10:20');
|
|
||||||
expect(workerTimeControl[1].timed.getHours()).toEqual(13);
|
|
||||||
expect(workerTimeControl[4].timed.getHours()).toEqual(14);
|
|
||||||
expect(workerTimeControl[5].timed.getHours()).toEqual(19);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
it('should fill time control of a worker with records in Journey and without rest', async() => {
|
|
||||||
const tx = await models.WorkerTimeControl.beginTransaction({});
|
|
||||||
|
|
||||||
try {
|
|
||||||
const options = {transaction: tx};
|
|
||||||
query = `INSERT INTO postgresql.journey(journey_id, day_id, start, end, business_id)
|
|
||||||
VALUES
|
|
||||||
(1, 1, '12:30:00', '14:00:00', ?);`;
|
|
||||||
await models.WorkerTimeControl.rawSql(query, [workerId, workerId, workerId], options);
|
|
||||||
|
|
||||||
await models.WorkerTimeControl.sendMail(ctx, options);
|
|
||||||
|
|
||||||
const workerTimeControl = await models.WorkerTimeControl.find({
|
|
||||||
where: {userFk: workerId}
|
|
||||||
}, options);
|
|
||||||
|
|
||||||
expect(`${workerTimeControl[0].timed.getHours()}:${workerTimeControl[0].timed.getMinutes()}`).toEqual('12:30');
|
|
||||||
expect(workerTimeControl[1].timed.getHours()).toEqual(14);
|
|
||||||
|
|
||||||
await tx.rollback();
|
|
||||||
} catch (e) {
|
|
||||||
await tx.rollback();
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
|
@ -46,8 +46,12 @@ module.exports = Self => {
|
||||||
if (notAllowed)
|
if (notAllowed)
|
||||||
throw new UserError(`You don't have enough privileges`);
|
throw new UserError(`You don't have enough privileges`);
|
||||||
|
|
||||||
return targetTimeEntry.updateAttributes({
|
const timeEntryUpdated = await targetTimeEntry.updateAttributes({
|
||||||
direction: args.direction
|
direction: args.direction
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
|
await models.WorkerTimeControl.resendWeeklyHourEmail(ctx, targetTimeEntry.userFk, targetTimeEntry.timed, myOptions);
|
||||||
|
|
||||||
|
return timeEntryUpdated;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -47,10 +47,6 @@ module.exports = Self => {
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const isHimself = userId == args.workerId;
|
|
||||||
if (!isHimself)
|
|
||||||
throw new UserError(`You don't have enough privileges`);
|
|
||||||
|
|
||||||
const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({
|
const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({
|
||||||
where: {
|
where: {
|
||||||
workerFk: args.workerId,
|
workerFk: args.workerId,
|
||||||
|
@ -69,6 +65,12 @@ module.exports = Self => {
|
||||||
reason: args.reason || null
|
reason: args.reason || null
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
|
if (args.state == 'SENDED') {
|
||||||
|
await workerTimeControlMail.updateAttributes({
|
||||||
|
sendedCounter: workerTimeControlMail.sendedCounter + 1
|
||||||
|
}, myOptions);
|
||||||
|
}
|
||||||
|
|
||||||
const logRecord = {
|
const logRecord = {
|
||||||
originFk: args.workerId,
|
originFk: args.workerId,
|
||||||
userFk: userId,
|
userFk: userId,
|
||||||
|
|
|
@ -1,5 +1,3 @@
|
||||||
const {Email} = require('vn-print');
|
|
||||||
|
|
||||||
module.exports = Self => {
|
module.exports = Self => {
|
||||||
Self.remoteMethodCtx('weeklyHourRecordEmail', {
|
Self.remoteMethodCtx('weeklyHourRecordEmail', {
|
||||||
description: 'Sends the weekly hour record',
|
description: 'Sends the weekly hour record',
|
||||||
|
@ -22,7 +20,12 @@ module.exports = Self => {
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
arg: 'url',
|
arg: 'workerId',
|
||||||
|
type: 'number',
|
||||||
|
required: true
|
||||||
|
},
|
||||||
|
{
|
||||||
|
arg: 'state',
|
||||||
type: 'string',
|
type: 'string',
|
||||||
required: true
|
required: true
|
||||||
}
|
}
|
||||||
|
@ -37,17 +40,48 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.weeklyHourRecordEmail = async(ctx, recipient, week, year, url) => {
|
Self.weeklyHourRecordEmail = async(ctx, options) => {
|
||||||
const params = {
|
const models = Self.app.models;
|
||||||
recipient: recipient,
|
const args = ctx.args;
|
||||||
lang: ctx.req.getLocale(),
|
const myOptions = {};
|
||||||
week: week,
|
|
||||||
year: year,
|
|
||||||
url: url
|
|
||||||
};
|
|
||||||
|
|
||||||
const email = new Email('weekly-hour-record', params);
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
return email.send();
|
const salix = await models.Url.findOne({
|
||||||
|
where: {
|
||||||
|
appName: 'salix',
|
||||||
|
environment: process.env.NODE_ENV || 'dev'
|
||||||
|
}
|
||||||
|
}, myOptions);
|
||||||
|
|
||||||
|
const dated = getMondayDateFromYearWeek(args.year, args.week);
|
||||||
|
const timestamp = dated.getTime() / 1000;
|
||||||
|
|
||||||
|
const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`;
|
||||||
|
ctx.args.url = url;
|
||||||
|
|
||||||
|
Self.sendTemplate(ctx, 'weekly-hour-record');
|
||||||
|
|
||||||
|
return models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, myOptions);
|
||||||
};
|
};
|
||||||
|
|
||||||
|
function getMondayDateFromYearWeek(yearNumber, weekNumber) {
|
||||||
|
const yearStart = new Date(yearNumber, 0, 1);
|
||||||
|
const firstMonday = new Date(yearStart.getTime() + ((7 - yearStart.getDay() + 1) % 7) * 86400000);
|
||||||
|
const firstMondayWeekNumber = getWeekNumber(firstMonday);
|
||||||
|
|
||||||
|
if (firstMondayWeekNumber > 1)
|
||||||
|
firstMonday.setDate(firstMonday.getDate() + 7);
|
||||||
|
|
||||||
|
firstMonday.setDate(firstMonday.getDate() + (weekNumber - 1) * 7);
|
||||||
|
|
||||||
|
return firstMonday;
|
||||||
|
}
|
||||||
|
|
||||||
|
function getWeekNumber(date) {
|
||||||
|
const firstDayOfYear = new Date(date.getFullYear(), 0, 1);
|
||||||
|
const daysPassed = (date - firstDayOfYear) / 86400000;
|
||||||
|
return Math.ceil((daysPassed + firstDayOfYear.getDay() + 1) / 7);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -28,6 +28,9 @@
|
||||||
},
|
},
|
||||||
"reason": {
|
"reason": {
|
||||||
"type": "string"
|
"type": "string"
|
||||||
|
},
|
||||||
|
"sendedCounter": {
|
||||||
|
"type": "number"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"acls": [
|
"acls": [
|
||||||
|
|
|
@ -9,6 +9,7 @@ module.exports = Self => {
|
||||||
require('../methods/worker-time-control/updateWorkerTimeControlMail')(Self);
|
require('../methods/worker-time-control/updateWorkerTimeControlMail')(Self);
|
||||||
require('../methods/worker-time-control/weeklyHourRecordEmail')(Self);
|
require('../methods/worker-time-control/weeklyHourRecordEmail')(Self);
|
||||||
require('../methods/worker-time-control/getMailStates')(Self);
|
require('../methods/worker-time-control/getMailStates')(Self);
|
||||||
|
require('../methods/worker-time-control/resendWeeklyHourEmail')(Self);
|
||||||
|
|
||||||
Self.rewriteDbError(function(err) {
|
Self.rewriteDbError(function(err) {
|
||||||
if (err.code === 'ER_DUP_ENTRY')
|
if (err.code === 'ER_DUP_ENTRY')
|
||||||
|
|
|
@ -204,7 +204,7 @@
|
||||||
vn-id="sendEmailConfirmation"
|
vn-id="sendEmailConfirmation"
|
||||||
on-accept="$ctrl.resendEmail()"
|
on-accept="$ctrl.resendEmail()"
|
||||||
message="Send time control email">
|
message="Send time control email">
|
||||||
<tpl-body style="min-width: 500px;">
|
<tpl-body>
|
||||||
<span translate>Are you sure you want to send it?</span>
|
<span translate>Are you sure you want to send it?</span>
|
||||||
</tpl-body>
|
</tpl-body>
|
||||||
<tpl-buttons>
|
<tpl-buttons>
|
||||||
|
|
|
@ -303,7 +303,10 @@ class Controller extends Section {
|
||||||
|
|
||||||
const query = `WorkerTimeControls/${this.worker.id}/addTimeEntry`;
|
const query = `WorkerTimeControls/${this.worker.id}/addTimeEntry`;
|
||||||
this.$http.post(query, entry)
|
this.$http.post(query, entry)
|
||||||
.then(() => this.fetchHours());
|
.then(() => {
|
||||||
|
this.fetchHours();
|
||||||
|
this.getMailStates(this.date);
|
||||||
|
});
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.vnApp.showError(this.$t(e.message));
|
this.vnApp.showError(this.$t(e.message));
|
||||||
return false;
|
return false;
|
||||||
|
@ -324,6 +327,7 @@ class Controller extends Section {
|
||||||
|
|
||||||
this.$http.post(`WorkerTimeControls/${entryId}/deleteTimeEntry`).then(() => {
|
this.$http.post(`WorkerTimeControls/${entryId}/deleteTimeEntry`).then(() => {
|
||||||
this.fetchHours();
|
this.fetchHours();
|
||||||
|
this.getMailStates(this.date);
|
||||||
this.vnApp.showSuccess(this.$t('Entry removed'));
|
this.vnApp.showSuccess(this.$t('Entry removed'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -395,23 +399,24 @@ class Controller extends Section {
|
||||||
this.$http.post(query, {direction: entry.direction})
|
this.$http.post(query, {direction: entry.direction})
|
||||||
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
|
.then(() => this.vnApp.showSuccess(this.$t('Data saved!')))
|
||||||
.then(() => this.$.editEntry.hide())
|
.then(() => this.$.editEntry.hide())
|
||||||
.then(() => this.fetchHours());
|
.then(() => this.fetchHours())
|
||||||
|
.then(() => this.getMailStates(this.date));
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
this.vnApp.showError(this.$t(e.message));
|
this.vnApp.showError(this.$t(e.message));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
resendEmail() {
|
resendEmail() {
|
||||||
const timestamp = this.date.getTime() / 1000;
|
|
||||||
const url = `${window.location.origin}/#!/worker/${this.worker.id}/time-control?timestamp=${timestamp}`;
|
|
||||||
const params = {
|
const params = {
|
||||||
recipient: this.worker.user.emailUser.email,
|
recipient: this.worker.user.emailUser.email,
|
||||||
week: this.weekNumber,
|
week: this.weekNumber,
|
||||||
year: this.date.getFullYear(),
|
year: this.date.getFullYear(),
|
||||||
url: url,
|
workerId: this.worker.id,
|
||||||
|
state: 'SENDED'
|
||||||
};
|
};
|
||||||
this.$http.post(`WorkerTimeControls/weekly-hour-hecord-email`, params)
|
this.$http.post(`WorkerTimeControls/weekly-hour-hecord-email`, params)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
|
this.getMailStates(this.date);
|
||||||
this.vnApp.showSuccess(this.$t('Email sended'));
|
this.vnApp.showSuccess(this.$t('Email sended'));
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
|
@ -120,6 +120,13 @@ describe('Component vnWorkerTimeControl', () => {
|
||||||
|
|
||||||
describe('save() ', () => {
|
describe('save() ', () => {
|
||||||
it(`should make a query an then call to the fetchHours() method`, () => {
|
it(`should make a query an then call to the fetchHours() method`, () => {
|
||||||
|
const today = Date.vnNew();
|
||||||
|
|
||||||
|
jest.spyOn(controller, 'getWeekData').mockReturnThis();
|
||||||
|
jest.spyOn(controller, 'getMailStates').mockReturnThis();
|
||||||
|
|
||||||
|
controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
|
||||||
|
controller.date = today;
|
||||||
controller.fetchHours = jest.fn();
|
controller.fetchHours = jest.fn();
|
||||||
controller.selectedRow = {id: 1, timed: Date.vnNew(), direction: 'in'};
|
controller.selectedRow = {id: 1, timed: Date.vnNew(), direction: 'in'};
|
||||||
controller.$.editEntry = {
|
controller.$.editEntry = {
|
||||||
|
@ -240,7 +247,9 @@ describe('Component vnWorkerTimeControl', () => {
|
||||||
describe('resendEmail() ', () => {
|
describe('resendEmail() ', () => {
|
||||||
it(`should make a query an then call showSuccess method`, () => {
|
it(`should make a query an then call showSuccess method`, () => {
|
||||||
const today = Date.vnNew();
|
const today = Date.vnNew();
|
||||||
|
|
||||||
jest.spyOn(controller, 'getWeekData').mockReturnThis();
|
jest.spyOn(controller, 'getWeekData').mockReturnThis();
|
||||||
|
jest.spyOn(controller, 'getMailStates').mockReturnThis();
|
||||||
jest.spyOn(controller.vnApp, 'showSuccess');
|
jest.spyOn(controller.vnApp, 'showSuccess');
|
||||||
|
|
||||||
controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
|
controller.$.model = {applyFilter: jest.fn().mockReturnValue(Promise.resolve())};
|
||||||
|
|
Loading…
Reference in New Issue