diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java index 739b313e..7807ebce 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java @@ -52,6 +52,7 @@ import org.xml.sax.SAXException; public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter { private static final Logger LOGGER = LoggerFactory.getLogger(ZUGFeRDImporter.class); + public ZUGFeRDImporter() { super(); } @@ -65,8 +66,6 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter { } - - /*** * Wrapper for protected method extractString * @param xpathStr the xpath expression to be evaluated @@ -77,7 +76,6 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter { } - //////////////////////////////////// /** @@ -221,7 +219,16 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter { * @return the BuyerTradeParty SpecifiedTaxRegistration ID */ public String getBuyertradePartySpecifiedTaxRegistrationID() { - return importedInvoice.getRecipient().getLegalOrganisation().getID(); + String id = null; + if ((importedInvoice.getRecipient()!=null) && (importedInvoice.getRecipient().getLegalOrganisation()!=null)) { + // this *should* be the official result + id = importedInvoice.getRecipient().getLegalOrganisation().getID(); + } + // but also provide some fallback + if (id == null) { + id = getBuyerTradePartyID(); + } + return id; } @@ -357,7 +364,7 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter { * @return the sender's account IBAN code */ public String getIBAN() { - for (IZUGFeRDTradeSettlement settlement:importedInvoice.getTradeSettlement()) { + for (IZUGFeRDTradeSettlement settlement : importedInvoice.getTradeSettlement()) { if (settlement instanceof IZUGFeRDTradeSettlementDebit) { return ((IZUGFeRDTradeSettlementDebit) settlement).getIBAN(); } @@ -389,7 +396,7 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter { * @return when the payment is due */ public String getDueDate() { - SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd"); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); return sdf.format(importedInvoice.getDueDate()); } @@ -421,14 +428,19 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter { * @return the BuyerTradeParty ID */ public String getBuyerTradePartyID() { - return importedInvoice.getRecipient().getID(); + String id = importedInvoice.getRecipient().getID(); + if (id == null) { + // provide some fallback + id = importedInvoice.getRecipient().getVATID(); + } + return id; } /** * @return the Issue Date() */ public String getIssueDate() { - SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd"); + SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd"); return sdf.format(importedInvoice.getIssueDate()); } @@ -508,7 +520,6 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter { } - /** * Returns the raw XML data as extracted from the ZUGFeRD PDF file. * diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index c86741b6..441c658f 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -300,6 +300,12 @@ public class ZUGFeRDInvoiceImporter { XPath xpath = xpathFact.newXPath(); XPathExpression xpr = xpath.compile("//*[local-name()=\"SellerTradeParty\"]|//*[local-name()=\"AccountingSupplierParty\"]/*"); NodeList SellerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); + XPathExpression shipEx = xpath.compile("//*[local-name()=\"ShipToTradeParty\"]"); + NodeList deliveryNodes = (NodeList) shipEx.evaluate(getDocument(), XPathConstants.NODESET); + if (deliveryNodes!=null) { + zpp.setDeliveryAddress(new TradeParty(deliveryNodes)); + } + xpr = xpath.compile("//*[local-name()=\"BuyerTradeParty\"]|//*[local-name()=\"AccountingCustomerParty\"]/*"); NodeList BuyerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2Test.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2Test.java index 2ae78e90..d945c770 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2Test.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2Test.java @@ -1,22 +1,24 @@ -/** ********************************************************************** - * +/** + * ********************************************************************* + *

* Copyright 2019 Jochen Staerk - * + *

* 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 java.io.IOException; @@ -99,9 +101,9 @@ public class ZF2Test extends MustangReaderTestCase { public IZUGFeRDExportableItem[] getZFItems() { final Item[] allItems = new Item[3]; final Product designProduct = new Product("", "Künstlerische Gestaltung (Stunde): Einer Beispielrechnung", "HUR", - new BigDecimal("7.000000")); + new BigDecimal("7.000000")); final Product balloonProduct = new Product("", "Bestellerweiterung für E&F Umbau", "C62", - new BigDecimal("19.000000"));// test for issue 103 + new BigDecimal("19.000000"));// test for issue 103 final Product airProduct = new Product("", "Heiße Luft pro Liter", "LTR", new BigDecimal("19.000000")); allItems[0] = new Item(new BigDecimal("160"), new BigDecimal("1"), designProduct); @@ -166,12 +168,12 @@ public class ZF2Test extends MustangReaderTestCase { // the writing part try (InputStream SOURCE_PDF = this.getClass() - .getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505PDFA3.pdf"); + .getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505PDFA3.pdf"); ZUGFeRDExporterFromA3 ze = new ZUGFeRDExporterFromA3().setProducer("My Application") - .setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).setProfile("EN16931") - .load(SOURCE_PDF)) { - + .setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).setProfile("EN16931") + .load(SOURCE_PDF)) { + ze.setTransaction(this); final String theXML = new String(ze.getProvider().getXML()); assertTrue(theXML.contains("