4856-worker.time-control #1375
|
@ -60,8 +60,6 @@ module.exports = Self => {
|
|||
const oldState = workerTimeControlMail.state;
|
||||
const oldReason = workerTimeControlMail.reason;
|
||||
|
||||
if (oldState == args.state) throw new UserError('Already has this status');
|
||||
|
||||
await workerTimeControlMail.updateAttributes({
|
||||
state: args.state,
|
||||
reason: args.reason || null
|
||||
|
|
|
@ -78,15 +78,27 @@
|
|||
</vn-table>
|
||||
</vn-card>
|
||||
|
||||
<vn-button-bar class="vn-pa-xs vn-w-lg">
|
||||
<vn-button-bar ng-show="$ctrl.state" class="vn-pa-xs vn-w-lg">
|
||||
<vn-button
|
||||
label="Satisfied"
|
||||
disabled="$ctrl.state == 'CONFIRMED'"
|
||||
ng-click="$ctrl.isSatisfied()">
|
||||
</vn-button>
|
||||
<vn-button
|
||||
label="Not satisfied"
|
||||
disabled="$ctrl.state == 'REVISE'"
|
||||
ng-click="reason.show()">
|
||||
</vn-button>
|
||||
<vn-button
|
||||
label="Reason"
|
||||
ng-if="$ctrl.reason"
|
||||
ng-click="reason.show()">
|
||||
</vn-button>
|
||||
<vn-button
|
||||
label="Resend"
|
||||
ng-click="$ctrl.resendEmail()"
|
||||
class="right">
|
||||
</vn-button>
|
||||
</vn-button-bar>
|
||||
|
||||
<vn-side-menu side="right">
|
||||
|
|
|
@ -294,11 +294,15 @@ class Controller extends Section {
|
|||
this.$.editEntry.show($event);
|
||||
}
|
||||
|
||||
getWeekNumber(currentDate) {
|
||||
const startDate = new Date(currentDate.getFullYear(), 0, 1);
|
||||
let days = Math.floor((currentDate - startDate) /
|
||||
(24 * 60 * 60 * 1000));
|
||||
return Math.ceil(days / 7);
|
||||
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 - 1;
|
||||
}
|
||||
|
||||
isSatisfied() {
|
||||
|
@ -312,6 +316,7 @@ class Controller extends Section {
|
|||
const query = `WorkerTimeControls/updateWorkerTimeControlMail`;
|
||||
this.$http.post(query, params).then(() => {
|
||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||
this.$state.reload();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -327,6 +332,7 @@ class Controller extends Section {
|
|||
const query = `WorkerTimeControls/updateWorkerTimeControlMail`;
|
||||
this.$http.post(query, params).then(() => {
|
||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||
this.$state.reload();
|
||||
});
|
||||
}
|
||||
|
||||
|
@ -348,13 +354,12 @@ class Controller extends Section {
|
|||
|
||||
formatWeek($element) {
|
||||
let weekNumber = $element.firstElementChild;
|
||||
let weekNumberValue = $element.firstElementChild.innerHTML;
|
||||
console.log(weekNumberValue);
|
||||
let weekNumberValue = $element.firstElementChild.innerHTML - 1;
|
||||
const filter = {
|
||||
where: {
|
||||
workerFk: 9,
|
||||
// year: this.date.getFullYear(),
|
||||
// week: weekNumberValue - 1
|
||||
workerFk: this.$params.id,
|
||||
year: this.date.getFullYear(),
|
||||
week: weekNumberValue
|
||||
}
|
||||
};
|
||||
// const filter = {
|
||||
|
@ -366,18 +371,51 @@ class Controller extends Section {
|
|||
// ]
|
||||
// }
|
||||
// };
|
||||
console.log(filter);
|
||||
this.$http.get('WorkerTimeControlMails', {filter})
|
||||
this.$http.get('WorkerTimeControlMails/findOne', {filter})
|
||||
.then(res => {
|
||||
console.log(res.data.state);
|
||||
const state = res.data.state;
|
||||
if (state == 'CONFIRMED') weekNumber.style.color = '#97B92F';
|
||||
else if (state == 'REVISE') weekNumber.style.color = '#FF4444';
|
||||
else weekNumber.style.color = '#5151c0';
|
||||
// weekNumber.title = event.name;
|
||||
// weekNumber.style.backgroundColor = event.color;
|
||||
const currentWeekNumber = this.getWeekNumber(this.date);
|
||||
if (currentWeekNumber == weekNumberValue) {
|
||||
this.state = state;
|
||||
this.reason = res.data.reason;
|
||||
console.log(currentWeekNumber, weekNumberValue, this.state, this.reason);
|
||||
}
|
||||
if (state == 'CONFIRMED') {
|
||||
weekNumber.classList.add('confirmed');
|
||||
weekNumber.setAttribute('vn-tooltip', 'Conforme');
|
||||
}
|
||||
if (state == 'REVISE') weekNumber.style.color = '#FF4444';
|
||||
if (state == 'SENDED') weekNumber.style.color = '#E65F00';
|
||||
});
|
||||
}
|
||||
|
||||
resendEmail() {
|
||||
const filter = {
|
||||
where: {userFk: this.$params.id},
|
||||
};
|
||||
this.$http.get('EmailUsers/findOne', {filter})
|
||||
.then(res => {
|
||||
const timestamp = this.date.getTime() / 1000;
|
||||
const url = `${window.location.origin}/#!/worker/${this.$params.id}/time-control?timestamp=${timestamp}`;
|
||||
const weekNumber = this.getWeekNumber(this.date);
|
||||
|
||||
const params = {
|
||||
recipient: res.data.email,
|
||||
week: weekNumber + 1,
|
||||
year: this.date.getFullYear(),
|
||||
url: url,
|
||||
};
|
||||
this.$http.post(`WorkerTimeControls/weekly-hour-hecord-email`, params)
|
||||
.then(res => {
|
||||
this.vnApp.showSuccess(this.$t('Email sended'));
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
getTime(timeString) {
|
||||
const [hours, minutes, seconds] = timeString.split(':');
|
||||
return [parseInt(hours), parseInt(minutes), parseInt(seconds)];
|
||||
}
|
||||
}
|
||||
|
||||
Controller.$inject = ['$element', '$scope', 'vnWeekDays'];
|
||||
|
|
|
@ -14,3 +14,5 @@ The entry type can't be empty: El tipo de fichada no puede quedar vacía
|
|||
Satisfied: Conforme
|
||||
Not satisfied: No conforme
|
||||
Reason: Motivo
|
||||
Resend: Reenviar
|
||||
Email sended: Email enviado
|
||||
|
|
|
@ -29,3 +29,11 @@ vn-worker-time-control {
|
|||
.edit-time-entry {
|
||||
width: 200px
|
||||
}
|
||||
|
||||
.right {
|
||||
float: right;
|
||||
}
|
||||
|
||||
.confirmed {
|
||||
color: #97B92F;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue