diff --git a/library/src/main/java/org/mustangproject/TradeParty.java b/library/src/main/java/org/mustangproject/TradeParty.java index 51c20f90..3dd8fb6a 100644 --- a/library/src/main/java/org/mustangproject/TradeParty.java +++ b/library/src/main/java/org/mustangproject/TradeParty.java @@ -30,8 +30,8 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { protected List debitDetails = new ArrayList<>(); protected Contact contact = null; protected LegalOrganisation legalOrg = null; - protected SchemedID globalId=null; - protected SchemedID uriUniversalCommunicationId=null; //e.g. the email address of the organization + protected SchemedID globalId = null; + protected SchemedID uriUniversalCommunicationId = null; //e.g. the email address of the organization /** * Default constructor. @@ -153,7 +153,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { if (itemChilds.item(itemChildIndex).getLocalName().equals("GlobalID")) { if (itemChilds.item(itemChildIndex).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(itemChilds.item(itemChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(itemChilds.item(itemChildIndex).getTextContent()); addGlobalID(gid); } @@ -198,8 +198,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { if ((taxChilds.item(taxChildIndex).getLocalName().equals("ID"))) { if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID") != null) { Node firstChild = taxChilds.item(taxChildIndex).getFirstChild(); - if (firstChild != null) - { + if (firstChild != null) { if (taxChilds.item(taxChildIndex).getAttributes() .getNamedItem("schemeID").getNodeValue().equals("VA")) { setVATID(firstChild.getNodeValue()); @@ -294,22 +293,19 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { parseFromUBL(nodes); return; } - if (itemChilds.item(itemChildIndex).getLocalName().equals("Name")) { setName(itemChilds.item(itemChildIndex).getTextContent()); } if (itemChilds.item(itemChildIndex).getLocalName().equals("GlobalID")) { if (itemChilds.item(itemChildIndex).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(itemChilds.item(itemChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(itemChilds.item(itemChildIndex).getTextContent()); addGlobalID(gid); } - } 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++) { @@ -337,6 +333,19 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } } + if (itemChilds.item(itemChildIndex).getLocalName().equals("URIUniversalCommunication")) { + NodeList URIchilds = itemChilds.item(itemChildIndex).getChildNodes(); + for (int URIChildIndex = 0; URIChildIndex < URIchilds.getLength(); URIChildIndex++) { + Node currentNode = URIchilds.item(URIChildIndex); + if ((currentNode.getLocalName() != null) && (currentNode.getLocalName().equals("URIID") + && + (currentNode.getAttributes().getNamedItem("schemeID") != null)) + && (URIchilds.item(URIChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue().equals("EM")) + ) { + setEmail(currentNode.getTextContent()); + } + } + } if (itemChilds.item(itemChildIndex).getLocalName().equals("SpecifiedTaxRegistration")) { NodeList taxChilds = itemChilds.item(itemChildIndex).getChildNodes(); @@ -345,14 +354,13 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { if ((taxChilds.item(taxChildIndex).getLocalName().equals("ID"))) { if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID") != null) { Node firstChild = taxChilds.item(taxChildIndex).getFirstChild(); - if (firstChild != null) - { + if (firstChild != null) { if (taxChilds.item(taxChildIndex).getAttributes() - .getNamedItem("schemeID").getNodeValue().equals("VA")) { + .getNamedItem("schemeID").getNodeValue().equals("VA")) { setVATID(firstChild.getNodeValue()); } if (taxChilds.item(taxChildIndex).getAttributes() - .getNamedItem("schemeID").getNodeValue().equals("FC")) { + .getNamedItem("schemeID").getNodeValue().equals("FC")) { setTaxID(firstChild.getNodeValue()); } } @@ -374,37 +382,35 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { @Override public String getGlobalID() { - if (globalId!=null) { + if (globalId != null) { return globalId.getID(); } return null; } - @Override public String getGlobalIDScheme() { - if (globalId!=null) { + if (globalId != null) { return globalId.getScheme(); } return null; } - + @Override public String getUriUniversalCommunicationID() { - if (uriUniversalCommunicationId!=null) { + if (uriUniversalCommunicationId != null) { return uriUniversalCommunicationId.getID(); } return null; } - @Override public String getUriUniversalCommunicationIDScheme() { - if (uriUniversalCommunicationId!=null) { + if (uriUniversalCommunicationId != null) { return uriUniversalCommunicationId.getScheme(); } return null; @@ -414,28 +420,15 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { /*** * sets the email of the organization (not the one of the contact person) + * (while setEmail has to be defined here getEmail comes from IZUGFeRDExportableTradeParty) * @return fluent setter */ public TradeParty setEmail(String eMail) { - SchemedID theSchemedID=new SchemedID("EM", eMail); + SchemedID theSchemedID = new SchemedID("EM", eMail); addUriUniversalCommunicationID(theSchemedID); return this; } - /*** - * gets the email of the organization (not the one of the contact person) - * will return null if not set or if the provided UriUniversalCommunicationID - * is not a email address - * - * @return String the email, or null - */ - public String getEmail() { - if (uriUniversalCommunicationId.getScheme().equals("EM")) { - return uriUniversalCommunicationId.getID(); - } - return null; - } - /** * if it's a customer, this can e.g. be the customer ID @@ -460,12 +453,12 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } public TradeParty addGlobalID(SchemedID schemedID) { - globalId=schemedID; + globalId = schemedID; return this; } - + public TradeParty addUriUniversalCommunicationID(SchemedID schemedID) { - uriUniversalCommunicationId=schemedID; + uriUniversalCommunicationId = schemedID; return this; } @@ -496,7 +489,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } public TradeParty setLegalOrganisation(LegalOrganisation legalOrganisation) { - legalOrg=legalOrganisation; + legalOrg = legalOrganisation; return this; } @@ -634,8 +627,8 @@ 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++) { @@ -651,7 +644,6 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } - /*** * additional info of the address, e.g. which building or which floor. * Street address will become "lineOne", this will become "lineTwo". diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTradeParty.java b/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTradeParty.java index 16ce44f1..e097ad86 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTradeParty.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/IZUGFeRDExportableTradeParty.java @@ -79,9 +79,11 @@ public interface IZUGFeRDExportableTradeParty { return null; } + + /** - * The URIID of URIUniversalCommunicationID - * It is used by some countries, i.e. Luxembourg + * The URIID of URIUniversalCommunicationID (e.g. email address) + * It is used by some countries, i.e. Luxembourg, Peppol * @return the URI as string */ default String getUriUniversalCommunicationID() { @@ -89,6 +91,24 @@ public interface IZUGFeRDExportableTradeParty { } + /*** + * gets the email of the organization (not the one of the contact person) + * will return null if not set or if the provided UriUniversalCommunicationID + * is not a email address + * + * @return String the email, or null + */ + default String getEmail() { + if ((getUriUniversalCommunicationIDScheme()!=null)&&(getUriUniversalCommunicationIDScheme().equals("EM"))) { + return getUriUniversalCommunicationID(); + } + return null; + } + + /*** + * the named contact person for inquiries + * @return contact + */ default IZUGFeRDExportableContact getContact() { return null; } diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/XRTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/XRTest.java index ac5f2aaf..937de436 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/XRTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/XRTest.java @@ -86,8 +86,8 @@ public class XRTest extends TestCase { FileAttachment fe1=new FileAttachment("one.pdf", "application/pdf", "Alternative", b); Invoice i = new Invoice().setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()) - .setSender(new TradeParty(orgname,"teststr","55232","teststadt","DE").addTaxID("DE4711").addVATID("DE0815").setContact(new Contact("Hans Test","+49123456789","test@example.org")).addBankDetails(new BankDetails("DE12500105170648489890","COBADEFXXX"))) - .setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE")) + .setSender(new TradeParty(orgname,"teststr","55232","teststadt","DE").setEmail("sender@example.com").addTaxID("DE4711").addVATID("DE0815").setContact(new Contact("Hans Test","+49123456789","test@example.org")).addBankDetails(new BankDetails("DE12500105170648489890","COBADEFXXX"))) + .setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").setEmail("recipient@sample.org")) .setReferenceNumber("991-01484-64")//leitweg-id // not using any VAT, this is also a test of zero-rated goods: .setNumber(number).setPaymentTermDescription("#SKONTO#TAGE=14#PROZENT=2.25#\n" + diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java index 34f17863..057ed101 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2PushTest.java @@ -386,10 +386,10 @@ public class ZF2PushTest extends TestCase { ze.setTransaction(new Invoice().setCurrency("CHF").addNote("document level 1/2").addNote("document level 2/2").setDueDate(new Date()).setIssueDate(new Date()).setDeliveryDate(new Date()) .setSellerOrderReferencedDocumentID("9384").setBuyerOrderReferencedDocumentID("28934") .setDetailedDeliveryPeriod(new SimpleDateFormat("yyyyMMdd").parse(occurrenceFrom), new SimpleDateFormat("yyyyMMdd").parse(occurrenceTo)) - .setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID(taxID).setID("0009845")) + .setSender(new TradeParty(orgname, "teststr", "55232", "teststadt", "DE").addTaxID(taxID).setEmail("sender@test.org").setID("0009845")) .setDeliveryAddress(new TradeParty("just the other side of the street", "teststr.12a", "55232", "Entenhausen", "DE").addVATID("DE47110")) .setContractReferencedDocument(contractID) - .setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addGlobalID(gln).addVATID("DE4711").setContact(new Contact("Franz Müller", "01779999999", "franz@mueller.de", "teststr. 12", "55232", "Entenhausen", "DE").setFax("++49555123456")).setAdditionalAddress("Hinterhaus 3")) + .setRecipient(new TradeParty("Franz Müller", "teststr.12", "55232", "Entenhausen", "DE").addGlobalID(gln).setEmail("recipient@test.org").addVATID("DE4711").setContact(new Contact("Franz Müller", "01779999999", "franz@mueller.de", "teststr. 12", "55232", "Entenhausen", "DE").setFax("++49555123456")).setAdditionalAddress("Hinterhaus 3")) .addItem(new Item(new Product("Testprodukt", "", "C62", new BigDecimal(16)).addGlobalID(gtin).setSellerAssignedID("4711"), price, new BigDecimal(1.0)).addReferencedLineID("xxx").addNote("item level 1/1").addAllowance(new Allowance(new BigDecimal(0.02)).setReason("item discount").setTaxPercent(new BigDecimal(16))).setDetailedDeliveryPeriod(sdf.parse("2020-01-13"), sdf.parse("2020-01-15"))) .addCharge(new Charge(new BigDecimal(0.5)).setReason("quick delivery charge").setTaxPercent(new BigDecimal(16))) .addAllowance(new Allowance(new BigDecimal(0.2)).setReason("discount").setTaxPercent(new BigDecimal(16))) diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java index 198353a6..154b5990 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java @@ -169,6 +169,8 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { // Reading ZUGFeRD assertEquals("4711", invoice.getZFItems()[0].getProduct().getSellerAssignedID()); assertEquals("9384", invoice.getSellerOrderReferencedDocumentID()); + assertEquals("sender@test.org", invoice.getSender().getEmail()); + assertEquals("recipient@test.org", invoice.getRecipient().getEmail()); assertEquals("28934", invoice.getBuyerOrderReferencedDocumentID()); } diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/test.xml b/library/src/test/java/org/mustangproject/ZUGFeRD/test.xml deleted file mode 100644 index b985dc7e..00000000 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/test.xml +++ /dev/null @@ -1,184 +0,0 @@ - - - - - - - urn:cen.eu:en16931:2017 - - - - 123 - 380 - - 20220725 - - - document level 1/2 - - - document level 2/2 - - - - - - 1 - - item level 1/1 - - - - Testprodukt - - - - - xxx - - - 1.0000 - 1.0000 - - - false - - 0.0200 - - - - 0.9800 - 1.0000 - - - - 1.0000 - - - - VAT - S - 16.00 - - - - 20200113 - - - 20200115 - - - - 0.98 - - - - - - 0009845 - Test company - - 55232 - teststr - teststadt - DE - - - DE0815 - - - 9990815 - - - - 4304171000002 - Franz Müller - - 55232 - teststr.12 - Hinterhaus 3 - Entenhausen - DE - - - DE4711 - - - - 376zreurzu0983 - - - - - just the other side of the street - - 55232 - teststr.12a - Entenhausen - DE - - - - - 20201102 - - - - - 123 - CHF - - 0.20 - VAT - 1.28 - S - 16.00 - - - - 20201001 - - - 20201005 - - - - - true - - 0.50 - quick delivery charge - - VAT - S - 16.00 - - - - - false - - 0.20 - discount - - VAT - S - 16.00 - - - - Zahlbar ohne Abzug bis 25.07.2022 - - - 0.98 - 0.50 - 0.20 - 1.28 - 0.20 - 1.48 - 0.00 - 1.48 - - - -