4856-worker.time-control #1375
|
@ -60,8 +60,6 @@ module.exports = Self => {
|
||||||
const oldState = workerTimeControlMail.state;
|
const oldState = workerTimeControlMail.state;
|
||||||
const oldReason = workerTimeControlMail.reason;
|
const oldReason = workerTimeControlMail.reason;
|
||||||
|
|
||||||
if (oldState == args.state) throw new UserError('Already has this status');
|
|
||||||
|
|
||||||
await workerTimeControlMail.updateAttributes({
|
await workerTimeControlMail.updateAttributes({
|
||||||
state: args.state,
|
state: args.state,
|
||||||
reason: args.reason || null
|
reason: args.reason || null
|
||||||
|
|
|
@ -78,15 +78,27 @@
|
||||||
</vn-table>
|
</vn-table>
|
||||||
</vn-card>
|
</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
|
<vn-button
|
||||||
label="Satisfied"
|
label="Satisfied"
|
||||||
|
disabled="$ctrl.state == 'CONFIRMED'"
|
||||||
ng-click="$ctrl.isSatisfied()">
|
ng-click="$ctrl.isSatisfied()">
|
||||||
</vn-button>
|
</vn-button>
|
||||||
<vn-button
|
<vn-button
|
||||||
label="Not satisfied"
|
label="Not satisfied"
|
||||||
|
disabled="$ctrl.state == 'REVISE'"
|
||||||
ng-click="reason.show()">
|
ng-click="reason.show()">
|
||||||
</vn-button>
|
</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-button-bar>
|
||||||
|
|
||||||
<vn-side-menu side="right">
|
<vn-side-menu side="right">
|
||||||
|
|
|
@ -294,11 +294,15 @@ class Controller extends Section {
|
||||||
this.$.editEntry.show($event);
|
this.$.editEntry.show($event);
|
||||||
}
|
}
|
||||||
|
|
||||||
getWeekNumber(currentDate) {
|
getWeekNumber(date) {
|
||||||
const startDate = new Date(currentDate.getFullYear(), 0, 1);
|
const tempDate = new Date(date);
|
||||||
let days = Math.floor((currentDate - startDate) /
|
let dayOfWeek = tempDate.getDay();
|
||||||
(24 * 60 * 60 * 1000));
|
dayOfWeek = (dayOfWeek === 0) ? 7 : dayOfWeek;
|
||||||
return Math.ceil(days / 7);
|
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() {
|
isSatisfied() {
|
||||||
|
@ -312,6 +316,7 @@ class Controller extends Section {
|
||||||
const query = `WorkerTimeControls/updateWorkerTimeControlMail`;
|
const query = `WorkerTimeControls/updateWorkerTimeControlMail`;
|
||||||
this.$http.post(query, params).then(() => {
|
this.$http.post(query, params).then(() => {
|
||||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||||
|
this.$state.reload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -327,6 +332,7 @@ class Controller extends Section {
|
||||||
const query = `WorkerTimeControls/updateWorkerTimeControlMail`;
|
const query = `WorkerTimeControls/updateWorkerTimeControlMail`;
|
||||||
this.$http.post(query, params).then(() => {
|
this.$http.post(query, params).then(() => {
|
||||||
this.vnApp.showSuccess(this.$t('Data saved!'));
|
this.vnApp.showSuccess(this.$t('Data saved!'));
|
||||||
|
this.$state.reload();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -348,13 +354,12 @@ class Controller extends Section {
|
||||||
|
|
||||||
formatWeek($element) {
|
formatWeek($element) {
|
||||||
let weekNumber = $element.firstElementChild;
|
let weekNumber = $element.firstElementChild;
|
||||||
let weekNumberValue = $element.firstElementChild.innerHTML;
|
let weekNumberValue = $element.firstElementChild.innerHTML - 1;
|
||||||
console.log(weekNumberValue);
|
|
||||||
const filter = {
|
const filter = {
|
||||||
where: {
|
where: {
|
||||||
workerFk: 9,
|
workerFk: this.$params.id,
|
||||||
// year: this.date.getFullYear(),
|
year: this.date.getFullYear(),
|
||||||
// week: weekNumberValue - 1
|
week: weekNumberValue
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// const filter = {
|
// const filter = {
|
||||||
|
@ -366,18 +371,51 @@ class Controller extends Section {
|
||||||
// ]
|
// ]
|
||||||
// }
|
// }
|
||||||
// };
|
// };
|
||||||
console.log(filter);
|
this.$http.get('WorkerTimeControlMails/findOne', {filter})
|
||||||
this.$http.get('WorkerTimeControlMails', {filter})
|
|
||||||
.then(res => {
|
.then(res => {
|
||||||
console.log(res.data.state);
|
|
||||||
const state = res.data.state;
|
const state = res.data.state;
|
||||||
if (state == 'CONFIRMED') weekNumber.style.color = '#97B92F';
|
const currentWeekNumber = this.getWeekNumber(this.date);
|
||||||
else if (state == 'REVISE') weekNumber.style.color = '#FF4444';
|
if (currentWeekNumber == weekNumberValue) {
|
||||||
else weekNumber.style.color = '#5151c0';
|
this.state = state;
|
||||||
// weekNumber.title = event.name;
|
this.reason = res.data.reason;
|
||||||
// weekNumber.style.backgroundColor = event.color;
|
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'];
|
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
|
Satisfied: Conforme
|
||||||
Not satisfied: No conforme
|
Not satisfied: No conforme
|
||||||
Reason: Motivo
|
Reason: Motivo
|
||||||
|
Resend: Reenviar
|
||||||
|
Email sended: Email enviado
|
||||||
|
|
|
@ -29,3 +29,11 @@ vn-worker-time-control {
|
||||||
.edit-time-entry {
|
.edit-time-entry {
|
||||||
width: 200px
|
width: 200px
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.right {
|
||||||
|
float: right;
|
||||||
|
}
|
||||||
|
|
||||||
|
.confirmed {
|
||||||
|
color: #97B92F;
|
||||||
|
}
|
||||||
|
|
Loading…
Reference in New Issue