IDEMPIERE-2459 Calculated Child Taxes Amount Sum is not equal to Parent Tax Amount Sum (cause wrong grand total)
This commit is contained in:
parent
358328d0c9
commit
60244ffc97
|
|
@ -255,25 +255,33 @@ public class MTax extends X_C_Tax
|
||||||
// Null Tax
|
// Null Tax
|
||||||
if (isZeroTax())
|
if (isZeroTax())
|
||||||
return Env.ZERO;
|
return Env.ZERO;
|
||||||
|
|
||||||
BigDecimal multiplier = getRate().divide(Env.ONEHUNDRED, 12, BigDecimal.ROUND_HALF_UP);
|
|
||||||
|
|
||||||
BigDecimal tax = null;
|
MTax[] taxarray;
|
||||||
if (!taxIncluded) // $100 * 6 / 100 == $6 == $100 * 0.06
|
if (isSummary())
|
||||||
{
|
taxarray = getChildTaxes(false);
|
||||||
tax = amount.multiply (multiplier);
|
else
|
||||||
|
taxarray = new MTax[] {this};
|
||||||
|
|
||||||
|
BigDecimal tax = Env.ZERO;
|
||||||
|
for (MTax taxc : taxarray) {
|
||||||
|
BigDecimal multiplier = taxc.getRate().divide(Env.ONEHUNDRED, 12, BigDecimal.ROUND_HALF_UP);
|
||||||
|
if (!taxIncluded) // $100 * 6 / 100 == $6 == $100 * 0.06
|
||||||
|
{
|
||||||
|
BigDecimal itax = amount.multiply(multiplier).setScale(scale, BigDecimal.ROUND_HALF_UP);
|
||||||
|
tax = tax.add(itax);
|
||||||
|
}
|
||||||
|
else // $106 - ($106 / (100+6)/100) == $6 == $106 - ($106/1.06)
|
||||||
|
{
|
||||||
|
multiplier = multiplier.add(Env.ONE);
|
||||||
|
BigDecimal base = amount.divide(multiplier, 12, BigDecimal.ROUND_HALF_UP);
|
||||||
|
BigDecimal itax = amount.subtract(base).setScale(scale, BigDecimal.ROUND_HALF_UP);
|
||||||
|
tax = tax.add(itax);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else // $106 - ($106 / (100+6)/100) == $6 == $106 - ($106/1.06)
|
|
||||||
{
|
|
||||||
multiplier = multiplier.add(Env.ONE);
|
|
||||||
BigDecimal base = amount.divide(multiplier, 12, BigDecimal.ROUND_HALF_UP);
|
|
||||||
tax = amount.subtract(base);
|
|
||||||
}
|
|
||||||
BigDecimal finalTax = tax.setScale(scale, BigDecimal.ROUND_HALF_UP);
|
|
||||||
if (log.isLoggable(Level.FINE)) log.fine("calculateTax " + amount
|
if (log.isLoggable(Level.FINE)) log.fine("calculateTax " + amount
|
||||||
+ " (incl=" + taxIncluded + ",mult=" + multiplier + ",scale=" + scale
|
+ " (incl=" + taxIncluded + ",scale=" + scale
|
||||||
+ ") = " + finalTax + " [" + tax + "]");
|
+ ") = " + tax + " [" + tax + "]");
|
||||||
return finalTax;
|
return tax;
|
||||||
} // calculateTax
|
} // calculateTax
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue