refs #4856 feat: si se modifica una fichada actualiza el estado a 'SENDED' y notifica al trabajador
gitea/salix/pipeline/head There was a failure building this commit
Details
gitea/salix/pipeline/head There was a failure building this commit
Details
This commit is contained in:
parent
e1bfdc3f3c
commit
862101c4b0
|
@ -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);
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
};
|
|
@ -322,17 +322,20 @@ 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({
|
await models.WorkerTimeControlMail.create({
|
||||||
where: {
|
workerFk: previousWorkerFk,
|
||||||
appName: 'salix',
|
year: args.year,
|
||||||
environment: process.env.NODE_ENV || 'dev'
|
week: args.week
|
||||||
}
|
|
||||||
}, myOptions);
|
}, 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;
|
||||||
|
|
|
@ -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;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
|
@ -19,11 +19,6 @@ module.exports = Self => {
|
||||||
type: 'number',
|
type: 'number',
|
||||||
required: true
|
required: true
|
||||||
},
|
},
|
||||||
{
|
|
||||||
arg: 'url',
|
|
||||||
type: 'string',
|
|
||||||
required: true
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
arg: 'workerId',
|
arg: 'workerId',
|
||||||
type: 'number',
|
type: 'number',
|
||||||
|
@ -45,11 +40,48 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.weeklyHourRecordEmail = async ctx => {
|
Self.weeklyHourRecordEmail = async(ctx, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
const args = ctx.args;
|
||||||
|
const myOptions = {};
|
||||||
|
|
||||||
|
if (typeof options == 'object')
|
||||||
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
|
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');
|
Self.sendTemplate(ctx, 'weekly-hour-record');
|
||||||
|
|
||||||
return models.WorkerTimeControl.updateWorkerTimeControlMail(ctx);
|
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);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
|
@ -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')
|
||||||
|
|
|
@ -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,20 +399,18 @@ 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,
|
workerId: this.worker.id,
|
||||||
state: 'SENDED'
|
state: 'SENDED'
|
||||||
};
|
};
|
||||||
|
|
Loading…
Reference in New Issue