diff --git a/db/changes/230801/00-acl_time.sql b/db/changes/230801/00-acl_time.sql new file mode 100644 index 000000000..9ef73d409 --- /dev/null +++ b/db/changes/230801/00-acl_time.sql @@ -0,0 +1,3 @@ +INSERT INTO `salix`.`ACL` (`model`, `property`, `accessType`, `permission`, `principalType`, `principalId`) + VALUES + ('Time', '*', '*', 'ALLOW', 'ROLE', 'employee'); diff --git a/modules/worker/back/models/time.json b/modules/worker/back/models/time.json index df9257540..e2f1161d7 100644 --- a/modules/worker/back/models/time.json +++ b/modules/worker/back/models/time.json @@ -14,6 +14,9 @@ "year": { "type": "number" }, + "month": { + "type": "number" + }, "week": { "type": "number" } diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index 24ae483d6..3726243cf 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -24,6 +24,97 @@ class Controller extends Section { } this.date = initialDate; + + const filterTime = { + fields: ['week'], + where: { + month: this.date.getMonth() + 1, + year: this.date.getFullYear() + } + }; + this.$http.get('Times', {filter: filterTime}) + .then(res => { + const weeks = res.data.map(time => time.week); + const weekNumbersSet = new Set(weeks); + const weekNumbers = Array.from(weekNumbersSet); + + const filter = { + where: { + workerFk: this.$params.id, + year: this.date.getFullYear(), + week: {inq: weekNumbers} + } + }; + this.$http.get('WorkerTimeControlMails', {filter}) + .then(res => { + const workerTimeControlMails = res.data; + console.log(workerTimeControlMails); + for (const workerTimeControlMail of workerTimeControlMails) { + // const [data] = res.data; + // if (!data) { + // if (this.weekNumber == weekNumberValue) this.state = null; + // return; + // } + + const state = workerTimeControlMail.state; + + console.log(workerTimeControlMail.week, this.weekNumberValue); + if (workerTimeControlMail.week == this.weekNumberValue) { + this.state = state; + this.reason = workerTimeControlMail.reason; + } + if (state == 'CONFIRMED') { + this.weekNumberHTML.classList.add('confirmed'); + this.weekNumberHTML.setAttribute('title', 'Conforme'); + } + if (state == 'REVISE') { + this.weekNumberHTML.classList.add('revise'); + this.weekNumberHTML.setAttribute('title', 'No conforme'); + } + if (state == 'SENDED') { + this.weekNumberHTML.classList.add('sended'); + this.weekNumberHTML.setAttribute('title', 'Pendiente'); + } + } + }); + }); + + // console.log(this.weekNumbers); + // const filter = { + // where: { + // workerFk: this.$params.id, + // year: this.date.getFullYear(), + // week: {inq: this.weekNumbers} + // } + // }; + // this.$http.get('WorkerTimeControlMails', {filter}) + // .then(res => { + // console.log(res.data); + // // const [data] = res.data; + // // if (!data) { + // // if (this.weekNumber == weekNumberValue) this.state = null; + // // return; + // // } + + // // const state = data.state; + // // if (this.weekNumber == weekNumberValue) { + // // this.state = state; + // // this.reason = data.reason; + // // } + + // // if (state == 'CONFIRMED') { + // // weekNumber.classList.add('confirmed'); + // // weekNumber.setAttribute('title', 'Conforme'); + // // } + // // if (state == 'REVISE') { + // // weekNumber.classList.add('revise'); + // // weekNumber.setAttribute('title', 'No conforme'); + // // } + // // if (state == 'SENDED') { + // // weekNumber.classList.add('sended'); + // // weekNumber.setAttribute('title', 'Pendiente'); + // // } + // }); } get isHr() { @@ -314,7 +405,7 @@ class Controller extends Section { 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; + return weekNumber; } isSatisfied() { @@ -363,43 +454,45 @@ class Controller extends Section { } formatWeek($element) { - let weekNumber = $element.firstElementChild; - let weekNumberValue = $element.firstElementChild.innerHTML - 1; - const filter = { - where: { - workerFk: this.$params.id, - year: this.date.getFullYear(), - week: weekNumberValue - } - }; + this.weekNumberHTML = $element.firstElementChild; + console.log(this.weekNumberHTML); + this.weekNumberValue = $element.firstElementChild.innerHTML; - this.$http.get('WorkerTimeControlMails', {filter}) - .then(res => { - const [data] = res.data; - if (!data) { - if (this.weekNumber == weekNumberValue) this.state = null; - return; - } + // const filter = { + // where: { + // workerFk: this.$params.id, + // year: this.date.getFullYear(), + // week: weekNumberValue + // } + // }; - const state = data.state; - if (this.weekNumber == weekNumberValue) { - this.state = state; - this.reason = data.reason; - } + // this.$http.get('WorkerTimeControlMails', {filter}) + // .then(res => { + // const [data] = res.data; + // if (!data) { + // if (this.weekNumber == weekNumberValue) this.state = null; + // return; + // } - if (state == 'CONFIRMED') { - weekNumber.classList.add('confirmed'); - weekNumber.setAttribute('title', 'Conforme'); - } - if (state == 'REVISE') { - weekNumber.classList.add('revise'); - weekNumber.setAttribute('title', 'No conforme'); - } - if (state == 'SENDED') { - weekNumber.classList.add('sended'); - weekNumber.setAttribute('title', 'Pendiente'); - } - }); + // const state = data.state; + // if (this.weekNumber == weekNumberValue) { + // this.state = state; + // this.reason = data.reason; + // } + + // if (state == 'CONFIRMED') { + // weekNumber.classList.add('confirmed'); + // weekNumber.setAttribute('title', 'Conforme'); + // } + // if (state == 'REVISE') { + // weekNumber.classList.add('revise'); + // weekNumber.setAttribute('title', 'No conforme'); + // } + // if (state == 'SENDED') { + // weekNumber.classList.add('sended'); + // weekNumber.setAttribute('title', 'Pendiente'); + // } + // }); } resendEmail() { @@ -407,7 +500,7 @@ class Controller extends Section { const url = `${window.location.origin}/#!/worker/${this.worker.id}/time-control?timestamp=${timestamp}`; const params = { recipient: this.worker.user.emailUser.email, - week: this.weekNumber + 1, + week: this.weekNumber, year: this.date.getFullYear(), url: url, };