diff --git a/modules/claim/front/detail/index.html b/modules/claim/front/detail/index.html
index 5c6de8466..456a2ac73 100644
--- a/modules/claim/front/detail/index.html
+++ b/modules/claim/front/detail/index.html
@@ -52,7 +52,13 @@
New price {{($ctrl.saleClaimed.quantity * $ctrl.saleClaimed.sale.price) -
+ (($ctrl.newDiscount * ($ctrl.saleClaimed.quantity * $ctrl.saleClaimed.sale.price))/100)
+ | currency: 'EUR':2}}
+ MANÁ: {{$ctrl.mana | currency: 'EUR':0}}
+
\ No newline at end of file diff --git a/modules/claim/front/detail/index.js b/modules/claim/front/detail/index.js index f859316a8..ef457807a 100644 --- a/modules/claim/front/detail/index.js +++ b/modules/claim/front/detail/index.js @@ -2,13 +2,14 @@ import ngModule from '../module'; import './style.scss'; class Controller { - constructor($state, $scope, $http, $translate, vnApp, aclService) { + constructor($state, $, $http, $translate, vnApp, aclService) { this.$state = $state; - this.$scope = $scope; + this.$ = $; this.$http = $http; this.$translate = $translate; this.vnApp = vnApp; this.aclService = aclService; + this.edit = {}; this.filter = { where: {claimFk: $state.params.id}, include: [ @@ -38,7 +39,7 @@ class Controller { openAddSalesDialog() { this.getClaimableFromTicket(); - this.$scope.addSales.show(); + this.$.addSales.show(); } getClaimableFromTicket() { @@ -55,8 +56,8 @@ class Controller { let saleToAdd = {saleFk: sale.saleFk, claimFk: this.claim.id, quantity: sale.quantity}; let query = `claim/api/ClaimBeginnings/`; this.$http.post(query, saleToAdd).then(() => { - this.$scope.addSales.hide(); - this.$scope.model.refresh(); + this.$.addSales.hide(); + this.$.model.refresh(); this.vnApp.showSuccess(this.$translate.instant('Data saved!')); if (this.aclService.hasAny(['salesAssistant'])) @@ -69,7 +70,7 @@ class Controller { let query = `claim/api/ClaimBeginnings/${sale.id}`; this.$http.delete(query).then(() => { this.vnApp.showSuccess(this.$translate.instant('Data saved!')); - this.$scope.model.remove(index); + this.$.model.remove(index); this.calculateTotals(); }); } @@ -103,9 +104,44 @@ class Controller { // Item Descriptor showDescriptor(event, itemFk) { - this.$scope.descriptor.itemFk = itemFk; - this.$scope.descriptor.parent = event.target; - this.$scope.descriptor.show(); + this.$.descriptor.itemFk = itemFk; + this.$.descriptor.parent = event.target; + this.$.descriptor.show(); + } + + showEditPopover(event, saleClaimed) { + this.saleClaimed = saleClaimed; + + if (!this.aclService.hasAny(['salesAssistant'])) + return this.vnApp.showError(this.$translate.instant('Insuficient permisos')); + + this.$.editPopover.parent = event.target; + this.$.editPopover.show(); + } + + getManaSalespersonMana() { + this.$http.get(`/api/Tickets/${this.claim.ticketFk}/getSalesPersonMana`).then(res => { + this.mana = res.data; + }); + } + + updateDiscount() { + if (this.newDiscount != this.saleClaimed.sale.discount) { + const params = {salesIds: [this.saleClaimed.sale.id], newDiscount: this.newDiscount}; + const query = `/api/Tickets/${this.saleClaimed.sale.ticketFk}/updateDiscount`; + + this.$http.post(query, params).then(() => { + this.vnApp.showSuccess(this.$translate.instant('Data saved!')); + this.clearDiscount(); + this.$.model.refresh(); + }).catch(err => { + this.vnApp.showError(err.message); + }); + } + } + + clearDiscount() { + this.newDiscount = null; } } diff --git a/modules/claim/front/detail/index.spec.js b/modules/claim/front/detail/index.spec.js index da0735528..9312ef2fc 100644 --- a/modules/claim/front/detail/index.spec.js +++ b/modules/claim/front/detail/index.spec.js @@ -19,8 +19,8 @@ describe('claim', () => { controller.salesToClaim = [{saleFk: 1}, {saleFk: 2}]; controller.salesClaimed = [{id: 1, sale: {}}]; controller.claim = {ticketFk: 1}; - controller.$scope.model = crudModel; - controller.$scope.addSales = { + controller.$.model = crudModel; + controller.$.addSales = { hide: () => {}, show: () => {} }; @@ -30,11 +30,11 @@ describe('claim', () => { it('should call getClaimableFromTicket and $.addSales.show', () => { controller.$ = {addSales: {show: () => {}}}; spyOn(controller, 'getClaimableFromTicket'); - spyOn(controller.$scope.addSales, 'show'); + spyOn(controller.$.addSales, 'show'); controller.openAddSalesDialog(); expect(controller.getClaimableFromTicket).toHaveBeenCalledWith(); - expect(controller.$scope.addSales.show).toHaveBeenCalledWith(); + expect(controller.$.addSales.show).toHaveBeenCalledWith(); }); }); @@ -50,25 +50,25 @@ describe('claim', () => { describe('addClaimedSale(index)', () => { it('should make a post and call refresh, hide and showSuccess', () => { - spyOn(controller.$scope.addSales, 'hide'); + spyOn(controller.$.addSales, 'hide'); spyOn(controller.$state, 'go'); $httpBackend.expectPOST(`claim/api/ClaimBeginnings/`).respond({}); controller.addClaimedSale(1); $httpBackend.flush(); - expect(controller.$scope.addSales.hide).toHaveBeenCalledWith(); + expect(controller.$.addSales.hide).toHaveBeenCalledWith(); expect(controller.$state.go).toHaveBeenCalledWith('claim.card.development'); }); }); describe('deleteClaimedSale(index)', () => { it('should make a delete and call refresh and showSuccess', () => { - spyOn(controller.$scope.model, 'remove'); + spyOn(controller.$.model, 'remove'); $httpBackend.expectDELETE(`claim/api/ClaimBeginnings/1`).respond({}); controller.deleteClaimedSale(0); $httpBackend.flush(); - expect(controller.$scope.model.remove).toHaveBeenCalledWith(0); + expect(controller.$.model.remove).toHaveBeenCalledWith(0); }); }); @@ -92,5 +92,26 @@ describe('claim', () => { expect(controller.claimedTotal).toEqual(0); }); }); + + describe('updateDiscount()', () => { + it('should perform a query if the new discount differs from the claim discount', () => { + controller.newDiscount = 10; + controller.saleClaimed = {sale: {discount: 5}}; + controller.saleClaimed = {sale: {id: 7}}; + controller.saleClaimed = {sale: {ticketFk: 1}}; + + spyOn(controller.vnApp, 'showSuccess'); + spyOn(controller, 'clearDiscount'); + spyOn(controller.$.model, 'refresh'); + + $httpBackend.when('POST', '/api/Tickets/1/updateDiscount').respond({}); + controller.updateDiscount(); + $httpBackend.flush(); + + expect(controller.vnApp.showSuccess).toHaveBeenCalledWith('Data saved!'); + expect(controller.clearDiscount).toHaveBeenCalledWith(); + expect(controller.$.model.refresh).toHaveBeenCalledWith(); + }); + }); }); }); diff --git a/modules/claim/front/detail/locale/es.yml b/modules/claim/front/detail/locale/es.yml index 072a699bc..ae648d51d 100644 --- a/modules/claim/front/detail/locale/es.yml +++ b/modules/claim/front/detail/locale/es.yml @@ -5,4 +5,5 @@ Landed: F. entrega Price: Precio Claimable sales from ticket: Lineas reclamables del ticket Detail: Detalles -Add sale item: Añadir artículo \ No newline at end of file +Add sale item: Añadir artículo +Insuficient permisos: Permisos insuficientes \ No newline at end of file diff --git a/modules/claim/front/detail/style.scss b/modules/claim/front/detail/style.scss index cb66b31ab..e555cb305 100644 --- a/modules/claim/front/detail/style.scss +++ b/modules/claim/front/detail/style.scss @@ -1,3 +1,5 @@ +@import "variables"; + vn-claim-detail { vn-textfield { margin: 0!important; @@ -16,5 +18,30 @@ vn-claim-detail { } } } + vn-popover.edit { + div.popover { + width: 200px; + } + vn-horizontal.header { + background-color: $color-main; + color: $color-font-dark; + + h5 { + color: inherit; + margin: 0 auto; + } + } + p.simulatorTitle { + margin-bottom: 0px; + font-size: 12px; + color: $color-main; + } + vn-label-value { + padding-bottom: 20px; + } + div.simulator{ + text-align: center; + } + } }