Add "Item Discount" line in totals

This commit is contained in:
Burak Çakırel
2020-03-24 21:37:08 +03:00
parent 100fc2c07c
commit 3f068ec979
12 changed files with 189 additions and 42 deletions

View File

@@ -32,6 +32,7 @@ const app = new Vue({
bulk_action: new BulkAction('bills'),
totals: {
sub: 0,
item_discount: '',
discount: '',
discount_text: false,
tax: 0,
@@ -107,6 +108,7 @@ const app = new Vue({
onCalculateTotal() {
let sub_total = 0;
let discount_total = 0;
let item_discount_total = 0;
let tax_total = 0;
let grand_total = 0;
let items = this.form.items;
@@ -122,18 +124,21 @@ const app = new Vue({
let item = items[index];
// item sub total calcute.
let item_sub_total = item.price * item.quantity;
let item_total = item.price * item.quantity;
// item discount calculate.
let item_discounted_total = item_sub_total;
let item_discounted_total = item_total;
if (discount_in_totals) {
item_discounted_total = item_sub_total - (item_sub_total * (discount_in_totals / 100));
item_discounted_total = item_total - (item_total * (discount_in_totals / 100));
discount = discount_in_totals;
}
let discount_amount = 0;
if (item.discount) {
item_discounted_total = item_sub_total = item_sub_total - (item_sub_total * (item.discount / 100));
discount_amount = item_total * (item.discount / 100);
item_discounted_total = item_total - discount_amount;
discount = item.discount;
}
@@ -186,7 +191,7 @@ const app = new Vue({
item_tax_total = item_sub_and_tax_total - item_base_rate;
item_sub_total = item_base_rate + discount;
item_total = item_base_rate + discount;
}
if (compounds.length) {
@@ -197,10 +202,15 @@ const app = new Vue({
}
// set item total
items[index].total = item_sub_total;
if (item.discount) {
items[index].total = item_discounted_total;
} else {
items[index].total = item_total;
}
// calculate sub, tax, discount all items.
sub_total += item_sub_total;
item_discount_total += discount_amount;
sub_total += item_total;
tax_total += item_tax_total;
}
}
@@ -208,6 +218,9 @@ const app = new Vue({
// set global total variable.
this.totals.sub = sub_total;
this.totals.tax = tax_total;
this.totals.item_discount = item_discount_total;
sub_total -= item_discount_total;
// Apply discount to total
if (discount_in_totals) {

View File

@@ -32,6 +32,7 @@ const app = new Vue({
bulk_action: new BulkAction('invoices'),
totals: {
sub: 0,
item_discount: '',
discount: '',
discount_text: false,
tax: 0,
@@ -107,6 +108,7 @@ const app = new Vue({
onCalculateTotal() {
let sub_total = 0;
let discount_total = 0;
let item_discount_total = 0;
let tax_total = 0;
let grand_total = 0;
let items = this.form.items;
@@ -122,18 +124,21 @@ const app = new Vue({
let item = items[index];
// item sub total calcute.
let item_sub_total = item.price * item.quantity;
let item_total = item.price * item.quantity;
// item discount calculate.
let item_discounted_total = item_sub_total;
let item_discounted_total = item_total;
if (discount_in_totals) {
item_discounted_total = item_sub_total - (item_sub_total * (discount_in_totals / 100));
item_discounted_total = item_total - (item_total * (discount_in_totals / 100));
discount = discount_in_totals;
}
let discount_amount = 0;
if (item.discount) {
item_discounted_total = item_sub_total = item_sub_total - (item_sub_total * (item.discount / 100));
discount_amount = item_total * (item.discount / 100);
item_discounted_total = item_total - discount_amount;
discount = item.discount;
}
@@ -186,7 +191,7 @@ const app = new Vue({
item_tax_total = item_sub_and_tax_total - item_base_rate;
item_sub_total = item_base_rate + discount;
item_total = item_base_rate + discount;
}
if (compounds.length) {
@@ -197,10 +202,15 @@ const app = new Vue({
}
// set item total
items[index].total = item_sub_total;
if (item.discount) {
items[index].total = item_discounted_total;
} else {
items[index].total = item_total;
}
// calculate sub, tax, discount all items.
sub_total += item_sub_total;
item_discount_total += discount_amount;
sub_total += item_total;
tax_total += item_tax_total;
}
}
@@ -208,6 +218,9 @@ const app = new Vue({
// set global total variable.
this.totals.sub = sub_total;
this.totals.tax = tax_total;
this.totals.item_discount = item_discount_total;
sub_total -= item_discount_total;
// Apply discount to total
if (discount_in_totals) {

View File

@@ -13,6 +13,7 @@ return [
'price' => 'Price',
'sub_total' => 'Subtotal',
'discount' => 'Discount',
'item_discount' => 'Item Discount',
'tax_total' => 'Tax Total',
'total' => 'Total',

View File

@@ -13,6 +13,7 @@ return [
'price' => 'Price',
'sub_total' => 'Subtotal',
'discount' => 'Discount',
'item_discount' => 'Item Discount',
'tax_total' => 'Tax Total',
'total' => 'Total',

View File

@@ -90,6 +90,19 @@
</tr>
@stack('sub_total_td_end')
@stack('item_discount_td_start')
<tr id="tr-subtotal">
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">
<strong>{{ trans('bills.item_discount') }}</strong>
</td>
<td class="text-right border-bottom-0 long-texts">
{{ Form::moneyGroup('item_discount', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.item_discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }}
<span id="item-discount" v-if="totals.item_discount" v-html="totals.item_discount"></span>
<span v-else>@money(0, $currency->code, true)</span>
</td>
</tr>
@stack('item_discount_td_end')
@stack('add_discount_td_start')
<tr id="tr-discount">
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">

View File

@@ -90,9 +90,22 @@
</tr>
@stack('sub_total_td_end')
@stack('item_discount_td_start')
<tr id="tr-subtotal">
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">
<strong>{{ trans('invoices.item_discount') }}</strong>
</td>
<td class="text-right border-bottom-0 long-texts">
{{ Form::moneyGroup('item_discount', '', '', ['disabled' => true, 'required' => 'required', 'v-model' => 'totals.item_discount', 'currency' => $currency, 'masked' => 'true'], 0.00, 'text-right d-none') }}
<span id="item-discount" v-if="totals.item_discount" v-html="totals.item_discount"></span>
<span v-else>@money(0, $currency->code, true)</span>
</td>
</tr>
@stack('item_discount_td_end')
@stack('add_discount_td_start')
<tr id="tr-discount">
<td class="text-right border-right-0 border-bottom-0" colspan="5" :colspan="colspan">
<td class="text-right border-right-0 border-bottom-0" colspan="6" :colspan="colspan">
<el-popover
popper-class="p-0 h-0"
placement="bottom"