Adding discount as an amount #kbcqjv
This commit is contained in:
31
resources/assets/js/views/common/documents.js
vendored
31
resources/assets/js/views/common/documents.js
vendored
@ -116,7 +116,12 @@ const app = new Vue({
|
|||||||
let line_discount_amount = 0;
|
let line_discount_amount = 0;
|
||||||
|
|
||||||
if (item.discount) {
|
if (item.discount) {
|
||||||
|
if (item.discount_type === 'percentage') {
|
||||||
line_discount_amount = item.total * (item.discount / 100);
|
line_discount_amount = item.total * (item.discount / 100);
|
||||||
|
} else {
|
||||||
|
line_discount_amount = item.discount;
|
||||||
|
}
|
||||||
|
|
||||||
item.discount_amount = line_discount_amount
|
item.discount_amount = line_discount_amount
|
||||||
|
|
||||||
item_discounted_total = item.total -= line_discount_amount;
|
item_discounted_total = item.total -= line_discount_amount;
|
||||||
@ -126,7 +131,11 @@ const app = new Vue({
|
|||||||
let item_discounted_total = item.total;
|
let item_discounted_total = item.total;
|
||||||
|
|
||||||
if (global_discount) {
|
if (global_discount) {
|
||||||
|
if (this.form.discount_type === 'percentage') {
|
||||||
item_discounted_total = item.total - (item.total * (global_discount / 100));
|
item_discounted_total = item.total - (item.total * (global_discount / 100));
|
||||||
|
} else {
|
||||||
|
item_discounted_total = item.total - global_discount;
|
||||||
|
}
|
||||||
|
|
||||||
item_discount = global_discount;
|
item_discount = global_discount;
|
||||||
}
|
}
|
||||||
@ -241,7 +250,11 @@ const app = new Vue({
|
|||||||
|
|
||||||
// Apply discount to total
|
// Apply discount to total
|
||||||
if (global_discount) {
|
if (global_discount) {
|
||||||
|
if (this.form.discount_type === 'percentage') {
|
||||||
discount_total = parseFloat(sub_total + inclusive_tax_total) * (global_discount / 100);
|
discount_total = parseFloat(sub_total + inclusive_tax_total) * (global_discount / 100);
|
||||||
|
} else {
|
||||||
|
discount_total = global_discount;
|
||||||
|
}
|
||||||
|
|
||||||
this.totals.discount = discount_total;
|
this.totals.discount = discount_total;
|
||||||
|
|
||||||
@ -389,14 +402,32 @@ const app = new Vue({
|
|||||||
this.items[item_index].add_discount = true;
|
this.items[item_index].add_discount = true;
|
||||||
},
|
},
|
||||||
|
|
||||||
|
onChangeDiscountType(type) {
|
||||||
|
this.form.discount_type = type;
|
||||||
|
this.onCalculateTotal();
|
||||||
|
},
|
||||||
|
|
||||||
|
onChangeLineDiscountType(item_index, type) {
|
||||||
|
this.items[item_index].discount_type = type;
|
||||||
|
this.onCalculateTotal();
|
||||||
|
},
|
||||||
|
|
||||||
onAddTotalDiscount() {
|
onAddTotalDiscount() {
|
||||||
let discount = document.getElementById('pre-discount').value;
|
let discount = document.getElementById('pre-discount').value;
|
||||||
|
|
||||||
|
if (this.form.discount_type === 'percentage') {
|
||||||
if (discount < 0) {
|
if (discount < 0) {
|
||||||
discount = 0;
|
discount = 0;
|
||||||
} else if (discount > 100) {
|
} else if (discount > 100) {
|
||||||
discount = 100;
|
discount = 100;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
if (discount < 0) {
|
||||||
|
discount = 0;
|
||||||
|
} else if (discount > this.totals.sub) {
|
||||||
|
discount = this.totals.sub;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
document.getElementById('pre-discount').value = discount;
|
document.getElementById('pre-discount').value = discount;
|
||||||
|
|
||||||
|
@ -161,11 +161,15 @@
|
|||||||
</div>
|
</div>
|
||||||
@stack('discount_input_start')
|
@stack('discount_input_start')
|
||||||
<div class="form-group mb-0 w-100" style="display: inline-block; position: relative;">
|
<div class="form-group mb-0 w-100" style="display: inline-block; position: relative;">
|
||||||
<div class="input-group input-group-merge mb-0 select-tax">
|
<div class="input-group mb-0 select-tax">
|
||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<span class="input-group-text" id="input-discount">
|
<button class="btn btn-sm" :class="[{'btn-outline-primary' : row.discount_type !== 'percentage'}, {'btn-primary' : row.discount_type === 'percentage'}]"
|
||||||
<i class="fa fa-percent"></i>
|
@click="onChangeLineDiscountType(index, 'percentage')" type="button">
|
||||||
</span>
|
<i class="fa fa-percent fa-sm"></i>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-sm" :class="[{'btn-outline-primary' : row.discount_type !== 'amount'}, {'btn-primary' : row.discount_type === 'amount'}]"
|
||||||
|
@click="onChangeLineDiscountType(index, 'amount')" type="button">{{ $currency->symbol }}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<input type="number"
|
<input type="number"
|
||||||
max="100"
|
max="100"
|
||||||
|
@ -54,23 +54,28 @@
|
|||||||
<div class="card d-none" :class="[{'show' : discount}]">
|
<div class="card d-none" :class="[{'show' : discount}]">
|
||||||
<div class="discount card-body">
|
<div class="discount card-body">
|
||||||
<div class="row align-items-center">
|
<div class="row align-items-center">
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-8">
|
||||||
<div class="input-group input-group-merge">
|
<div class="input-group">
|
||||||
<div class="input-group-prepend">
|
<div class="input-group-prepend">
|
||||||
<span class="input-group-text" id="input-discount">
|
<button class="btn btn-sm" :class="[{'btn-outline-primary' : form.discount_type !== 'percentage'}, {'btn-primary' : form.discount_type === 'percentage'}]"
|
||||||
<i class="fa fa-percent"></i>
|
@click="onChangeDiscountType('percentage')" type="button">
|
||||||
</span>
|
<i class="fa fa-percent fa-sm"></i>
|
||||||
|
</button>
|
||||||
|
<button class="btn btn-sm" :class="[{'btn-outline-primary' : form.discount_type !== 'amount'}, {'btn-primary' : form.discount_type === 'amount'}]"
|
||||||
|
@click="onChangeDiscountType('amount')" type="button">{{ $currency->symbol }}
|
||||||
|
</button>
|
||||||
</div>
|
</div>
|
||||||
{!! Form::number('pre_discount', null, ['id' => 'pre-discount', 'class' => 'form-control', 'v-model' => 'form.discount']) !!}
|
{!! Form::number('pre_discount', null, ['id' => 'pre-discount', 'class' => 'form-control', 'v-model' => 'form.discount']) !!}
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="col-sm-6">
|
<div class="col-sm-4">
|
||||||
<div class="discount-description">
|
<div class="discount-description">
|
||||||
<strong>{{ trans('invoices.discount_desc') }}</strong>
|
<strong>{{ trans('invoices.discount_desc') }}</strong>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
<div class="discount card-footer">
|
<div class="discount card-footer">
|
||||||
<div class="row float-right">
|
<div class="row float-right">
|
||||||
<div class="col-xs-12 col-sm-12">
|
<div class="col-xs-12 col-sm-12">
|
||||||
|
Reference in New Issue
Block a user