diff --git a/library/src/main/java/org/mustangproject/Contact.java b/library/src/main/java/org/mustangproject/Contact.java index cfbfc1e9..08e57772 100644 --- a/library/src/main/java/org/mustangproject/Contact.java +++ b/library/src/main/java/org/mustangproject/Contact.java @@ -1,6 +1,8 @@ package org.mustangproject; import org.mustangproject.ZUGFeRD.IZUGFeRDExportableContact; +import org.w3c.dom.Node; +import org.w3c.dom.NodeList; /*** * a named contact person in an organisation @@ -9,8 +11,8 @@ import org.mustangproject.ZUGFeRD.IZUGFeRDExportableContact; */ public class Contact implements IZUGFeRDExportableContact { - protected String name,phone,email,zip,street,location,country; - protected String fax=null; + protected String name, phone, email, zip, street, location, country; + protected String fax = null; /*** * default constructor. @@ -46,6 +48,58 @@ public class Contact implements IZUGFeRDExportableContact { } + /*** + * XML parsing constructor + * @param nodes the nodelist returned e.g. from xpath + * + * e.g. sth like + * + * Name + * + * 069 100-0 + * + * + * test@example.com + * + * + */ + public Contact(NodeList nodes) { + if (nodes.getLength() > 0) { + + for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) { + //nodes.item(i).getTextContent())) { + Node currentItemNode = nodes.item(nodeIndex); + if (currentItemNode.getLocalName() != null) { + + if (currentItemNode.getLocalName().equals("PersonName")) { + setName(currentItemNode.getFirstChild().getNodeValue()); + } + if (currentItemNode.getLocalName().equals("TelephoneUniversalCommunication")) { + NodeList tel = currentItemNode.getChildNodes(); + for (int telChildIndex = 0; telChildIndex < tel.getLength(); telChildIndex++) { + if (tel.item(telChildIndex).getLocalName() != null) { + if (tel.item(telChildIndex).getLocalName().equals("CompleteNumber")) { + setPhone(tel.item(telChildIndex).getTextContent()); + } + } + } + } + if (currentItemNode.getLocalName().equals("EmailURIUniversalCommunication")) { + NodeList email = currentItemNode.getChildNodes(); + for (int emailChildIndex = 0; emailChildIndex < email.getLength(); emailChildIndex++) { + if (email.item(emailChildIndex).getLocalName() != null) { + if (email.item(emailChildIndex).getLocalName().equals("URIID")) { + setEMail(email.item(emailChildIndex).getTextContent()); + } + } + } + } + } + } + } + } + + @Override public String getName() { return name; @@ -53,6 +107,7 @@ public class Contact implements IZUGFeRDExportableContact { /** * the first and last name of the contact + * * @param name first and last name * @return fluent setter */ @@ -126,6 +181,7 @@ public class Contact implements IZUGFeRDExportableContact { /** * street and number, if the address is different to the organisation + * * @param street street and number of the contact * @return fluent setter */ diff --git a/library/src/main/java/org/mustangproject/TradeParty.java b/library/src/main/java/org/mustangproject/TradeParty.java index 0e906846..ffac8008 100644 --- a/library/src/main/java/org/mustangproject/TradeParty.java +++ b/library/src/main/java/org/mustangproject/TradeParty.java @@ -78,35 +78,64 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { 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:LineTwo")) { - setAdditionalAddress(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()); - } + if (itemChilds.item(itemChildIndex).getLocalName() != null) { + + if (itemChilds.item(itemChildIndex).getLocalName().equals("Name")) { + setName(itemChilds.item(itemChildIndex).getTextContent()); + } + if (itemChilds.item(itemChildIndex).getLocalName().equals("DefinedTradeContact")) { + NodeList contact = itemChilds.item(itemChildIndex).getChildNodes(); + setContact(new Contact(contact)); } - } + if (itemChilds.item(itemChildIndex).getLocalName().equals("PostalTradeAddress")) { + NodeList postal = itemChilds.item(itemChildIndex).getChildNodes(); + for (int postalChildIndex = 0; postalChildIndex < postal.getLength(); postalChildIndex++) { + if (postal.item(postalChildIndex).getLocalName() != null) { + if (postal.item(postalChildIndex).getLocalName().equals("LineOne")) { + setStreet(postal.item(postalChildIndex).getTextContent()); + } + if (postal.item(postalChildIndex).getLocalName().equals("LineTwo")) { + setAdditionalAddress(postal.item(postalChildIndex).getTextContent()); + } + if (postal.item(postalChildIndex).getLocalName().equals("CityName")) { + setLocation(postal.item(postalChildIndex).getTextContent()); + } + if (postal.item(postalChildIndex).getLocalName().equals("PostcodeCode")) { + setZIP(postal.item(postalChildIndex).getTextContent()); + } + if (postal.item(postalChildIndex).getLocalName().equals("CountryID")) { + setCountry(postal.item(postalChildIndex).getTextContent()); + } + } + } + + } + + if (itemChilds.item(itemChildIndex).getLocalName().equals("SpecifiedTaxRegistration")) { + NodeList taxChilds = itemChilds.item(itemChildIndex).getChildNodes(); + for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) { + if (taxChilds.item(taxChildIndex).getLocalName() != null) { + if ((taxChilds.item(taxChildIndex).getLocalName().equals("ID"))) { + if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID")!=null) { + if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue().equals("VA")) + { + setVATID(taxChilds.item(taxChildIndex).getFirstChild().getNodeValue()); + } + if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue().equals("FC")) + { + setTaxID(taxChilds.item(taxChildIndex).getFirstChild().getNodeValue()); + } + } + } + } + } + } + } } } } - } @Override @@ -116,6 +145,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { /** * if it's a customer, this can e.g. be the customer ID + * * @param ID customer/seller number * @return fluent setter */ @@ -144,14 +174,16 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { bankDetails.add(s); return this; } + /** * (optional) + * * @param debitDetail * @return fluent setter */ public TradeParty addDebitDetails(IZUGFeRDTradeSettlementDebit debitDetail) { - debitDetails.add(debitDetail); - return this; + debitDetails.add(debitDetail); + return this; } public List getBankDetails() { @@ -183,11 +215,21 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { return vatID; } + public TradeParty setVATID(String VATid) { + this.vatID = VATid; + return this; + } + @Override public String getTaxID() { return taxID; } + public TradeParty setTaxID(String tax) { + this.taxID = tax; + return this; + } + public String getName() { return name; } @@ -278,13 +320,13 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { return null; } List tradeSettlements = Stream.concat(bankDetails.stream(), debitDetails.stream()) - .map(IZUGFeRDTradeSettlement.class::cast) - .collect(Collectors.toList()); - + .map(IZUGFeRDTradeSettlement.class::cast) + .collect(Collectors.toList()); + IZUGFeRDTradeSettlement[] result = new IZUGFeRDTradeSettlement[tradeSettlements.size()]; for (int i = 0; i < tradeSettlements.size(); i++) { - IZUGFeRDTradeSettlement izugFeRDTradeSettlement = tradeSettlements.get(i); - result[i]=izugFeRDTradeSettlement; + IZUGFeRDTradeSettlement izugFeRDTradeSettlement = tradeSettlements.get(i); + result[i] = izugFeRDTradeSettlement; } return result; } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java index 32eabf2d..fa7c5e02 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRD2PullProvider.java @@ -130,8 +130,11 @@ public class ZUGFeRD2PullProvider implements IXMLProvider { xml += " " + XMLTools.encodeXML(party.getName()) + "\n"; if ((party.getContact() != null) && (isSender || profile == Profiles.getByName("Extended") || profile == Profiles.getByName("XRechnung"))) { - xml = xml + "\n" + " " + XMLTools.encodeXML(party.getContact().getName()) - + "\n"; + xml = xml + "\n"; + if (party.getContact().getPhone() != null) { + xml = xml + "" + XMLTools.encodeXML(party.getContact().getName()) + + "\n"; + } if (party.getContact().getPhone() != null) { xml = xml + " \n" + " "