diff --git a/client/claim/src/action/index.html b/client/claim/src/action/index.html new file mode 100644 index 000000000..7a1a1515f --- /dev/null +++ b/client/claim/src/action/index.html @@ -0,0 +1,116 @@ + + + + + + + Action +
+ + +
+
+ + + + Id + Destination + Landed + Quantity + Description + Price + Disc. + Total + + + + + {{saleClaimed.sale.id}} + + + + + {{saleClaimed.sale.ticket.landed | dateTime: 'dd/MM/yyyy'}} + {{saleClaimed.sale.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 + + +
+
+ + + + + +

Claimable sales from ticket

{{$ctrl.claim.ticketFk}}

+ + + + Id + Landed + Quantity + Description + Price + Disc. + Total + + + + + {{sale.saleFk}} + {{sale.landed | dateTime: 'dd/MM/yyyy'}} + {{sale.quantity}} + {{sale.concept}} + {{sale.price | currency:'€':2}} + {{sale.discount}} % + + {{(sale.quantity * sale.price) - ((sale.discount * (sale.quantity * sale.price))/100) | currency:'€':2}} + + + + + No results + + +
+
\ No newline at end of file diff --git a/client/claim/src/action/index.js b/client/claim/src/action/index.js new file mode 100644 index 000000000..295b9a955 --- /dev/null +++ b/client/claim/src/action/index.js @@ -0,0 +1,93 @@ +import ngModule from '../module'; +import './style.scss'; + +class Controller { + constructor($state, $scope, $http, $translate, vnApp) { + this.$state = $state; + this.$ = $scope; + this.$http = $http; + this.$translate = $translate; + this.vnApp = vnApp; + this.filter = { + where: {claimFk: $state.params.id}, + include: [ + {relation: 'sale', + scope: { + fields: ['concept', 'ticketFk', 'price', 'quantity', 'discount'], + include: { + relation: 'ticket' + } + } + }, + {relation: 'claimBeggining'} + ] + }; + } + + openAddSalesDialog() { + this.getClaimedSales(); + this.$.addSales.show(); + } + + getClaimedSales() { + let json = encodeURIComponent(JSON.stringify(this.claim.id)); + + let query = `/claim/api/ClaimBeginnings/${json}`; + this.$http.get(query).then(res => { + if (res.data) { + this.claimedSales = res.data; + } + }); + } + + addClaimedSale(saleFk) { + let saleToAdd = {saleFk: saleFk, claimFk: this.claim.id, workerFk: this.claim.workerFk, claimDestinationFk: 1}; + let query = `claim/api/ClaimEnds/`; + this.$http.post(query, saleToAdd).then(() => { + this.$.model.refresh(); + this.$.addSales.hide(); + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + }); + } + + deleteClaimedSale(id) { + let json = encodeURIComponent(JSON.stringify(id)); + let query = `claim/api/ClaimEnds/${json}`; + this.$http.delete(query).then(() => { + this.$.model.refresh(); + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + }); + } + + focusLastInput() { + let inputs = document.querySelectorAll("#claimDestinationFk"); + inputs[inputs.length - 1].querySelector("input").focus(); + this.calculateTotals(); + } + + setClaimDestination(id, claimDestinationFk) { + let params = {id: id, claimDestinationFk: claimDestinationFk}; + let query = `claim/api/ClaimEnds/`; + this.$http.patch(query, params).then(() => { + this.$.model.refresh(); + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + }); + } + + calculateTotals() { + this.claimedTotal = 0; + this.salesClaimed.forEach(sale => { + this.claimedTotal += (sale.sale.quantity * sale.sale.price) - ((sale.sale.discount * (sale.sale.quantity * sale.sale.price)) / 100); + }); + } +} + +Controller.$inject = ['$state', '$scope', '$http', '$translate', 'vnApp']; + +ngModule.component('vnClaimAction', { + template: require('./index.html'), + controller: Controller, + bindings: { + claim: '<' + } +}); diff --git a/client/claim/src/action/index.spec.js b/client/claim/src/action/index.spec.js new file mode 100644 index 000000000..d6769a022 --- /dev/null +++ b/client/claim/src/action/index.spec.js @@ -0,0 +1,94 @@ +import './index.js'; + +describe('claim', () => { + describe('Component vnClaimDetail', () => { + let $componentController; + let controller; + let $httpBackend; + let $state; + + beforeEach(() => { + angular.mock.module('claim'); + }); + + beforeEach(angular.mock.inject((_$componentController_, _$state_, _$httpBackend_, $rootScope) => { + $componentController = _$componentController_; + $httpBackend = _$httpBackend_; + $httpBackend.when('GET', /\/locale\/\w+\/[a-z]{2}\.json/).respond({}); + $httpBackend.when('GET', 'claim/api/Claims/ClaimBeginnings').respond({}); + $state = _$state_; + $state.params.id = 1; + + controller = $componentController('vnClaimDetail', {$state: $state}); + controller.claim = {ticketFk: 1}; + controller.$.model = {refresh: () => {}}; + controller.$.addSales = { + hide: () => {}, + show: () => {} + }; + })); + + describe('openAddSalesDialog()', () => { + it('should call getClaimableFromTicket and $.addSales.show', () => { + controller.$ = {addSales: {show: () => {}}}; + spyOn(controller, 'getClaimableFromTicket'); + spyOn(controller.$.addSales, 'show'); + controller.openAddSalesDialog(); + + expect(controller.getClaimableFromTicket).toHaveBeenCalledWith(); + expect(controller.$.addSales.show).toHaveBeenCalledWith(); + }); + }); + + describe('getClaimableFromTicket()', () => { + it('should make a query and set salesToClaim', () => { + $httpBackend.expectGET(`/api/Sales/getClaimableFromTicket?ticketFk=1`).respond(200, 1); + controller.getClaimableFromTicket(); + $httpBackend.flush(); + + expect(controller.salesToClaim).toEqual(1); + }); + }); + + describe('addClaimedSale(saleFk)', () => { + it('should make a post and call refresh, hide and showSuccess', () => { + spyOn(controller.$.model, 'refresh'); + spyOn(controller.$.addSales, 'hide'); + spyOn(controller.vnApp, 'showSuccess'); + $httpBackend.expectPOST(`claim/api/ClaimBeginnings/`).respond({}); + controller.addClaimedSale(1); + $httpBackend.flush(); + + expect(controller.$.model.refresh).toHaveBeenCalledWith(); + expect(controller.$.addSales.hide).toHaveBeenCalledWith(); + expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + }); + }); + + describe('deleteClaimedSale(id)', () => { + it('should make a delete and call refresh and showSuccess', () => { + spyOn(controller.$.model, 'refresh'); + spyOn(controller.vnApp, 'showSuccess'); + $httpBackend.expectDELETE(`claim/api/ClaimBeginnings/1`).respond({}); + controller.deleteClaimedSale(1); + $httpBackend.flush(); + + expect(controller.$.model.refresh).toHaveBeenCalledWith(); + expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + }); + }); + + describe('setClaimedQuantity(id, claimedQuantity)', () => { + it('should make a patch and call refresh and showSuccess', () => { + spyOn(controller.$.model, 'refresh'); + spyOn(controller.vnApp, 'showSuccess'); + $httpBackend.expectPATCH(`claim/api/ClaimBeginnings/`).respond({}); + controller.setClaimedQuantity(1, 1); + $httpBackend.flush(); + + expect(controller.$.model.refresh).toHaveBeenCalledWith(); + expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + }); + }); + }); +}); diff --git a/client/claim/src/action/locale/es.yml b/client/claim/src/action/locale/es.yml new file mode 100644 index 000000000..7620ef965 --- /dev/null +++ b/client/claim/src/action/locale/es.yml @@ -0,0 +1,3 @@ +Destination: Destino +Action: Actuaciones +Total claimed: Total Reclamado \ No newline at end of file diff --git a/client/claim/src/action/style.scss b/client/claim/src/action/style.scss new file mode 100644 index 000000000..a3947e63c --- /dev/null +++ b/client/claim/src/action/style.scss @@ -0,0 +1,16 @@ +vn-claim-action { + vn-dialog[vn-id=addSales] { + tpl-body { + width: 950px; + div { + div.buttons { + display: none; + } + vn-table{ + min-width: 950px; + } + } + } + } +} + diff --git a/client/claim/src/index.js b/client/claim/src/index.js index 74b6343ee..ef11ae80e 100644 --- a/client/claim/src/index.js +++ b/client/claim/src/index.js @@ -1,9 +1,11 @@ export * from './module'; -import './index/'; +import './action'; +import './basic-data'; import './card'; -import './search-panel'; import './detail'; import './descriptor'; -import './basic-data'; +// import './development'; +import './index/'; +import './search-panel'; // import './summary';