Fixes
gitea/salix/pipeline/head There was a failure building this commit Details

This commit is contained in:
Joan Sanchez 2020-06-23 16:39:20 +02:00
parent d4c78b46c1
commit a8377950f5
2 changed files with 21 additions and 17 deletions

View File

@ -53,9 +53,9 @@
</vn-button> </vn-button>
</vn-tool-bar> </vn-tool-bar>
<vn-one class="taxes" ng-if="$ctrl.sales.length > 0"> <vn-one class="taxes" ng-if="$ctrl.sales.length > 0">
<p><vn-label translate>Subtotal</vn-label> {{$ctrl.subtotal | currency: 'EUR':2}}</p> <p><vn-label translate>Subtotal</vn-label> {{$ctrl.subtotal | currency: 'EUR': 2}}</p>
<p><vn-label translate>VAT</vn-label> {{$ctrl.VAT | currency: 'EUR':2}}</p> <p><vn-label translate>VAT</vn-label> {{$ctrl.VAT | currency: 'EUR': 2}}</p>
<p><vn-label><strong>Total</strong></vn-label> <strong>{{$ctrl.total | currency: 'EUR':2}}</strong></p> <p><vn-label><strong>Total</strong></vn-label> <strong>{{$ctrl.total | currency: 'EUR': 2}}</strong></p>
</vn-one> </vn-one>
</vn-horizontal> </vn-horizontal>
<vn-table model="model"> <vn-table model="model">

View File

@ -69,11 +69,11 @@ class Controller extends Section {
} }
refreshTotal() { refreshTotal() {
this.loadSubTotal(); this.getSubTotal();
this.loadVAT(); this.getVat();
} }
loadSubTotal() { getSubTotal() {
if (!this.$params.id || !this.sales) return; if (!this.$params.id || !this.sales) return;
this.$http.get(`Tickets/${this.$params.id}/subtotal`).then(res => { this.$http.get(`Tickets/${this.$params.id}/subtotal`).then(res => {
this.subtotal = res.data || 0.0; this.subtotal = res.data || 0.0;
@ -81,13 +81,16 @@ class Controller extends Section {
} }
getSaleTotal(sale) { getSaleTotal(sale) {
if (!sale.quantity || !sale.price) if (sale.quantity == null || sale.price == null)
return; return null;
return sale.quantity * sale.price * ((100 - sale.discount) / 100); const price = sale.quantity * sale.price;
const discount = (sale.discount * price) / 100;
return price - discount;
} }
loadVAT() { getVat() {
this.VAT = 0.0; this.VAT = 0.0;
if (!this.$params.id || !this.sales) return; if (!this.$params.id || !this.sales) return;
this.$http.get(`Tickets/${this.$params.id}/getVAT`).then(res => { this.$http.get(`Tickets/${this.$params.id}/getVAT`).then(res => {
@ -320,9 +323,10 @@ class Controller extends Section {
updatePrice() { updatePrice() {
const sale = this.edit.sale; const sale = this.edit.sale;
if (this.edit.price != sale.price) { const newPrice = this.edit.price;
if (newPrice != null && newPrice != sale.price) {
const query = `Sales/${sale.id}/updatePrice`; const query = `Sales/${sale.id}/updatePrice`;
this.$http.post(query, {newPrice: this.edit.price}).then(res => { this.$http.post(query, {newPrice}).then(res => {
sale.price = res.data.price; sale.price = res.data.price;
this.vnApp.showSuccess(this.$t('Data saved!')); this.vnApp.showSuccess(this.$t('Data saved!'));
@ -363,7 +367,8 @@ class Controller extends Section {
changeDiscount() { changeDiscount() {
const sale = this.edit.sale; const sale = this.edit.sale;
if (this.edit.discount != sale.discount) const newDiscount = this.edit.discount;
if (newDiscount != null && newDiscount != sale.discount)
this.updateDiscount([sale]); this.updateDiscount([sale]);
this.$.editDiscount.hide(); this.$.editDiscount.hide();
@ -371,13 +376,12 @@ class Controller extends Section {
changeMultipleDiscount() { changeMultipleDiscount() {
const sales = this.edit.sales; const sales = this.edit.sales;
const newDiscount = this.edit.discount;
const hasChanges = sales.some(sale => { const hasChanges = sales.some(sale => {
return sale.discount != this.edit.discount; return sale.discount != newDiscount;
}); });
console.log(hasChanges); if (newDiscount != null && hasChanges)
if (hasChanges)
this.updateDiscount(sales); this.updateDiscount(sales);
this.$.editDiscountDialog.hide(); this.$.editDiscountDialog.hide();