4856-worker.time-control #1375

Merged
joan merged 32 commits from 4856-worker.time-control into dev 2023-03-16 06:39:02 +00:00
5 changed files with 82 additions and 24 deletions
Showing only changes of commit 05d91ed50e - Show all commits

View File

@ -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

View File

@ -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">

View File

@ -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'];

View File

@ -13,4 +13,6 @@ Entry removed: Fichada borrada
The entry type can't be empty: El tipo de fichada no puede quedar vacía
Satisfied: Conforme
Not satisfied: No conforme
Reason: Motivo
Reason: Motivo
Resend: Reenviar
Email sended: Email enviado

View File

@ -14,7 +14,7 @@ vn-worker-time-control {
align-items: center;
justify-content: center;
padding: 4px 0;
& > vn-icon {
color: $color-font-secondary;
padding-right: 1px;
@ -28,4 +28,12 @@ vn-worker-time-control {
.edit-time-entry {
width: 200px
}
}
.right {
float: right;
}
.confirmed {
color: #97B92F;
}