diff --git a/loopback/locale/es.json b/loopback/locale/es.json
index 67370b343..69259c857 100644
--- a/loopback/locale/es.json
+++ b/loopback/locale/es.json
@@ -153,6 +153,7 @@
"Email already exists": "Email already exists",
"User already exists": "User already exists",
"Absence change notification on the labour calendar": "Notificacion de cambio de ausencia en el calendario laboral",
+ "Record of hours week": "Registro de horas semana {{week}} año {{year}} ",
"Created absence": "El empleado {{author}} ha añadido una ausencia de tipo '{{absenceType}}' a {{employee}} para el día {{dated}}.",
"Deleted absence": "El empleado {{author}} ha eliminado una ausencia de tipo '{{absenceType}}' a {{employee}} del día {{dated}}.",
"I have deleted the ticket id": "He eliminado el ticket id [{{id}}]({{{url}}})",
diff --git a/modules/worker/back/methods/worker-time-control/sendMail.js b/modules/worker/back/methods/worker-time-control/sendMail.js
index fef8a4e2d..8716ec172 100644
--- a/modules/worker/back/methods/worker-time-control/sendMail.js
+++ b/modules/worker/back/methods/worker-time-control/sendMail.js
@@ -30,6 +30,7 @@ module.exports = Self => {
Self.sendMail = async(ctx, options) => {
const models = Self.app.models;
+ const $t = ctx.req.__; // $translate
const args = ctx.args;
const myOptions = {};
const conn = Self.dataSource.connector;
@@ -137,7 +138,7 @@ module.exports = Self => {
SELECT * FROM tmp.timeBusinessCalculate`);
stmt = new ParameterizedSQL(`
- SELECT CONCAT(u.name, '@verdnatura.es'),
+ SELECT CONCAT(u.name, '@verdnatura.es') receiver,
u.id workerFk,
tb.dated,
tb.timeWorkDecimal,
@@ -177,6 +178,9 @@ module.exports = Self => {
const sql = ParameterizedSQL.join(stmts, ';');
const days = await conn.executeStmt(sql, myOptions);
+ let previousWorkerFk = days[index][0].workerFk;
+ let previousReceiver = days[index][0].receiver;
+
for (let day of days[index]) {
if (day.timeWorkDecimal > 0 && day.timeWorkedDecimal == null
&& (day.permissionRate ? day.permissionRate : true)) {
@@ -332,7 +336,23 @@ module.exports = Self => {
if (lastWorkerTimeControl) lastWorkerTimeControl.updateAttribute('direction', 'out', myOptions);
}
}
+
+ const origin = ctx.req.headers.origin;
+ const lastDay = days[index][days[index].length - 1];
+ if (day.workerFk != previousWorkerFk || day == lastDay) {
+ await models.Mail.create({
+ receiver: previousReceiver,
+ subject: $t('Record of hours week', {
+ week: args.week,
+ year: args.year
+ }),
+ body: `${origin}/#!/worker/${previousWorkerFk}/time-control?timestamp=`
+ });
+ previousWorkerFk = day.workerFk;
+ previousReceiver = day.receiver;
+ }
}
+
return true;
};
};