diff --git a/library/src/main/java/org/mustangproject/Charge.java b/library/src/main/java/org/mustangproject/Charge.java index 93335a13..c1810c57 100644 --- a/library/src/main/java/org/mustangproject/Charge.java +++ b/library/src/main/java/org/mustangproject/Charge.java @@ -26,6 +26,10 @@ public class Charge implements IZUGFeRDAllowanceCharge { * a simple human readable description */ protected String reason; + /** + * Code from list UNTDID 5189 + */ + protected String reasonCode; /** * the category ID why this charge has been applied */ @@ -94,6 +98,22 @@ public class Charge implements IZUGFeRDAllowanceCharge { } + @Override + public String getReasonCode() { + return reasonCode; + } + + /*** + * Reason code for the charge + * @param reasonCode from list UNTDID 5189 + * @return fluid setter + */ + public Charge setReasonCode(String reasonCode) { + this.reasonCode = reasonCode; + return this; + } + + @Override public BigDecimal getTotalAmount(IAbsoluteValueProvider currentItem) { if (totalAmount!=null) { @@ -137,7 +157,7 @@ public class Charge implements IZUGFeRDAllowanceCharge { /*** - * machine readable reason for this allowance/charge + * the category ID why this has been applied * @param categoryCode usually S * @return fluid setter */ diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDAllowanceCharge.java b/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDAllowanceCharge.java index 75b01a67..0c61ba5b 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDAllowanceCharge.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDAllowanceCharge.java @@ -44,6 +44,12 @@ public interface IZUGFeRDAllowanceCharge { */ String getReason(); + /*** + * get the code for the allowance/charge + * @return the code + */ + String getReasonCode(); + /*** * get the applicable tax percentage for the allowance/charge * @return the percentage diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java index e1111220..345fed91 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java @@ -141,7 +141,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { if (party.getLegalOrganisation() != null) { xml += " "; - xml += " " + XMLTools.encodeXML(party.getLegalOrganisation().getID()) + ""; + xml += "" + XMLTools.encodeXML(party.getLegalOrganisation().getID()) + ""; xml += ""; } @@ -244,10 +244,16 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { // only in extended profile reason = "" + XMLTools.encodeXML(allowance.getReason()) + ""; } + String reasonCode = ""; + if ((allowance.getReasonCode() != null) && (profile == Profiles.getByName("XRechnung"))) { + // only in XRechnung profile + reasonCode = "" + allowance.getReasonCode() + ""; + } final String allowanceChargeStr = "" + chargeIndicator + "" + percentage + "" + priceFormat(allowance.getTotalAmount(item)) + "" + reason + + reasonCode + ""; return allowanceChargeStr; } @@ -269,10 +275,21 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { chargeIndicator = "true"; } + String reason = ""; + if ((allowance.getReason() != null) && (profile == Profiles.getByName("Extended"))) { + // only in extended profile + reason = "" + XMLTools.encodeXML(allowance.getReason()) + ""; + } + String reasonCode = ""; + if ((allowance.getReasonCode() != null) && (profile == Profiles.getByName("XRechnung"))) { + // only in XRechnung profile + reasonCode = "" + allowance.getReasonCode() + ""; + } final String itemTotalAllowanceChargeStr = "" + chargeIndicator + "" + percentage + "" + currencyFormat(allowance.getTotalAmount(item)) + "" + - "" + XMLTools.encodeXML(allowance.getReason()) + "" + + reason + + reasonCode + ""; return itemTotalAllowanceChargeStr; } @@ -325,9 +342,9 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { // if (getProfile() == Profiles.getByName("XRechnung")) { - xml += " \n" - + " urn:fdc:peppol.eu:2017:poacc:billing:01:1.0\n" - + " \n"; + xml += "\n" + + "urn:fdc:peppol.eu:2017:poacc:billing:01:1.0\n" + + "\n"; } xml += "" @@ -336,7 +353,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { + "" + "" + "" + XMLTools.encodeXML(trans.getNumber()) + "" - // + " RECHNUNG" + // + "RECHNUNG" // + "380" + "" + typecode + "" + "" @@ -436,11 +453,11 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { + "" + quantityFormat(currentItem.getBasisQuantity()) + "" + allowanceChargeStr - // + " " - // + " false" - // + " 0.6667" - // + " Rabatt" - // + " " + // + "" + // + "false" + // + "0.6667" + // + "Rabatt" + // + "" + ""; } @@ -499,53 +516,53 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { + getTradePartyAsXML(trans.getSender(), true, false) + "" + ""; - // + " GE2020211" - // + " 4000001987658" + // + "GE2020211" + // + "4000001987658" xml += getTradePartyAsXML(trans.getRecipient(), false, false); xml += ""; if (trans.getSellerOrderReferencedDocumentID() != null) { - xml += " " - + " " + xml += "" + + "" + XMLTools.encodeXML(trans.getSellerOrderReferencedDocumentID()) + "" - + " "; + + ""; } if (trans.getBuyerOrderReferencedDocumentID() != null) { - xml += " " - + " " + xml += "" + + "" + XMLTools.encodeXML(trans.getBuyerOrderReferencedDocumentID()) + "" - + " "; + + ""; } if (trans.getContractReferencedDocument() != null) { - xml += " " - + " " + xml += "" + + "" + XMLTools.encodeXML(trans.getContractReferencedDocument()) + "" - + " "; + + ""; } // Additional Documents of XRechnung (Rechnungsbegruendende Unterlagen - BG-24 XRechnung) if (trans.getAdditionalReferencedDocuments() != null) { for (final FileAttachment f : trans.getAdditionalReferencedDocuments()) { final String documentContent = new String(Base64.getEncoder().encodeToString(f.getData())); - xml += " " - + " " + f.getFilename() + "" - + " 916" - + " " + f.getDescription() + "" - + " " + documentContent + "" - + " "; + xml += "" + + "" + f.getFilename() + "" + + "916" + + "" + f.getDescription() + "" + + "" + documentContent + "" + + ""; } } if (trans.getSpecifiedProcuringProjectID() != null) { - xml += " " - + " " + xml += "" + + "" + XMLTools.encodeXML(trans.getSpecifiedProcuringProjectID()) + ""; if (trans.getSpecifiedProcuringProjectName() != null) { - xml += " " + XMLTools.encodeXML(trans.getSpecifiedProcuringProjectName()) + ""; + xml += "" + XMLTools.encodeXML(trans.getSpecifiedProcuringProjectName()) + ""; } - xml += " "; + xml += ""; } xml += ""; xml += ""; @@ -562,7 +579,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { + ""; xml += DATE.udtFormat(trans.getDeliveryDate()); xml += ""; - xml += " "; + xml += ""; } /* @@ -581,9 +598,9 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { xml += ""; xml += ""; if ((trans.getNumber() != null) && (getProfile() != Profiles.getByName("Minimum"))) { - xml += " " + XMLTools.encodeXML(trans.getNumber()) + ""; + xml += "" + XMLTools.encodeXML(trans.getNumber()) + ""; } - xml += " " + trans.getCurrency() + ""; + xml += "" + trans.getCurrency() + ""; if (trans.getTradeSettlementPayment() != null) { for (final IZUGFeRDTradeSettlementPayment payment : trans.getTradeSettlementPayment()) { @@ -645,40 +662,87 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { } if ((trans.getZFCharges() != null) && (trans.getZFCharges().length > 0)) { - - for (final BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) { - if (calc.getChargesForPercent(currentTaxPercent).compareTo(BigDecimal.ZERO) != 0) { - xml += " " + + if (profile == Profiles.getByName("XRechnung")) { + for(IZUGFeRDAllowanceCharge charge : trans.getZFCharges()) { + xml += "" + "" + "true" + "" + - "" + currencyFormat(calc.getChargesForPercent(currentTaxPercent)) + "" + - "" + XMLTools.encodeXML(calc.getChargeReasonForPercent(currentTaxPercent)) + "" + - "" + + "" + currencyFormat(charge.getTotalAmount(calc)) + ""; + if (charge.getReason() != null) { + xml += "" + XMLTools.encodeXML(charge.getReason()) + ""; + } + if (charge.getReasonCode() != null) { + xml += "" + charge.getReasonCode() + ""; + } + xml += "" + "VAT" + - "" + VATPercentAmountMap.get(currentTaxPercent).getCategoryCode() + "" + - "" + vatFormat(currentTaxPercent) + "" + - "" + - " "; + "" + charge.getCategoryCode() + ""; + if (charge.getTaxPercent() != null) { + xml += "" + vatFormat(charge.getTaxPercent()) + ""; + } + xml += "" + + ""; + } + } else { + for (final BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) { + if (calc.getChargesForPercent(currentTaxPercent).compareTo(BigDecimal.ZERO) != 0) { + xml += "" + + "" + + "true" + + "" + + "" + currencyFormat(calc.getChargesForPercent(currentTaxPercent)) + "" + + "" + XMLTools.encodeXML(calc.getChargeReasonForPercent(currentTaxPercent)) + "" + + "" + + "VAT" + + "" + VATPercentAmountMap.get(currentTaxPercent).getCategoryCode() + "" + + "" + vatFormat(currentTaxPercent) + "" + + "" + + ""; + } } } } if ((trans.getZFAllowances() != null) && (trans.getZFAllowances().length > 0)) { - for (final BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) { - if (calc.getAllowancesForPercent(currentTaxPercent).compareTo(BigDecimal.ZERO) != 0) { + if (profile == Profiles.getByName("XRechnung")) { + for(IZUGFeRDAllowanceCharge allowance : trans.getZFAllowances()) { xml += "" + "" + "false" + "" + - "" + currencyFormat(calc.getAllowancesForPercent(currentTaxPercent)) + "" + - "" + XMLTools.encodeXML(calc.getAllowanceReasonForPercent(currentTaxPercent)) + "" + - "" + + "" + currencyFormat(allowance.getTotalAmount(calc)) + ""; + if (allowance.getReason() != null) { + xml += "" + XMLTools.encodeXML(allowance.getReason()) + ""; + } + if (allowance.getReasonCode() != null) { + xml += "" + allowance.getReasonCode() + ""; + } + xml += "" + "VAT" + - "" + VATPercentAmountMap.get(currentTaxPercent).getCategoryCode() + "" + - "" + vatFormat(currentTaxPercent) + "" + - "" + - " "; + "" + allowance.getCategoryCode() + ""; + if (allowance.getTaxPercent() != null) { + xml += "" + vatFormat(allowance.getTaxPercent()) + ""; + } + xml += "" + + ""; + } + } else { + for (final BigDecimal currentTaxPercent : VATPercentAmountMap.keySet()) { + if (calc.getAllowancesForPercent(currentTaxPercent).compareTo(BigDecimal.ZERO) != 0) { + xml += "" + + "" + + "false" + + "" + + "" + currencyFormat(calc.getAllowancesForPercent(currentTaxPercent)) + "" + + "" + XMLTools.encodeXML(calc.getAllowanceReasonForPercent(currentTaxPercent)) + "" + + "" + + "VAT" + + "" + VATPercentAmountMap.get(currentTaxPercent).getCategoryCode() + "" + + "" + vatFormat(currentTaxPercent) + "" + + "" + + ""; + } } } } @@ -736,31 +800,31 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { // // // currencyID=\"EUR\" if (getProfile() != Profiles.getByName("Minimum")) { - xml += " " + currencyFormat(calc.getTotalPrepaid()) + ""; + xml += "" + currencyFormat(calc.getTotalPrepaid()) + ""; } xml += "" + currencyFormat(calc.getGrandTotal().subtract(calc.getTotalPrepaid())) + "" + ""; if (trans.getInvoiceReferencedDocumentID() != null) { - xml += " " - + " " + xml += "" + + "" + XMLTools.encodeXML(trans.getInvoiceReferencedDocumentID()) + ""; if (trans.getInvoiceReferencedIssueDate() != null) { xml += "" + DATE.qdtFormat(trans.getInvoiceReferencedIssueDate()) + ""; } - xml += " "; + xml += ""; } xml += ""; - // + " \n" - // + " \n" - // + " \n" - // + " Wir erlauben uns Ihnen folgende Positionen aus der Lieferung Nr. + // + "\n" + // + "\n" + // + "\n" + // + "Wir erlauben uns Ihnen folgende Positionen aus der Lieferung Nr. // 2013-51112 in Rechnung zu stellen:\n" - // + " \n" - // + " \n" - // + " \n"; + // + "\n" + // + "\n" + // + "\n"; xml += "" + ""; diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index d2921474..5207bcf2 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -357,6 +357,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter { boolean isCharge = true; String chargeAmount = null; String reason = null; + String reasonCode = null; String taxPercent = null; for (int chargeChildIndex = 0; chargeChildIndex < chargeNodeChilds.getLength(); chargeChildIndex++) { String chargeChildName = chargeNodeChilds.item(chargeChildIndex).getLocalName(); @@ -377,6 +378,8 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter { chargeAmount = chargeNodeChilds.item(chargeChildIndex).getTextContent(); } else if (chargeChildName.equals("Reason")) { reason = chargeNodeChilds.item(chargeChildIndex).getTextContent(); + } else if (chargeChildName.equals("ReasonCode")) { + reasonCode = chargeNodeChilds.item(chargeChildIndex).getTextContent(); } else if (chargeChildName.equals("CategoryTradeTax")) { NodeList taxChilds = chargeNodeChilds.item(chargeChildIndex).getChildNodes(); for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) { @@ -395,16 +398,21 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter { if (reason != null) { c.setReason(reason); } + if (reasonCode != null) { + c.setReasonCode(reasonCode); + } if (taxPercent != null) { c.setTaxPercent(new BigDecimal(taxPercent)); } - zpp.addCharge(c); } else { Allowance a = new Allowance(new BigDecimal(chargeAmount)); if (reason != null) { a.setReason(reason); } + if (reasonCode != null) { + a.setReasonCode(reasonCode); + } if (taxPercent != null) { a.setTaxPercent(new BigDecimal(taxPercent)); } diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/IZUGFeRDAllowanceChargeImpl.java b/library/src/test/java/org/mustangproject/ZUGFeRD/IZUGFeRDAllowanceChargeImpl.java index 899e5adc..ea25c9b2 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/IZUGFeRDAllowanceChargeImpl.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/IZUGFeRDAllowanceChargeImpl.java @@ -23,6 +23,7 @@ import java.math.BigDecimal; public class IZUGFeRDAllowanceChargeImpl implements IZUGFeRDAllowanceCharge { private BigDecimal totalAmount; private String reason; + private String reasonCode; private BigDecimal taxPercent; boolean isCharge=true; @@ -36,6 +37,11 @@ public class IZUGFeRDAllowanceChargeImpl implements IZUGFeRDAllowanceCharge { return reason; } + @Override + public String getReasonCode() { + return reasonCode; + } + @Override public BigDecimal getTaxPercent() { return taxPercent; @@ -61,6 +67,11 @@ public class IZUGFeRDAllowanceChargeImpl implements IZUGFeRDAllowanceCharge { return this; } + public IZUGFeRDAllowanceChargeImpl setReasonCode(String reasonCode) { + this.reasonCode = reasonCode; + return this; + } + public IZUGFeRDAllowanceChargeImpl setTaxPercent(BigDecimal taxPercent) { this.taxPercent = taxPercent; return this;