From b5cc1eee7f32462012f8362bcc2b061db45ace99 Mon Sep 17 00:00:00 2001 From: AlexanderSchmidt Date: Thu, 12 Nov 2015 16:02:00 +0100 Subject: [PATCH] implementation of header charged and header logistics service charges --- .../ZUGFeRD/ZUGFeRDExporter.java | 182 +++++++++++++++++- 1 file changed, 173 insertions(+), 9 deletions(-) diff --git a/mustang/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java b/mustang/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java index 07cbd183..d00ad9d6 100644 --- a/mustang/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java +++ b/mustang/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDExporter.java @@ -479,6 +479,13 @@ public class ZUGFeRDExporter { if(trans.getZFAllowances() != null){ tradeSettlement.getSpecifiedTradeAllowanceCharge().addAll(this.getHeaderAllowances()); } + if(trans.getZFLogisticsServiceCharges()!= null){ + tradeSettlement.getSpecifiedLogisticsServiceCharge().addAll(this.getHeaderLogisticsServiceCharges()); + } + if(trans.getZFCharges()!= null){ + tradeSettlement.getSpecifiedTradeAllowanceCharge().addAll(this.getHeaderCharges()); + } + tradeSettlement.setSpecifiedTradeSettlementMonetarySummation(this.getMonetarySummation()); return tradeSettlement; @@ -550,8 +557,7 @@ public class ZUGFeRDExporter { private Collection getHeaderAllowances() { List headerAllowances = new ArrayList(); - - HashMap VATPercentAmountMap = this.getVATPercentAmountMap(); + for (IZUGFeRDAllowanceCharge iAllowance : trans.getZFAllowances()) { TradeAllowanceChargeType allowance = xmlFactory.createTradeAllowanceChargeType(); @@ -574,8 +580,6 @@ public class ZUGFeRDExporter { PercentType vatPercent = xmlFactory.createPercentType(); vatPercent.setValue(currencyFormat(iAllowance.getTaxPercent())); tradeTax.setApplicablePercent(vatPercent); - - VATAmount amount = VATPercentAmountMap.get(iAllowance.getTaxPercent()); /* Only in extended AmountType basisAmount = xmlFactory.createAmountType(); @@ -598,6 +602,100 @@ public class ZUGFeRDExporter { return headerAllowances; } + + private Collection getHeaderCharges() { + List headerCharges = new ArrayList(); + + for (IZUGFeRDAllowanceCharge iCharge : trans.getZFCharges()) { + + TradeAllowanceChargeType charge = xmlFactory.createTradeAllowanceChargeType(); + + IndicatorType chargeIndicator = xmlFactory.createIndicatorType(); + chargeIndicator.setIndicator(true); + charge.setChargeIndicator(chargeIndicator); + + AmountType actualAmount = xmlFactory.createAmountType(); + actualAmount.setCurrencyID(trans.getInvoiceCurrency()); + actualAmount.setValue(currencyFormat(iCharge.getAmount())); + charge.getActualAmount().add(actualAmount); + + TextType reason = xmlFactory.createTextType(); + reason.setValue(iCharge.getReason()); + charge.setReason(reason); + + TradeTaxType tradeTax = xmlFactory.createTradeTaxType(); + + PercentType vatPercent = xmlFactory.createPercentType(); + vatPercent.setValue(currencyFormat(iCharge.getTaxPercent())); + tradeTax.setApplicablePercent(vatPercent); + + /* Only in extended + AmountType basisAmount = xmlFactory.createAmountType(); + basisAmount.setCurrencyID(trans.getInvoiceCurrency()); + basisAmount.setValue(amount.getBasis()); + allowance.setBasisAmount(basisAmount); + */ + TaxCategoryCodeType taxType = xmlFactory.createTaxCategoryCodeType(); + taxType.setValue(TaxCategoryCodeType.STANDARDRATE); + tradeTax.setCategoryCode(taxType); + + TaxTypeCodeType taxCode = xmlFactory.createTaxTypeCodeType(); + taxCode.setValue(TaxTypeCodeType.SALESTAX); + tradeTax.setTypeCode(taxCode); + + charge.getCategoryTradeTax().add(tradeTax); + headerCharges.add(charge); + + } + + return headerCharges; + } + + private Collection getHeaderLogisticsServiceCharges() { + List headerServiceCharge = new ArrayList(); + + for (IZUGFeRDAllowanceCharge iServiceCharge : trans.getZFLogisticsServiceCharges()) { + + LogisticsServiceChargeType serviceCharge = xmlFactory.createLogisticsServiceChargeType(); + + AmountType actualAmount = xmlFactory.createAmountType(); + actualAmount.setCurrencyID(trans.getInvoiceCurrency()); + actualAmount.setValue(currencyFormat(iServiceCharge.getAmount())); + serviceCharge.getAppliedAmount().add(actualAmount); + + TextType reason = xmlFactory.createTextType(); + reason.setValue(iServiceCharge.getReason()); + serviceCharge.getDescription().add(reason); + + TradeTaxType tradeTax = xmlFactory.createTradeTaxType(); + + PercentType vatPercent = xmlFactory.createPercentType(); + vatPercent.setValue(currencyFormat(iServiceCharge.getTaxPercent())); + tradeTax.setApplicablePercent(vatPercent); + + /* Only in extended + AmountType basisAmount = xmlFactory.createAmountType(); + basisAmount.setCurrencyID(trans.getInvoiceCurrency()); + basisAmount.setValue(amount.getBasis()); + allowance.setBasisAmount(basisAmount); + */ + TaxCategoryCodeType taxType = xmlFactory.createTaxCategoryCodeType(); + taxType.setValue(TaxCategoryCodeType.STANDARDRATE); + tradeTax.setCategoryCode(taxType); + + TaxTypeCodeType taxCode = xmlFactory.createTaxTypeCodeType(); + taxCode.setValue(TaxTypeCodeType.SALESTAX); + tradeTax.setTypeCode(taxCode); + + + + serviceCharge.getAppliedTradeTax().add(tradeTax); + headerServiceCharge.add(serviceCharge); + + } + + return headerServiceCharge; + } private Collection getPaymentTerms() { List paymentTerms = new ArrayList(); @@ -622,6 +720,8 @@ public class ZUGFeRDExporter { private TradeSettlementMonetarySummationType getMonetarySummation() { TradeSettlementMonetarySummationType monetarySummation = xmlFactory.createTradeSettlementMonetarySummationType(); + + // AllowanceTotalAmount = sum of all allowances AmountType allowanceTotalAmount = xmlFactory.createAmountType(); allowanceTotalAmount.setCurrencyID(trans.getInvoiceCurrency()); if(trans.getZFAllowances() != null){ @@ -633,13 +733,31 @@ public class ZUGFeRDExporter { }else{ allowanceTotalAmount.setValue(currencyFormat(BigDecimal.ZERO)); } + monetarySummation.getAllowanceTotalAmount().add(allowanceTotalAmount); + + // ChargeTotalAmount = sum of all Logistic service charges + normal charges + BigDecimal totalCharge = BigDecimal.ZERO; + AmountType totalChargeAmount = xmlFactory.createAmountType(); + totalChargeAmount.setCurrencyID(trans.getInvoiceCurrency()); + if(trans.getZFLogisticsServiceCharges()!= null){ + for(IZUGFeRDAllowanceCharge logisticsServiceCharge : trans.getZFLogisticsServiceCharges()){ + totalCharge = logisticsServiceCharge.getAmount().add(totalCharge); + } + } + if(trans.getZFCharges()!= null){ + for(IZUGFeRDAllowanceCharge charge : trans.getZFCharges()){ + totalCharge = charge.getAmount().add(totalCharge); + } + } + + totalChargeAmount.setValue(currencyFormat(totalCharge)); + + monetarySummation.getChargeTotalAmount().add(totalChargeAmount); - monetarySummation.getAllowanceTotalAmount().add(allowanceTotalAmount); - - AmountType chargeTotalAmount = xmlFactory.createAmountType(); + /*AmountType chargeTotalAmount = xmlFactory.createAmountType(); chargeTotalAmount.setCurrencyID(trans.getInvoiceCurrency()); chargeTotalAmount.setValue(currencyFormat(BigDecimal.ZERO)); - monetarySummation.getChargeTotalAmount().add(chargeTotalAmount); + monetarySummation.getChargeTotalAmount().add(chargeTotalAmount);*/ AmountType lineTotalAmount = xmlFactory.createAmountType(); lineTotalAmount.setCurrencyID(trans.getInvoiceCurrency()); @@ -788,11 +906,24 @@ public class ZUGFeRDExporter { LineCalc lc = new LineCalc(currentItem); res = res.add(lc.getItemTotalNetAmount()); } + if(trans.getZFAllowances() != null){ for (IZUGFeRDAllowanceCharge headerAllowance : trans.getZFAllowances()){ res = res.subtract(headerAllowance.getAmount()); } } + + if(trans.getZFLogisticsServiceCharges()!= null){ + for (IZUGFeRDAllowanceCharge logisticsServiceCharge : trans.getZFLogisticsServiceCharges()){ + res = res.add(logisticsServiceCharge.getAmount()); + } + } + + if(trans.getZFCharges()!= null){ + for (IZUGFeRDAllowanceCharge charge : trans.getZFCharges()){ + res = res.add(charge.getAmount()); + } + } return res; } @@ -807,6 +938,10 @@ public class ZUGFeRDExporter { * */ private HashMap getVATPercentAmountMap() { + return getVATPercentAmountMap(false); + } + + private HashMap getVATPercentAmountMap(Boolean itemOnly){ HashMap hm = new HashMap(); for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) { @@ -820,6 +955,9 @@ public class ZUGFeRDExporter { hm.put(percent, current.add(itemVATAmount)); } } + if(itemOnly){ + return hm; + } if(trans.getZFAllowances() != null){ for (IZUGFeRDAllowanceCharge headerAllowance : trans.getZFAllowances()){ BigDecimal percent = headerAllowance.getTaxPercent(); @@ -832,8 +970,34 @@ public class ZUGFeRDExporter { } } } + + if(trans.getZFLogisticsServiceCharges()!= null){ + for (IZUGFeRDAllowanceCharge logisticsServiceCharge : trans.getZFLogisticsServiceCharges()){ + BigDecimal percent = logisticsServiceCharge.getTaxPercent(); + VATAmount itemVATAmount = new VATAmount(logisticsServiceCharge.getAmount(), logisticsServiceCharge.getAmount().multiply(percent).divide(new BigDecimal(100))); + VATAmount current = hm.get(percent); + if (current == null) { + hm.put(percent, itemVATAmount); + } else { + hm.put(percent, current.add(itemVATAmount)); + } + } + } + + if(trans.getZFCharges()!= null){ + for (IZUGFeRDAllowanceCharge charge : trans.getZFCharges()){ + BigDecimal percent = charge.getTaxPercent(); + VATAmount itemVATAmount = new VATAmount(charge.getAmount(), charge.getAmount().multiply(percent).divide(new BigDecimal(100))); + VATAmount current = hm.get(percent); + if (current == null) { + hm.put(percent, itemVATAmount); + } else { + hm.put(percent, current.add(itemVATAmount)); + } + } + } - return hm; + return hm; } /**