Merge pull request #209 from weclapp-dev/Improvements
thank you very much
This commit is contained in:
@@ -1,8 +1,11 @@
|
||||
package org.mustangproject.ZUGFeRD;
|
||||
|
||||
import static java.math.BigDecimal.ZERO;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.util.HashMap;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
/***
|
||||
* 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) {
|
||||
return BigDecimal.ZERO;
|
||||
} else {
|
||||
return trans.getTotalPrepaidAmount();
|
||||
return trans.getTotalPrepaidAmount().setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -37,13 +40,11 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
||||
*/
|
||||
public BigDecimal getGrandTotal() {
|
||||
|
||||
BigDecimal res = getTaxBasis();
|
||||
HashMap<BigDecimal, VATAmount> VATPercentAmountMap = getVATPercentAmountMap();
|
||||
for (BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) {
|
||||
VATAmount amount = VATPercentAmountMap.get(currentTaxPercent);
|
||||
res = res.add(amount.getCalculated());
|
||||
}
|
||||
return res.setScale(2, RoundingMode.HALF_UP);
|
||||
final BigDecimal res = getTaxBasis();
|
||||
return getVATPercentAmountMap().values().stream()
|
||||
.map(VATAmount::getCalculated)
|
||||
.map(p -> p.setScale(2, RoundingMode.HALF_UP))
|
||||
.reduce(BigDecimal.ZERO, BigDecimal::add).add(res);
|
||||
}
|
||||
|
||||
/***
|
||||
@@ -52,8 +53,12 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
||||
* @return the total amount
|
||||
*/
|
||||
protected BigDecimal getChargesForPercent(BigDecimal percent) {
|
||||
BigDecimal res = BigDecimal.ZERO;
|
||||
IZUGFeRDAllowanceCharge[] charges = trans.getZFCharges();
|
||||
return sumAllowanceCharge(percent, charges);
|
||||
}
|
||||
|
||||
private BigDecimal sumAllowanceCharge(BigDecimal percent, IZUGFeRDAllowanceCharge[] charges) {
|
||||
BigDecimal res = BigDecimal.ZERO;
|
||||
if ((charges != null) && (charges.length > 0)) {
|
||||
for (IZUGFeRDAllowanceCharge currentCharge : charges) {
|
||||
if ((percent==null)||(currentCharge.getTaxPercent().compareTo(percent)==0)) {
|
||||
@@ -70,21 +75,25 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
||||
* @return the space separated String
|
||||
*/
|
||||
protected String getChargeReasonForPercent(BigDecimal percent) {
|
||||
String res = " ";
|
||||
IZUGFeRDAllowanceCharge[] charges = trans.getZFCharges();
|
||||
String res = getAllowanceChargeReasonForPercent(percent, charges);
|
||||
if ("".equals(res)) {
|
||||
res="Charges";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
private String getAllowanceChargeReasonForPercent(BigDecimal percent, IZUGFeRDAllowanceCharge[] charges) {
|
||||
String res = " ";
|
||||
if ((charges != null) && (charges.length > 0)) {
|
||||
for (IZUGFeRDAllowanceCharge currentCharge : charges) {
|
||||
if ((percent==null)||(currentCharge.getTaxPercent().compareTo(percent)==0)) {
|
||||
if (currentCharge.getReason()!=null) {
|
||||
res = res+currentCharge.getReason()+" ";
|
||||
}
|
||||
if ((percent==null)||(currentCharge.getTaxPercent().compareTo(percent)==0)
|
||||
&& currentCharge.getReason()!=null) {
|
||||
res += currentCharge.getReason()+" ";
|
||||
}
|
||||
}
|
||||
}
|
||||
res=res.substring(0,res.length()-1);
|
||||
if (res.equals("")) {
|
||||
res="Charges";
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@@ -94,19 +103,9 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
||||
* @return the space separated String
|
||||
*/
|
||||
protected String getAllowanceReasonForPercent(BigDecimal percent) {
|
||||
String res = " ";
|
||||
IZUGFeRDAllowanceCharge[] allowances = trans.getZFAllowances();
|
||||
if ((allowances != null) && (allowances.length > 0)) {
|
||||
for (IZUGFeRDAllowanceCharge currentAllowance : allowances) {
|
||||
if ((percent==null)||(currentAllowance.getTaxPercent().compareTo(percent)==0)) {
|
||||
if (currentAllowance.getReason()!=null) {
|
||||
res = res+currentAllowance.getReason()+" ";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
res=res.substring(0,res.length()-1);
|
||||
if (res.equals("")) {
|
||||
String res = getAllowanceChargeReasonForPercent(percent, allowances);
|
||||
if ("".equals(res)) {
|
||||
res="Allowances";
|
||||
}
|
||||
return res;
|
||||
@@ -119,16 +118,8 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
||||
* @return the total amount
|
||||
*/
|
||||
protected BigDecimal getAllowancesForPercent(BigDecimal percent) {
|
||||
BigDecimal res = BigDecimal.ZERO;
|
||||
IZUGFeRDAllowanceCharge[] allowances = trans.getZFAllowances();
|
||||
if ((allowances != null) && (allowances.length > 0)) {
|
||||
for (IZUGFeRDAllowanceCharge currentAllowance : allowances) {
|
||||
if ((percent==null)||(currentAllowance.getTaxPercent().compareTo(percent)==0)) {
|
||||
res = res.add(currentAllowance.getTotalAmount(this));
|
||||
}
|
||||
}
|
||||
}
|
||||
return res;
|
||||
return sumAllowanceCharge(percent, allowances);
|
||||
}
|
||||
|
||||
/***
|
||||
@@ -136,12 +127,10 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
||||
* @return item sum
|
||||
*/
|
||||
protected BigDecimal getTotal() {
|
||||
BigDecimal res = BigDecimal.ZERO;
|
||||
for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) {
|
||||
LineCalculator lc = new LineCalculator(currentItem);
|
||||
res = res.add(lc.getItemTotalNetAmount());
|
||||
}
|
||||
return res;
|
||||
return Stream.of(trans.getZFItems())
|
||||
.map(LineCalculator::new)
|
||||
.map(LineCalculator::getItemTotalNetAmount)
|
||||
.reduce(ZERO, BigDecimal::add);
|
||||
}
|
||||
|
||||
/***
|
||||
@@ -151,7 +140,7 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
||||
*/
|
||||
protected BigDecimal getTaxBasis() {
|
||||
BigDecimal res = getTotal().add(getChargesForPercent(null)).subtract(getAllowancesForPercent(null));
|
||||
return res;
|
||||
return res.setScale(2, RoundingMode.HALF_UP);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -208,7 +197,6 @@ public class TransactionCalculator implements IAbsoluteValueProvider {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
return hm;
|
||||
}
|
||||
|
||||
|
||||
@@ -24,6 +24,7 @@ import java.io.IOException;
|
||||
import java.io.StringWriter;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.math.BigDecimal;
|
||||
import java.math.RoundingMode;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
|
||||
Reference in New Issue
Block a user