diff --git a/doc/development_documentation.md b/doc/development_documentation.md index 347a0bcf..6fe18f33 100644 --- a/doc/development_documentation.md +++ b/doc/development_documentation.md @@ -79,7 +79,8 @@ You will need a git client on the console, if that's available can e.g. be check Change to the root of the repo. Change to the project directory and run - * `mvn clean install` . If that works you can + * `mvn clean install` confirm javadoc is OK with + * `mvn javadoc:javadoc`. If that works you can * clean the release with `mvn release:clean` and prepare the release with * `mvn release:prepare -DignoreSnapshots=true` and enter the version numbers. * After that is through you can create a new release via `mvn release:perform -Dmaven.java.skip=True`.This will also update the maven repo. diff --git a/src/main/java/org/mustangproject/XMLTools.java b/src/main/java/org/mustangproject/XMLTools.java new file mode 100644 index 00000000..4c2877b3 --- /dev/null +++ b/src/main/java/org/mustangproject/XMLTools.java @@ -0,0 +1,43 @@ +package org.mustangproject; + +public class XMLTools { + public static String encodeXML(CharSequence s) { + StringBuilder sb = new StringBuilder(); + int len = s.length(); + for (int i=0;i= 0xd800 && c <= 0xdbff && i + 1 < len) { + c = ((c-0xd7c0)<<10) | (s.charAt(++i)&0x3ff); // UTF16 decode + } + if (c < 0x80) { // ASCII range: test most common case first + if (c < 0x20 && (c != '\t' && c != '\r' && c != '\n')) { + // Illegal XML character, even encoded. Skip or substitute + sb.append("�"); // Unicode replacement character + } else { + switch(c) { + case '&': sb.append("&"); break; + case '>': sb.append(">"); break; + case '<': sb.append("<"); break; + // Uncomment next two if encoding for an XML attribute +// case '\'' sb.append("'"); break; +// case '\"' sb.append("""); break; + // Uncomment next three if you prefer, but not required +// case '\n' sb.append(" "); break; +// case '\r' sb.append(" "); break; +// case '\t' sb.append(" "); break; + + default: sb.append((char)c); + } + } + } else if ((c >= 0xd800 && c <= 0xdfff) || c == 0xfffe || c == 0xffff) { + // Illegal XML character, even encoded. Skip or substitute + sb.append("�"); // Unicode replacement character + } else { + sb.append("&#x"); + sb.append(Integer.toHexString(c)); + sb.append(';'); + } + } + return sb.toString(); + } +} diff --git a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTransaction.java b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTransaction.java index ef636764..ba603eb2 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTransaction.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTransaction.java @@ -128,10 +128,20 @@ public interface IZUGFeRDExportableTransaction { /** * the creditors payment informations - * + * @deprecated use getTradeSettlement * @return an array of IZUGFeRDTradeSettlementPayment */ - IZUGFeRDTradeSettlementPayment[] getTradeSettlementPayment(); + default IZUGFeRDTradeSettlementPayment[] getTradeSettlementPayment() { + return null; + } + /** + * the payment information for any payment means + * + * @return an array of IZUGFeRDTradeSettlement + */ + default IZUGFeRDTradeSettlement[] getTradeSettlement() { + return null; + } /** diff --git a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlement.java b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlement.java new file mode 100644 index 00000000..7e92b204 --- /dev/null +++ b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlement.java @@ -0,0 +1,40 @@ +/** ********************************************************************** + * + * Copyright 2019 by ak on 12.04.19. + * + * Use is subject to license terms. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + * + *********************************************************************** */ +package org.mustangproject.ZUGFeRD; + +public interface IZUGFeRDTradeSettlement { + + /*** + * + * @return zf2 xml for applicableHeaderTradeSettlement + */ + String getSettlementXML(); + + + /*** + * + * @return zf2 xml for applicableHeaderTradePayment + */ + default String getPaymentXML() { + return null; + } + + + +} diff --git a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlementDebit.java b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlementDebit.java new file mode 100644 index 00000000..457c2a3d --- /dev/null +++ b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlementDebit.java @@ -0,0 +1,57 @@ +/** ********************************************************************** + * + * Copyright 2019 by ak on 12.04.19. + * + * Use is subject to license terms. + * + * Licensed under the Apache License, Version 2.0 (the "License"); you may not + * use this file except in compliance with the License. You may obtain a copy + * of the License at http://www.apache.org/licenses/LICENSE-2.0. + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT + * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * + * See the License for the specific language governing permissions and + * limitations under the License. + * + *********************************************************************** */ +package org.mustangproject.ZUGFeRD; + +import org.mustangproject.XMLTools; + +public interface IZUGFeRDTradeSettlementDebit extends IZUGFeRDTradeSettlement { + + + + default String getSettlementXML() { + + + + String xml = " \n" //$NON-NLS-1$ + + " 59\n" //$NON-NLS-1$ + + " \n" //$NON-NLS-1$ + + " "+XMLTools.encodeXML(getIBAN())+"\n" //$NON-NLS-1$ + + " \n"; //$NON-NLS-1$ + + xml = xml + " \n"; //$NON-NLS-1$ + return xml; + } + + default String getPaymentXML() { + return ""+XMLTools.encodeXML(getMandate())+""; + } + + + /*** + * @return IBAN of the debtor (optional) + */ + String getIBAN(); + + + /*** + * @return sepa direct debit mandate reference + */ + String getMandate(); + +} diff --git a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlementPayment.java b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlementPayment.java index 3b45b9c8..f4ecaf4d 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlementPayment.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDTradeSettlementPayment.java @@ -18,7 +18,11 @@ *********************************************************************** */ package org.mustangproject.ZUGFeRD; -public interface IZUGFeRDTradeSettlementPayment { +import java.text.SimpleDateFormat; + +import org.mustangproject.XMLTools; + +public interface IZUGFeRDTradeSettlementPayment extends IZUGFeRDTradeSettlement { /** * get payment information text. e.g. Bank transfer @@ -77,5 +81,31 @@ public interface IZUGFeRDTradeSettlementPayment { default String getOwnKto() { return null; } + + default String getSettlementXML() { + String xml = " \n" //$NON-NLS-1$ + + " 42\n" //$NON-NLS-1$ + + " Überweisung\n" //$NON-NLS-1$ + + " \n" //$NON-NLS-1$ + + " " + XMLTools.encodeXML(getOwnIBAN()) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ + if (getOwnKto()!=null) { + xml+= " " + XMLTools.encodeXML(getOwnKto()) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ + + } + xml+= " \n" //$NON-NLS-1$ + + " \n" //$NON-NLS-1$ + + " " + XMLTools.encodeXML(getOwnBIC()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + // + " "+trans.getOwnBankName()+"\n" //$NON-NLS-1$ + // //$NON-NLS-2$ + + " \n" //$NON-NLS-1$ + + " \n"; //$NON-NLS-1$ + return xml; + } + + + /* I'd love to implement getPaymentXML() and put there because this is where it belongs + * unfortunately, the due date is part of the transaction which is not accessible here :-( + */ + } diff --git a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java index bd8a70ff..5b7f8d54 100644 --- a/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java +++ b/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java @@ -18,17 +18,12 @@ *********************************************************************** */ package org.mustangproject.ZUGFeRD; -import java.io.BufferedWriter; -import java.io.FileWriter; import java.io.IOException; import java.io.StringWriter; import java.io.UnsupportedEncodingException; import java.math.BigDecimal; import java.math.RoundingMode; -import java.text.DecimalFormat; -import java.text.DecimalFormatSymbols; import java.text.SimpleDateFormat; -import java.util.Arrays; import java.util.HashMap; import java.util.logging.Level; import java.util.logging.Logger; @@ -38,6 +33,7 @@ import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.io.OutputFormat; import org.dom4j.io.XMLWriter; +import org.mustangproject.XMLTools; import org.mustangproject.toecount.Toecount; public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider { @@ -72,6 +68,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider { protected byte[] zugferdData; private IZUGFeRDExportableTransaction trans; private ZUGFeRDConformanceLevel level; + private String paymentTermsDescription; public void setProfile(ZUGFeRDConformanceLevel level) { this.level = level; @@ -202,55 +199,28 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider { return "urn:cen.eu:en16931:2017"; } - public static String encodeXML(CharSequence s) { - StringBuilder sb = new StringBuilder(); - int len = s.length(); - for (int i=0;i= 0xd800 && c <= 0xdbff && i + 1 < len) { - c = ((c-0xd7c0)<<10) | (s.charAt(++i)&0x3ff); // UTF16 decode - } - if (c < 0x80) { // ASCII range: test most common case first - if (c < 0x20 && (c != '\t' && c != '\r' && c != '\n')) { - // Illegal XML character, even encoded. Skip or substitute - sb.append("�"); // Unicode replacement character - } else { - switch(c) { - case '&': sb.append("&"); break; - case '>': sb.append(">"); break; - case '<': sb.append("<"); break; - // Uncomment next two if encoding for an XML attribute -// case '\'' sb.append("'"); break; -// case '\"' sb.append("""); break; - // Uncomment next three if you prefer, but not required -// case '\n' sb.append(" "); break; -// case '\r' sb.append(" "); break; -// case '\t' sb.append(" "); break; - - default: sb.append((char)c); - } - } - } else if ((c >= 0xd800 && c <= 0xdfff) || c == 0xfffe || c == 0xffff) { - // Illegal XML character, even encoded. Skip or substitute - sb.append("�"); // Unicode replacement character - } else { - sb.append("&#x"); - sb.append(Integer.toHexString(c)); - sb.append(';'); - } - } - return sb.toString(); - } + @Override public void generateXML(IZUGFeRDExportableTransaction trans) { this.trans = trans; + + boolean hasDueDate=false; SimpleDateFormat germanDateFormat = new SimpleDateFormat("dd.MM.yyyy"); //$NON-NLS-1$ SimpleDateFormat zugferdDateFormat = new SimpleDateFormat("yyyyMMdd"); //$NON-NLS-1$ + + if (paymentTermsDescription==null) { + paymentTermsDescription= "Zahlbar ohne Abzug bis " + germanDateFormat.format(trans.getDueDate()); + + } + if (trans.getPaymentTermDescription()!=null) { + paymentTermsDescription=trans.getPaymentTermDescription(); + } + String senderReg = ""; if (trans.getOwnOrganisationFullPlaintextInfo() != null) { senderReg = "" + "\n" + " \n" - + encodeXML(trans.getOwnOrganisationFullPlaintextInfo()) + " \n" + + XMLTools.encodeXML(trans.getOwnOrganisationFullPlaintextInfo()) + " \n" + "REG\n" + "\n"; } @@ -272,7 +242,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider { + " \n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ - + " " + encodeXML(trans.getNumber()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " " + XMLTools.encodeXML(trans.getNumber()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ // + " RECHNUNG\n" //$NON-NLS-1$ + " 380\n" //$NON-NLS-1$ + " " //$NON-NLS-1$ @@ -308,8 +278,8 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider { // + " 4012345001235\n" // + " KR3M\n" // + " 55T01\n" - + " " + encodeXML(currentItem.getProduct().getName()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ - + " " + encodeXML(currentItem.getProduct().getDescription()) //$NON-NLS-1$ + + " " + XMLTools.encodeXML(currentItem.getProduct().getName()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " " + XMLTools.encodeXML(currentItem.getProduct().getDescription()) //$NON-NLS-1$ + "\n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ @@ -317,7 +287,7 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider { + " \n" //$NON-NLS-1$ + " " + priceFormat(currentItem.getPrice()) //$NON-NLS-1$ + "\n" //$NON-NLS-1$ //currencyID=\"EUR\" - + " 1.0000\n" //$NON-NLS-1$ // + " \n" // + " false\n" @@ -328,13 +298,13 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider { + " \n" //$NON-NLS-1$ + " " + priceFormat(currentItem.getPrice()) //$NON-NLS-1$ + "\n" //$NON-NLS-1$ // currencyID=\"EUR\" - + " 1.0000\n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ - + " " //$NON-NLS-1$ //$NON-NLS-2$ + + " " //$NON-NLS-1$ //$NON-NLS-2$ + quantityFormat(currentItem.getQuantity()) + "\n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ @@ -355,34 +325,34 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider { xml = xml + " \n"; //$NON-NLS-1$ if (trans.getReferenceNumber() != null) { - xml = xml + " " + encodeXML(trans.getReferenceNumber()) + "\n"; + xml = xml + " " + XMLTools.encodeXML(trans.getReferenceNumber()) + "\n"; } xml = xml + " \n" //$NON-NLS-1$ // + " 4000001123452\n" - + " " + encodeXML(trans.getOwnOrganisationName()) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ + + " " + XMLTools.encodeXML(trans.getOwnOrganisationName()) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ if ((trans.getOwnVATID()!=null)&&(trans.getOwnOrganisationName()!=null)) { xml = xml + " \n" + " " - + encodeXML(trans.getOwnVATID()) + "\n" + " " - + encodeXML(trans.getOwnOrganisationName()) + "\n" + + XMLTools.encodeXML(trans.getOwnVATID()) + "\n" + " " + + XMLTools.encodeXML(trans.getOwnOrganisationName()) + "\n" + " "; } if (trans.getOwnContact() != null) { - xml = xml + "\n" + " " + encodeXML(trans.getOwnContact().getName()) + xml = xml + "\n" + " " + XMLTools.encodeXML(trans.getOwnContact().getName()) + "\n"; if (trans.getOwnContact().getPhone() != null) { xml = xml + " \n" + " " - + encodeXML(trans.getOwnContact().getPhone()) + "\n" + + XMLTools.encodeXML(trans.getOwnContact().getPhone()) + "\n" + " \n"; } if (trans.getOwnContact().getEMail() != null) { xml = xml + " \n" + " " - + encodeXML(trans.getOwnContact().getEMail()) + "\n" + + XMLTools.encodeXML(trans.getOwnContact().getEMail()) + "\n" + " \n"; } xml = xml + " "; @@ -390,33 +360,33 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider { } xml = xml + " \n" + " " - + encodeXML(trans.getOwnZIP()) + "\n" + " " - + encodeXML(trans.getOwnStreet()) + "\n" + " " + encodeXML(trans.getOwnLocation()) - + "\n" + " " + encodeXML(trans.getOwnCountry()) + + XMLTools.encodeXML(trans.getOwnZIP()) + "\n" + " " + + XMLTools.encodeXML(trans.getOwnStreet()) + "\n" + " " + XMLTools.encodeXML(trans.getOwnLocation()) + + "\n" + " " + XMLTools.encodeXML(trans.getOwnCountry()) + "\n" + " \n" + " \n" //$NON-NLS-1$ - + " " + encodeXML(trans.getOwnTaxID()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " " + XMLTools.encodeXML(trans.getOwnTaxID()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + " \n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ - + " " + encodeXML(trans.getOwnVATID()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " " + XMLTools.encodeXML(trans.getOwnVATID()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + " \n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ // + " GE2020211\n" // + " 4000001987658\n" - + " " + encodeXML(trans.getRecipient().getName()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " " + XMLTools.encodeXML(trans.getRecipient().getName()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ // + " \n" // + " xxx\n" // + " \n" + " \n" //$NON-NLS-1$ - + " " + encodeXML(trans.getRecipient().getZIP()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ - + " " + encodeXML(trans.getRecipient().getStreet()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ - + " " + encodeXML(trans.getRecipient().getLocation()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ - + " " + encodeXML(trans.getRecipient().getCountry()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " " + XMLTools.encodeXML(trans.getRecipient().getZIP()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " " + XMLTools.encodeXML(trans.getRecipient().getStreet()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " " + XMLTools.encodeXML(trans.getRecipient().getLocation()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " " + XMLTools.encodeXML(trans.getRecipient().getCountry()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + " \n"; //$NON-NLS-1$ if (trans.getRecipient().getVATID() != null) { xml += " \n" //$NON-NLS-1$ - + " " + encodeXML(trans.getRecipient().getVATID()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " " + XMLTools.encodeXML(trans.getRecipient().getVATID()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + " \n"; //$NON-NLS-1$ } xml += " \n" //$NON-NLS-1$ @@ -436,26 +406,26 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider { * " \n" */ + " \n" + " \n" //$NON-NLS-2$ - + " " + encodeXML(trans.getNumber()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + + " " + XMLTools.encodeXML(trans.getNumber()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ + " EUR\n"; //$NON-NLS-1$ - for (IZUGFeRDTradeSettlementPayment payment : trans.getTradeSettlementPayment()) { - xml += " \n" //$NON-NLS-1$ - + " 42\n" //$NON-NLS-1$ - + " Überweisung\n" //$NON-NLS-1$ - + " \n" //$NON-NLS-1$ - + " " + encodeXML(payment.getOwnIBAN()) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ - if (payment.getOwnKto()!=null) { - xml+= " " + encodeXML(payment.getOwnKto()) + "\n"; //$NON-NLS-1$ //$NON-NLS-2$ - + if (trans.getTradeSettlementPayment()!=null) { + for (IZUGFeRDTradeSettlementPayment payment : trans.getTradeSettlementPayment()) { + if(payment!=null) { + hasDueDate=true; + xml+=payment.getSettlementXML(); } - xml+= " \n" //$NON-NLS-1$ - + " \n" //$NON-NLS-1$ - + " " + encodeXML(payment.getOwnBIC()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ - // + " "+trans.getOwnBankName()+"\n" //$NON-NLS-1$ - // //$NON-NLS-2$ - + " \n" //$NON-NLS-1$ - + " \n"; //$NON-NLS-1$ + } + } + if (trans.getTradeSettlement()!=null) { + for (IZUGFeRDTradeSettlement payment : trans.getTradeSettlement()) { + if(payment!=null) { + if (payment instanceof IZUGFeRDTradeSettlementPayment) { + hasDueDate=true; + } + xml+=payment.getSettlementXML(); + } + } } HashMap VATPercentAmountMap = getVATPercentAmountMap(); @@ -473,45 +443,29 @@ public class ZUGFeRD2PullProvider implements IXMLProvider, IProfileProvider { } } - /* - * xml+= " + " \n" + - * " false\n" + - * " 10\n" + - * " 1.00\n" + - * " Sondernachlass\n" + - * " \n" + - * " VAT\n" + - * " S\n" + - * " 19\n" + - * " \n" + - * " \n" + - * " \n" + - * " false\n" + - * " 137.30\n" + - * " 13.73\n" + - * " Sondernachlass\n" + - * " \n" + - * " VAT\n" + - * " S\n" + - * " 7\n" + - * " \n" + - * " \n" + - * " \n" + - * " Versandkosten\n" + - * " 5.80\n" + - * " \n" + - * " VAT\n" + - * " S\n" + - * " 7\n" + - * " \n" + - * " \n" - */ xml = xml + " \n" //$NON-NLS-1$ - + " Zahlbar ohne Abzug bis " + germanDateFormat.format(trans.getDueDate()) - + "\n" + " " //$NON-NLS-2$ - + zugferdDateFormat.format(trans.getDueDate()) + "\n"// 20130704 //$NON-NLS-1$ - + " \n" //$NON-NLS-1$ + + " "+ + paymentTermsDescription + + "\n"; + + if (trans.getTradeSettlement()!=null) { + for (IZUGFeRDTradeSettlement payment : trans.getTradeSettlement()) { + if(payment!=null) { + xml+=payment.getPaymentXML(); + } + } + } + + if(hasDueDate) { + xml=xml+" " //$NON-NLS-2$ + + zugferdDateFormat.format(trans.getDueDate()) + "\n";// 20130704 //$NON-NLS-1$ + + } + + + + xml = xml + " \n" //$NON-NLS-1$ + " \n" //$NON-NLS-1$ + " " + currencyFormat(getTotal()) + "\n" //$NON-NLS-1$ //$NON-NLS-2$ // currencyID=\"EUR\" diff --git a/src/test/java/org/mustangproject/ZUGFeRD/ZF2EdgeTest.java b/src/test/java/org/mustangproject/ZUGFeRD/ZF2EdgeTest.java index d578630c..484e6b3d 100644 --- a/src/test/java/org/mustangproject/ZUGFeRD/ZF2EdgeTest.java +++ b/src/test/java/org/mustangproject/ZUGFeRD/ZF2EdgeTest.java @@ -18,23 +18,52 @@ *********************************************************************** */ package org.mustangproject.ZUGFeRD; -import junit.framework.Test; -import junit.framework.TestSuite; -import org.junit.FixMethodOrder; -import org.junit.runners.MethodSorters; - import java.io.ByteArrayOutputStream; import java.io.IOException; import java.io.InputStream; import java.math.BigDecimal; -import java.text.SimpleDateFormat; import java.util.Calendar; import java.util.Date; import java.util.GregorianCalendar; +import org.junit.FixMethodOrder; +import org.junit.runners.MethodSorters; + +import junit.framework.Test; +import junit.framework.TestSuite; + @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class ZF2EdgeTest extends MustangReaderTestCase { final String TARGET_PDF = "./target/testout-ZF2newEdge.pdf"; + + protected class DebitPayment implements IZUGFeRDTradeSettlementDebit { + + + @Override + public String getIBAN() { + return "DE540815"; + } + + + @Override + public String getMandate() { + return "DE99XX12345"; + } + + } + + + @Override + public IZUGFeRDTradeSettlementPayment[] getTradeSettlementPayment() { + return null; + } + + @Override + public IZUGFeRDTradeSettlement[] getTradeSettlement() { + IZUGFeRDTradeSettlement[] payments = new DebitPayment[1]; + payments[0] = new DebitPayment(); + return payments; + } @Override public Date getDeliveryDate() { @@ -70,7 +99,7 @@ public class ZF2EdgeTest extends MustangReaderTestCase { public String getOwnOrganisationName() { return "Bei Spiel GmbH"; } - + @Override public String getOwnStreet() { return "Ecke 12"; @@ -129,8 +158,7 @@ public class ZF2EdgeTest extends MustangReaderTestCase { @Override public String getPaymentTermDescription() { - SimpleDateFormat germanDateFormat = new SimpleDateFormat("dd.MM.yyyy"); - return "Zahlbar ohne Abzug bis zum " + germanDateFormat.format(getDueDate()); + return "Zahlbar sofort"; } @Override @@ -191,6 +219,7 @@ public class ZF2EdgeTest extends MustangReaderTestCase { ze.PDFattachZugferdFile(this); String theXML = new String(ze.getProvider().getXML()); assertTrue(theXML.contains("59")); + assertTrue(zi.getUTF8().contains("DE540815")); + assertTrue(zi.getUTF8().contains("DE99XX12345")); + // Reading ZUGFeRD assertEquals(zi.getAmount(), "571.04"); - assertEquals(zi.getBIC(), getTradeSettlementPayment()[0].getOwnBIC()); - assertEquals(zi.getIBAN(), getTradeSettlementPayment()[0].getOwnIBAN()); assertEquals(zi.getHolder(), getOwnOrganisationName()); assertEquals(zi.getForeignReference(), getNumber()); try {