Skip to content

Commit

Permalink
[Backport] Full Tax Summary display wrong numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
mage2pratik committed Feb 18, 2019
1 parent 994348f commit 8825752
Show file tree
Hide file tree
Showing 3 changed files with 53 additions and 27 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,16 @@ define([
'Magento_Checkout/js/model/quote',
'Magento_Checkout/js/model/totals',
'jquery',
'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,
taxAmount = 0,
rates = 0;

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

/**
* @param {*} parent
* @param {*} percentage
* @return {*|String}
*/
getTaxAmount: function (parent, percentage) {
var totalPercentage = 0;

taxAmount = parent.amount;
rates = parent.rates;
_.each(rates, function (rate) {
totalPercentage += parseFloat(rate.percent);
});

return this.getFormattedPrice(this.getPercentAmount(taxAmount, totalPercentage, percentage));
},

/**
* @param {*} amount
* @param {*} totalPercentage
* @param {*} percentage
* @return {*|String}
*/
getPercentAmount: function (amount, totalPercentage, percentage) {
return parseFloat(amount * percentage / totalPercentage);
},

/**
* @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 8825752

Please sign in to comment.