Refactor #1527 claim/detail, ticket/sale updateDiscount y updatePrice
gitea/salix/dev This commit looks good Details

This commit is contained in:
Bernat 2019-06-17 12:13:05 +02:00
parent c435eb456f
commit 53f6db7a4a
7 changed files with 54 additions and 15 deletions

View File

@ -146,9 +146,7 @@
</vn-input-number> </vn-input-number>
<div class="simulator"> <div class="simulator">
<p class="simulatorTitle" translate>New price</p> <p class="simulatorTitle" translate>New price</p>
<p>{{($ctrl.saleClaimed.quantity * $ctrl.saleClaimed.sale.price) - <p>{{$ctrl.newPrice | currency: 'EUR':2}}
(($ctrl.newDiscount * ($ctrl.saleClaimed.quantity * $ctrl.saleClaimed.sale.price))/100)
| currency: 'EUR':2}}
</p> </p>
</div> </div>
</div> </div>

View File

@ -37,6 +37,15 @@ class Controller {
return this._salesClaimed; return this._salesClaimed;
} }
get newDiscount() {
return this._newDiscount;
}
set newDiscount(value) {
this._newDiscount = value;
this.updateNewPrice();
}
openAddSalesDialog() { openAddSalesDialog() {
this.getClaimableFromTicket(); this.getClaimableFromTicket();
this.$.addSales.show(); this.$.addSales.show();
@ -140,6 +149,11 @@ class Controller {
} }
} }
updateNewPrice() {
this.newPrice = (this.saleClaimed.quantity * this.saleClaimed.sale.price) -
((this.newDiscount * (this.saleClaimed.quantity * this.saleClaimed.sale.price)) / 100);
}
clearDiscount() { clearDiscount() {
this.newDiscount = null; this.newDiscount = null;
} }

View File

@ -93,12 +93,16 @@ describe('claim', () => {
}); });
}); });
describe('updateDiscount()', () => { fdescribe('updateDiscount()', () => {
it('should perform a query if the new discount differs from the claim discount', () => { it('should perform a query if the new discount differs from the claim discount', () => {
controller.saleClaimed = {sale: {
discount: 5,
id: 7,
ticketFk: 1,
price: 2,
quantity: 10}};
controller.newDiscount = 10; controller.newDiscount = 10;
controller.saleClaimed = {sale: {discount: 5}};
controller.saleClaimed = {sale: {id: 7}};
controller.saleClaimed = {sale: {ticketFk: 1}};
spyOn(controller.vnApp, 'showSuccess'); spyOn(controller.vnApp, 'showSuccess');
spyOn(controller, 'clearDiscount'); spyOn(controller, 'clearDiscount');

View File

@ -13,8 +13,6 @@
</vn-input-number> </vn-input-number>
<div class="simulator"> <div class="simulator">
<p class="simulatorTitle" translate>New price</p> <p class="simulatorTitle" translate>New price</p>
<p>{{($ctrl.edit[0].quantity * $ctrl.edit[0].price) <p>{{$ctrl.newPrice | currency: 'EUR':2}}</p>
- (($ctrl.newDiscount * ($ctrl.edit[0].quantity * $ctrl.edit[0].price))/100)
| currency: 'EUR':2}}</p>
</div> </div>
</div> </div>

View File

@ -28,6 +28,20 @@ class Controller {
return this._bulk; return this._bulk;
} }
get newDiscount() {
return this._newDiscount;
}
set newDiscount(value) {
this._newDiscount = value;
this.updateNewPrice();
}
updateNewPrice() {
if (this.newDiscount && this.edit[0])
this.newPrice = (this.edit[0].quantity * this.edit[0].price) - ((this.newDiscount * (this.edit[0].quantity * this.edit[0].price)) / 100);
}
setNewDiscount() { setNewDiscount() {
if (!this.newDiscount && this.edit[0]) if (!this.newDiscount && this.edit[0])
this.newDiscount = this.edit[0].discount; this.newDiscount = this.edit[0].discount;

View File

@ -186,9 +186,7 @@
</vn-input-number> </vn-input-number>
<div class="simulator"> <div class="simulator">
<p class="simulatorTitle" translate>New price</p> <p class="simulatorTitle" translate>New price</p>
<p>{{($ctrl.sale.quantity * $ctrl.editedPrice) <p>{{$ctrl.newPrice | currency: 'EUR':2}}</p>
- (($ctrl.sale.discount * ($ctrl.sale.quantity * $ctrl.editedPrice))/100)
| currency: 'EUR':2}}</p>
</div> </div>
</div> </div>
</div> </div>

View File

@ -21,16 +21,25 @@ class Controller {
this.imagesPath = '//verdnatura.es/vn-image-data/catalog'; this.imagesPath = '//verdnatura.es/vn-image-data/catalog';
} }
get sales() {
return this._sales;
}
set sales(value) { set sales(value) {
this._sales = value; this._sales = value;
this.refreshTotal(); this.refreshTotal();
} }
get sales() { get editedPrice() {
return this._sales; return this._editedPrice;
} }
set editedPrice(value) {
this._editedPrice = value;
this.updateNewPrice();
}
refreshTotal() { refreshTotal() {
this.loadSubTotal(); this.loadSubTotal();
this.loadVAT(); this.loadVAT();
@ -270,6 +279,10 @@ class Controller {
this.$scope.editPricePopover.hide(); this.$scope.editPricePopover.hide();
} }
updateNewPrice() {
this.newPrice = this.sale.quantity * this.editedPrice - ((this.sale.discount * (this.sale.quantity * this.editedPrice)) / 100);
}
showEditPopover(event, sale) { showEditPopover(event, sale) {
this.sale = sale; this.sale = sale;
this.edit = [{ this.edit = [{