From 326d2ae875bccb71cfffe79c7de737207d5b0526 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=BCneyt=20=C5=9Eent=C3=BCrk?= Date: Thu, 16 Jun 2022 12:37:15 +0300 Subject: [PATCH] Document discount calculate issue fixed ( #31zyb44 ) --- resources/assets/js/views/common/documents.js | 35 +++++++++++++++++-- .../documents/form/totals.blade.php | 2 +- 2 files changed, 34 insertions(+), 3 deletions(-) diff --git a/resources/assets/js/views/common/documents.js b/resources/assets/js/views/common/documents.js index ad08dbd63..4c16b4348 100644 --- a/resources/assets/js/views/common/documents.js +++ b/resources/assets/js/views/common/documents.js @@ -68,7 +68,13 @@ const app = new Vue({ dynamic_taxes: [], show_discount: false, show_discount_text: true, - delete_discount: false + delete_discount: false, + regex_condition: [ + '..', + '.,', + ',.', + ',,' + ], } }, @@ -488,11 +494,14 @@ const app = new Vue({ onChangeDiscountType(type) { this.form.discount_type = type; + + this.onAddTotalDiscount(); this.onCalculateTotal(); }, onChangeLineDiscountType(item_index, type) { this.items[item_index].discount_type = type; + this.onCalculateTotal(); }, @@ -1062,5 +1071,27 @@ const app = new Vue({ } this.page_loaded = true; - } + }, + + watch: { + 'form.discount': function (newVal, oldVal) { + if (newVal != '' && newVal.search('^(?=.*?[0-9])[0-9.,]+$') !== 0) { + this.form.discount = oldVal; + this.form.discount = this.form.discount.replace(',', '.'); + + return; + } + + for (let item of this.regex_condition) { + if (this.form.discount.includes(item)) { + const removeLastChar = newVal.length - 1; + const inputShown = newVal.slice(0, removeLastChar); + + this.form.discount = inputShown; + } + } + + this.form.discount = this.form.discount.replace(',', '.'); + }, + }, }); diff --git a/resources/views/components/documents/form/totals.blade.php b/resources/views/components/documents/form/totals.blade.php index 682cf9320..f603b362c 100644 --- a/resources/views/components/documents/form/totals.blade.php +++ b/resources/views/components/documents/form/totals.blade.php @@ -106,7 +106,7 @@ - +