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

View File

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

View File

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

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

View File

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