diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 03daded01..17f90bb26 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -1851,6 +1851,15 @@ INSERT INTO `postgresql`.`business_labour`(`business_id`, `notes`, `department_i SELECT b.business_id, NULL, 23, 1, 0, 1, 1, 1, 1 FROM `postgresql`.`business` `b`; +INSERT INTO `postgresql`.`business` (`client_id`, `provider_id`, `date_start`, `date_end`, `workerBusiness`, `reasonEndFk`) + SELECT p.profile_id, 1000, CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL -2 YEAR)), '-12-25'), CONCAT(YEAR(DATE_ADD(CURDATE(), INTERVAL -1 YEAR)), '-12-24'), CONCAT('E-46-',RPAD(CONCAT(p.profile_id,9),8,p.profile_id)), NULL + FROM `postgresql`.`profile` `p` + WHERE `p`.`profile_id` = 1109; + +INSERT INTO `postgresql`.`business_labour` (`business_id`, `notes`, `department_id`, `professional_category_id`, `incentivo`, `calendar_labour_type_id`, `porhoras`, `labour_agreement_id`, `workcenter_id`) + VALUES + (1111, NULL, 23, 1, 0.0, 1, 1, 1, 1); + UPDATE `postgresql`.`business_labour` bl JOIN `postgresql`.`business` b ON b.business_id = bl.business_id JOIN `postgresql`.`profile` pr ON pr.profile_id = b.client_id diff --git a/e2e/helpers/selectors.js b/e2e/helpers/selectors.js index 0ce29ef07..d5b075e13 100644 --- a/e2e/helpers/selectors.js +++ b/e2e/helpers/selectors.js @@ -305,12 +305,12 @@ export default { anyCreditInsuranceLine: 'vn-client-credit-insurance-insurance-index vn-tbody > vn-tr', }, clientDefaulter: { - anyClient: 'vn-client-defaulter-index tbody > tr', - firstClientName: 'vn-client-defaulter-index tbody > tr:nth-child(1) > td:nth-child(2) > span', - firstSalesPersonName: 'vn-client-defaulter-index tbody > tr:nth-child(1) > td:nth-child(3) > span', - firstObservation: 'vn-client-defaulter-index tbody > tr:nth-child(1) > td:nth-child(6) > vn-textarea[ng-model="defaulter.observation"]', - allDefaulterCheckbox: 'vn-client-defaulter-index thead vn-multi-check', - addObservationButton: 'vn-client-defaulter-index vn-button[icon="icon-notes"]', + anyClient: 'vn-client-defaulter tbody > tr', + firstClientName: 'vn-client-defaulter tbody > tr:nth-child(1) > td:nth-child(2) > span', + firstSalesPersonName: 'vn-client-defaulter tbody > tr:nth-child(1) > td:nth-child(3) > span', + firstObservation: 'vn-client-defaulter tbody > tr:nth-child(1) > td:nth-child(6) > vn-textarea[ng-model="defaulter.observation"]', + allDefaulterCheckbox: 'vn-client-defaulter thead vn-multi-check', + addObservationButton: 'vn-client-defaulter vn-button[icon="icon-notes"]', observation: '.vn-dialog.shown vn-textarea[ng-model="$ctrl.defaulter.observation"]', saveButton: 'button[response="accept"]' }, diff --git a/e2e/paths/02-client/21_defaulter.spec.js b/e2e/paths/02-client/21_defaulter.spec.js index 3630a958a..d51f2113f 100644 --- a/e2e/paths/02-client/21_defaulter.spec.js +++ b/e2e/paths/02-client/21_defaulter.spec.js @@ -9,7 +9,7 @@ describe('Client defaulter path', () => { browser = await getBrowser(); page = browser.page; await page.loginAndModule('insurance', 'client'); - await page.accessToSection('client.defaulter.index'); + await page.accessToSection('client.defaulter'); }); afterAll(async() => { @@ -52,7 +52,7 @@ describe('Client defaulter path', () => { it('shoul checked all defaulters', async() => { await page.loginAndModule('insurance', 'client'); - await page.accessToSection('client.defaulter.index'); + await page.accessToSection('client.defaulter'); await page.waitToClick(selectors.clientDefaulter.allDefaulterCheckbox); }); diff --git a/modules/client/front/defaulter/index.js b/modules/client/front/defaulter/index.js index 9595be61c..82719bef0 100644 --- a/modules/client/front/defaulter/index.js +++ b/modules/client/front/defaulter/index.js @@ -122,7 +122,7 @@ export default class Controller extends Section { } } -ngModule.vnComponent('vnClientDefaulterIndex', { +ngModule.vnComponent('vnClientDefaulter', { template: require('./index.html'), controller: Controller }); diff --git a/modules/client/front/defaulter/index.spec.js b/modules/client/front/defaulter/index.spec.js index 8d6c8c307..d7d1a684d 100644 --- a/modules/client/front/defaulter/index.spec.js +++ b/modules/client/front/defaulter/index.spec.js @@ -2,7 +2,7 @@ import './index'; import crudModel from 'core/mocks/crud-model'; describe('client defaulter', () => { - describe('Component vnClientDefaulterIndex', () => { + describe('Component vnClientDefaulter', () => { let controller; let $httpBackend; @@ -11,7 +11,7 @@ describe('client defaulter', () => { beforeEach(inject(($componentController, _$httpBackend_) => { $httpBackend = _$httpBackend_; const $element = angular.element(''); - controller = $componentController('vnClientDefaulterIndex', {$element}); + controller = $componentController('vnClientDefaulter', {$element}); controller.$.model = crudModel; controller.$.model.data = [ {clientFk: 1101, amount: 125}, diff --git a/modules/client/front/routes.json b/modules/client/front/routes.json index d6f8a70bd..8398a8745 100644 --- a/modules/client/front/routes.json +++ b/modules/client/front/routes.json @@ -8,7 +8,7 @@ "main": [ {"state": "client.index", "icon": "person"}, {"state": "client.notification", "icon": "campaign"}, - {"state": "client.defaulter.index", "icon": "icon-defaulter"} + {"state": "client.defaulter", "icon": "icon-defaulter"} ], "card": [ {"state": "client.card.basicData", "icon": "settings"}, @@ -366,13 +366,7 @@ { "url": "/defaulter", "state": "client.defaulter", - "component": "ui-view", - "description": "Defaulter" - }, - { - "url": "/index?q", - "state": "client.defaulter.index", - "component": "vn-client-defaulter-index", + "component": "vn-client-defaulter", "description": "Defaulter" }, { diff --git a/modules/worker/back/methods/calendar/absences.js b/modules/worker/back/methods/calendar/absences.js index 32d311cdb..c2ec27dd8 100644 --- a/modules/worker/back/methods/calendar/absences.js +++ b/modules/worker/back/methods/calendar/absences.js @@ -4,14 +4,24 @@ module.exports = Self => { Self.remoteMethodCtx('absences', { description: 'Returns an array of absences from an specified contract', accepts: [{ - arg: 'businessFk', + arg: 'workerFk', type: 'number', required: true, }, + { + arg: 'businessFk', + type: 'number', + required: false, + }, { arg: 'year', type: 'date', required: true, + }, + { + arg: 'all', + type: 'boolean', + required: false, }], returns: [{ arg: 'absences', @@ -27,7 +37,7 @@ module.exports = Self => { } }); - Self.absences = async(ctx, businessFk, year, options) => { + Self.absences = async(ctx, workerFk, businessFk, year, options) => { const models = Self.app.models; const started = new Date(); @@ -45,7 +55,17 @@ module.exports = Self => { if (typeof options == 'object') Object.assign(myOptions, options); - const contract = await models.WorkerLabour.findOne({ + let condition = { + and: [ + {workerFk: workerFk}, + {businessFk: businessFk} + ] + }; + + if (businessFk) + condition.and.push({workerFk: workerFk}); + + const contracts = await models.WorkerLabour.find({ include: [{ relation: 'holidays', scope: { @@ -82,31 +102,32 @@ module.exports = Self => { } } }], - where: {businessFk} + where: condition }, myOptions); - if (!contract) return; + if (!contracts) return; - const isSubordinate = await models.Worker.isSubordinate(ctx, contract.workerFk, myOptions); + const isSubordinate = await models.Worker.isSubordinate(ctx, workerFk, myOptions); if (!isSubordinate) throw new UserError(`You don't have enough privileges`); const absences = []; - for (let absence of contract.absences()) { - absence.dated = new Date(absence.dated); - absence.dated.setHours(0, 0, 0, 0); - - absences.push(absence); - } - - // Workcenter holidays const holidays = []; - const holidayList = contract.workCenter().holidays(); - for (let day of holidayList) { - day.dated = new Date(day.dated); - day.dated.setHours(0, 0, 0, 0); - holidays.push(day); + for (let contract of contracts) { + for (let absence of contract.absences()) { + absence.dated = new Date(absence.dated); + absence.dated.setHours(0, 0, 0, 0); + + absences.push(absence); + } + + for (let day of contract.workCenter().holidays()) { + day.dated = new Date(day.dated); + day.dated.setHours(0, 0, 0, 0); + + holidays.push(day); + } } return [absences, holidays]; diff --git a/modules/worker/back/methods/calendar/specs/absences.spec.js b/modules/worker/back/methods/calendar/specs/absences.spec.js index cfe7379c3..812b9c23c 100644 --- a/modules/worker/back/methods/calendar/specs/absences.spec.js +++ b/modules/worker/back/methods/calendar/specs/absences.spec.js @@ -3,12 +3,13 @@ const app = require('vn-loopback/server/server'); describe('Worker absences()', () => { it('should get the absence calendar for a full year contract', async() => { const ctx = {req: {accessToken: {userId: 1106}}}; + const workerId = 1106; const businessId = 1106; const now = new Date(); const year = now.getFullYear(); - const [absences] = await app.models.Calendar.absences(ctx, businessId, year); + const [absences] = await app.models.Calendar.absences(ctx, workerId, businessId, year); const firstType = absences[0].absenceType().name; const sixthType = absences[5].absenceType().name; @@ -35,7 +36,7 @@ describe('Worker absences()', () => { `UPDATE postgresql.business SET date_end = ? WHERE business_id = ?`, [null, worker.businessFk], options); - const [absences] = await app.models.Calendar.absences(ctx, businessId, year, options); + const [absences] = await app.models.Calendar.absences(ctx, worker.id, businessId, year, options); let firstType = absences[0].absenceType().name; let sixthType = absences[5].absenceType().name; @@ -51,6 +52,8 @@ describe('Worker absences()', () => { it('should give the same holidays as worked days since the holidays amount matches the amount of days in a year', async() => { const businessId = 1106; + const workerId = 1106; + const userId = 1106; const today = new Date(); @@ -101,7 +104,7 @@ describe('Worker absences()', () => { const ctx = {req: {accessToken: {userId: userId}}}; - const [absences] = await app.models.Calendar.absences(ctx, businessId, currentYear); + const [absences] = await app.models.Calendar.absences(ctx, workerId, businessId, currentYear); const firstType = absences[0].absenceType().name; const sixthType = absences[5].absenceType().name; diff --git a/modules/worker/front/calendar/index.js b/modules/worker/front/calendar/index.js index 6e0cf0d9a..92bad1f0f 100644 --- a/modules/worker/front/calendar/index.js +++ b/modules/worker/front/calendar/index.js @@ -282,6 +282,7 @@ class Controller extends Section { refresh() { const params = { + workerFk: this.$params.id, businessFk: this.businessId, year: this.year }; diff --git a/modules/worker/front/calendar/index.spec.js b/modules/worker/front/calendar/index.spec.js index e8f9b3130..3d5775663 100644 --- a/modules/worker/front/calendar/index.spec.js +++ b/modules/worker/front/calendar/index.spec.js @@ -328,7 +328,7 @@ describe('Worker', () => { jest.spyOn(controller, 'onData').mockReturnThis(); const expecteResponse = [{id: 1}]; - const expectedParams = {year: year}; + const expectedParams = {workerFk: controller.worker.id, year: year}; const serializedParams = $httpParamSerializer(expectedParams); $httpBackend.expect('GET', `Calendars/absences?${serializedParams}`).respond(200, expecteResponse); controller.refresh(); diff --git a/modules/worker/front/time-control/index.js b/modules/worker/front/time-control/index.js index 1f6251391..ebf70e886 100644 --- a/modules/worker/front/time-control/index.js +++ b/modules/worker/front/time-control/index.js @@ -32,11 +32,6 @@ class Controller extends Section { set worker(value) { this._worker = value; - - if (value) { - this.getActiveContract() - .then(() => this.getAbsences()); - } } /** @@ -96,14 +91,6 @@ class Controller extends Section { } } - getActiveContract() { - return this.$http.get(`Workers/${this.worker.id}/activeContract`) - .then(res => { - if (res.data) - this.businessId = res.data.businessFk; - }); - } - fetchHours() { const params = {workerFk: this.$params.id}; const filter = { @@ -123,11 +110,10 @@ class Controller extends Section { } getAbsences() { - if (!this.businessId) return; - const fullYear = this.started.getFullYear(); let params = { - businessFk: this.businessId, + workerFk: this.$params.id, + businessFk: null, year: fullYear };