diff --git a/client/claim/src/index.js b/client/claim/src/index.js index 2d9b4fa216..f3cb8d052e 100644 --- a/client/claim/src/index.js +++ b/client/claim/src/index.js @@ -8,4 +8,4 @@ import './descriptor'; import './development'; import './index/'; import './search-panel'; -// import './summary'; +import './summary'; diff --git a/client/claim/src/index/index.html b/client/claim/src/index/index.html index 861697a4a1..af7a9b2638 100644 --- a/client/claim/src/index/index.html +++ b/client/claim/src/index/index.html @@ -30,7 +30,7 @@ - + {{::claim.id}} {{::claim.client.id}} {{::claim.client.name}} @@ -39,7 +39,7 @@ {{::claim.claimState.description}} @@ -53,4 +53,10 @@ scroll-selector="ui-view"> - \ No newline at end of file + + + + + + \ No newline at end of file diff --git a/client/claim/src/index/index.js b/client/claim/src/index/index.js index 03a44a7ec3..fc371b60c1 100644 --- a/client/claim/src/index/index.js +++ b/client/claim/src/index/index.js @@ -56,6 +56,13 @@ export default class Controller { event.stopImmediatePropagation(); } + preview(event, claim) { + this.claimSelected = claim; + this.$.dialogSummaryClaim.show(); + event.preventDefault(); + event.stopImmediatePropagation(); + } + onDescriptorLoad() { this.$.popover.relocate(); } diff --git a/client/claim/src/summary/index.html b/client/claim/src/summary/index.html new file mode 100644 index 0000000000..05ded4c62f --- /dev/null +++ b/client/claim/src/summary/index.html @@ -0,0 +1,152 @@ + + + + +
{{$ctrl.summary.claim.id}} - {{$ctrl.summary.claim.client.name}}
+
+ + + + + + + + + + + + + + + + + + + + + + + + +
Detail
+ + + + Id + Landed + Quantity + Claimed + Description + Price + Disc. + Total + + + + + {{saleClaimed.sale.id}} + {{saleClaimed.sale.ticket.landed | dateTime: 'dd/MM/yyyy'}} + {{saleClaimed.sale.quantity}} + {{saleClaimed.quantity}} + {{saleClaimed.sale.concept}} + {{saleClaimed.sale.price | currency:'€':2}} + {{saleClaimed.sale.discount}} % + + {{(saleClaimed.sale.quantity * saleClaimed.sale.price) - + ((saleClaimed.sale.discount * + (saleClaimed.sale.quantity * saleClaimed.sale.price))/100) | currency:'€':2 + }} + + + + + No results + + +
+
+ + +
Development
+ + + + Reason + Result + Responsible + Worker + Redelivery + + + + + {{development.claimReason.description}} + {{development.claimResult.description}} + {{development.claimResponsible.description}} + {{development.worker.firstName}} + {{development.claimRedelivery.description}} + + + + No results + + +
+
+ + +
Action
+ + + + Id + Destination + Landed + Quantity + Description + Price + Disc. + Total + + + + + {{action.sale.id}} + {{action.claimBeggining.description}} + {{action.sale.ticket.landed | dateTime: 'dd/MM/yyyy'}} + {{action.sale.quantity}} + {{action.sale.concept}} + {{action.sale.price}} + {{action.sale.discount}} % + + {{(action.sale.quantity * action.sale.price) - + ((action.sale.discount * + (action.sale.quantity * action.sale.price))/100) | currency:'€':2 + }} + + + + + No results + + +
+
+
+
+
\ No newline at end of file diff --git a/client/claim/src/summary/index.js b/client/claim/src/summary/index.js new file mode 100644 index 0000000000..f20133abce --- /dev/null +++ b/client/claim/src/summary/index.js @@ -0,0 +1,28 @@ +import ngModule from '../module'; + +class Controller { + constructor($http) { + this.$http = $http; + } + + getSummary() { + this.$http.get(`/claim/api/Claims/${this.claim.id}/getSummary`).then(response => { + this.summary = response.data; + }); + } + + $onChanges() { + if (this.claim && this.claim.id) + this.getSummary(); + } +} + +Controller.$inject = ['$http']; + +ngModule.component('vnClaimSummary', { + template: require('./index.html'), + controller: Controller, + bindings: { + claim: '<' + } +}); diff --git a/client/claim/src/summary/index.spec.js b/client/claim/src/summary/index.spec.js new file mode 100644 index 0000000000..89ee4e9302 --- /dev/null +++ b/client/claim/src/summary/index.spec.js @@ -0,0 +1,41 @@ +import './index.js'; + +describe('Claim', () => { + describe('Component summary', () => { + let $componentController; + let controller; + let $httpBackend; + + beforeEach(() => { + angular.mock.module('claim'); + }); + + beforeEach(angular.mock.inject((_$componentController_, _$httpBackend_) => { + $componentController = _$componentController_; + $httpBackend = _$httpBackend_; + $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); + controller = $componentController('vnClaimSummary'); + controller.claim = {id: 1}; + })); + + describe('getSummary()', () => { + it("should perform a query to set summary", () => { + $httpBackend.when('GET', `/claim/api/Claims/1/getSummary`).respond(200, 24); + $httpBackend.expect('GET', `/claim/api/Claims/1/getSummary`); + controller.getSummary(); + $httpBackend.flush(); + + expect(controller.summary).toEqual(24); + }); + }); + + describe('$onChanges()', () => { + it("should call getSummary when item.id is defined", () => { + spyOn(controller, 'getSummary'); + controller.$onChanges(); + + expect(controller.getSummary).toHaveBeenCalledWith(); + }); + }); + }); +}); diff --git a/services/claim/common/methods/claim/getSummary.js b/services/claim/common/methods/claim/getSummary.js new file mode 100644 index 0000000000..11ed52522b --- /dev/null +++ b/services/claim/common/methods/claim/getSummary.js @@ -0,0 +1,104 @@ +module.exports = Self => { + Self.remoteMethod('getSummary', { + description: 'Updates the item taxes', + accessType: 'READ', + accepts: [{ + arg: 'id', + type: 'number', + required: true, + description: 'The item id', + http: {source: 'path'} + }], + returns: { + type: 'object', + root: true + }, + http: { + path: `/:id/getSummary`, + verb: 'GET' + } + }); + + Self.getSummary = async id => { + let promises = []; + let summary = {}; + + // Claim + + let filter = { + where: {id: id}, + include: [ + {relation: 'worker', scope: {fields: ['name', 'firstName']}}, + {relation: 'claimState', scope: {fields: ['id', 'description']}}, + { + relation: 'client', + scope: { + fields: ['salesPersonFk', 'name'], + include: { + relation: 'salesPerson', + fields: ['firstName', 'name'] + } + } + } + ] + }; + + promises.push(Self.app.models.Claim.find(filter)); + + // Claim detail + filter = { + where: {claimFk: id}, + include: [ + {relation: 'sale', + scope: { + fields: ['concept', 'ticketFk', 'price', 'quantity', 'discount'], + include: { + relation: 'ticket' + } + } + } + ] + }; + promises.push(Self.app.models.ClaimBeginning.find(filter)); + + // Claim developments + filter = { + where: {claimFk: id}, + include: [ + {relation: 'claimResponsible'}, + {relation: 'worker'}, + {relation: 'claimDestination'}, + {relation: 'claimReason'}, + {relation: 'claimResult'}, + {relation: 'claimRedelivery'} + ] + }; + promises.push(Self.app.models.ClaimDevelopment.find(filter)); + + // Claim action + filter = { + where: {claimFk: id}, + include: [ + {relation: 'sale', + scope: { + fields: ['concept', 'price', 'quantity', 'discount', 'ticketFk', 'itemFk'], + include: [ + {relation: 'ticket'} + ] + } + }, + {relation: 'claimBeggining'} + ] + }; + promises.push(Self.app.models.ClaimEnd.find(filter)); + + let res = await Promise.all(promises); + + [summary.claim] = res[0]; + summary.salesClaimed = res[1]; + summary.developments = res[2]; + summary.actions = res[3]; + + return summary; + }; +}; diff --git a/services/claim/common/methods/claim/specs/getSummary.spec.js b/services/claim/common/methods/claim/specs/getSummary.spec.js new file mode 100644 index 0000000000..8f816bb966 --- /dev/null +++ b/services/claim/common/methods/claim/specs/getSummary.spec.js @@ -0,0 +1,13 @@ +const app = require(`${servicesDir}/claim/server/server`); + +describe('claim getSummary()', () => { + it('should return summary with claim, salesClaimed, developments and actions defined ', async() => { + let result = await app.models.Claim.getSummary(1); + let keys = Object.keys(result); + + expect(keys).toContain('claim'); + expect(keys).toContain('salesClaimed'); + expect(keys).toContain('developments'); + expect(keys).toContain('actions'); + }); +}); diff --git a/services/claim/common/models/claim.js b/services/claim/common/models/claim.js new file mode 100644 index 0000000000..dd01547ea8 --- /dev/null +++ b/services/claim/common/models/claim.js @@ -0,0 +1,3 @@ +module.exports = Self => { + require('../methods/claim/getSummary')(Self); +};