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