Skip to content

Commit

Permalink
Adding discount as an amount #kbcqjv
Browse files Browse the repository at this point in the history
  • Loading branch information
burakcakirel committed Aug 11, 2021
1 parent 5114367 commit 8d87832
Show file tree
Hide file tree
Showing 3 changed files with 60 additions and 20 deletions.
45 changes: 38 additions & 7 deletions resources/assets/js/views/common/documents.js
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,12 @@ const app = new Vue({
let line_discount_amount = 0;

if (item.discount) {
line_discount_amount = item.total * (item.discount / 100);
if (item.discount_type === 'percentage') {
line_discount_amount = item.total * (item.discount / 100);
} else {
line_discount_amount = item.discount;
}

item.discount_amount = line_discount_amount

item_discounted_total = item.total -= line_discount_amount;
Expand All @@ -126,7 +131,11 @@ const app = new Vue({
let item_discounted_total = item.total;

if (global_discount) {
item_discounted_total = item.total - (item.total * (global_discount / 100));
if (this.form.discount_type === 'percentage') {
item_discounted_total = item.total - (item.total * (global_discount / 100));
} else {
item_discounted_total = item.total - global_discount;
}

item_discount = global_discount;
}
Expand Down Expand Up @@ -241,7 +250,11 @@ const app = new Vue({

// Apply discount to total
if (global_discount) {
discount_total = parseFloat(sub_total + inclusive_tax_total) * (global_discount / 100);
if (this.form.discount_type === 'percentage') {
discount_total = parseFloat(sub_total + inclusive_tax_total) * (global_discount / 100);
} else {
discount_total = global_discount;
}

this.totals.discount = discount_total;

Expand Down Expand Up @@ -389,13 +402,31 @@ const app = new Vue({
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() {
let discount = document.getElementById('pre-discount').value;

if (discount < 0) {
discount = 0;
} else if (discount > 100) {
discount = 100;
if (this.form.discount_type === 'percentage') {
if (discount < 0) {
discount = 0;
} else if (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;
Expand Down
18 changes: 11 additions & 7 deletions resources/views/components/documents/form/line-item.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ class="form-control"
@if (!$hideQuantity)
<div>
@stack('quantity_input_start')
<input
<input
type="number"
min="0"
class="form-control text-center p-0 input-number-disabled"
Expand Down Expand Up @@ -161,11 +161,15 @@ class="form-control text-center p-0 input-number-disabled"
</div>
@stack('discount_input_start')
<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">
<span class="input-group-text" id="input-discount">
<i class="fa fa-percent"></i>
</span>
<button class="btn btn-sm" :class="[{'btn-outline-primary' : row.discount_type !== 'percentage'}, {'btn-primary' : row.discount_type === 'percentage'}]"
@click="onChangeLineDiscountType(index, 'percentage')" type="button">
<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>
<input type="number"
max="100"
Expand Down Expand Up @@ -227,7 +231,7 @@ class="mb-0 select-tax"
></akaunting-select>
@stack('taxes_input_end')
</div>

<div class="line-item-content-right">
<div class="line-item-content-right-price long-texts text-right">
{{ Form::moneyGroup('tax', '', '', ['required' => 'required', 'disabled' => 'true' , 'row-input' => 'true', 'v-model' => 'row_tax.price', 'data-item' => 'total', 'currency' => $currency, 'dynamic-currency' => 'currency'], 0.00, 'text-right input-price disabled-money') }}
Expand All @@ -242,7 +246,7 @@ class="mb-0 select-tax"
<div v-if="row.add_tax" class="line-item-area pb-3" :class="{'pt-2' : row.add_discount}">
<div class="line-item-content">
<div class="long-texts line-item-text" style="float: left; margin-top: 15px; margin-right:2px; position: absolute; left: -63px;">
{{ trans_choice('general.taxes', 1) }}
{{ trans_choice('general.taxes', 1) }}
</div>

@stack('taxes_input_start')
Expand Down
17 changes: 11 additions & 6 deletions resources/views/components/documents/form/totals.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -54,22 +54,27 @@
<div class="card d-none" :class="[{'show' : discount}]">
<div class="discount card-body">
<div class="row align-items-center">
<div class="col-sm-6">
<div class="input-group input-group-merge">
<div class="col-sm-8">
<div class="input-group">
<div class="input-group-prepend">
<span class="input-group-text" id="input-discount">
<i class="fa fa-percent"></i>
</span>
<button class="btn btn-sm" :class="[{'btn-outline-primary' : form.discount_type !== 'percentage'}, {'btn-primary' : form.discount_type === 'percentage'}]"
@click="onChangeDiscountType('percentage')" type="button">
<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>
{!! Form::number('pre_discount', null, ['id' => 'pre-discount', 'class' => 'form-control', 'v-model' => 'form.discount']) !!}
</div>
</div>
<div class="col-sm-6">
<div class="col-sm-4">
<div class="discount-description">
<strong>{{ trans('invoices.discount_desc') }}</strong>
</div>
</div>
</div>
</div>
</div>
<div class="discount card-footer">
<div class="row float-right">
Expand Down

0 comments on commit 8d87832

Please sign in to comment.