Revert previous change.
Instead, calculate the total amounts on amounts with scale 2 to avoid errors in validation.
This commit is contained in:
@@ -1,8 +1,11 @@
|
|||||||
package org.mustangproject.ZUGFeRD;
|
package org.mustangproject.ZUGFeRD;
|
||||||
|
|
||||||
|
import static java.math.BigDecimal.ZERO;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.math.RoundingMode;
|
import java.math.RoundingMode;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
import java.util.stream.Stream;
|
||||||
|
|
||||||
/***
|
/***
|
||||||
* The Transactioncalculator e.g. adds the line totals and applies VAT on whole invoices
|
* The Transactioncalculator e.g. adds the line totals and applies VAT on whole invoices
|
||||||
@@ -27,7 +30,7 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
|||||||
if (trans.getTotalPrepaidAmount() == null) {
|
if (trans.getTotalPrepaidAmount() == null) {
|
||||||
return BigDecimal.ZERO;
|
return BigDecimal.ZERO;
|
||||||
} else {
|
} else {
|
||||||
return trans.getTotalPrepaidAmount();
|
return trans.getTotalPrepaidAmount().setScale(2, RoundingMode.HALF_UP);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -37,13 +40,11 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
|||||||
*/
|
*/
|
||||||
public BigDecimal getGrandTotal() {
|
public BigDecimal getGrandTotal() {
|
||||||
|
|
||||||
BigDecimal res = getTaxBasis();
|
final BigDecimal res = getTaxBasis();
|
||||||
HashMap<BigDecimal, VATAmount> VATPercentAmountMap = getVATPercentAmountMap();
|
return getVATPercentAmountMap().values().stream()
|
||||||
for (BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) {
|
.map(VATAmount::getCalculated)
|
||||||
VATAmount amount = VATPercentAmountMap.get(currentTaxPercent);
|
.map(p -> p.setScale(2, RoundingMode.HALF_UP))
|
||||||
res = res.add(amount.getCalculated());
|
.reduce(BigDecimal.ZERO, BigDecimal::add).add(res);
|
||||||
}
|
|
||||||
return res.setScale(2, RoundingMode.HALF_UP);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
@@ -86,11 +87,10 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
|||||||
String res = " ";
|
String res = " ";
|
||||||
if ((charges != null) && (charges.length > 0)) {
|
if ((charges != null) && (charges.length > 0)) {
|
||||||
for (IZUGFeRDAllowanceCharge currentCharge : charges) {
|
for (IZUGFeRDAllowanceCharge currentCharge : charges) {
|
||||||
if ((percent==null)||(currentCharge.getTaxPercent().compareTo(percent)==0)) {
|
if ((percent==null)||(currentCharge.getTaxPercent().compareTo(percent)==0)
|
||||||
if (currentCharge.getReason()!=null) {
|
&& currentCharge.getReason()!=null) {
|
||||||
res = res+currentCharge.getReason()+" ";
|
res += currentCharge.getReason()+" ";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
res=res.substring(0,res.length()-1);
|
res=res.substring(0,res.length()-1);
|
||||||
@@ -127,12 +127,10 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
|||||||
* @return item sum
|
* @return item sum
|
||||||
*/
|
*/
|
||||||
protected BigDecimal getTotal() {
|
protected BigDecimal getTotal() {
|
||||||
BigDecimal res = BigDecimal.ZERO;
|
return Stream.of(trans.getZFItems())
|
||||||
for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) {
|
.map(LineCalculator::new)
|
||||||
LineCalculator lc = new LineCalculator(currentItem);
|
.map(LineCalculator::getItemTotalNetAmount)
|
||||||
res = res.add(lc.getItemTotalNetAmount());
|
.reduce(ZERO, BigDecimal::add);
|
||||||
}
|
|
||||||
return res;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/***
|
/***
|
||||||
@@ -142,7 +140,7 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
|||||||
*/
|
*/
|
||||||
protected BigDecimal getTaxBasis() {
|
protected BigDecimal getTaxBasis() {
|
||||||
BigDecimal res = getTotal().add(getChargesForPercent(null)).subtract(getAllowancesForPercent(null));
|
BigDecimal res = getTotal().add(getChargesForPercent(null)).subtract(getAllowancesForPercent(null));
|
||||||
return res;
|
return res.setScale(2, RoundingMode.HALF_UP);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -199,7 +197,6 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
return hm;
|
return hm;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -613,10 +613,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider {
|
|||||||
// //
|
// //
|
||||||
// currencyID=\"EUR\"
|
// currencyID=\"EUR\"
|
||||||
+ " <ram:TaxTotalAmount currencyID=\"" + trans.getCurrency() + "\">"
|
+ " <ram:TaxTotalAmount currencyID=\"" + trans.getCurrency() + "\">"
|
||||||
+ currencyFormat(VATPercentAmountMap.values().stream()
|
+ currencyFormat(calc.getGrandTotal().subtract(calc.getTaxBasis()))+ "</ram:TaxTotalAmount>\n"
|
||||||
.map(VATAmount::getCalculated)
|
|
||||||
.map(p -> p.setScale(2, RoundingMode.HALF_UP))
|
|
||||||
.reduce(BigDecimal.ZERO, BigDecimal::add)) + "</ram:TaxTotalAmount>\n"
|
|
||||||
+ " <ram:GrandTotalAmount>" + currencyFormat(calc.getGrandTotal()) + "</ram:GrandTotalAmount>\n" //$NON-NLS-2$
|
+ " <ram:GrandTotalAmount>" + currencyFormat(calc.getGrandTotal()) + "</ram:GrandTotalAmount>\n" //$NON-NLS-2$
|
||||||
// //
|
// //
|
||||||
// currencyID=\"EUR\"
|
// currencyID=\"EUR\"
|
||||||
|
|||||||
Reference in New Issue
Block a user