diff --git a/resources/assets/js/views/common/documents.js b/resources/assets/js/views/common/documents.js
index 9fc970c6d..e791afd17 100644
--- a/resources/assets/js/views/common/documents.js
+++ b/resources/assets/js/views/common/documents.js
@@ -65,14 +65,14 @@ const app = new Vue({
methods: {
onCalculateTotal() {
- let global_discount = this.discount;
+ let global_discount = this.form.discount;
let discount_total = 0;
let line_item_discount_total = 0;
let taxes = document_taxes;
let sub_total = 0;
let totals_taxes = [];
let grand_total = 0;
-
+
// items calculate
this.items.forEach(function(item, index) {
let item_discount = 0;
@@ -188,16 +188,16 @@ const app = new Vue({
}
- // calculate sub, tax, discount all items.
+ // set item total
+ if (item.discount) {
+ item.grand_total = item_discounted_total;
+ }
+
+ // calculate sub, tax, discount all items.
line_item_discount_total += line_discount_amount;
sub_total += item.total;
grand_total += item.grand_total;
- // set item total
- if (item.discount) {
- item.total = item_discounted_total;
- }
-
this.form.items[index].name = item.name;
this.form.items[index].description = item.description;
this.form.items[index].quantity = item.quantity;
@@ -207,15 +207,13 @@ const app = new Vue({
}, this);
// Apply discount to total
- /*
- if (discount_in_totals) {
- discount_total = sub_total * (discount_in_totals / 100);
+ if (global_discount) {
+ discount_total = sub_total * (global_discount / 100);
this.totals.discount = discount_total;
- sub_total = sub_total - (sub_total * (discount_in_totals / 100));
+ grand_total = sub_total - (sub_total * (global_discount / 100));
}
- */
this.totals.item_discount = line_item_discount_total;
this.totals.sub = sub_total;
@@ -333,10 +331,27 @@ const app = new Vue({
this.onCalculateTotal();
},
- onAddDiscount(item_index) {
+ onAddLineDiscount(item_index) {
this.items[item_index].add_discount = true;
},
+ onAddTotalDiscount() {
+ let discount = document.getElementById('pre-discount').value;
+
+ if (discount < 0) {
+ discount = 0;
+ } else if (discount > 100) {
+ discount = 100;
+ }
+
+ document.getElementById('pre-discount').value = discount;
+
+ this.form.discount = discount;
+ this.discount = false;
+
+ this.onCalculateTotal();
+ },
+
onDeleteDiscount(item_index) {
this.items[item_index].add_discount = false;
},
@@ -503,9 +518,9 @@ const app = new Vue({
this.taxes[tax_id].push(item.id);
} else {
this.taxes.push(tax_id);
-
+
this.taxes[tax_id] = [];
-
+
this.taxes[tax_id].push(item.id);
}
}, this);
diff --git a/resources/views/components/documents/form/items.blade.php b/resources/views/components/documents/form/items.blade.php
index 5fb9ebd9e..7b6b9cbb1 100644
--- a/resources/views/components/documents/form/items.blade.php
+++ b/resources/views/components/documents/form/items.blade.php
@@ -13,11 +13,6 @@
- @if (!$hideDiscount)
- @if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both']))
-
- @endif
- @endif
@@ -57,16 +52,6 @@
@endif
@stack('price_th_end')
- @if (!$hideDiscount)
- @if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both']))
- @stack('discount_th_start')
-
- {{ trans('invoices.discount') }}
- |
- @stack('discount_th_end')
- @endif
- @endif
-
@stack('total_th_start')
@if (!$hideAmount)
diff --git a/resources/views/components/documents/form/line-item.blade.php b/resources/views/components/documents/form/line-item.blade.php
index de88f348e..7eeb02e79 100644
--- a/resources/views/components/documents/form/line-item.blade.php
+++ b/resources/views/components/documents/form/line-item.blade.php
@@ -2,7 +2,7 @@
:index="index">
@stack('name_td_start')
|
@@ -11,11 +11,6 @@
- @if (!$hideDiscount)
- @if (in_array(setting('localisation.discount_location', 'total'), ['item', 'both']))
-
- @endif
- @endif
@@ -46,7 +41,7 @@
v-model="row.name"
@input="onBindingItemField(index, 'name')"
@change="form.errors.clear('items.' + index + '.name')">
-
+
@@ -58,9 +53,9 @@
@stack('name_td_end')
@stack('description_td_start')
- @if (!$hideDescription)
+ @if (!$hideDescription)
- |
-
+ |
@@ -185,11 +146,11 @@
- @if (!$hideDiscount && in_array(setting('localisation.discount_location', 'total'), ['item', 'both']))
+ @if (!$hideDiscount && in_array(setting('localisation.discount_location'), ['item', 'both']))
-
+
|
@@ -210,7 +171,7 @@
@stack('discount_input_start')
@stack('discount_input_end')
@@ -236,7 +197,7 @@
|
- {{ Form::moneyGroup('discount', '', '', ['required' => 'required', 'disabled' => 'true' , 'row-input' => 'true', 'v-model' => 'row.discount', 'data-item' => 'discount', 'currency' => $currency, 'dynamic-currency' => 'currency'], 0.00, 'text-right input-price disabled-money') }}
+ {{ Form::moneyGroup('discount', '', '', ['required' => 'required', 'disabled' => 'true' , 'row-input' => 'true', 'value' => 'row.discount', 'data-item' => 'discount', 'currency' => $currency, 'dynamic-currency' => 'currency'], 0.00, 'text-right input-price disabled-money') }}
|
@@ -342,10 +303,10 @@
|
- @if (!$hideDiscount && in_array(setting('localisation.discount_location', 'total'), ['item', 'both']))
-
+
@endif
|
diff --git a/resources/views/components/documents/form/totals.blade.php b/resources/views/components/documents/form/totals.blade.php
index f471fd644..58156ee12 100644
--- a/resources/views/components/documents/form/totals.blade.php
+++ b/resources/views/components/documents/form/totals.blade.php
@@ -77,7 +77,7 @@
{{ trans('general.cancel') }}
- {!! Form::button(trans('general.save'), ['type' => 'button', 'id' => 'save-discount', '@click' => 'onAddDiscount', 'class' => 'btn btn-success']) !!}
+ {!! Form::button(trans('general.save'), ['type' => 'button', 'id' => 'save-discount', '@click' => 'onAddTotalDiscount', 'class' => 'btn btn-success']) !!}
@@ -133,7 +133,7 @@
|
-
-
\ No newline at end of file
+
| | |