first implementation of header allowances
This commit is contained in:
@@ -4,32 +4,36 @@ import java.math.BigDecimal;
|
|||||||
|
|
||||||
public class VATAmount {
|
public class VATAmount {
|
||||||
|
|
||||||
public VATAmount(BigDecimal basis, BigDecimal calculated) {
|
public VATAmount(BigDecimal basis, BigDecimal calculated) {
|
||||||
super();
|
super();
|
||||||
this.basis = basis;
|
this.basis = basis;
|
||||||
this.calculated = calculated;
|
this.calculated = calculated;
|
||||||
}
|
}
|
||||||
|
|
||||||
BigDecimal basis, calculated;
|
BigDecimal basis, calculated;
|
||||||
|
|
||||||
public BigDecimal getBasis() {
|
public BigDecimal getBasis() {
|
||||||
return basis;
|
return basis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setBasis(BigDecimal basis) {
|
public void setBasis(BigDecimal basis) {
|
||||||
this.basis = basis;
|
this.basis = basis;
|
||||||
}
|
}
|
||||||
|
|
||||||
public BigDecimal getCalculated() {
|
public BigDecimal getCalculated() {
|
||||||
return calculated;
|
return calculated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void setCalculated(BigDecimal calculated) {
|
public void setCalculated(BigDecimal calculated) {
|
||||||
this.calculated = calculated;
|
this.calculated = calculated;
|
||||||
}
|
}
|
||||||
|
|
||||||
public VATAmount add(VATAmount v) {
|
public VATAmount add(VATAmount v) {
|
||||||
return new VATAmount(basis.add(v.getBasis()), calculated.add(v.getCalculated()));
|
return new VATAmount(basis.add(v.getBasis()), calculated.add(v.getCalculated()));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public VATAmount subtract(VATAmount v) {
|
||||||
|
return new VATAmount(basis.subtract(v.getBasis()), calculated.subtract(v.getCalculated()));
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -550,7 +550,8 @@ public class ZUGFeRDExporter {
|
|||||||
|
|
||||||
private Collection<TradeAllowanceChargeType> getHeaderAllowances() {
|
private Collection<TradeAllowanceChargeType> getHeaderAllowances() {
|
||||||
List<TradeAllowanceChargeType> headerAllowances = new ArrayList<TradeAllowanceChargeType>();
|
List<TradeAllowanceChargeType> headerAllowances = new ArrayList<TradeAllowanceChargeType>();
|
||||||
|
|
||||||
|
HashMap<BigDecimal, VATAmount> VATPercentAmountMap = this.getVATPercentAmountMap();
|
||||||
for (IZUGFeRDAllowanceCharge iAllowance : trans.getZFAllowances()) {
|
for (IZUGFeRDAllowanceCharge iAllowance : trans.getZFAllowances()) {
|
||||||
|
|
||||||
TradeAllowanceChargeType allowance = xmlFactory.createTradeAllowanceChargeType();
|
TradeAllowanceChargeType allowance = xmlFactory.createTradeAllowanceChargeType();
|
||||||
@@ -559,6 +560,11 @@ public class ZUGFeRDExporter {
|
|||||||
chargeIndicator.setIndicator(false);
|
chargeIndicator.setIndicator(false);
|
||||||
allowance.setChargeIndicator(chargeIndicator);
|
allowance.setChargeIndicator(chargeIndicator);
|
||||||
|
|
||||||
|
AmountType actualAmount = xmlFactory.createAmountType();
|
||||||
|
actualAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||||
|
actualAmount.setValue(currencyFormat(iAllowance.getAmount()));
|
||||||
|
allowance.getActualAmount().add(actualAmount);
|
||||||
|
|
||||||
TextType reason = xmlFactory.createTextType();
|
TextType reason = xmlFactory.createTextType();
|
||||||
reason.setValue(iAllowance.getReason());
|
reason.setValue(iAllowance.getReason());
|
||||||
allowance.setReason(reason);
|
allowance.setReason(reason);
|
||||||
@@ -566,9 +572,17 @@ public class ZUGFeRDExporter {
|
|||||||
TradeTaxType tradeTax = xmlFactory.createTradeTaxType();
|
TradeTaxType tradeTax = xmlFactory.createTradeTaxType();
|
||||||
|
|
||||||
PercentType vatPercent = xmlFactory.createPercentType();
|
PercentType vatPercent = xmlFactory.createPercentType();
|
||||||
vatPercent.setValue(iAllowance.getTaxPercent());
|
vatPercent.setValue(currencyFormat(iAllowance.getTaxPercent()));
|
||||||
tradeTax.setApplicablePercent(vatPercent);
|
tradeTax.setApplicablePercent(vatPercent);
|
||||||
|
|
||||||
|
VATAmount amount = VATPercentAmountMap.get(iAllowance.getTaxPercent());
|
||||||
|
|
||||||
|
/* Only in extended
|
||||||
|
AmountType basisAmount = xmlFactory.createAmountType();
|
||||||
|
basisAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||||
|
basisAmount.setValue(amount.getBasis());
|
||||||
|
allowance.setBasisAmount(basisAmount);
|
||||||
|
*/
|
||||||
TaxCategoryCodeType taxType = xmlFactory.createTaxCategoryCodeType();
|
TaxCategoryCodeType taxType = xmlFactory.createTaxCategoryCodeType();
|
||||||
taxType.setValue(TaxCategoryCodeType.STANDARDRATE);
|
taxType.setValue(TaxCategoryCodeType.STANDARDRATE);
|
||||||
tradeTax.setCategoryCode(taxType);
|
tradeTax.setCategoryCode(taxType);
|
||||||
@@ -610,7 +624,16 @@ public class ZUGFeRDExporter {
|
|||||||
TradeSettlementMonetarySummationType monetarySummation = xmlFactory.createTradeSettlementMonetarySummationType();
|
TradeSettlementMonetarySummationType monetarySummation = xmlFactory.createTradeSettlementMonetarySummationType();
|
||||||
AmountType allowanceTotalAmount = xmlFactory.createAmountType();
|
AmountType allowanceTotalAmount = xmlFactory.createAmountType();
|
||||||
allowanceTotalAmount.setCurrencyID(trans.getInvoiceCurrency());
|
allowanceTotalAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||||
allowanceTotalAmount.setValue(currencyFormat(BigDecimal.ZERO));
|
if(trans.getZFAllowances() != null){
|
||||||
|
BigDecimal totalHeaderAllowance = BigDecimal.ZERO;
|
||||||
|
for(IZUGFeRDAllowanceCharge headerAllowance : trans.getZFAllowances()){
|
||||||
|
totalHeaderAllowance = headerAllowance.getAmount().add(totalHeaderAllowance);
|
||||||
|
}
|
||||||
|
allowanceTotalAmount.setValue(currencyFormat(totalHeaderAllowance));
|
||||||
|
}else{
|
||||||
|
allowanceTotalAmount.setValue(currencyFormat(BigDecimal.ZERO));
|
||||||
|
}
|
||||||
|
|
||||||
monetarySummation.getAllowanceTotalAmount().add(allowanceTotalAmount);
|
monetarySummation.getAllowanceTotalAmount().add(allowanceTotalAmount);
|
||||||
|
|
||||||
AmountType chargeTotalAmount = xmlFactory.createAmountType();
|
AmountType chargeTotalAmount = xmlFactory.createAmountType();
|
||||||
@@ -620,7 +643,7 @@ public class ZUGFeRDExporter {
|
|||||||
|
|
||||||
AmountType lineTotalAmount = xmlFactory.createAmountType();
|
AmountType lineTotalAmount = xmlFactory.createAmountType();
|
||||||
lineTotalAmount.setCurrencyID(trans.getInvoiceCurrency());
|
lineTotalAmount.setCurrencyID(trans.getInvoiceCurrency());
|
||||||
lineTotalAmount.setValue(currencyFormat(this.getTotal()));
|
lineTotalAmount.setValue(currencyFormat(this.getLineTotal()));
|
||||||
monetarySummation.getLineTotalAmount().add(lineTotalAmount);
|
monetarySummation.getLineTotalAmount().add(lineTotalAmount);
|
||||||
|
|
||||||
AmountType taxBasisTotalAmount = xmlFactory.createAmountType();
|
AmountType taxBasisTotalAmount = xmlFactory.createAmountType();
|
||||||
@@ -749,12 +772,28 @@ public class ZUGFeRDExporter {
|
|||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
private BigDecimal getTotal() {
|
private BigDecimal getLineTotal() {
|
||||||
BigDecimal res = new BigDecimal(0);
|
BigDecimal res = BigDecimal.ZERO;
|
||||||
for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) {
|
for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) {
|
||||||
LineCalc lc = new LineCalc(currentItem);
|
LineCalc lc = new LineCalc(currentItem);
|
||||||
res = res.add(lc.getItemTotalNetAmount());
|
res = res.add(lc.getItemTotalNetAmount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return res;
|
||||||
|
}
|
||||||
|
|
||||||
|
private BigDecimal getTotal() {
|
||||||
|
BigDecimal res = BigDecimal.ZERO;
|
||||||
|
for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) {
|
||||||
|
LineCalc lc = new LineCalc(currentItem);
|
||||||
|
res = res.add(lc.getItemTotalNetAmount());
|
||||||
|
}
|
||||||
|
if(trans.getZFAllowances() != null){
|
||||||
|
for (IZUGFeRDAllowanceCharge headerAllowance : trans.getZFAllowances()){
|
||||||
|
res = res.subtract(headerAllowance.getAmount());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -779,7 +818,18 @@ public class ZUGFeRDExporter {
|
|||||||
hm.put(percent, itemVATAmount);
|
hm.put(percent, itemVATAmount);
|
||||||
} else {
|
} else {
|
||||||
hm.put(percent, current.add(itemVATAmount));
|
hm.put(percent, current.add(itemVATAmount));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if(trans.getZFAllowances() != null){
|
||||||
|
for (IZUGFeRDAllowanceCharge headerAllowance : trans.getZFAllowances()){
|
||||||
|
BigDecimal percent = headerAllowance.getTaxPercent();
|
||||||
|
VATAmount itemVATAmount = new VATAmount(headerAllowance.getAmount(), headerAllowance.getAmount().multiply(percent).divide(new BigDecimal(100)));
|
||||||
|
VATAmount current = hm.get(percent);
|
||||||
|
if (current == null) {
|
||||||
|
hm.put(percent, itemVATAmount);
|
||||||
|
} else {
|
||||||
|
hm.put(percent, current.subtract(itemVATAmount));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user