5918-worker.time-control_resend #1685
|
@ -37,31 +37,40 @@ module.exports = Self => {
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
Self.updateWorkerTimeControlMail = async(ctx, workerId, year, week, state, reason, options) => {
|
Self.updateWorkerTimeControlMail = async(ctx, options) => {
|
||||||
const models = Self.app.models;
|
const models = Self.app.models;
|
||||||
|
const args = ctx.args;
|
||||||
const myOptions = {};
|
const myOptions = {};
|
||||||
|
|
||||||
if (typeof options == 'object')
|
if (typeof options == 'object')
|
||||||
Object.assign(myOptions, options);
|
Object.assign(myOptions, options);
|
||||||
|
|
||||||
const workerTimeControlMail = await models.WorkerTimeControlMail.findOne({
|
const [sent] = await models.WorkerTimeControlMail.find({
|
||||||
where: {
|
where: {
|
||||||
workerFk: workerId,
|
year: args.year,
|
||||||
year,
|
week: args.week,
|
||||||
week
|
},
|
||||||
}
|
limit: 1
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
||||||
console.log('workerTimeControlMail: ', workerTimeControlMail);
|
if (!sent) throw new UserError(`There aren't records for this week`);
|
||||||
if (!workerTimeControlMail) throw new UserError(`There aren't records for this week`);
|
|
||||||
|
|
||||||
await workerTimeControlMail.updateAttributes({
|
const workerTimeControlMail = await models.WorkerTimeControlMail.upsertWithWhere(
|
||||||
state,
|
{
|
||||||
reason: reason || null
|
year: args.year,
|
||||||
}, myOptions);
|
week: args.week,
|
||||||
|
workerFk: args.workerId
|
||||||
|
},
|
||||||
|
{
|
||||||
|
state: args.state,
|
||||||
|
reason: args.workerId,
|
||||||
|
year: args.year,
|
||||||
|
week: args.week,
|
||||||
|
workerFk: args.workerId
|
||||||
|
},
|
||||||
|
myOptions);
|
||||||
|
|
||||||
if (state == 'SENDED') {
|
if (args.state == 'SENDED') {
|
||||||
await workerTimeControlMail.updateAttributes({
|
await workerTimeControlMail.updateAttributes({
|
||||||
sendedCounter: workerTimeControlMail.sendedCounter + 1
|
sendedCounter: workerTimeControlMail.sendedCounter + 1
|
||||||
}, myOptions);
|
}, myOptions);
|
||||||
|
|
|
@ -61,9 +61,8 @@ module.exports = Self => {
|
||||||
const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`;
|
const url = `${salix.url}worker/${args.workerId}/time-control?timestamp=${timestamp}`;
|
||||||
ctx.args.url = url;
|
ctx.args.url = url;
|
||||||
|
|
||||||
await Self.sendTemplate(ctx, 'weekly-hour-record');
|
await models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, myOptions);
|
||||||
|
return Self.sendTemplate(ctx, 'weekly-hour-record');
|
||||||
return models.WorkerTimeControl.updateWorkerTimeControlMail(ctx, myOptions);
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function getMondayDateFromYearWeek(yearNumber, weekNumber) {
|
function getMondayDateFromYearWeek(yearNumber, weekNumber) {
|
||||||
|
|
|
@ -102,7 +102,7 @@
|
||||||
ng-click="sendEmailConfirmation.show()"
|
ng-click="sendEmailConfirmation.show()"
|
||||||
class="right"
|
class="right"
|
||||||
vn-tooltip="Resend email of this week to the user"
|
vn-tooltip="Resend email of this week to the user"
|
||||||
ng-show="$ctrl.isHr && $ctrl.canResend">
|
ng-show="$ctrl.isHr && $ctrl.state != 'CONFIRMED' && $ctrl.canResend">
|
||||||
</vn-button>
|
</vn-button>
|
||||||
</vn-button-bar>
|
</vn-button-bar>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
@ -53,6 +53,8 @@ class Controller extends Section {
|
||||||
set worker(value) {
|
set worker(value) {
|
||||||
this._worker = value;
|
this._worker = value;
|
||||||
this.fetchHours();
|
this.fetchHours();
|
||||||
|
if (this.date)
|
||||||
|
this.getWeekData();
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -110,8 +112,8 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!this.weekTotalHours) this.fetchHours();
|
if (!this.weekTotalHours) this.fetchHours();
|
||||||
|
if (this.worker)
|
||||||
this.getWeekData();
|
this.getWeekData();
|
||||||
this.isMailSended();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
set weekTotalHours(totalHours) {
|
set weekTotalHours(totalHours) {
|
||||||
vicent marked this conversation as resolved
Outdated
|
|||||||
|
@ -128,21 +130,23 @@ class Controller extends Section {
|
||||||
workerFk: this.$params.id,
|
workerFk: this.$params.id,
|
||||||
year: this._date.getFullYear(),
|
year: this._date.getFullYear(),
|
||||||
week: this.getWeekNumber(this._date)
|
week: this.getWeekNumber(this._date)
|
||||||
}
|
},
|
||||||
};
|
};
|
||||||
this.$http.get('WorkerTimeControlMails', {filter})
|
this.$http.get('WorkerTimeControlMails', {filter})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
const mail = res.data;
|
if (!res.data.length) {
|
||||||
if (!mail.length) {
|
|
||||||
this.state = null;
|
this.state = null;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
this.state = mail[0].state;
|
const [mail] = res.data;
|
||||||
this.reason = mail[0].reason;
|
this.state = mail.state;
|
||||||
|
this.reason = mail.reason;
|
||||||
});
|
});
|
||||||
|
this.canBeResend();
|
||||||
}
|
}
|
||||||
|
|
||||||
isMailSended() {
|
canBeResend() {
|
||||||
|
this.canResend = false;
|
||||||
const filter = {
|
const filter = {
|
||||||
where: {
|
where: {
|
||||||
year: this._date.getFullYear(),
|
year: this._date.getFullYear(),
|
||||||
|
@ -150,27 +154,10 @@ class Controller extends Section {
|
||||||
},
|
},
|
||||||
limit: 1
|
limit: 1
|
||||||
};
|
};
|
||||||
// no repeat request
|
|
||||||
this.$http.get('WorkerTimeControlMails', {filter})
|
this.$http.get('WorkerTimeControlMails', {filter})
|
||||||
.then(res => {
|
.then(res => {
|
||||||
if (!res.data.length) {
|
if (res.data.length)
|
||||||
this.canResend = false;
|
this.canResend = true;
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
const filter = {
|
|
||||||
where: {
|
|
||||||
workerFk: this.$params.id
|
|
||||||
},
|
|
||||||
include: {
|
|
||||||
relation: 'department'
|
|
||||||
}
|
|
||||||
};
|
|
||||||
this.$http.get('WorkerDepartments/findOne', {filter})
|
|
||||||
.then(res => {
|
|
||||||
const department = res.data.department;
|
|
||||||
if (department.isTeleworking) this.canResend = true;
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -389,30 +376,25 @@ class Controller extends Section {
|
||||||
}
|
}
|
||||||
|
|
||||||
isSatisfied() {
|
isSatisfied() {
|
||||||
const params = {
|
this.updateWorkerTimeControlMail('CONFIRMED');
|
||||||
workerId: this.worker.id,
|
|
||||||
year: this.date.getFullYear(),
|
|
||||||
week: this.weekNumber,
|
|
||||||
state: 'CONFIRMED'
|
|
||||||
};
|
|
||||||
const query = `WorkerTimeControls/updateWorkerTimeControlMail`;
|
|
||||||
this.$http.post(query, params).then(() => {
|
|
||||||
this.getMailStates(this.date);
|
|
||||||
this.getWeekData();
|
|
||||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
isUnsatisfied() {
|
isUnsatisfied() {
|
||||||
if (!this.reason) throw new UserError(`You must indicate a reason`);
|
if (!this.reason) throw new UserError(`You must indicate a reason`);
|
||||||
|
this.updateWorkerTimeControlMail('REVISE', this.reason);
|
||||||
|
}
|
||||||
|
|
||||||
|
updateWorkerTimeControlMail(state, reason) {
|
||||||
const params = {
|
const params = {
|
||||||
workerId: this.worker.id,
|
workerId: this.worker.id,
|
||||||
year: this.date.getFullYear(),
|
year: this.date.getFullYear(),
|
||||||
week: this.weekNumber,
|
week: this.weekNumber,
|
||||||
state: 'REVISE',
|
state
|
||||||
reason: this.reason
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
if (reason)
|
||||||
|
params.reason = reason;
|
||||||
|
|
||||||
const query = `WorkerTimeControls/updateWorkerTimeControlMail`;
|
const query = `WorkerTimeControls/updateWorkerTimeControlMail`;
|
||||||
this.$http.post(query, params).then(() => {
|
this.$http.post(query, params).then(() => {
|
||||||
this.getMailStates(this.date);
|
this.getMailStates(this.date);
|
||||||
|
|
Loading…
Reference in New Issue
ací al final no pugueres posar el workerFk?
Teu havia possat en la nota de ahir:
No se envía el workerFk, pq puede que ese workerFk no tenga ningún registro. Se ha solucionado poniendo un limit 1 en la petición.
Just lo que soluciona esta tarea es poder enviar el registro horario aunq no se li haja enviat la ninguna volta.