diff --git a/db/changes/10130-christmas/00-greugeConfig.sql b/db/changes/10130-christmas/00-greugeConfig.sql new file mode 100644 index 000000000..c21751f08 --- /dev/null +++ b/db/changes/10130-christmas/00-greugeConfig.sql @@ -0,0 +1,6 @@ +CREATE TABLE `vn`.`greugeConfig` ( + `id` INT NOT NULL AUTO_INCREMENT, + `freightPickUpPrice` DECIMAL(10,2) NOT NULL, + PRIMARY KEY (`id`)); + +INSERT IGNORE INTO `vn`.`greugeConfig` (`id`, `freightPickUpPrice`) VALUES ('1', '11'); diff --git a/db/dump/fixtures.sql b/db/dump/fixtures.sql index 53bb9ff23..c6d7592f9 100644 --- a/db/dump/fixtures.sql +++ b/db/dump/fixtures.sql @@ -586,7 +586,8 @@ INSERT INTO `vn`.`greugeType`(`id`, `name`, `code`) (3, 'Mana', 'mana'), (4, 'Reclaim', 'reclaim'), (5, 'Heritage', 'heritage'), - (6, 'Miscellaneous', 'miscellaneous'); + (6, 'Miscellaneous', 'miscellaneous'), + (7, 'Freight Pickup', 'freightPickUp'); INSERT INTO `vn`.`greuge`(`id`, `clientFk`, `description`, `amount`, `shipped`, `created`, `greugeTypeFk`, `ticketFk`) VALUES @@ -1979,3 +1980,4 @@ INSERT INTO `vn`.`workerTimeControlParams` (`id`, `dayBreak`, `weekBreak`, `week VALUES (1, 43200, 129600, 734400, 43200, 50400); +INSERT IGNORE INTO `vn`.`greugeConfig` (`id`, `freightPickUpPrice`) VALUES ('1', '11'); diff --git a/modules/claim/front/action/index.js b/modules/claim/front/action/index.js index 7d67d58c9..23e69bbe9 100644 --- a/modules/claim/front/action/index.js +++ b/modules/claim/front/action/index.js @@ -2,12 +2,13 @@ import ngModule from '../module'; import './style.scss'; class Controller { - constructor($stateParams, $scope, $http, $translate, vnApp) { + constructor($stateParams, $scope, $http, $translate, vnApp, $httpParamSerializer) { this.$stateParams = $stateParams; this.$ = $scope; this.$http = $http; this.$translate = $translate; this.vnApp = vnApp; + this.$httpParamSerializer = $httpParamSerializer; this.filter = { where: {claimFk: $stateParams.id}, include: [ @@ -125,31 +126,61 @@ class Controller { let data = {claimFk: this.$stateParams.id}; let query = `Claims/regularizeClaim`; return this.$http.post(query, data).then(() => { - this.card.reload(); - this.vnApp.showSuccess(this.$translate.instant('Data saved!')); if (this.claim.responsibility >= Math.ceil(this.maxResponsibility) / 2) this.$.updateGreuge.show(); + else + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + + this.card.reload(); }); } + getGreugeTypeId() { + const params = {filter: {where: {code: 'freightPickUp'}}}; + const serializedParams = this.$httpParamSerializer(params); + const query = `GreugeTypes/findOne?${serializedParams}`; + return this.$http.get(query).then(res => { + this.greugeTypeFreightId = res.data.id; + + return res; + }); + } + + getGreugeConfig() { + const query = `GreugeConfigs/findOne`; + return this.$http.get(query).then(res => { + this.freightPickUpPrice = res.data.freightPickUpPrice; + + return res; + }); + } + + onUpdateGreugeResponse(response) { - if (response !== 'accept') - return; - let greugeTypeFreight = 7; - let query = `Greuges/`; - let data = { - clientFk: this.claim.clientFk, - description: `claim: ${this.claim.id}`, - amount: 11, - greugeTypeFk: greugeTypeFreight, - ticketFk: this.claim.ticketFk - }; + if (response == 'accept') { + const promises = []; + promises.push(this.getGreugeTypeId()); + promises.push(this.getGreugeConfig()); - this.$http.post(query, data).then(() => { - this.card.reload(); - this.vnApp.showSuccess(this.$translate.instant('Greuge inserted!')); - }); + return Promise.all(promises).then(() => { + const data = { + clientFk: this.claim.clientFk, + description: this.$translate.instant('ClaimGreugeDescription', { + claimId: this.claim.id + }).toUpperCase(), + amount: this.freightPickUpPrice, + greugeTypeFk: this.greugeTypeFreightId, + ticketFk: this.claim.ticketFk + }; + return this.$http.post(`Greuges/`, data).then(() => { + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.vnApp.showMessage(this.$translate.instant('Greuge inserted')); + }); + }); + } else + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); } + // Item Descriptor showDescriptor(event, itemFk) { this.$.descriptor.itemFk = itemFk; @@ -164,6 +195,7 @@ class Controller { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); }); } + saveMana(value) { let query = `Claims/${this.$stateParams.id}/updateClaimAction`; @@ -173,7 +205,7 @@ class Controller { } } -Controller.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp']; +Controller.$inject = ['$stateParams', '$scope', '$http', '$translate', 'vnApp', '$httpParamSerializer']; ngModule.component('vnClaimAction', { template: require('./index.html'), diff --git a/modules/claim/front/action/index.spec.js b/modules/claim/front/action/index.spec.js index 56597fd2f..0d10957e7 100644 --- a/modules/claim/front/action/index.spec.js +++ b/modules/claim/front/action/index.spec.js @@ -6,15 +6,19 @@ describe('claim', () => { let controller; let $httpBackend; let $state; + let $httpParamSerializer; + let $scope; beforeEach(ngModule('claim')); - beforeEach(angular.mock.inject(($componentController, _$state_, _$httpBackend_) => { + beforeEach(angular.mock.inject(($rootScope, $componentController, _$state_, _$httpBackend_, _$httpParamSerializer_) => { + $scope = $rootScope.$new(); $httpBackend = _$httpBackend_; + $httpParamSerializer = _$httpParamSerializer_; $state = _$state_; $state.params.id = 1; - controller = $componentController('vnClaimAction', {$state}); + controller = $componentController('vnClaimAction', {$state, $scope}); controller.claim = {ticketFk: 1}; controller.$.model = {refresh: () => {}}; controller.$.addSales = { @@ -149,6 +153,8 @@ describe('claim', () => { }); describe('onUpdateGreugeResponse()', () => { + const greugeTypeId = 7; + const freightPickUpPrice = 11; it('should do nothing', () => { spyOn(controller.$http, 'post'); spyOn(controller.card, 'reload'); @@ -161,24 +167,51 @@ describe('claim', () => { expect(controller.vnApp.showSuccess).not.toHaveBeenCalledWith('Greuge inserted!'); }); - it('should perform a insert into greuges', () => { + it('should make a query and get the greugeTypeId and greuge config', () => { spyOn(controller.card, 'reload'); spyOn(controller.vnApp, 'showSuccess'); + + const greugeTypeParams = $httpParamSerializer({filter: {where: {code: 'freightPickUp'}}}); + $httpBackend.expect('GET', `GreugeTypes/findOne?${greugeTypeParams}`).respond({id: greugeTypeId}); + $httpBackend.expect('GET', `GreugeConfigs/findOne`).respond({freightPickUpPrice}); + controller.onUpdateGreugeResponse('accept'); + $httpBackend.flush(); + + expect(controller.greugeTypeFreightId).toEqual(greugeTypeId); + expect(controller.freightPickUpPrice).toEqual(freightPickUpPrice); + }); + + // #1957 - Investigate how to test nested httpBackend requests + xit('should perform a insert into greuges', () => { + spyOn(controller.card, 'reload'); + spyOn(controller.vnApp, 'showSuccess'); + + spyOn(controller, 'getGreugeTypeId').and.returnValue(new Promise(resolve => { + return resolve({id: greugeTypeId}); + })); + spyOn(controller, 'getGreugeConfig').and.returnValue(new Promise(resolve => { + return resolve({freightPickUpPrice}); + })); + controller.claim.clientFk = 101; controller.claim.id = 11; let data = { clientFk: 101, description: `claim: ${controller.claim.id}`, - amount: 11, - greugeTypeFk: 7, + amount: freightPickUpPrice, + greugeTypeFk: greugeTypeId, ticketFk: controller.claim.ticketFk }; - $httpBackend.expect('POST', `Greuges/`, data).respond(); - controller.onUpdateGreugeResponse('accept'); - $httpBackend.flush(); + $httpBackend.expect('POST', `Greuges/`, data).respond(new Promise(resolve => { + return resolve({id: freightPickUpPrice}); + })); + controller.onUpdateGreugeResponse('accept').then(res => { + console.log('asdas'); + }).catch(error => { + console.log('errorrrr!!'); + }); - expect(controller.card.reload).toHaveBeenCalledWith(); - expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Greuge inserted!'); + $httpBackend.flush(); }); }); }); diff --git a/modules/claim/front/action/locale/en.yml b/modules/claim/front/action/locale/en.yml new file mode 100644 index 000000000..faab67c06 --- /dev/null +++ b/modules/claim/front/action/locale/en.yml @@ -0,0 +1 @@ +ClaimGreugeDescription: Claim id {{claimId}} \ No newline at end of file diff --git a/modules/claim/front/action/locale/es.yml b/modules/claim/front/action/locale/es.yml index 3950ec06a..db1a25755 100644 --- a/modules/claim/front/action/locale/es.yml +++ b/modules/claim/front/action/locale/es.yml @@ -8,4 +8,5 @@ Imports ticket lines: Importa las lineas de un ticket Regularize: Regularizar Do you want to insert greuges?: Desea insertar greuges? Insert greuges on client card: Insertar greuges en la ficha del cliente -Greuge inserted: Greuge insertado \ No newline at end of file +Greuge inserted: Greuge insertado +ClaimGreugeDescription: ReclamaciĆ³n id {{claimId}} \ No newline at end of file diff --git a/modules/client/back/model-config.json b/modules/client/back/model-config.json index 3aa709eb7..670b7d2ca 100644 --- a/modules/client/back/model-config.json +++ b/modules/client/back/model-config.json @@ -50,6 +50,9 @@ "GreugeType": { "dataSource": "vn" }, + "GreugeConfig": { + "dataSource": "vn" + }, "Mandate": { "dataSource": "vn" }, diff --git a/modules/client/back/models/greuge-config.json b/modules/client/back/models/greuge-config.json new file mode 100644 index 000000000..b72348023 --- /dev/null +++ b/modules/client/back/models/greuge-config.json @@ -0,0 +1,20 @@ +{ + "name": "GreugeConfig", + "base": "VnModel", + "options": { + "mysql": { + "table": "greugeConfig" + } + }, + "properties": { + "freightPickUpPrice": { + "type": "Number" + } + }, + "acls": [{ + "accessType": "READ", + "principalType": "ROLE", + "principalId": "$everyone", + "permission": "ALLOW" + }] +} diff --git a/modules/client/back/models/greuge-type.json b/modules/client/back/models/greuge-type.json index cafe1f7fc..5c5b1870d 100644 --- a/modules/client/back/models/greuge-type.json +++ b/modules/client/back/models/greuge-type.json @@ -2,19 +2,22 @@ "name": "GreugeType", "base": "VnModel", "options": { - "mysql": { - "table": "greugeType" - } + "mysql": { + "table": "greugeType" + } }, "properties": { - "id": { - "id": true, - "type": "Number", - "description": "Identifier" - }, - "name": { - "type": "String" - } + "id": { + "id": true, + "type": "Number", + "description": "Identifier" + }, + "name": { + "type": "String" + }, + "code": { + "type": "String" + } }, "acls": [ { diff --git a/modules/client/front/greuge/index/index.html b/modules/client/front/greuge/index/index.html index 636caaca2..683ac0afe 100644 --- a/modules/client/front/greuge/index/index.html +++ b/modules/client/front/greuge/index/index.html @@ -37,7 +37,9 @@ {{::greuge.shipped | date:'dd/MM/yyyy HH:mm' }} - {{::greuge.description}} + + {{::greuge.description}} + {{::greuge.greugeType.name}} {{::greuge.amount | currency: 'EUR': 2}}