Adding discount as an amount #kbcqjv
This commit is contained in:
		
							
								
								
									
										45
									
								
								resources/assets/js/views/common/documents.js
									
									
									
									
										vendored
									
									
								
							
							
						
						
									
										45
									
								
								resources/assets/js/views/common/documents.js
									
									
									
									
										vendored
									
									
								
							@@ -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;
 | 
			
		||||
@@ -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;
 | 
			
		||||
                }
 | 
			
		||||
@@ -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;
 | 
			
		||||
 | 
			
		||||
@@ -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;
 | 
			
		||||
 
 | 
			
		||||
@@ -161,11 +161,15 @@
 | 
			
		||||
                                    </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"
 | 
			
		||||
 
 | 
			
		||||
@@ -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">
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user