also import deliveryaddress

This commit is contained in:
jstaerk
2024-10-09 13:52:55 +02:00
parent 41693d6909
commit 17b6841071
3 changed files with 59 additions and 38 deletions

View File

@@ -52,6 +52,7 @@ import org.xml.sax.SAXException;
public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter { public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
private static final Logger LOGGER = LoggerFactory.getLogger(ZUGFeRDImporter.class); private static final Logger LOGGER = LoggerFactory.getLogger(ZUGFeRDImporter.class);
public ZUGFeRDImporter() { public ZUGFeRDImporter() {
super(); super();
} }
@@ -65,8 +66,6 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
} }
/*** /***
* Wrapper for protected method extractString * Wrapper for protected method extractString
* @param xpathStr the xpath expression to be evaluated * @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 * @return the BuyerTradeParty SpecifiedTaxRegistration ID
*/ */
public String getBuyertradePartySpecifiedTaxRegistrationID() { 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 * @return the sender's account IBAN code
*/ */
public String getIBAN() { public String getIBAN() {
for (IZUGFeRDTradeSettlement settlement:importedInvoice.getTradeSettlement()) { for (IZUGFeRDTradeSettlement settlement : importedInvoice.getTradeSettlement()) {
if (settlement instanceof IZUGFeRDTradeSettlementDebit) { if (settlement instanceof IZUGFeRDTradeSettlementDebit) {
return ((IZUGFeRDTradeSettlementDebit) settlement).getIBAN(); return ((IZUGFeRDTradeSettlementDebit) settlement).getIBAN();
} }
@@ -389,7 +396,7 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
* @return when the payment is due * @return when the payment is due
*/ */
public String getDueDate() { public String getDueDate() {
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
return sdf.format(importedInvoice.getDueDate()); return sdf.format(importedInvoice.getDueDate());
} }
@@ -421,14 +428,19 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
* @return the BuyerTradeParty ID * @return the BuyerTradeParty ID
*/ */
public String getBuyerTradePartyID() { 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() * @return the Issue Date()
*/ */
public String getIssueDate() { public String getIssueDate() {
SimpleDateFormat sdf=new SimpleDateFormat("yyyyMMdd"); SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMdd");
return sdf.format(importedInvoice.getIssueDate()); 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. * Returns the raw XML data as extracted from the ZUGFeRD PDF file.
* *

View File

@@ -300,6 +300,12 @@ public class ZUGFeRDInvoiceImporter {
XPath xpath = xpathFact.newXPath(); XPath xpath = xpathFact.newXPath();
XPathExpression xpr = xpath.compile("//*[local-name()=\"SellerTradeParty\"]|//*[local-name()=\"AccountingSupplierParty\"]/*"); XPathExpression xpr = xpath.compile("//*[local-name()=\"SellerTradeParty\"]|//*[local-name()=\"AccountingSupplierParty\"]/*");
NodeList SellerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); 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\"]/*"); xpr = xpath.compile("//*[local-name()=\"BuyerTradeParty\"]|//*[local-name()=\"AccountingCustomerParty\"]/*");
NodeList BuyerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); NodeList BuyerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);

View File

@@ -1,22 +1,24 @@
/** ********************************************************************** /**
* * *********************************************************************
* <p>
* Copyright 2019 Jochen Staerk * Copyright 2019 Jochen Staerk
* * <p>
* Use is subject to license terms. * Use is subject to license terms.
* * <p>
* Licensed under the Apache License, Version 2.0 (the "License"); you may not * 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 * 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. * of the License at http://www.apache.org/licenses/LICENSE-2.0.
* * <p>
* Unless required by applicable law or agreed to in writing, software * Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* * <p>
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
* * <p>
*********************************************************************** */ * **********************************************************************
*/
package org.mustangproject.ZUGFeRD; package org.mustangproject.ZUGFeRD;
import java.io.IOException; import java.io.IOException;
@@ -190,13 +192,13 @@ public class ZF2Test extends MustangReaderTestCase {
assertEquals(zi.getInvoiceID(), "RE-20170509/505"); assertEquals(zi.getInvoiceID(), "RE-20170509/505");
assertEquals(zi.getZUGFeRDProfil(), "COMFORT"); assertEquals(zi.getZUGFeRDProfil(), "COMFORT");
assertEquals(zi.getInvoiceCurrencyCode(), "EUR"); assertEquals(zi.getInvoiceCurrencyCode(), "EUR");
assertEquals(zi.getIssuerAssignedID(),""); assertEquals(zi.getIssuerAssignedID(), "");
assertEquals(zi.getIssueDate(), "20170509"); assertEquals(zi.getIssueDate(), "20170509");
assertEquals(zi.getTaxPointDate(), "20170507"); assertEquals(zi.getTaxPointDate(), "20170507");
assertEquals(zi.getPaymentTerms(), "Zahlbar ohne Abzug bis zum 30.05.2017"); assertEquals(zi.getPaymentTerms(), "Zahlbar ohne Abzug bis zum 30.05.2017");
assertEquals(zi.getLineTotalAmount(), "496.00"); assertEquals(zi.getLineTotalAmount(), "496.00");
assertEquals(zi.getTaxBasisTotalAmount(), "496.00"); assertEquals(zi.getTaxBasisTotalAmount(), "496.00");
assertEquals(zi.getTaxTotalAmount(),"75.04"); assertEquals(zi.getTaxTotalAmount(), "75.04");
assertEquals(zi.getRoundingAmount(), ""); assertEquals(zi.getRoundingAmount(), "");
assertEquals(zi.getPaidAmount(), "0.00"); assertEquals(zi.getPaidAmount(), "0.00");
assertEquals(zi.getBuyerTradePartyName(), "Theodor Est"); assertEquals(zi.getBuyerTradePartyName(), "Theodor Est");
@@ -206,8 +208,8 @@ public class ZF2Test extends MustangReaderTestCase {
assertEquals(zi.getBuyertradePartySpecifiedTaxRegistrationID(), "DE999999999"); assertEquals(zi.getBuyertradePartySpecifiedTaxRegistrationID(), "DE999999999");
assertEquals(zi.getIncludedNote(), ""); assertEquals(zi.getIncludedNote(), "");
assertEquals(zi.getHolder(), getOwnOrganisationName()); assertEquals(zi.getHolder(), getOwnOrganisationName());
assertEquals(zi.getDocumentCode(),"380"); assertEquals(zi.getDocumentCode(), "380");
assertEquals(zi.getReference(),"AB321"); assertEquals(zi.getReference(), "AB321");
assertEquals(zi.getAmount(), "571.04"); assertEquals(zi.getAmount(), "571.04");
assertEquals(zi.getBIC(), "COBADEFFXXX"); assertEquals(zi.getBIC(), "COBADEFFXXX");
assertEquals(zi.getIBAN(), "DE88 2008 0000 0970 3757 00"); assertEquals(zi.getIBAN(), "DE88 2008 0000 0970 3757 00");
@@ -244,7 +246,9 @@ public class ZF2Test extends MustangReaderTestCase {
// TODO Auto-generated catch block // TODO Auto-generated catch block
e.printStackTrace(); e.printStackTrace();
} }
} /** }
/**
* The exporter test bases on @{code * The exporter test bases on @{code
* ./src/test/MustangBeispiel20221026.pdf}, adds * ./src/test/MustangBeispiel20221026.pdf}, adds
* metadata, writes to @{code ./target/testout-*} and then imports to check the * metadata, writes to @{code ./target/testout-*} and then imports to check the
@@ -264,7 +268,7 @@ public class ZF2Test extends MustangReaderTestCase {
assertEquals("Innerhalb von 30 Tagen 2% Skonto, 60 Tage ohne Abzug", zi.getPaymentTerms()); assertEquals("Innerhalb von 30 Tagen 2% Skonto, 60 Tage ohne Abzug", zi.getPaymentTerms());
assertEquals("804.35", zi.getLineTotalAmount()); assertEquals("804.35", zi.getLineTotalAmount());
assertEquals("809.34", zi.getTaxBasisTotalAmount()); assertEquals("809.34", zi.getTaxBasisTotalAmount());
assertEquals("153.77",zi.getTaxTotalAmount()); assertEquals("153.77", zi.getTaxTotalAmount());
assertEquals("", zi.getRoundingAmount()); assertEquals("", zi.getRoundingAmount());
assertEquals("0.00", zi.getPaidAmount()); assertEquals("0.00", zi.getPaidAmount());
assertEquals("Beispiel AG", zi.getBuyerTradePartyName()); assertEquals("Beispiel AG", zi.getBuyerTradePartyName());
@@ -273,8 +277,8 @@ public class ZF2Test extends MustangReaderTestCase {
assertEquals("10000", zi.getBuyerTradePartyID()); assertEquals("10000", zi.getBuyerTradePartyID());
assertEquals("\n weclapp.com\nSomestreet 42\n08155 Some city\nDE\n ", zi.getIncludedNote()); assertEquals("\n weclapp.com\nSomestreet 42\n08155 Some city\nDE\n ", zi.getIncludedNote());
assertEquals("weclapp.com", zi.getHolder()); assertEquals("weclapp.com", zi.getHolder());
assertEquals("380",zi.getDocumentCode()); assertEquals("380", zi.getDocumentCode());
assertEquals("01-95",zi.getReference()); assertEquals("01-95", zi.getReference());
assertEquals("RE1001", zi.getForeignReference()); assertEquals("RE1001", zi.getForeignReference());
assertEquals("54321", zi.getBuyerTradePartyAddress().getPostcodeCode()); assertEquals("54321", zi.getBuyerTradePartyAddress().getPostcodeCode());
assertEquals("Feldstraße 34", zi.getBuyerTradePartyAddress().getLineOne()); assertEquals("Feldstraße 34", zi.getBuyerTradePartyAddress().getLineOne());