Skip to content

Commit

Permalink
fixed tax summary calculation issue
Browse files Browse the repository at this point in the history
  • Loading branch information
niravkrish committed Jan 28, 2019
1 parent 2258f50 commit 938eaf3
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,17 @@ define([
'Magento_Checkout/js/view/summary/abstract-total',
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/totals',
'mage/translate'
], function (ko, Component, quote, totals, $t) {
'mage/translate',
'underscore'
], function (ko, Component, quote, totals, $t, _) {
'use strict';

var isTaxDisplayedInGrandTotal = window.checkoutConfig.includeTaxInGrandTotal,
isFullTaxSummaryDisplayed = window.checkoutConfig.isFullTaxSummaryDisplayed,
isZeroTaxDisplayed = window.checkoutConfig.isZeroTaxDisplayed;
isZeroTaxDisplayed = window.checkoutConfig.isZeroTaxDisplayed,
totalPercentage = 0,
amount = '',
rates = '';

return Component.extend({
defaults: {
Expand Down Expand Up @@ -98,6 +102,31 @@ define([
return this.getFormattedPrice(amount);
},

/**
* @param {*} parent
* @param {*} percentage
* @return {*|String}
*/
getTaxAmount: function (parent, percentage) {
amount = parent.amount;
rates = parent.rates;
totalPercentage = 0;
_.each(rates, function (rate) {
totalPercentage += parseFloat(rate.percent);
});
return this.getFormattedPrice(this.getPercerntAmount(amount, totalPercentage, percentage));
},

/**
* @param {*} amount
* @param {*} totalper
* @param {*} per
* @return {*|String}
*/
getPercerntAmount: function (amount, totalper, per) {
return parseFloat((amount * per) / totalper);
},

/**
* @return {Array}
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,18 +32,16 @@
<!-- ko if: !percent -->
<th class="mark" scope="row" colspan="1" data-bind="text: title"></th>
<!-- /ko -->
<!-- ko if: $index() == 0 -->
<td class="amount" rowspan="1">
<!-- ko if: $parents[1].isCalculated() -->
<span class="price"
data-bind="text: $parents[1].formatPrice($parents[0].amount), attr: {'data-th': title, 'rowspan': $parents[0].rates.length }"></span>
<!-- /ko -->
<!-- ko ifnot: $parents[1].isCalculated() -->
<span class="not-calculated"
data-bind="text: $parents[1].formatPrice($parents[0].amount), attr: {'data-th': title, 'rowspan': $parents[0].rates.length }"></span>
<!-- /ko -->
</td>
<!-- /ko -->
<td class="amount" rowspan="1">
<!-- ko if: $parents[1].isCalculated() -->
<span class="price"
data-bind="text: $parents[1].getTaxAmount($parents[0], percent), attr: {'data-th': title, 'rowspan': $parents[0].rates.length }"></span>
<!-- /ko -->
<!-- ko ifnot: $parents[1].isCalculated() -->
<span class="not-calculated"
data-bind="text: $parents[1].getTaxAmount($parents[0], percent), attr: {'data-th': title, 'rowspan': $parents[0].rates.length }"></span>
<!-- /ko -->
</td>
</tr>
<!-- /ko -->
<!-- /ko -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,18 +43,16 @@
<!-- ko if: !percent -->
<th class="mark" scope="row" data-bind="text: title"></th>
<!-- /ko -->
<!-- ko if: $index() == 0 -->
<td class="amount">
<!-- ko if: $parents[1].isCalculated() -->
<span class="price"
data-bind="text: $parents[1].formatPrice($parents[0].amount), attr: {'data-th': title, 'rowspan': $parents[0].rates.length }"></span>
<!-- /ko -->
<!-- ko ifnot: $parents[1].isCalculated() -->
<span class="not-calculated"
data-bind="text: $parents[1].formatPrice($parents[0].amount), attr: {'data-th': title, 'rowspan': $parents[0].rates.length }"></span>
<!-- /ko -->
</td>
<!-- /ko -->
<td class="amount">
<!-- ko if: $parents[1].isCalculated() -->
<span class="price"
data-bind="text: $parents[1].getTaxAmount($parents[0], percent), attr: {'data-th': title, 'rowspan': $parents[0].rates.length }"></span>
<!-- /ko -->
<!-- ko ifnot: $parents[1].isCalculated() -->
<span class="not-calculated"
data-bind="text: $parents[1].getTaxAmount($parents[0], percent), attr: {'data-th': title, 'rowspan': $parents[0].rates.length }"></span>
<!-- /ko -->
</td>
</tr>
<!-- /ko -->
<!-- /ko -->
Expand Down

0 comments on commit 938eaf3

Please sign in to comment.