From 11bc7680fc7746e5f94ac72474b1213a5c3342fc Mon Sep 17 00:00:00 2001 From: Andre Kemper Date: Thu, 11 Apr 2019 07:44:09 +0200 Subject: [PATCH] use DocumentCode --- .../ZUGFeRD/IZUGFeRDAllowanceCharge.java | 7 ++ .../ZUGFeRD/IZUGFeRDExportableItem.java | 5 + .../org/mustangproject/ZUGFeRD/VATAmount.java | 17 +++- .../ZUGFeRD/ZUGFeRD2PullProvider.java | 6 +- .../ZUGFeRDTransactionModelConverter.java | 92 +++++++------------ 5 files changed, 62 insertions(+), 65 deletions(-) diff --git a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDAllowanceCharge.java b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDAllowanceCharge.java index 36f0d428..667a4c78 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDAllowanceCharge.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDAllowanceCharge.java @@ -15,16 +15,23 @@ */ package org.mustangproject.ZUGFeRD; +import org.mustangproject.ZUGFeRD.model.TaxCategoryCodeTypeConstants; + import java.math.BigDecimal; /** * @author AlexanderSchmidt */ public interface IZUGFeRDAllowanceCharge { + BigDecimal getTotalAmount(); String getReason(); BigDecimal getTaxPercent(); + default String getCategoryCode() { + return TaxCategoryCodeTypeConstants.STANDARDRATE; + } + } diff --git a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java index d1b30732..85b0577d 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableItem.java @@ -26,6 +26,8 @@ package org.mustangproject.ZUGFeRD; * @author jstaerk * */ +import org.mustangproject.ZUGFeRD.model.TaxCategoryCodeTypeConstants; + import java.math.BigDecimal; public interface IZUGFeRDExportableItem { @@ -51,5 +53,8 @@ public interface IZUGFeRDExportableItem { */ BigDecimal getQuantity(); + default String getCategoryCode() { + return TaxCategoryCodeTypeConstants.STANDARDRATE; + } } diff --git a/src/main/java/org/mustangproject/ZUGFeRD/VATAmount.java b/src/main/java/org/mustangproject/ZUGFeRD/VATAmount.java index 32d180ca..408ea69f 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/VATAmount.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/VATAmount.java @@ -31,14 +31,17 @@ import java.math.BigDecimal; */ public class VATAmount { - public VATAmount(BigDecimal basis, BigDecimal calculated) { + public VATAmount(BigDecimal basis, BigDecimal calculated, String documentCode) { super(); this.basis = basis; this.calculated = calculated; + this.documentCode = documentCode; } BigDecimal basis, calculated; + String documentCode; + public BigDecimal getBasis() { return basis; } @@ -55,12 +58,20 @@ public class VATAmount { this.calculated = calculated; } + public String getDocumentCode() { + return documentCode; + } + + public void setDocumentCode(String documentCode) { + this.documentCode = documentCode; + } + 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()), this.documentCode); } public VATAmount subtract(VATAmount v) { - return new VATAmount(basis.subtract(v.getBasis()), calculated.subtract(v.getCalculated())); + return new VATAmount(basis.subtract(v.getBasis()), calculated.subtract(v.getCalculated()), this.documentCode); } } diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java index 2fb91343..52a77fe5 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java @@ -134,8 +134,6 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { VATAmount amount = VATPercentAmountMap.get(currentTaxPercent); res = res.add(amount.getCalculated()); } - - return res; } @@ -162,16 +160,14 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) { BigDecimal percent = currentItem.getProduct().getVATPercent(); LineCalc lc = new LineCalc(currentItem); - VATAmount itemVATAmount = new VATAmount(lc.getItemTotalNetAmount(), lc.getItemTotalVATAmount()); + VATAmount itemVATAmount = new VATAmount(lc.getItemTotalNetAmount(), lc.getItemTotalVATAmount(), trans.getDocumentCode()); VATAmount current = hm.get(percent); if (current == null) { hm.put(percent, itemVATAmount); } else { hm.put(percent, current.add(itemVATAmount)); - } } - return hm; } diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDTransactionModelConverter.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDTransactionModelConverter.java index 265c6f98..8d087e8a 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDTransactionModelConverter.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDTransactionModelConverter.java @@ -113,7 +113,7 @@ class ZUGFeRDTransactionModelConverter { document.getIncludedNote().add(regularInfo); } - if (trans.getReferenceNumber() != null && !new String().equals(trans.getReferenceNumber())) { + if (trans.getReferenceNumber() != null && !"".equals(trans.getReferenceNumber())) { NoteType referenceInfo = xmlFactory.createNoteType(); TextType referenceInfoContent = xmlFactory.createTextType(); referenceInfoContent.setValue("Ursprungsbeleg: " + trans.getReferenceNumber()); @@ -336,10 +336,9 @@ class ZUGFeRDTransactionModelConverter { } private Collection getTradeTax() { - List tradeTaxTypes = new ArrayList(); + List tradeTaxTypes = new ArrayList<>(); - HashMap VATPercentAmountMap = this - .getVATPercentAmountMap(); + HashMap VATPercentAmountMap = this.getVATPercentAmountMap(); for (BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) { TradeTaxType tradeTax = xmlFactory.createTradeTaxType(); @@ -347,9 +346,9 @@ class ZUGFeRDTransactionModelConverter { taxTypeCode.setValue(TaxTypeCodeTypeConstants.SALESTAX); tradeTax.setTypeCode(taxTypeCode); - TaxCategoryCodeType taxCategoryCode = xmlFactory - .createTaxCategoryCodeType(); - taxCategoryCode.setValue(TaxCategoryCodeTypeConstants.STANDARDRATE); + TaxCategoryCodeType taxCategoryCode = xmlFactory.createTaxCategoryCodeType(); + VATAmount vatAmount = VATPercentAmountMap.get(currentTaxPercent); + taxCategoryCode.setValue(vatAmount.getDocumentCode()); tradeTax.setCategoryCode(taxCategoryCode); VATAmount amount = VATPercentAmountMap.get(currentTaxPercent); @@ -360,8 +359,7 @@ class ZUGFeRDTransactionModelConverter { AmountType calculatedTaxAmount = xmlFactory.createAmountType(); calculatedTaxAmount.setCurrencyID(currency); - calculatedTaxAmount - .setValue(currencyFormat(amount.getCalculated())); + calculatedTaxAmount.setValue(currencyFormat(amount.getCalculated())); tradeTax.getCalculatedAmount().add(calculatedTaxAmount); AmountType basisTaxAmount = xmlFactory.createAmountType(); @@ -376,13 +374,11 @@ class ZUGFeRDTransactionModelConverter { } private Collection getHeaderAllowances() { - List headerAllowances = new ArrayList(); + List headerAllowances = new ArrayList<>(); for (IZUGFeRDAllowanceCharge iAllowance : trans.getZFAllowances()) { - TradeAllowanceChargeType allowance = xmlFactory - .createTradeAllowanceChargeType(); - + TradeAllowanceChargeType allowance = xmlFactory.createTradeAllowanceChargeType(); IndicatorType chargeIndicator = xmlFactory.createIndicatorType(); chargeIndicator.setIndicator(false); allowance.setChargeIndicator(chargeIndicator); @@ -397,7 +393,6 @@ class ZUGFeRDTransactionModelConverter { allowance.setReason(reason); TradeTaxType tradeTax = xmlFactory.createTradeTaxType(); - PercentType vatPercent = xmlFactory.createPercentType(); vatPercent.setValue(currencyFormat(iAllowance.getTaxPercent())); tradeTax.setApplicablePercent(vatPercent); @@ -409,9 +404,8 @@ class ZUGFeRDTransactionModelConverter { * basisAmount.setValue(amount.getBasis()); * allowance.setBasisAmount(basisAmount); */ - TaxCategoryCodeType taxType = xmlFactory - .createTaxCategoryCodeType(); - taxType.setValue(TaxCategoryCodeTypeConstants.STANDARDRATE); + TaxCategoryCodeType taxType = xmlFactory.createTaxCategoryCodeType(); + taxType.setValue(iAllowance.getCategoryCode()); tradeTax.setCategoryCode(taxType); TaxTypeCodeType taxCode = xmlFactory.createTaxTypeCodeType(); @@ -420,20 +414,17 @@ class ZUGFeRDTransactionModelConverter { allowance.getCategoryTradeTax().add(tradeTax); headerAllowances.add(allowance); - } return headerAllowances; } private Collection getHeaderCharges() { - List headerCharges = new ArrayList(); + List headerCharges = new ArrayList<>(); for (IZUGFeRDAllowanceCharge iCharge : trans.getZFCharges()) { - TradeAllowanceChargeType charge = xmlFactory - .createTradeAllowanceChargeType(); - + TradeAllowanceChargeType charge = xmlFactory.createTradeAllowanceChargeType(); IndicatorType chargeIndicator = xmlFactory.createIndicatorType(); chargeIndicator.setIndicator(true); charge.setChargeIndicator(chargeIndicator); @@ -448,7 +439,6 @@ class ZUGFeRDTransactionModelConverter { charge.setReason(reason); TradeTaxType tradeTax = xmlFactory.createTradeTaxType(); - PercentType vatPercent = xmlFactory.createPercentType(); vatPercent.setValue(currencyFormat(iCharge.getTaxPercent())); tradeTax.setApplicablePercent(vatPercent); @@ -460,9 +450,8 @@ class ZUGFeRDTransactionModelConverter { * basisAmount.setValue(amount.getBasis()); * allowance.setBasisAmount(basisAmount); */ - TaxCategoryCodeType taxType = xmlFactory - .createTaxCategoryCodeType(); - taxType.setValue(TaxCategoryCodeTypeConstants.STANDARDRATE); + TaxCategoryCodeType taxType = xmlFactory.createTaxCategoryCodeType(); + taxType.setValue(iCharge.getCategoryCode()); tradeTax.setCategoryCode(taxType); TaxTypeCodeType taxCode = xmlFactory.createTaxTypeCodeType(); @@ -478,18 +467,15 @@ class ZUGFeRDTransactionModelConverter { } private Collection getHeaderLogisticsServiceCharges() { - List headerServiceCharge = new ArrayList(); + List headerServiceCharge = new ArrayList<>(); - for (IZUGFeRDAllowanceCharge iServiceCharge : trans - .getZFLogisticsServiceCharges()) { + for (IZUGFeRDAllowanceCharge iServiceCharge : trans.getZFLogisticsServiceCharges()) { - LogisticsServiceChargeType serviceCharge = xmlFactory - .createLogisticsServiceChargeType(); + LogisticsServiceChargeType serviceCharge = xmlFactory.createLogisticsServiceChargeType(); AmountType actualAmount = xmlFactory.createAmountType(); actualAmount.setCurrencyID(currency); - actualAmount.setValue(currencyFormat(iServiceCharge - .getTotalAmount())); + actualAmount.setValue(currencyFormat(iServiceCharge.getTotalAmount())); serviceCharge.getAppliedAmount().add(actualAmount); TextType reason = xmlFactory.createTextType(); @@ -509,9 +495,8 @@ class ZUGFeRDTransactionModelConverter { * basisAmount.setValue(amount.getBasis()); * allowance.setBasisAmount(basisAmount); */ - TaxCategoryCodeType taxType = xmlFactory - .createTaxCategoryCodeType(); - taxType.setValue(TaxCategoryCodeTypeConstants.STANDARDRATE); + TaxCategoryCodeType taxType = xmlFactory.createTaxCategoryCodeType(); + taxType.setValue(iServiceCharge.getCategoryCode()); tradeTax.setCategoryCode(taxType); TaxTypeCodeType taxCode = xmlFactory.createTaxTypeCodeType(); @@ -527,7 +512,7 @@ class ZUGFeRDTransactionModelConverter { } private Collection getPaymentTerms() { - List paymentTerms = new ArrayList(); + List paymentTerms = new ArrayList<>(); TradePaymentTermsType paymentTerm = xmlFactory .createTradePaymentTermsType(); @@ -632,7 +617,7 @@ class ZUGFeRDTransactionModelConverter { private Collection getLineItems() { - ArrayList lineItems = new ArrayList(); + ArrayList lineItems = new ArrayList<>(); int lineID = 0; for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) { lineID++; @@ -734,9 +719,8 @@ class ZUGFeRDTransactionModelConverter { .createSupplyChainTradeSettlementType(); TradeTaxType tradeTax = xmlFactory.createTradeTaxType(); - TaxCategoryCodeType taxCategoryCode = xmlFactory - .createTaxCategoryCodeType(); - taxCategoryCode.setValue(TaxCategoryCodeTypeConstants.STANDARDRATE); + TaxCategoryCodeType taxCategoryCode = xmlFactory.createTaxCategoryCodeType(); + taxCategoryCode.setValue(currentItem.getCategoryCode()); tradeTax.setCategoryCode(taxCategoryCode); TaxTypeCodeType taxCode = xmlFactory.createTaxTypeCodeType(); @@ -849,15 +833,13 @@ class ZUGFeRDTransactionModelConverter { return getVATPercentAmountMap(false); } - private HashMap getVATPercentAmountMap( - Boolean itemOnly) { - HashMap hm = new HashMap(); + private HashMap getVATPercentAmountMap(Boolean itemOnly) { + HashMap hm = new HashMap<>(); for (IZUGFeRDExportableItem currentItem : trans.getZFItems()) { BigDecimal percent = currentItem.getProduct().getVATPercent(); LineCalc lc = new LineCalc(currentItem); - VATAmount itemVATAmount = new VATAmount(lc.getItemTotalNetAmount(), - lc.getItemTotalVATAmount()); + VATAmount itemVATAmount = new VATAmount(lc.getItemTotalNetAmount(), lc.getItemTotalVATAmount(), trans.getDocumentCode()); VATAmount current = hm.get(percent); if (current == null) { hm.put(percent, itemVATAmount); @@ -869,13 +851,12 @@ class ZUGFeRDTransactionModelConverter { return hm; } if (trans.getZFAllowances() != null) { - for (IZUGFeRDAllowanceCharge headerAllowance : trans - .getZFAllowances()) { + for (IZUGFeRDAllowanceCharge headerAllowance : trans.getZFAllowances()) { BigDecimal percent = headerAllowance.getTaxPercent(); VATAmount itemVATAmount = new VATAmount( headerAllowance.getTotalAmount(), headerAllowance .getTotalAmount().multiply(percent) - .divide(new BigDecimal(100))); + .divide(new BigDecimal(100)), trans.getDocumentCode()); VATAmount current = hm.get(percent); if (current == null) { hm.put(percent, itemVATAmount); @@ -892,7 +873,7 @@ class ZUGFeRDTransactionModelConverter { VATAmount itemVATAmount = new VATAmount( logisticsServiceCharge.getTotalAmount(), logisticsServiceCharge.getTotalAmount() - .multiply(percent).divide(new BigDecimal(100))); + .multiply(percent).divide(new BigDecimal(100)), trans.getDocumentCode()); VATAmount current = hm.get(percent); if (current == null) { hm.put(percent, itemVATAmount); @@ -907,7 +888,7 @@ class ZUGFeRDTransactionModelConverter { BigDecimal percent = charge.getTaxPercent(); VATAmount itemVATAmount = new VATAmount( charge.getTotalAmount(), charge.getTotalAmount() - .multiply(percent).divide(new BigDecimal(100))); + .multiply(percent).divide(new BigDecimal(100)), trans.getDocumentCode()); VATAmount current = hm.get(percent); if (current == null) { hm.put(percent, itemVATAmount); @@ -1026,17 +1007,14 @@ class ZUGFeRDTransactionModelConverter { // Set total net amount this.totalNetAmount = res; - HashMap VATPercentAmountMap = getVATPercentAmountMap(); - for (BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) { - VATAmount amount = VATPercentAmountMap.get(currentTaxPercent); + HashMap vatAmountHashMap = getVATPercentAmountMap(); + for (VATAmount amount : vatAmountHashMap.values()) { res = res.add(amount.getCalculated()); } // Set total gross amount this.totalGrossAmount = res; - - this.totalTaxAmount = this.totalGrossAmount - .subtract(this.totalNetAmount); + this.totalTaxAmount = this.totalGrossAmount.subtract(this.totalNetAmount); } public BigDecimal getTotalNet() {