ubl impoter to parse contacts

This commit is contained in:
jstaerk
2024-04-01 08:45:29 +02:00
parent df0eef061f
commit 6cea38f57b
6 changed files with 251 additions and 149 deletions

View File

@@ -1,7 +1,10 @@
- EN16931 validation 1.3.11 codelists v11 #357 - EN16931 validation 1.3.11 codelists v11 #357
- Fonts removed #358 - Fonts removed #358
- xrechnungimporter to read from filename, inputstream - xrechnungimporter to read from filename, inputstream
- invoice's getSender/getRecipient() now return tradeparty no IZUGFeRDExportableTradeParty
- (first) IBAN is now parsed into sender's getBankDetails
- zugferdimporter to accept xml files - zugferdimporter to accept xml files
- UBL importer to also parse contacts
2.10.0 2.10.0
======= =======

View File

@@ -455,7 +455,7 @@ public class Invoice implements IExportableTransaction {
} }
@Override @Override
public IZUGFeRDExportableTradeParty getSender() { public TradeParty getSender() {
return sender; return sender;
} }
@@ -473,7 +473,7 @@ public class Invoice implements IExportableTransaction {
} }
@Override @Override
public IZUGFeRDExportableTradeParty getRecipient() { public TradeParty getRecipient() {
return recipient; return recipient;
} }

View File

@@ -65,16 +65,15 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) { for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) {
//nodes.item(i).getTextContent())) { //nodes.item(i).getTextContent())) {
Node currentItemNode = nodes.item(nodeIndex); Node currentItemNode = nodes.item(nodeIndex);
NodeList itemChilds = currentItemNode.getChildNodes();
for (int itemChildIndex = 0; itemChildIndex < itemChilds.getLength(); itemChildIndex++) {
if (itemChilds.item(itemChildIndex).getLocalName() != null) {
if (itemChilds.item(itemChildIndex).getLocalName().equals("Party")) { if (nodes.item(nodeIndex).getLocalName() != null) {
String debcurrentChild = nodes.item(nodeIndex).getLocalName();
if (nodes.item(nodeIndex).getLocalName().equals("Party")) {
NodeList party = itemChilds.item(itemChildIndex).getChildNodes(); NodeList party = nodes.item(nodeIndex).getChildNodes();
for (int partyIndex = 0; partyIndex < party.getLength(); partyIndex++) { for (int partyIndex = 0; partyIndex < party.getLength(); partyIndex++) {
if (party.item(partyIndex).getLocalName() != null) { if (party.item(partyIndex).getLocalName() != null) {
String debCN = party.item(partyIndex).getLocalName();
if (party.item(partyIndex).getLocalName().equals("PartyName")) { if (party.item(partyIndex).getLocalName().equals("PartyName")) {
NodeList partyName = party.item(partyIndex).getChildNodes(); NodeList partyName = party.item(partyIndex).getChildNodes();
@@ -145,26 +144,32 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
} }
} }
} }
if (party.item(partyIndex).getLocalName().equals("Contact")) {
NodeList contact = party.item(partyIndex).getChildNodes();
setContact(new Contact(contact));
}
} }
} }
} }
if (itemChilds.item(itemChildIndex).getLocalName().equals("GlobalID")) { if (nodes.item(nodeIndex).getLocalName().equals("GlobalID")) {
if (itemChilds.item(itemChildIndex).getAttributes().getNamedItem("schemeID") != null) { if (nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID") != null) {
SchemedID gid = new SchemedID().setScheme(itemChilds.item(itemChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(itemChilds.item(itemChildIndex).getTextContent()); SchemedID gid = new SchemedID().setScheme(nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(nodes.item(nodeIndex).getTextContent());
addGlobalID(gid); addGlobalID(gid);
} }
} }
if (itemChilds.item(itemChildIndex).getLocalName().equals("DefinedTradeContact")) { if (nodes.item(nodeIndex).getLocalName().equals("DefinedTradeContact")) {
NodeList contact = itemChilds.item(itemChildIndex).getChildNodes(); NodeList contact = nodes.item(nodeIndex).getChildNodes();
setContact(new Contact(contact)); setContact(new Contact(contact));
} }
if (itemChilds.item(itemChildIndex).getLocalName().equals("PostalTradeAddress")) { if (nodes.item(nodeIndex).getLocalName().equals("PostalTradeAddress")) {
NodeList postal = itemChilds.item(itemChildIndex).getChildNodes(); NodeList postal = nodes.item(nodeIndex).getChildNodes();
for (int postalChildIndex = 0; postalChildIndex < postal.getLength(); postalChildIndex++) { for (int postalChildIndex = 0; postalChildIndex < postal.getLength(); postalChildIndex++) {
if (postal.item(postalChildIndex).getLocalName() != null) { if (postal.item(postalChildIndex).getLocalName() != null) {
if (postal.item(postalChildIndex).getLocalName().equals("LineOne")) { if (postal.item(postalChildIndex).getLocalName().equals("LineOne")) {
@@ -191,8 +196,8 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
} }
if (itemChilds.item(itemChildIndex).getLocalName().equals("SpecifiedTaxRegistration")) { if (nodes.item(nodeIndex).getLocalName().equals("SpecifiedTaxRegistration")) {
NodeList taxChilds = itemChilds.item(itemChildIndex).getChildNodes(); NodeList taxChilds = nodes.item(nodeIndex).getChildNodes();
for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) { for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) {
if (taxChilds.item(taxChildIndex).getLocalName() != null) { if (taxChilds.item(taxChildIndex).getLocalName() != null) {
if ((taxChilds.item(taxChildIndex).getLocalName().equals("ID"))) { if ((taxChilds.item(taxChildIndex).getLocalName().equals("ID"))) {
@@ -212,7 +217,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
} }
} }
} }
}
} }
} }
} }
@@ -284,15 +289,16 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) { for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) {
//nodes.item(i).getTextContent())) { //nodes.item(i).getTextContent())) {
String debLN = nodes.item(nodeIndex).getLocalName();
if (nodes.item(nodeIndex).getLocalName().equals("Party")) {
// take one step back and parse from top
parseFromUBL(nodes);
return;
}
Node currentItemNode = nodes.item(nodeIndex); Node currentItemNode = nodes.item(nodeIndex);
NodeList itemChilds = currentItemNode.getChildNodes(); NodeList itemChilds = currentItemNode.getChildNodes();
for (int itemChildIndex = 0; itemChildIndex < itemChilds.getLength(); itemChildIndex++) { for (int itemChildIndex = 0; itemChildIndex < itemChilds.getLength(); itemChildIndex++) {
if (itemChilds.item(itemChildIndex).getLocalName() != null) { if (itemChilds.item(itemChildIndex).getLocalName() != null) {
if (itemChilds.item(itemChildIndex).getLocalName().equals("Party")) {
parseFromUBL(nodes);
return;
}
if (itemChilds.item(itemChildIndex).getLocalName().equals("Name")) { if (itemChilds.item(itemChildIndex).getLocalName().equals("Name")) {
setName(itemChilds.item(itemChildIndex).getTextContent()); setName(itemChilds.item(itemChildIndex).getTextContent());
} }
@@ -328,10 +334,8 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
if (postal.item(postalChildIndex).getLocalName().equals("CountryID")) { if (postal.item(postalChildIndex).getLocalName().equals("CountryID")) {
setCountry(postal.item(postalChildIndex).getTextContent()); setCountry(postal.item(postalChildIndex).getTextContent());
} }
} }
} }
} }
if (itemChilds.item(itemChildIndex).getLocalName().equals("URIUniversalCommunication")) { if (itemChilds.item(itemChildIndex).getLocalName().equals("URIUniversalCommunication")) {
NodeList URIchilds = itemChilds.item(itemChildIndex).getChildNodes(); NodeList URIchilds = itemChilds.item(itemChildIndex).getChildNodes();

View File

@@ -16,16 +16,7 @@ import javax.xml.xpath.XPathExpression;
import javax.xml.xpath.XPathExpressionException; import javax.xml.xpath.XPathExpressionException;
import javax.xml.xpath.XPathFactory; import javax.xml.xpath.XPathFactory;
import org.mustangproject.Allowance; import org.mustangproject.*;
import org.mustangproject.Charge;
import org.mustangproject.EStandard;
import org.mustangproject.Invoice;
import org.mustangproject.Item;
import org.mustangproject.Product;
import org.mustangproject.ReferencedDocument;
import org.mustangproject.SchemedID;
import org.mustangproject.TradeParty;
import org.mustangproject.XMLTools;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.w3c.dom.Node; import org.w3c.dom.Node;
@@ -75,10 +66,10 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
*/ */
XPathFactory xpathFact = XPathFactory.newInstance(); XPathFactory xpathFact = XPathFactory.newInstance();
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);
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);
xpr = xpath.compile("//*[local-name()=\"ExchangedDocument\"]|//*[local-name()=\"HeaderExchangedDocument\"]"); xpr = xpath.compile("//*[local-name()=\"ExchangedDocument\"]|//*[local-name()=\"HeaderExchangedDocument\"]");
NodeList ExchangedDocumentNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); NodeList ExchangedDocumentNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
@@ -119,8 +110,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
} }
} }
String rootNode = extractString("local-name(/*)"); String rootNode = extractString("local-name(/*)");
if (rootNode.equals("Invoice")) if (rootNode.equals("Invoice")) {
{
// UBL... // UBL...
number = extractString("//*[local-name()=\"Invoice\"]/*[local-name()=\"ID\"]").trim(); number = extractString("//*[local-name()=\"Invoice\"]/*[local-name()=\"ID\"]").trim();
issueDate = new SimpleDateFormat("yyyy-MM-dd") issueDate = new SimpleDateFormat("yyyy-MM-dd")
@@ -214,6 +204,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
xpr = xpath.compile("//*[local-name()=\"ApplicableHeaderTradeSettlement\"]|//*[local-name()=\"ApplicableSupplyChainTradeSettlement\"]"); xpr = xpath.compile("//*[local-name()=\"ApplicableHeaderTradeSettlement\"]|//*[local-name()=\"ApplicableSupplyChainTradeSettlement\"]");
NodeList headerTradeSettlementNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); NodeList headerTradeSettlementNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
String IBAN = null, BIC = null;
for (int i = 0; i < headerTradeSettlementNodes.getLength(); i++) { for (int i = 0; i < headerTradeSettlementNodes.getLength(); i++) {
// nodes.item(i).getTextContent())) { // nodes.item(i).getTextContent())) {
@@ -241,11 +232,75 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
} }
} }
} }
if ((headerTradeSettlementChilds.item(settlementChildIndex).getLocalName() != null)
&& (headerTradeSettlementChilds.item(settlementChildIndex).getLocalName()
.equals("SpecifiedTradeSettlementPaymentMeans"))) {
NodeList paymentMeansChilds = headerTradeSettlementChilds.item(settlementChildIndex).getChildNodes();
for (int paymentMeansChildIndex = 0; paymentMeansChildIndex < paymentMeansChilds
.getLength(); paymentMeansChildIndex++) {
if ((paymentMeansChilds.item(paymentMeansChildIndex).getLocalName() != null) && (paymentMeansChilds
.item(paymentMeansChildIndex).getLocalName().equals("PayeePartyCreditorFinancialAccount"))) {
NodeList accountChilds = paymentMeansChilds.item(paymentMeansChildIndex).getChildNodes();
for (int accountChildIndex = 0; accountChildIndex < accountChilds
.getLength(); accountChildIndex++) {
if ((accountChilds.item(accountChildIndex).getLocalName() != null) && (accountChilds
.item(accountChildIndex).getLocalName().equals("IBANID"))) {//CII
IBAN = accountChilds.item(accountChildIndex).getTextContent();
}
}
}
if ((paymentMeansChilds.item(paymentMeansChildIndex).getLocalName() != null) && (paymentMeansChilds
.item(paymentMeansChildIndex).getLocalName().equals("PayeePartyCreditorFinancialInstitution"))) {
NodeList accountChilds = paymentMeansChilds.item(paymentMeansChildIndex).getChildNodes();
for (int accountChildIndex = 0; accountChildIndex < accountChilds
.getLength(); accountChildIndex++) {
if ((accountChilds.item(accountChildIndex).getLocalName() != null) && (accountChilds
.item(accountChildIndex).getLocalName().equals("BICID"))) {//CII
BIC = accountChilds.item(accountChildIndex).getTextContent();
}
}
}
}
}
}
}
xpr = xpath.compile("//*[local-name()=\"PaymentMeans\"]"); //UBL only
NodeList paymentMeansNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
for (int i = 0; i < paymentMeansNodes.getLength(); i++) {
// nodes.item(i).getTextContent())) {
Node paymentMeansNode = paymentMeansNodes.item(i);
NodeList paymentMeansChilds = paymentMeansNode.getChildNodes();
for (int meansChildIndex = 0; meansChildIndex < paymentMeansChilds
.getLength(); meansChildIndex++) {
if ((paymentMeansChilds.item(meansChildIndex).getLocalName() != null)
&& (paymentMeansChilds.item(meansChildIndex).getLocalName()
.equals("PayeeFinancialAccount"))) {
NodeList paymentTermChilds = paymentMeansChilds.item(meansChildIndex).getChildNodes();
for (int paymentTermChildIndex = 0; paymentTermChildIndex < paymentTermChilds
.getLength(); paymentTermChildIndex++) {
if ((paymentTermChilds.item(paymentTermChildIndex).getLocalName() != null) && (paymentTermChilds
.item(paymentTermChildIndex).getLocalName().equals("ID"))) {
IBAN = paymentTermChilds.item(paymentTermChildIndex).getTextContent();
}
}
}
} }
} }
zpp.setDueDate(dueDate).setDeliveryDate(deliveryDate).setIssueDate(issueDate) zpp.setDueDate(dueDate).setDeliveryDate(deliveryDate).setIssueDate(issueDate)
.setSender(new TradeParty(SellerNodes)).setRecipient(new TradeParty(BuyerNodes)).setNumber(number); .setSender(new TradeParty(SellerNodes)).setRecipient(new TradeParty(BuyerNodes)).setNumber(number);
if (IBAN != null) {
BankDetails bd = new BankDetails(IBAN);
if (BIC != null) {
bd.setBIC(BIC);
}
zpp.getSender().addBankDetails(bd);
}
if (buyerOrderIssuerAssignedID != null) { if (buyerOrderIssuerAssignedID != null) {
zpp.setBuyerOrderReferencedDocumentID(buyerOrderIssuerAssignedID); zpp.setBuyerOrderReferencedDocumentID(buyerOrderIssuerAssignedID);
} }
@@ -269,8 +324,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
xpr = xpath.compile("//*[local-name()=\"IncludedSupplyChainTradeLineItem\"]|//*[local-name()=\"InvoiceLine\"]"); xpr = xpath.compile("//*[local-name()=\"IncludedSupplyChainTradeLineItem\"]|//*[local-name()=\"InvoiceLine\"]");
NodeList nodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); NodeList nodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
if (nodes.getLength() == 0) { if (nodes.getLength() != 0) {
} else {
for (int i = 0; i < nodes.getLength(); i++) { for (int i = 0; i < nodes.getLength(); i++) {
Node currentItemNode = nodes.item(i); Node currentItemNode = nodes.item(i);

View File

@@ -21,12 +21,15 @@
*/ */
package org.mustangproject.ZUGFeRD; package org.mustangproject.ZUGFeRD;
import java.io.ByteArrayInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.math.BigDecimal; import java.math.BigDecimal;
import java.nio.charset.StandardCharsets;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Date; import java.util.Date;
import java.util.List;
import org.mustangproject.*; import org.mustangproject.*;
import org.junit.FixMethodOrder; import org.junit.FixMethodOrder;
@@ -54,6 +57,7 @@ public class ZF2PushTest extends TestCase {
final String TARGET_CHARGESALLOWANCESPDF = "./target/testout-ZF2PushChargesAllowances.pdf"; final String TARGET_CHARGESALLOWANCESPDF = "./target/testout-ZF2PushChargesAllowances.pdf";
final String TARGET_RELATIVECHARGESALLOWANCESPDF = "./target/testout-ZF2PushRelativeChargesAllowances.pdf"; final String TARGET_RELATIVECHARGESALLOWANCESPDF = "./target/testout-ZF2PushRelativeChargesAllowances.pdf";
final String TARGET_ATTACHMENTSPDF = "./target/testout-ZF2PushAttachments.pdf"; final String TARGET_ATTACHMENTSPDF = "./target/testout-ZF2PushAttachments.pdf";
final String TARGET_BANKPDF = "./target/testout-ZF2PushBank.pdf";
final String TARGET_PUSHEDGE = "./target/testout-ZF2PushEdge.pdf"; final String TARGET_PUSHEDGE = "./target/testout-ZF2PushEdge.pdf";
final String TARGET_INTRACOMMUNITYSUPPLYPDF = "./target/testout-ZF2PushIntraCommunitySupply.pdf"; final String TARGET_INTRACOMMUNITYSUPPLYPDF = "./target/testout-ZF2PushIntraCommunitySupply.pdf";
final String TARGET_REVERSECHARGEPDF = "./target/testout-ZF2PushReverseCharge.pdf"; final String TARGET_REVERSECHARGEPDF = "./target/testout-ZF2PushReverseCharge.pdf";
@@ -158,6 +162,44 @@ public class ZF2PushTest extends TestCase {
} }
}
public void testBankTransferExport() {
String orgname = "Test company";
String number = "123";
String priceStr = "1.00";
String taxID = "9990815";
BigDecimal price = new BigDecimal(priceStr);
try (InputStream SOURCE_PDF = this.getClass()
.getResourceAsStream("/MustangGnuaccountingBeispielRE-20170509_505blanko.pdf");
ZUGFeRDExporterFromA1 ze = new ZUGFeRDExporterFromA1().setProducer("My Application")
.setCreator(System.getProperty("user.name")).setZUGFeRDVersion(2).ignorePDFAErrors()
.load(SOURCE_PDF)) {
String IBAN="DE999888777";
String BIC="COBADEFXXX";
BankDetails bd=new BankDetails(IBAN, BIC);
ze.setTransaction(new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addBankDetails(bd).addTaxID(taxID)).setOwnVATID("DE0815").setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addVATID("DE4711").setContact(new Contact("Franz Müller", "01779999999", "franz@mueller.de", "teststr. 12", "55232", "Entenhausen", "DE"))).setNumber(number).addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(19)), price, new BigDecimal(1.0)))
);
String theXML = new String(ze.getProvider().getXML());
Invoice read=new Invoice();
ZUGFeRDInvoiceImporter zii=new ZUGFeRDInvoiceImporter(new ByteArrayInputStream(theXML.getBytes(StandardCharsets.UTF_8)));
zii.extractInto(read);
assertTrue(theXML.contains("<rsm:CrossIndustryInvoice"));
//assertEquals(IBAN,read.getSender().getBankDetails().get(0).getIBAN());
ze.export(TARGET_BANKPDF);
} catch (IOException e) {
fail("IOException should not be raised in testEdgeExport");
} catch (XPathExpressionException e) {
fail("XPathException should not be raised in testEdgeExport");
} catch (ParseException e) {
fail("ParseException should not be raised in testEdgeExport");
}
} }
public void testItemChargesAllowancesExport() { public void testItemChargesAllowancesExport() {

View File

@@ -193,8 +193,7 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
assertEquals("04011000-12345-03", invoice.getReferenceNumber()); assertEquals("04011000-12345-03", invoice.getReferenceNumber());
assertEquals("seller@email.de", invoice.getSender().getContact().getEMail()); assertEquals("seller@email.de", invoice.getSender().getContact().getEMail());
assertEquals("12345", invoice.getRecipient().getZIP()); assertEquals("12345", invoice.getRecipient().getZIP());
invoice.getPaymentTerms().get assertEquals("DE75512108001245126199", invoice.getSender().getBankDetails().get(0).getIBAN());
assertEquals("DE75512108001245126199", invoice.getDeliveryAddress().getBankDetails().getIBAN());
} }