From 47146ad3f435b67265e32380404f3fcf2ebfdc62 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jochen=20Sta=CC=88rk?= Date: Thu, 15 Oct 2020 12:22:28 +0200 Subject: [PATCH] first attempt to parse tradeparties from XML --- .../main/java/org/mustangproject/Contact.java | 1 + .../java/org/mustangproject/TradeParty.java | 68 ++++++++++++++++++- .../ZUGFeRD/ZUGFeRDInvoiceImporter.java | 17 +++-- 3 files changed, 80 insertions(+), 6 deletions(-) diff --git a/library/src/main/java/org/mustangproject/Contact.java b/library/src/main/java/org/mustangproject/Contact.java index 74f92669..0a7fd59f 100644 --- a/library/src/main/java/org/mustangproject/Contact.java +++ b/library/src/main/java/org/mustangproject/Contact.java @@ -90,4 +90,5 @@ public class Contact implements IZUGFeRDExportableContact { this.country = country; return this; } + } diff --git a/library/src/main/java/org/mustangproject/TradeParty.java b/library/src/main/java/org/mustangproject/TradeParty.java index dc536e60..fb7fd958 100644 --- a/library/src/main/java/org/mustangproject/TradeParty.java +++ b/library/src/main/java/org/mustangproject/TradeParty.java @@ -3,7 +3,10 @@ package org.mustangproject; import org.mustangproject.ZUGFeRD.IZUGFeRDExportableContact; import org.mustangproject.ZUGFeRD.IZUGFeRDExportableTradeParty; import org.mustangproject.ZUGFeRD.IZUGFeRDTradeSettlement; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import javax.xml.xpath.XPathConstants; import java.util.ArrayList; public class TradeParty implements IZUGFeRDExportableTradeParty { @@ -22,17 +25,80 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } + public TradeParty(NodeList nodes) { +/** + * + * LIEF-987654321 + * Max Mustermann IT GmbH + * + * Herr Treudiener + * + * +49 1234-98765-12 + * + * + * treudiener@max-mustermann-it.de + * + * + * + * 12345 + * Musterstraße 1 + * Musterstadt + * DE + * + * + * DE123456789 + * + * + */ + if (nodes.getLength() > 0) { + + for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) { + //nodes.item(i).getTextContent())) { + Node currentItemNode = nodes.item(nodeIndex); + NodeList itemChilds = currentItemNode.getChildNodes(); + for (int itemChildIndex = 0; itemChildIndex < itemChilds.getLength(); itemChildIndex++) { + if (itemChilds.item(itemChildIndex).getNodeName().equals("ram:Name")) { + setName(itemChilds.item(itemChildIndex).getTextContent()); + } + if (itemChilds.item(itemChildIndex).getNodeName().equals("ram:PostalTradeAddress")) { + NodeList postal = itemChilds.item(itemChildIndex).getChildNodes(); + for (int postalChildIndex = 0; postalChildIndex < postal.getLength(); postalChildIndex++) { + if (postal.item(postalChildIndex).getNodeName().equals("ram:LineOne")) { + setStreet(postal.item(postalChildIndex).getTextContent()); + } + if (postal.item(postalChildIndex).getNodeName().equals("ram:CityName")) { + setLocation(postal.item(postalChildIndex).getTextContent()); + } + if (postal.item(postalChildIndex).getNodeName().equals("ram:PostcodeCode")) { + setZIP(postal.item(postalChildIndex).getTextContent()); + } + if (postal.item(postalChildIndex).getNodeName().equals("ram:CountryID")) { + setCountry(postal.item(postalChildIndex).getTextContent()); + } + } + + } + + } + } + } + + } + public TradeParty setContact(Contact c) { this.contact = c; return this; } + public TradeParty addBankDetails(BankDetails s) { bankDetails.add(s); return this; } + public ArrayList getBankDetails() { return bankDetails; } + public TradeParty addTaxID(String taxID) { this.taxID = taxID; return this; @@ -117,7 +183,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } public IZUGFeRDTradeSettlement[] getAsTradeSettlement() { - if (bankDetails.size()==0) { + if (bankDetails.size() == 0) { return null; } return bankDetails.toArray(new IZUGFeRDTradeSettlement[0]); diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index 2ab750e6..4ef4f238 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -20,15 +20,22 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter { * dummywerte sind derzeit noch setDueDate setIssueDate setDeliveryDate setSender setRecipient setnumber * bspw. due date //ExchangedDocument//IssueDateTime//DateTimeString : due date optional */ - Invoice zpp = new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty("company", "teststr", "55232", "teststadt", "DE")).setOwnTaxID("4711").setOwnVATID("0815").setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE")).setNumber(number); -//.addItem(new Item(new Product("Testprodukt","","C62",new BigDecimal(0)),amount,new BigDecimal(1.0))) - zpp.setOwnOrganisationName(extractString("//SellerTradeParty/Name")); - XPathFactory xpathFact = XPathFactory.newInstance(); XPath xpath = xpathFact.newXPath(); + Invoice zpp = null; try { - XPathExpression xpr = xpath.compile( + "//SellerTradeParty"); + NodeList SellerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); + xpr = xpath.compile( + "//BuyerTradeParty"); + NodeList BuyerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); + + zpp= new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()).setSender(new TradeParty(SellerNodes)).setRecipient(new TradeParty(BuyerNodes)).setNumber(number); +//.addItem(new Item(new Product("Testprodukt","","C62",new BigDecimal(0)),amount,new BigDecimal(1.0))) + zpp.setOwnOrganisationName(extractString("//SellerTradeParty/Name")); + + xpr = xpath.compile( "//*[local-name()=\"IncludedSupplyChainTradeLineItem\"]"); NodeList nodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);