From e1991b2b2816790191849c68a773dc02b371cc18 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Fri, 4 Oct 2024 16:33:36 +0200 Subject: [PATCH 01/22] recipient.id --- .../java/org/mustangproject/TradeParty.java | 15 +- .../ZUGFeRD/ZF2ZInvoiceImporterTest.java | 45 ++- ...sed_onTest_EeISI_300_CENfullmodel2.cii.xml | 353 ++++++++++++++++++ ...sed_onTest_EeISI_300_CENfullmodel2.ubl.xml | 2 +- 4 files changed, 407 insertions(+), 8 deletions(-) create mode 100644 library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.cii.xml diff --git a/library/src/main/java/org/mustangproject/TradeParty.java b/library/src/main/java/org/mustangproject/TradeParty.java index e67567e4..46a457c5 100644 --- a/library/src/main/java/org/mustangproject/TradeParty.java +++ b/library/src/main/java/org/mustangproject/TradeParty.java @@ -89,6 +89,19 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } } + if (currentTopElementName.equals("PartyIdentification")) { + + NodeList partyName = party.item(partyIndex).getChildNodes(); + for (int partyNameIndex = 0; partyNameIndex < partyName.getLength(); partyNameIndex++) { + if (partyName.item(partyNameIndex).getLocalName() != null) { + if (partyName.item(partyNameIndex).getLocalName().equals("ID")) { + setID(partyName.item(partyNameIndex).getTextContent()); + } + + } + } + } + // UBL only: formally it can have a name as well but BT27 party name *should* be stored in // so overwrite if one exists if (currentTopElementName.equals("PartyLegalEntity")) { @@ -311,7 +324,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { NodeList itemChilds = currentItemNode.getChildNodes(); for (int itemChildIndex = 0; itemChildIndex < itemChilds.getLength(); itemChildIndex++) { if (itemChilds.item(itemChildIndex).getLocalName() != null) { - if (itemChilds.item(itemChildIndex).getLocalName().equals("ID")) { + if (itemChilds.item(itemChildIndex).getLocalName().equals("GlobalID")) { setID(itemChilds.item(itemChildIndex).getTextContent()); } if (itemChilds.item(itemChildIndex).getLocalName().equals("Name")) { diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java index 175aa9f1..505c9029 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java @@ -42,9 +42,23 @@ import java.util.Arrays; public class ZF2ZInvoiceImporterTest extends ResourceCase { - public void testInvoiceImport() { + public void testInvoiceImportSupportCase145() { - ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter("./target/testout-ZF2new.pdf"); + ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter("C:\\Users\\jstaerk\\workspace\\XMLExamples\\zfdiverses\\20241004_\\IGEPA-Rechnung_41102839_00200_20240918.PDF"); + boolean hasExceptions = false; + Invoice invoice = null; + try { + invoice = zii.extractInvoice(); + } catch (XPathExpressionException | ParseException e) { + hasExceptions = true; + } + assertFalse(hasExceptions); + + } + + public void testInvoiceImport() { + + ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter("./target/testout-ZF2new.pdf"); boolean hasExceptions = false; Invoice invoice = null; @@ -318,12 +332,30 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { } -/* + public void testEEISI_300_cii_Import() { boolean hasExceptions = false; File input = getResourceAsFile("not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.ubl.xml"); + File inputCorrect = getResourceAsFile("not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.cii.xml"); + ZUGFeRDInvoiceImporter cii = new ZUGFeRDInvoiceImporter(); + try { + cii.fromXML(new String(Files.readAllBytes(inputCorrect.toPath()), StandardCharsets.UTF_8)); + + } catch (IOException e) { + hasExceptions = true; + } + + Invoice ciiinvoice = null; + try { + ciiinvoice = cii.extractInvoice(); + + } catch (XPathExpressionException e) { + throw new RuntimeException(e); + } catch (ParseException e) { + throw new RuntimeException(e); + } ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(); try { zii.fromXML(new String(Files.readAllBytes(input.toPath()), StandardCharsets.UTF_8)); @@ -335,11 +367,12 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { Invoice invoice = null; try { invoice = zii.extractInvoice(); - assertEquals("Seller contact point",invoice.getSender().getName()); + assertEquals("Seller name",invoice.getSender().getName()); + assertEquals(ciiinvoice.getRecipient().getID(),invoice.getRecipient().getID()); /* Seller contact point +41 345 654455 - seller@contact.de);* + seller@contact.de);*/ } catch (XPathExpressionException | ParseException e) { hasExceptions = true; } @@ -349,5 +382,5 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { } -*/ + } diff --git a/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.cii.xml b/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.cii.xml new file mode 100644 index 00000000..94a81f4c --- /dev/null +++ b/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.cii.xml @@ -0,0 +1,353 @@ + + + + + BT-23 Business Process Type + + + urn:cen.eu:en16931:2017 + + + + Test_EeISI_100 + 380 + + 20181112 + + + invoice note text + #AAA# + + + invoice note text 2 + #AAA# + + + + + + 1a + + Invoice line note + + + + Item standar identifier + Item seller's identifier + Item buyer's identifier + Item name + Item description + + Color + Red + + + Size + L + + + Item classification identifier0 + + + IT + + + + + 12345 + + + 11.00 + 1.00 + + + 10.00 + 1.00 + + + + 10.00 + + + + VAT + S + 5.00 + + + + 20181112 + + + 20181130 + + + + 1000.00 + + + Line object identifier + 130 + + + + 6789 + + + + + + 1b + + + Item name 2 + + + + 10.00 + + + + 10.00 + + + + VAT + E + 0.00 + + + 1000.00 + + + + + 123 + + Seller identifier 1 + Seller identifier 2 + Seller name + Seller additional legal information + + Seller legal identifier + Seller trading name + + + Seller contact point + + +41 345 654455 + + + seller@contact.de + + + + 12345 + Seller address line 1 + Seller address line 2 + Seller address line 3 + Seller city + DE + Seller country subdivision + + + Seller electronic address + + + DE12345677 + + + DE49294093 + + + + Buyer identifier + Buyer name + + Buyer legal registration identifier + Buyer trading name + + + Buyer contact point + + +353 2948584 + + + buyer@contact.ie + + + + 34562 + Buyer address line 1 + Buyer address line 2 + Buyer address line 3 + Buyer city + IE + Buyer country subdivision + + + Buyer electronic address + + + IE394838894 + + + + Tax representative name + + 23455 + Tax representative address line 1 + Tax representative address line 2 + Tax representative address line 3 + Tax representative city + DE + Tax representative country subdivision + + + DE3949053 + + + + def + + + abc + + + 789 + + + Supporting document ref + External document location + 916 + Supporting document descr + ZGVmYXVsdA== + + + rst + 130 + 0090 + + + 456 + Project reference + + + + + deliver location identifier + Deliver to party name + + 98765 + Deliver to address line 1 + Deliver to address line 2 + Deliver to address line 3 + Deliver to city + IE + Deliver to country subdivision + + + + + 20181204 + + + + lmn + + + ghi + + + + Bank assigned creditor identifier + Remittance information + NOK + EUR + + Payee identifier + Payee name + + Payee legal registration identifier + + + + 4 + SEPA + + 1234 + Payment card holder name + + + Debited account identifier + + + IT1212341234123412 + Payment account name + + + BSCTCH22 + + + IT1212341234123413 + Payment account name 2 + + + BSCTCH22 + + + + 50.00 + VAT + 1000.00 + S + 29 + 5.00 + + + 0.00 + VAT + Exemtion reason text + 1000.00 + E + Exemption reason code + 29 + 0.00 + + + + 20181112 + + + 20181130 + + + + total amount + + 20181130 + + Mandate reference identifier + + + 200.00 + 200.00 + 50.00 + 46.00 + 0.00 + 205.00 + 0.00 + 205.00 + + + abc123 + + 20181004 + + + + uvz + + + + diff --git a/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.ubl.xml b/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.ubl.xml index 7e71103c..1654b0ac 100644 --- a/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.ubl.xml +++ b/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.ubl.xml @@ -112,7 +112,7 @@ Buyer electronic address - 0190:Buyer identifier + Buyer identifier Buyer trading name From 135a577c9f2539ba2df5f874f930b240bcd3a3fa Mon Sep 17 00:00:00 2001 From: Bharti Date: Mon, 18 Nov 2024 10:58:21 +0100 Subject: [PATCH 02/22] UBL updates --- .../java/org/mustangproject/BankDetails.java | 26 +-- .../java/org/mustangproject/TradeParty.java | 166 +++++++----------- .../ZUGFeRD/ZUGFeRDInvoiceImporter.java | 8 +- 3 files changed, 81 insertions(+), 119 deletions(-) diff --git a/library/src/main/java/org/mustangproject/BankDetails.java b/library/src/main/java/org/mustangproject/BankDetails.java index c6edcc86..5998bf16 100644 --- a/library/src/main/java/org/mustangproject/BankDetails.java +++ b/library/src/main/java/org/mustangproject/BankDetails.java @@ -84,19 +84,19 @@ public class BankDetails implements IZUGFeRDTradeSettlementPayment { /*** * getOwn... methods will be removed in the future in favor of Tradeparty (e.g. Sender) class * */ - @Override - @Deprecated - @JsonIgnore - public String getOwnBIC() { - return getBIC(); - } - - @Override - @Deprecated - @JsonIgnore - public String getOwnIBAN() { - return getIBAN(); - } +// @Override +// @Deprecated +// @JsonIgnore +// public String getOwnBIC() { +// return getBIC(); +// } +// +// @Override +// @Deprecated +// @JsonIgnore +// public String getOwnIBAN() { +// return getIBAN(); +// } /** diff --git a/library/src/main/java/org/mustangproject/TradeParty.java b/library/src/main/java/org/mustangproject/TradeParty.java index 871a0e82..95619d76 100644 --- a/library/src/main/java/org/mustangproject/TradeParty.java +++ b/library/src/main/java/org/mustangproject/TradeParty.java @@ -2,6 +2,7 @@ package org.mustangproject; import java.util.ArrayList; import java.util.List; +import java.util.Objects; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -16,6 +17,8 @@ import org.w3c.dom.NodeList; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; +import static org.apache.fop.fonts.type1.AdobeStandardEncoding.a; + /*** * A organisation, i.e. usually a company */ @@ -92,127 +95,103 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } if (currentTopElementName.equals("PartyTaxScheme")) { - NodeList partyTaxScheme = party.item(partyIndex).getChildNodes(); - for (int partyTaxSchemeIndex = 0; partyTaxSchemeIndex < partyTaxScheme.getLength(); partyTaxSchemeIndex++) { + NodeList partyTaxScheme = party.item(partyIndex).getChildNodes(); + for (int partyTaxSchemeIndex = 0; partyTaxSchemeIndex < partyTaxScheme.getLength(); partyTaxSchemeIndex++) { if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName() != null) { - if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName().equals("CompanyID")) { + if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName().equals("CompanyID")){ setTaxID(partyTaxScheme.item(partyTaxSchemeIndex).getTextContent()); - } } - } + + } } -// if (currentTopElementName.equals("PartyTaxScheme")) { -// NodeList partyTaxScheme = party.item(partyIndex).getChildNodes(); -// for (int partyTaxSchemeIndex = 0; partyTaxSchemeIndex < partyTaxScheme.getLength(); partyTaxSchemeIndex++) { -// if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName() != null) { -// if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName().equals("TaxScheme")) { -// NodeList taxScheme = partyTaxScheme.item(partyTaxSchemeIndex).getChildNodes(); -// for (int taxSchemeIndex = 0 ; taxSchemeIndex < taxScheme.getLength(); taxSchemeIndex++) { -// if (taxScheme.item(taxSchemeIndex).getLocalName() != null) { -// if(taxScheme.item(taxSchemeIndex).getLocalName().equals("ID")){ -// if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName().equals("CompanyID")) { -// setTaxID(partyTaxScheme.item(partyTaxSchemeIndex).getTextContent()); -// } else { -// setVATID(partyTaxScheme.item(partyTaxSchemeIndex).getTextContent()); -// } -// } -// } -// } -// } -// -// } -// } -// } /* UBL only: formally it can have a name as well but BT27 party name *should* be stored in so overwrite if one exists */ - if (currentTopElementName.equals("PartyLegalEntity")) { - NodeList legal = party.item(partyIndex).getChildNodes(); - for (int legalChildIndex = 0; legalChildIndex < legal.getLength(); legalChildIndex++) { - if (legal.item(legalChildIndex).getLocalName() != null) { - if (legal.item(legalChildIndex).getLocalName().equals("RegistrationName")) { - setName(legal.item(legalChildIndex).getTextContent()); - } - if (legal.item(legalChildIndex).getLocalName().equals("CompanyLegalForm")) { - setDescription(legal.item(legalChildIndex).getTextContent()); + if (currentTopElementName.equals("PartyLegalEntity")) { + NodeList legal = party.item(partyIndex).getChildNodes(); + for (int legalChildIndex = 0; legalChildIndex < legal.getLength(); legalChildIndex++) { + if (legal.item(legalChildIndex).getLocalName() != null) { + if (legal.item(legalChildIndex).getLocalName().equals("RegistrationName")) { + setName(legal.item(legalChildIndex).getTextContent()); + } + if (legal.item(legalChildIndex).getLocalName().equals("CompanyLegalForm")) { + setDescription(legal.item(legalChildIndex).getTextContent()); + } } } } - } - if (currentTopElementName.equals("PostalAddress")) { + if (currentTopElementName.equals("PostalAddress")) { - NodeList postal = party.item(partyIndex).getChildNodes(); - for (int postalChildIndex = 0; postalChildIndex < postal.getLength(); postalChildIndex++) { - if (postal.item(postalChildIndex).getLocalName() != null) { + NodeList postal = party.item(partyIndex).getChildNodes(); + for (int postalChildIndex = 0; postalChildIndex < postal.getLength(); postalChildIndex++) { + if (postal.item(postalChildIndex).getLocalName() != null) { - if (postal.item(postalChildIndex).getLocalName().equals("StreetName")) { - setStreet(postal.item(postalChildIndex).getTextContent()); - } - if (postal.item(postalChildIndex).getLocalName().equals("AdditionalStreetName")) { - setAdditionalAddress(postal.item(postalChildIndex).getTextContent()); - } - //unknow correspondence if (postal.item(postalChildIndex).getLocalName().equals("LineThree")) { + if (postal.item(postalChildIndex).getLocalName().equals("StreetName")) { + setStreet(postal.item(postalChildIndex).getTextContent()); + } + if (postal.item(postalChildIndex).getLocalName().equals("AdditionalStreetName")) { + setAdditionalAddress(postal.item(postalChildIndex).getTextContent()); + } + //unknow correspondence if (postal.item(postalChildIndex).getLocalName().equals("LineThree")) { - if (postal.item(postalChildIndex).getLocalName().equals("CityName")) { - setLocation(postal.item(postalChildIndex).getTextContent()); - } - if (postal.item(postalChildIndex).getLocalName().equals("PostalZone")) { - setZIP(postal.item(postalChildIndex).getTextContent()); - } - if (postal.item(postalChildIndex).getLocalName().equals("Country")) { - NodeList country = postal.item(postalChildIndex).getChildNodes(); - for (int countryIndex = 0; countryIndex < country.getLength(); countryIndex++) { - if (country.item(countryIndex).getLocalName() != null) { + if (postal.item(postalChildIndex).getLocalName().equals("CityName")) { + setLocation(postal.item(postalChildIndex).getTextContent()); + } + if (postal.item(postalChildIndex).getLocalName().equals("PostalZone")) { + setZIP(postal.item(postalChildIndex).getTextContent()); + } + if (postal.item(postalChildIndex).getLocalName().equals("Country")) { + NodeList country = postal.item(postalChildIndex).getChildNodes(); + for (int countryIndex = 0; countryIndex < country.getLength(); countryIndex++) { + if (country.item(countryIndex).getLocalName() != null) { + + if (country.item(countryIndex).getLocalName().equals("IdentificationCode")) { + setCountry(country.item(countryIndex).getTextContent()); + } - if (country.item(countryIndex).getLocalName().equals("IdentificationCode")) { - setCountry(country.item(countryIndex).getTextContent()); } - } + + } + if (postal.item(postalChildIndex).getLocalName().equals("AddressLine")) { + NodeList AddressLine = postal.item(postalChildIndex).getChildNodes(); + for (int lineIndex = 0; lineIndex < AddressLine.getLength(); lineIndex++) { + if (AddressLine.item(lineIndex).getLocalName() != null) { - } + if (AddressLine.item(lineIndex).getLocalName().equals("Line")) { + setAdditionalAddressExtension(AddressLine.item(lineIndex).getTextContent()); + } - if (postal.item(postalChildIndex).getLocalName().equals("AddressLine")) { - NodeList AddressLine = postal.item(postalChildIndex).getChildNodes(); - for (int lineIndex = 0; lineIndex < AddressLine.getLength(); lineIndex++) { - if (AddressLine.item(lineIndex).getLocalName() != null) { - - if (AddressLine.item(lineIndex).getLocalName().equals("Line")) { - setAdditionalAddressExtension(AddressLine.item(lineIndex).getTextContent()); } - } + + + } + if (postal.item(postalChildIndex).getLocalName().equals("Name")) { + setName(postal.item(postalChildIndex).getTextContent()); } - } - if (postal.item(postalChildIndex).getLocalName().equals("Name")) { - setName(postal.item(postalChildIndex).getTextContent()); - } - } } - } - if (currentTopElementName.equals("Contact")) { - NodeList contact = party.item(partyIndex).getChildNodes(); - setContact(new Contact(contact)); + if (currentTopElementName.equals("Contact")) { + NodeList contact = party.item(partyIndex).getChildNodes(); + setContact(new Contact(contact)); + } } } } - - } - if (currentUBLChild.equals("GlobalID")) { if (nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID") != null) { SchemedID gid = new SchemedID().setScheme(nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(nodes.item(nodeIndex).getTextContent()); @@ -252,29 +231,6 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } } - - if (currentUBLChild.equals("PartyTaxScheme")) { - NodeList taxChilds = nodes.item(nodeIndex).getChildNodes(); - for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) { - if (taxChilds.item(taxChildIndex).getLocalName() != null) { - if ((taxChilds.item(taxChildIndex).getLocalName().equals("TaxScheme"))) { - if (taxChilds.item(taxChildIndex).getLocalName().equals("CompanyID")) { - if (taxChilds.item(taxChildIndex).getLocalName().equals("ID")) { - if (taxChilds.item(taxChildIndex).getLocalName().equals("CompanyID")) { - setVATID(taxChilds.item(taxChildIndex).getTextContent()); - } -// setTaxID(partyTaxScheme.item(partyTaxSchemeIndex).getTextContent()); - if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("ID").getNodeValue().equals("FC")) { - if (taxChilds.item(taxChildIndex).getLocalName().equals("CompanyID")) { - setTaxID(taxChilds.item(taxChildIndex).getTextContent()); - } - } - } - } - } - } - } - } } } } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index 600b2879..b1404251 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -587,11 +587,17 @@ public class ZUGFeRDInvoiceImporter { if (sellerOrderIssuerAssignedID != null) { zpp.setSellerOrderReferencedDocumentID(sellerOrderIssuerAssignedID); } + else { + zpp.setSellerOrderReferencedDocumentID(extractString("//*[local-name()=\"OrderReference\"]/*[local-name()=\"SalesOrderID\"]")); + } if (despatchAdviceReferencedDocument != null) { zpp.setDespatchAdviceReferencedDocumentID(despatchAdviceReferencedDocument); } + else { + zpp.setDespatchAdviceReferencedDocumentID(extractString("//*[local-name()=\"DespatchDocumentReference\"]/*[local-name()=\"ID\"]")); + } - zpp.setOwnOrganisationName(extractString("//*[local-name()=\"SellerTradeParty\"]/*[local-name()=\"Name\"]|//*[local-name()=\"AccountingSupplierParty\"]/*[local-name()=\"Party\"]/*[local-name()=\"PartyName\"]").trim()); + //zpp.setOwnOrganisationName(extractString("//*[local-name()=\"SellerTradeParty\"]/*[local-name()=\"Name\"]|//*[local-name()=\"AccountingSupplierParty\"]/*[local-name()=\"Party\"]/*[local-name()=\"PartyName\"]").trim()); xpr = xpath.compile("//*[local-name()=\"BuyerReference\"]"); String buyerReference = null; From ac3a2a8c7863b6f99743c2cc170b5ef89c609c2d Mon Sep 17 00:00:00 2001 From: Bharti Date: Mon, 18 Nov 2024 12:35:16 +0100 Subject: [PATCH 03/22] adding back ZF2ZInvoiceImporterTest --- .../ZUGFeRD/ZF2ZInvoiceImporterTest.java | 54 +++++++++++++++++++ 1 file changed, 54 insertions(+) diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java index 7d7473bb..f75d0775 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java @@ -372,4 +372,58 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { } + /* +this would test if for all elements/attributes + */ + + public void testEEISI_300_cii_Import() throws XPathExpressionException, ParseException { + boolean hasExceptions = false; + File inputCII = getResourceAsFile("not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel.cii.xml"); + File inputUBL = getResourceAsFile("not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel.ubl.xml"); + + + ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(); + try { + zii.fromXML(new String(Files.readAllBytes(inputCII.toPath()), StandardCharsets.UTF_8)); + + } catch (IOException e) { + hasExceptions = true; + } + + Invoice invoiceUBL = null; + invoiceUBL = zii.extractInvoice(); + + try { + zii.fromXML(new String(Files.readAllBytes(inputUBL.toPath()), StandardCharsets.UTF_8)); + + } catch (IOException e) { + hasExceptions = true; + } + + Invoice invoiceCII = null; + try { + invoiceCII = zii.extractInvoice(); + ObjectMapper mapper = new ObjectMapper(); + String ubl=mapper.writeValueAsString(invoiceUBL).replace("," ,"\n"); + String cii=mapper.writeValueAsString(invoiceCII).replace("," ,"\n"); + + assertEquals(cii,ubl); + + + /* + Seller contact point + +41 345 654455 + seller@contact.de);*/ + } catch (XPathExpressionException | ParseException e) { + hasExceptions = true; + } catch (JsonProcessingException e) { + throw new RuntimeException(e); + } + assertFalse(hasExceptions); + +// TransactionCalculator tc = new TransactionCalculator(invoiceCII); +// assertEquals(new BigDecimal("205.00"), tc.getGrandTotal()); + + } + } From 697c870d9cd7a3036b086ab2aed46386a2aa7c34 Mon Sep 17 00:00:00 2001 From: Bharti Date: Mon, 18 Nov 2024 14:01:39 +0100 Subject: [PATCH 04/22] UBL updates : PartyTaxScheme and EndpointID thing --- .../java/org/mustangproject/TradeParty.java | 29 +++++++++++++++++-- 1 file changed, 27 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/org/mustangproject/TradeParty.java b/library/src/main/java/org/mustangproject/TradeParty.java index fe519522..dd95eefd 100644 --- a/library/src/main/java/org/mustangproject/TradeParty.java +++ b/library/src/main/java/org/mustangproject/TradeParty.java @@ -93,13 +93,37 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } } } + if (party.item(partyIndex).getLocalName().equals("EndpointID")) { + Node currentNode = party.item(partyIndex); + if ((currentNode.getAttributes() != null && + (currentNode.getAttributes().getNamedItem("schemeID") != null)) + && (party.item(partyIndex).getAttributes().getNamedItem("schemeID").getNodeValue().equals("EM")) + ) { + setEmail(currentNode.getTextContent()); + } + + } if (currentTopElementName.equals("PartyTaxScheme")) { NodeList partyTaxScheme = party.item(partyIndex).getChildNodes(); + String CompanyId = null; for (int partyTaxSchemeIndex = 0; partyTaxSchemeIndex < partyTaxScheme.getLength(); partyTaxSchemeIndex++) { if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName() != null) { if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName().equals("CompanyID")){ - setTaxID(partyTaxScheme.item(partyTaxSchemeIndex).getTextContent()); + CompanyId = (partyTaxScheme.item(partyTaxSchemeIndex).getTextContent()); + } + if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName().equals("TaxScheme")){ + NodeList taxSchemechilds = partyTaxScheme.item(partyTaxSchemeIndex).getChildNodes(); + for (int taxSchemechildsIndex = 0; taxSchemechildsIndex < taxSchemechilds.getLength(); taxSchemechildsIndex++) { + if (taxSchemechilds.item(taxSchemechildsIndex).getLocalName() != null){ + if (taxSchemechilds.item(taxSchemechildsIndex).getTextContent().equals("FC")) { + setTaxID(CompanyId); + } + else{ + setVATID(CompanyId); + } + } + } } } @@ -190,7 +214,8 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } } } - } + + } if (currentUBLChild.equals("GlobalID")) { if (nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID") != null) { From 71af55c3f0a87d3ce2928da100f88e0fefca4233 Mon Sep 17 00:00:00 2001 From: Bharti Date: Mon, 18 Nov 2024 16:46:17 +0100 Subject: [PATCH 05/22] UBL updates --- .../java/org/mustangproject/TradeParty.java | 24 +++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/library/src/main/java/org/mustangproject/TradeParty.java b/library/src/main/java/org/mustangproject/TradeParty.java index dd95eefd..fd5fc2aa 100644 --- a/library/src/main/java/org/mustangproject/TradeParty.java +++ b/library/src/main/java/org/mustangproject/TradeParty.java @@ -104,6 +104,30 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } + if (currentTopElementName.equals("PartyIdentification")) { + NodeList partyID = party.item(partyIndex).getChildNodes(); + for (int partyIDIndex = 0; partyIDIndex < partyID.getLength(); partyIDIndex++) { + if (partyID.item(partyIDIndex).getLocalName() != null) { + if (partyID.item(partyIDIndex).getLocalName().equals("ID")) { + Node currentNode = partyID.item(partyIDIndex); + setID(currentNode.getTextContent()); + if ((currentNode.getAttributes() != null && + (currentNode.getAttributes().getNamedItem("schemeID") != null)) + ) { + //SchemedID gid = new SchemedID().setScheme(nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(nodes.item(nodeIndex).getTextContent()); + // addGlobalID(gid); + SchemedID sID = new SchemedID().setScheme(currentNode.getAttributes().getNamedItem("schemeID").getTextContent()); + addGlobalID(sID); + + //&& ((currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0110") && currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0100")) + } + + } + } + } + } + + if (currentTopElementName.equals("PartyTaxScheme")) { NodeList partyTaxScheme = party.item(partyIndex).getChildNodes(); String CompanyId = null; From c30ce8d03aa11fc7036d7525422f48273a7717b2 Mon Sep 17 00:00:00 2001 From: Bharti Date: Tue, 19 Nov 2024 13:04:17 +0100 Subject: [PATCH 06/22] UBL updates : adding delivery (incomplete) --- .../java/org/mustangproject/TradeParty.java | 46 +++++++++++++++++++ .../ZUGFeRD/ZUGFeRDInvoiceImporter.java | 4 +- 2 files changed, 48 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/org/mustangproject/TradeParty.java b/library/src/main/java/org/mustangproject/TradeParty.java index fd5fc2aa..a8c90eb9 100644 --- a/library/src/main/java/org/mustangproject/TradeParty.java +++ b/library/src/main/java/org/mustangproject/TradeParty.java @@ -74,6 +74,50 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { if (currentItemNode.getLocalName() != null) { String currentUBLChild = currentItemNode.getLocalName(); + if (currentUBLChild.equals("Delivery")) { + NodeList delivery = currentItemNode.getChildNodes(); + for (int deliveryIndex = 0; deliveryIndex < delivery.getLength(); deliveryIndex++) { + if (delivery.item(deliveryIndex).getLocalName() != null) { + Node currentNode = delivery.item(deliveryIndex); + if (currentNode.getLocalName().equals("DeliveryLocation")) { + NodeList deliveryLocation = currentNode.getChildNodes(); + for (int deliveryLocationIndex = 0; deliveryLocationIndex < deliveryLocation.getLength(); deliveryLocationIndex++) { + if (deliveryLocation.item(deliveryLocationIndex).getLocalName() != null){ + if (deliveryLocation.item(deliveryLocationIndex).getLocalName().equals("ID")) { + //Node currentNode = partyID.item(partyIDIndex); + setID(deliveryLocation.item(deliveryLocationIndex).getTextContent()); + if ((deliveryLocation.item(deliveryLocationIndex).getAttributes() != null && + (deliveryLocation.item(deliveryLocationIndex).getAttributes().getNamedItem("schemeID") != null)) + ) { + //SchemedID gid = new SchemedID().setScheme(nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(nodes.item(nodeIndex).getTextContent()); + // addGlobalID(gid); + SchemedID sID = new SchemedID().setScheme(deliveryLocation.item(deliveryLocationIndex).getAttributes().getNamedItem("schemeID").getTextContent()); + addGlobalID(sID); + + //&& ((currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0110") && currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0100")) + } + + } + if (deliveryLocation.item(deliveryLocationIndex).getLocalName().equals("Address")) { + NodeList address = deliveryLocation.item(deliveryLocationIndex).getChildNodes(); + for (int addressIndex = 0; addressIndex < address.getLength(); addressIndex++) { + if (address.item(addressIndex).getLocalName() != null) { + if (address.item(addressIndex).getLocalName().equals("StreetName")) { + //Node currentNode = partyID.item(partyIDIndex); + setStreet(address.item(addressIndex).getTextContent()); + } + } + } + } + + } + } + } + + } + } + } + if (currentUBLChild.equals("Party")) { NodeList party = currentItemNode.getChildNodes(); @@ -173,6 +217,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } } } + if (currentTopElementName.equals("PostalAddress")) { NodeList postal = party.item(partyIndex).getChildNodes(); @@ -280,6 +325,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } } + } } } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index b1404251..d4479b96 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -295,7 +295,7 @@ public class ZUGFeRDInvoiceImporter { XPath xpath = xpathFact.newXPath(); XPathExpression xpr = xpath.compile("//*[local-name()=\"SellerTradeParty\"]|//*[local-name()=\"AccountingSupplierParty\"]/*"); NodeList SellerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); - XPathExpression shipEx = xpath.compile("//*[local-name()=\"ShipToTradeParty\"]"); + XPathExpression shipEx = xpath.compile("//*[local-name()=\"ShipToTradeParty\"]|//*[local-name()=\"DeliveryLocation\"]"); NodeList deliveryNodes = (NodeList) shipEx.evaluate(getDocument(), XPathConstants.NODESET); if (deliveryNodes != null) { zpp.setDeliveryAddress(new TradeParty(deliveryNodes)); @@ -371,7 +371,7 @@ public class ZUGFeRDInvoiceImporter { deliveryDate = new SimpleDateFormat("yyyy-MM-dd").parse(deliveryDt); } } - xpr = xpath.compile("//*[local-name()=\"ApplicableHeaderTradeDelivery\"]"); + xpr = xpath.compile("//*[local-name()=\"ApplicableHeaderTradeDelivery\"]|//*[local-name()=\"Delivery\"]"); NodeList headerTradeDeliveryNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); for (int i = 0; i < headerTradeDeliveryNodes.getLength(); i++) { From 25392195f604f975d5a7496d8b6adbf1c24e1127 Mon Sep 17 00:00:00 2001 From: Bharti Date: Thu, 21 Nov 2024 15:39:00 +0100 Subject: [PATCH 07/22] UBL updates --- .../java/org/mustangproject/TradeParty.java | 81 +++++++++---------- .../ZUGFeRD/ZUGFeRDInvoiceImporter.java | 2 +- 2 files changed, 38 insertions(+), 45 deletions(-) diff --git a/library/src/main/java/org/mustangproject/TradeParty.java b/library/src/main/java/org/mustangproject/TradeParty.java index a8c90eb9..7d9e3be7 100644 --- a/library/src/main/java/org/mustangproject/TradeParty.java +++ b/library/src/main/java/org/mustangproject/TradeParty.java @@ -89,25 +89,44 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { if ((deliveryLocation.item(deliveryLocationIndex).getAttributes() != null && (deliveryLocation.item(deliveryLocationIndex).getAttributes().getNamedItem("schemeID") != null)) ) { - //SchemedID gid = new SchemedID().setScheme(nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(nodes.item(nodeIndex).getTextContent()); - // addGlobalID(gid); SchemedID sID = new SchemedID().setScheme(deliveryLocation.item(deliveryLocationIndex).getAttributes().getNamedItem("schemeID").getTextContent()); addGlobalID(sID); - - //&& ((currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0110") && currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0100")) } - - } - if (deliveryLocation.item(deliveryLocationIndex).getLocalName().equals("Address")) { - NodeList address = deliveryLocation.item(deliveryLocationIndex).getChildNodes(); - for (int addressIndex = 0; addressIndex < address.getLength(); addressIndex++) { - if (address.item(addressIndex).getLocalName() != null) { - if (address.item(addressIndex).getLocalName().equals("StreetName")) { - //Node currentNode = partyID.item(partyIDIndex); - setStreet(address.item(addressIndex).getTextContent()); + } + if (deliveryLocation.item(deliveryLocationIndex).getLocalName().equals("Address")) { + NodeList address = currentNode.getChildNodes(); + for (int addressChildIndex = 0; addressChildIndex < address.getLength(); addressChildIndex++) { + if (address.item(addressChildIndex).getLocalName() != null) { + if (address.item(addressChildIndex).getLocalName().equals("StreetName")) { + setStreet(address.item(addressChildIndex).getTextContent()); + } + if (address.item(addressChildIndex).getLocalName().equals("AdditionalStreetName")) { + setAdditionalAddress(address.item(addressChildIndex).getTextContent()); + } + if (address.item(addressChildIndex).getLocalName().equals("CityName")) { + setLocation(address.item(addressChildIndex).getTextContent()); + } + if (address.item(addressChildIndex).getLocalName().equals("PostalZone")) { + setZIP(address.item(addressChildIndex).getTextContent()); + } } } } + } + } + } + if (currentNode.getLocalName().equals("DeliveryParty")) { + NodeList deliveryParty = currentNode.getChildNodes(); + for (int deliveryPartyChildIndex = 0; deliveryPartyChildIndex < deliveryParty.getLength(); deliveryPartyChildIndex++) { + if (deliveryParty.item(deliveryPartyChildIndex).getLocalName() != null) { + if (deliveryParty.item(deliveryPartyChildIndex).getLocalName().equals("PartyName")) { + NodeList partyName = deliveryParty.item(deliveryPartyChildIndex).getChildNodes(); + for (int partyNameIndex = 0; partyNameIndex < partyName.getLength(); partyNameIndex++) { + if (partyName.item(partyNameIndex).getLocalName() != null) { + setName(partyName.item(partyNameIndex).getTextContent()); + } + } + } } @@ -154,17 +173,20 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { if (partyID.item(partyIDIndex).getLocalName() != null) { if (partyID.item(partyIDIndex).getLocalName().equals("ID")) { Node currentNode = partyID.item(partyIDIndex); - setID(currentNode.getTextContent()); + if ((currentNode.getAttributes() != null && (currentNode.getAttributes().getNamedItem("schemeID") != null)) ) { //SchemedID gid = new SchemedID().setScheme(nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(nodes.item(nodeIndex).getTextContent()); // addGlobalID(gid); - SchemedID sID = new SchemedID().setScheme(currentNode.getAttributes().getNamedItem("schemeID").getTextContent()); + SchemedID sID = new SchemedID(currentNode.getAttributes().getNamedItem("schemeID").getTextContent(), currentNode.getTextContent()); addGlobalID(sID); //&& ((currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0110") && currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0100")) } + else{ + setID(currentNode.getTextContent()); + } } } @@ -297,35 +319,6 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { NodeList contact = nodes.item(nodeIndex).getChildNodes(); setContact(new Contact(contact)); } - - if (currentUBLChild.equals("PostalTradeAddress")) { - NodeList postal = nodes.item(nodeIndex).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("LineThree")) { - setAdditionalAddressExtension(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()); - } - - } - } - - } - } } } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index d4479b96..f8219b96 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -295,7 +295,7 @@ public class ZUGFeRDInvoiceImporter { XPath xpath = xpathFact.newXPath(); XPathExpression xpr = xpath.compile("//*[local-name()=\"SellerTradeParty\"]|//*[local-name()=\"AccountingSupplierParty\"]/*"); NodeList SellerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); - XPathExpression shipEx = xpath.compile("//*[local-name()=\"ShipToTradeParty\"]|//*[local-name()=\"DeliveryLocation\"]"); + XPathExpression shipEx = xpath.compile("//*[local-name()=\"ShipToTradeParty\"]|//*[local-name()=\"DeliveryLocation\"]|//*[local-name()=\"DeliveryParty\"]"); NodeList deliveryNodes = (NodeList) shipEx.evaluate(getDocument(), XPathConstants.NODESET); if (deliveryNodes != null) { zpp.setDeliveryAddress(new TradeParty(deliveryNodes)); From e87b78db8e4dcd25acb8ead979c1438856b6c893 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Thu, 21 Nov 2024 15:54:02 +0100 Subject: [PATCH 08/22] jochens thing to be completely rewritten --- .../ZUGFeRD/ZUGFeRDInvoiceImporter.java | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index f8219b96..000a9cc3 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -295,12 +295,25 @@ public class ZUGFeRDInvoiceImporter { XPath xpath = xpathFact.newXPath(); XPathExpression xpr = xpath.compile("//*[local-name()=\"SellerTradeParty\"]|//*[local-name()=\"AccountingSupplierParty\"]/*"); NodeList SellerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); - XPathExpression shipEx = xpath.compile("//*[local-name()=\"ShipToTradeParty\"]|//*[local-name()=\"DeliveryLocation\"]|//*[local-name()=\"DeliveryParty\"]"); + XPathExpression shipEx = xpath.compile("//*[local-name()=\"ShipToTradeParty\"]"); NodeList deliveryNodes = (NodeList) shipEx.evaluate(getDocument(), XPathConstants.NODESET); if (deliveryNodes != null) { zpp.setDeliveryAddress(new TradeParty(deliveryNodes)); } + //UBL... + shipEx = xpath.compile("//*[local-name()=\"DeliveryLocation\"]"); + deliveryNodes = (NodeList) shipEx.evaluate(getDocument(), XPathConstants.NODESET); + if (deliveryNodes!=null) { + String street = ""; + if (deliveryNodes != null) { + + //street=.... + } + name=ectractString("//DeliveryParty/name"); + zpp.setDeliveryAddress(new TradeParty(name, street...)); + } + xpr = xpath.compile("//*[local-name()=\"BuyerTradeParty\"]|//*[local-name()=\"AccountingCustomerParty\"]/*"); NodeList BuyerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); From 2cffdc05b23be891f01648a7bd9b2d0f130608af Mon Sep 17 00:00:00 2001 From: Bharti Date: Thu, 21 Nov 2024 18:04:09 +0100 Subject: [PATCH 09/22] UBL updates : delivery stuff --- .../java/org/mustangproject/TradeParty.java | 37 +------------------ .../ZUGFeRD/ZUGFeRDInvoiceImporter.java | 19 +++++++--- 2 files changed, 14 insertions(+), 42 deletions(-) diff --git a/library/src/main/java/org/mustangproject/TradeParty.java b/library/src/main/java/org/mustangproject/TradeParty.java index 7d9e3be7..3590e9e1 100644 --- a/library/src/main/java/org/mustangproject/TradeParty.java +++ b/library/src/main/java/org/mustangproject/TradeParty.java @@ -65,6 +65,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } + protected void parseFromUBL(NodeList nodes) { if (nodes.getLength() > 0) { @@ -92,43 +93,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { SchemedID sID = new SchemedID().setScheme(deliveryLocation.item(deliveryLocationIndex).getAttributes().getNamedItem("schemeID").getTextContent()); addGlobalID(sID); } - } - if (deliveryLocation.item(deliveryLocationIndex).getLocalName().equals("Address")) { - NodeList address = currentNode.getChildNodes(); - for (int addressChildIndex = 0; addressChildIndex < address.getLength(); addressChildIndex++) { - if (address.item(addressChildIndex).getLocalName() != null) { - if (address.item(addressChildIndex).getLocalName().equals("StreetName")) { - setStreet(address.item(addressChildIndex).getTextContent()); - } - if (address.item(addressChildIndex).getLocalName().equals("AdditionalStreetName")) { - setAdditionalAddress(address.item(addressChildIndex).getTextContent()); - } - if (address.item(addressChildIndex).getLocalName().equals("CityName")) { - setLocation(address.item(addressChildIndex).getTextContent()); - } - if (address.item(addressChildIndex).getLocalName().equals("PostalZone")) { - setZIP(address.item(addressChildIndex).getTextContent()); - } - } - } - } - } - } - } - if (currentNode.getLocalName().equals("DeliveryParty")) { - NodeList deliveryParty = currentNode.getChildNodes(); - for (int deliveryPartyChildIndex = 0; deliveryPartyChildIndex < deliveryParty.getLength(); deliveryPartyChildIndex++) { - if (deliveryParty.item(deliveryPartyChildIndex).getLocalName() != null) { - if (deliveryParty.item(deliveryPartyChildIndex).getLocalName().equals("PartyName")) { - NodeList partyName = deliveryParty.item(deliveryPartyChildIndex).getChildNodes(); - for (int partyNameIndex = 0; partyNameIndex < partyName.getLength(); partyNameIndex++) { - if (partyName.item(partyNameIndex).getLocalName() != null) { - setName(partyName.item(partyNameIndex).getTextContent()); - } - } - } - } } } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index 000a9cc3..1172526a 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -305,16 +305,23 @@ public class ZUGFeRDInvoiceImporter { shipEx = xpath.compile("//*[local-name()=\"DeliveryLocation\"]"); deliveryNodes = (NodeList) shipEx.evaluate(getDocument(), XPathConstants.NODESET); if (deliveryNodes!=null) { - String street = ""; - if (deliveryNodes != null) { + String street, name, additionalStreet, city, postal, countrySubentity, line, country = null; + street = extractString("//*[local-name() = \"Address\"]/*[local-name() = \"StreetName\"]"); + additionalStreet = extractString("//*[local-name() = \"Address\"]/*[local-name() = \"AdditionalStreetName\"]"); + city = extractString("//*[local-name() = \"Address\"]/*[local-name() = \"CityName\"]"); + postal = extractString("//*[local-name() = \"Address\"]/*[local-name() = \"PostalZone\"]"); + countrySubentity = extractString("//*[local-name() = \"Address\"]/*[local-name() = \"CountrySubentity\"]"); + line = extractString("//*[local-name() = \"Address\"]//*[local-name() = \"AddressLine\"]/*[local-name() = \"Line\"]"); + country = extractString("//*[local-name() = \"Address\"]//*[local-name() = \"Country\"]/*[local-name() = \"IdentificationCode\"]"); + name = extractString("//*[local-name() = \"DeliveryParty\"]//*[local-name() = \"PartyName\"]/*[local-name() = \"Name\"]"); + + zpp.setDeliveryAddress(new TradeParty(deliveryNodes).setStreet(street).setAdditionalAddress(additionalStreet).setLocation(city).setZIP(postal).setAdditionalAddressExtension(line).setCountry(country).setName(name)); + - //street=.... - } - name=ectractString("//DeliveryParty/name"); - zpp.setDeliveryAddress(new TradeParty(name, street...)); } + xpr = xpath.compile("//*[local-name()=\"BuyerTradeParty\"]|//*[local-name()=\"AccountingCustomerParty\"]/*"); NodeList BuyerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); From 7fcd86f449dcac05ab594be5770c0f5bea9ce764 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Sat, 23 Nov 2024 16:15:47 +0100 Subject: [PATCH 10/22] added item tests --- .../ZUGFeRD/ZF2ZInvoiceImporterTest.java | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java index f75d0775..9fd351cc 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java @@ -272,12 +272,16 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { public void testXRImport() { boolean hasExceptions = false; - ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(); + ZUGFeRDImporter zii = new ZUGFeRDImporter(); + + int version=-1; try { zii.fromXML(new String(Files.readAllBytes(Paths.get("./target/testout-XR-Edge.xml")), StandardCharsets.UTF_8)); - + version=zii.getVersion(); } catch (IOException e) { hasExceptions = true; + } catch (Exception e) { + throw new RuntimeException(e); } Invoice invoice = null; @@ -287,8 +291,17 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { hasExceptions = true; } assertFalse(hasExceptions); + + + TransactionCalculator tc = new TransactionCalculator(invoice); assertEquals(new BigDecimal("1.00"), tc.getGrandTotal()); + + assertEquals(version,2); + assertTrue(new BigDecimal("1").compareTo(invoice.getZFItems()[0].getQuantity()) == 0); + LineCalculator lc=new LineCalculator(invoice.getZFItems()[0]); + assertTrue(new BigDecimal("1").compareTo(lc.getItemTotalNetAmount()) == 0); + assertTrue(invoice.getTradeSettlement().length==1); assertTrue(invoice.getTradeSettlement()[0] instanceof IZUGFeRDTradeSettlementPayment); IZUGFeRDTradeSettlementPayment paym=(IZUGFeRDTradeSettlementPayment)invoice.getTradeSettlement()[0]; From 5d0e3421440c6cece32fa570fd82476023c84857 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Sat, 23 Nov 2024 16:39:58 +0100 Subject: [PATCH 11/22] import doc level allowance charges --- .../ZUGFeRD/ZUGFeRDInvoiceImporter.java | 42 +++++++++++-------- .../ZUGFeRD/ZF2ZInvoiceImporterTest.java | 1 + 2 files changed, 25 insertions(+), 18 deletions(-) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index 1172526a..160de8a1 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -304,7 +304,7 @@ public class ZUGFeRDInvoiceImporter { //UBL... shipEx = xpath.compile("//*[local-name()=\"DeliveryLocation\"]"); deliveryNodes = (NodeList) shipEx.evaluate(getDocument(), XPathConstants.NODESET); - if (deliveryNodes!=null) { + if (deliveryNodes != null) { String street, name, additionalStreet, city, postal, countrySubentity, line, country = null; street = extractString("//*[local-name() = \"Address\"]/*[local-name() = \"StreetName\"]"); additionalStreet = extractString("//*[local-name() = \"Address\"]/*[local-name() = \"AdditionalStreetName\"]"); @@ -321,7 +321,6 @@ public class ZUGFeRDInvoiceImporter { } - xpr = xpath.compile("//*[local-name()=\"BuyerTradeParty\"]|//*[local-name()=\"AccountingCustomerParty\"]/*"); NodeList BuyerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); @@ -463,7 +462,7 @@ public class ZUGFeRDInvoiceImporter { } - String currency = extractString("//*[local-name()=\"ApplicableHeaderTradeSettlement\"]/*[local-name()=\"InvoiceCurrencyCode\"]|//*[local-name()=\"DocumentCurrencyCode\"]") ; + String currency = extractString("//*[local-name()=\"ApplicableHeaderTradeSettlement\"]/*[local-name()=\"InvoiceCurrencyCode\"]|//*[local-name()=\"DocumentCurrencyCode\"]"); zpp.setCurrency(currency); xpr = xpath.compile("//*[local-name()=\"ApplicableHeaderTradeSettlement\"]|//*[local-name()=\"ApplicableSupplyChainTradeSettlement\"]"); @@ -600,20 +599,17 @@ public class ZUGFeRDInvoiceImporter { if (buyerOrderIssuerAssignedID != null) { zpp.setBuyerOrderReferencedDocumentID(buyerOrderIssuerAssignedID); - } - else { + } else { zpp.setBuyerOrderReferencedDocumentID(extractString("//*[local-name()=\"OrderReference\"]/*[local-name()=\"ID\"]")); } if (sellerOrderIssuerAssignedID != null) { zpp.setSellerOrderReferencedDocumentID(sellerOrderIssuerAssignedID); - } - else { + } else { zpp.setSellerOrderReferencedDocumentID(extractString("//*[local-name()=\"OrderReference\"]/*[local-name()=\"SalesOrderID\"]")); } if (despatchAdviceReferencedDocument != null) { zpp.setDespatchAdviceReferencedDocumentID(despatchAdviceReferencedDocument); - } - else { + } else { zpp.setDespatchAdviceReferencedDocumentID(extractString("//*[local-name()=\"DespatchDocumentReference\"]/*[local-name()=\"ID\"]")); } @@ -655,7 +651,7 @@ public class ZUGFeRDInvoiceImporter { // be read, // so the invoice remains arithmetically correct // -> parse document level charges+allowances - xpr = xpath.compile("//*[local-name()=\"SpecifiedTradeAllowanceCharge\"]"); + xpr = xpath.compile("//*[local-name()=\"SpecifiedTradeAllowanceCharge\"]|/*[local-name()=\"Invoice\"]/*[local-name()=\"AllowanceCharge\"]");//CII and UBL NodeList chargeNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); for (int i = 0; i < chargeNodes.getLength(); i++) { NodeList chargeNodeChilds = chargeNodes.item(i).getChildNodes(); @@ -669,18 +665,28 @@ public class ZUGFeRDInvoiceImporter { if (chargeChildName != null) { if (chargeChildName.equals("ChargeIndicator")) { - NodeList indicatorChilds = chargeNodeChilds.item(chargeChildIndex).getChildNodes(); - for (int indicatorChildIndex = 0; indicatorChildIndex < indicatorChilds.getLength(); indicatorChildIndex++) { - if ((indicatorChilds.item(indicatorChildIndex).getLocalName() != null) - && (indicatorChilds.item(indicatorChildIndex).getLocalName().equals("Indicator"))) { - isCharge = XMLTools.trimOrNull(indicatorChilds.item(indicatorChildIndex)).equalsIgnoreCase("true"); + if (chargeNodeChilds.item(chargeChildIndex).getTextContent().trim().equalsIgnoreCase("false")) { + // UBL + isCharge = false; + } else if (chargeNodeChilds.item(chargeChildIndex).getTextContent().trim().equalsIgnoreCase("true")) { + // still UBL + isCharge = true; + } else { + //CII + NodeList indicatorChilds = chargeNodeChilds.item(chargeChildIndex).getChildNodes(); + for (int indicatorChildIndex = 0; indicatorChildIndex < indicatorChilds.getLength(); indicatorChildIndex++) { + if ((indicatorChilds.item(indicatorChildIndex).getLocalName() != null) + && (indicatorChilds.item(indicatorChildIndex).getLocalName().equals("Indicator"))) { + isCharge = XMLTools.trimOrNull(indicatorChilds.item(indicatorChildIndex)).equalsIgnoreCase("true"); + } } } - } else if (chargeChildName.equals("ActualAmount")) { + + } else if (chargeChildName.equals("ActualAmount") || chargeChildName.equals("Amount")) { chargeAmount = XMLTools.trimOrNull(chargeNodeChilds.item(chargeChildIndex)); - } else if (chargeChildName.equals("Reason")) { + } else if (chargeChildName.equals("Reason") || chargeChildName.equals("AllowanceChargeReason")) { reason = XMLTools.trimOrNull(chargeNodeChilds.item(chargeChildIndex)); - } else if (chargeChildName.equals("ReasonCode")) { + } else if (chargeChildName.equals("ReasonCode") || chargeChildName.equals("AllowanceChargeReasonCode")) { reasonCode = XMLTools.trimOrNull(chargeNodeChilds.item(chargeChildIndex)); } else if (chargeChildName.equals("CategoryTradeTax")) { NodeList taxChilds = chargeNodeChilds.item(chargeChildIndex).getChildNodes(); diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java index 9fd351cc..441d9a1d 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java @@ -407,6 +407,7 @@ this would test if for all elements/attributes invoiceUBL = zii.extractInvoice(); try { + zii.ignoreCalculationErrors=true; zii.fromXML(new String(Files.readAllBytes(inputUBL.toPath()), StandardCharsets.UTF_8)); } catch (IOException e) { From 295d9ce276d9dcda726d75abdeb57b78685e211d Mon Sep 17 00:00:00 2001 From: jstaerk Date: Sat, 23 Nov 2024 16:50:23 +0100 Subject: [PATCH 12/22] also import vat rate for doc charge --- .../org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index 160de8a1..08397508 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -688,11 +688,11 @@ public class ZUGFeRDInvoiceImporter { reason = XMLTools.trimOrNull(chargeNodeChilds.item(chargeChildIndex)); } else if (chargeChildName.equals("ReasonCode") || chargeChildName.equals("AllowanceChargeReasonCode")) { reasonCode = XMLTools.trimOrNull(chargeNodeChilds.item(chargeChildIndex)); - } else if (chargeChildName.equals("CategoryTradeTax")) { + } else if (chargeChildName.equals("CategoryTradeTax")||chargeChildName.equals("TaxCategory")) { NodeList taxChilds = chargeNodeChilds.item(chargeChildIndex).getChildNodes(); for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) { String taxItemName = taxChilds.item(taxChildIndex).getLocalName(); - if ((taxItemName != null) && (taxItemName.equals("RateApplicablePercent") || taxItemName.equals("ApplicablePercent"))) { + if ((taxItemName != null) && (taxItemName.equals("RateApplicablePercent") || taxItemName.equals("ApplicablePercent") || taxItemName.equals("Percent"))) { taxPercent = XMLTools.trimOrNull(taxChilds.item(taxChildIndex)); } } From 5bd04e0bbc005e5b126a62cfee949992b791c063 Mon Sep 17 00:00:00 2001 From: Bharti Date: Mon, 25 Nov 2024 14:52:38 +0100 Subject: [PATCH 13/22] UBL updates : line charge / allowance --- .../java/org/mustangproject/TradeParty.java | 39 +++++++++++++++++-- .../ZUGFeRD/ZUGFeRDInvoiceImporter.java | 18 ++++++--- 2 files changed, 49 insertions(+), 8 deletions(-) diff --git a/library/src/main/java/org/mustangproject/TradeParty.java b/library/src/main/java/org/mustangproject/TradeParty.java index 3590e9e1..42838984 100644 --- a/library/src/main/java/org/mustangproject/TradeParty.java +++ b/library/src/main/java/org/mustangproject/TradeParty.java @@ -171,7 +171,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { NodeList taxSchemechilds = partyTaxScheme.item(partyTaxSchemeIndex).getChildNodes(); for (int taxSchemechildsIndex = 0; taxSchemechildsIndex < taxSchemechilds.getLength(); taxSchemechildsIndex++) { if (taxSchemechilds.item(taxSchemechildsIndex).getLocalName() != null){ - if (taxSchemechilds.item(taxSchemechildsIndex).getTextContent().equals("FC")) { + if (taxSchemechilds.item(taxSchemechildsIndex).getTextContent().equals("FC") ||(taxSchemechilds.item(taxSchemechildsIndex).getTextContent().equals("NOVAT"))) { setTaxID(CompanyId); } else{ @@ -252,8 +252,6 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } } - - } if (postal.item(postalChildIndex).getLocalName().equals("Name")) { setName(postal.item(postalChildIndex).getTextContent()); @@ -284,6 +282,41 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { NodeList contact = nodes.item(nodeIndex).getChildNodes(); setContact(new Contact(contact)); } + if(currentUBLChild.equals("PayeeParty")){ + NodeList payeeParty = nodes.item(nodeIndex).getChildNodes(); + for (int payeePartyIndex = 0; payeePartyIndex < payeeParty.getLength(); payeePartyIndex++) { + if (payeeParty.item(payeePartyIndex).getLocalName() != null) { + if (payeeParty.item(payeePartyIndex).getLocalName().equals("PartyIdentification")) { + NodeList partyID = payeeParty.item(payeePartyIndex).getChildNodes(); + for (int partyIDIndex = 0; partyIDIndex < partyID.getLength(); partyIDIndex++) { + if (partyID.item(partyIDIndex).getLocalName() != null) { + if (partyID.item(partyIDIndex).getLocalName().equals("ID")) { + Node currentNode = partyID.item(partyIDIndex); + + if ((currentNode.getAttributes() != null && + (currentNode.getAttributes().getNamedItem("schemeID") != null)) + ) { + //SchemedID gid = new SchemedID().setScheme(nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(nodes.item(nodeIndex).getTextContent()); + // addGlobalID(gid); + SchemedID sID = new SchemedID(currentNode.getAttributes().getNamedItem("schemeID").getTextContent(), currentNode.getTextContent()); + addGlobalID(sID); + + //&& ((currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0110") && currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0100")) + } + else{ + setID(currentNode.getTextContent()); + } + + } + } + } + } + + + } + } + + } } } } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index 08397508..8932d50c 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -302,8 +302,8 @@ public class ZUGFeRDInvoiceImporter { } //UBL... - shipEx = xpath.compile("//*[local-name()=\"DeliveryLocation\"]"); - deliveryNodes = (NodeList) shipEx.evaluate(getDocument(), XPathConstants.NODESET); + XPathExpression shipExUBL = xpath.compile("//*[local-name()=\"DeliveryLocation\"]"); + deliveryNodes = (NodeList) shipExUBL.evaluate(getDocument(), XPathConstants.NODESET); if (deliveryNodes != null) { String street, name, additionalStreet, city, postal, countrySubentity, line, country = null; street = extractString("//*[local-name() = \"Address\"]/*[local-name() = \"StreetName\"]"); @@ -315,7 +315,15 @@ public class ZUGFeRDInvoiceImporter { country = extractString("//*[local-name() = \"Address\"]//*[local-name() = \"Country\"]/*[local-name() = \"IdentificationCode\"]"); name = extractString("//*[local-name() = \"DeliveryParty\"]//*[local-name() = \"PartyName\"]/*[local-name() = \"Name\"]"); - zpp.setDeliveryAddress(new TradeParty(deliveryNodes).setStreet(street).setAdditionalAddress(additionalStreet).setLocation(city).setZIP(postal).setAdditionalAddressExtension(line).setCountry(country).setName(name)); + zpp.setDeliveryAddress(new TradeParty(deliveryNodes) + .setStreet(street) + .setAdditionalAddress(additionalStreet) + .setLocation(city) + .setZIP(postal) + .setAdditionalAddressExtension(line) + .setCountry(country) + .setName(name) + ); } @@ -613,7 +621,7 @@ public class ZUGFeRDInvoiceImporter { zpp.setDespatchAdviceReferencedDocumentID(extractString("//*[local-name()=\"DespatchDocumentReference\"]/*[local-name()=\"ID\"]")); } - //zpp.setOwnOrganisationName(extractString("//*[local-name()=\"SellerTradeParty\"]/*[local-name()=\"Name\"]|//*[local-name()=\"AccountingSupplierParty\"]/*[local-name()=\"Party\"]/*[local-name()=\"PartyName\"]").trim()); + zpp.setOwnOrganisationName(extractString("//*[local-name()=\"SellerTradeParty\"]/*[local-name()=\"Name\"]|//*[local-name()=\"AccountingSupplierParty\"]/*[local-name()=\"Party\"]/*[local-name()=\"PartyName\"]").trim()); xpr = xpath.compile("//*[local-name()=\"BuyerReference\"]"); String buyerReference = null; @@ -651,7 +659,7 @@ public class ZUGFeRDInvoiceImporter { // be read, // so the invoice remains arithmetically correct // -> parse document level charges+allowances - xpr = xpath.compile("//*[local-name()=\"SpecifiedTradeAllowanceCharge\"]|/*[local-name()=\"Invoice\"]/*[local-name()=\"AllowanceCharge\"]");//CII and UBL + xpr = xpath.compile("//*[local-name()=\"SpecifiedTradeAllowanceCharge\"]|//*[local-name()=\"AllowanceCharge\"]");//CII and UBL NodeList chargeNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); for (int i = 0; i < chargeNodes.getLength(); i++) { NodeList chargeNodeChilds = chargeNodes.item(i).getChildNodes(); From 1baaf0513ed7789a04e0489a20dcbf76218ac60b Mon Sep 17 00:00:00 2001 From: Bharti Date: Mon, 25 Nov 2024 17:53:35 +0100 Subject: [PATCH 14/22] UBL updates --- .../main/java/org/mustangproject/Product.java | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/org/mustangproject/Product.java b/library/src/main/java/org/mustangproject/Product.java index 1263d593..352d3368 100644 --- a/library/src/main/java/org/mustangproject/Product.java +++ b/library/src/main/java/org/mustangproject/Product.java @@ -6,6 +6,7 @@ import org.mustangproject.ZUGFeRD.IDesignatedProductClassification; import org.mustangproject.ZUGFeRD.IZUGFeRDExportableProduct; import org.mustangproject.util.NodeMap; import org.w3c.dom.Node; +import org.w3c.dom.NodeList; import java.math.BigDecimal; import java.util.ArrayList; @@ -21,7 +22,7 @@ import java.util.Map; @JsonInclude(JsonInclude.Include.NON_EMPTY) public class Product implements IZUGFeRDExportableProduct { - protected String unit, name, sellerAssignedID, buyerAssignedID; + protected String unit, name, sellerAssignedID, buyerAssignedID,ID; protected String description=""; protected String taxExemptionReason=null; protected String taxCategoryCode=null; @@ -59,11 +60,15 @@ public class Product implements IZUGFeRDExportableProduct { } }); + + + nodeMap.getAsString("SellerAssignedID").ifPresent(this::setSellerAssignedID); nodeMap.getAsString("BuyerAssignedID").ifPresent(this::setBuyerAssignedID); nodeMap.getAsString("Name").ifPresent(this::setName); nodeMap.getAsString("Description").ifPresent(this::setDescription); + nodeMap.getAsNodeMap("ApplicableProductCharacteristic").ifPresent(apcNodes -> { String key = apcNodes.getAsStringOrNull("Description"); String value = apcNodes.getAsStringOrNull("Value"); @@ -75,6 +80,18 @@ public class Product implements IZUGFeRDExportableProduct { } }); + //UBL + nodeMap.getAsNodeMap("AdditionalItemProperty").ifPresent(aipNodes -> { + String key = aipNodes.getAsStringOrNull("Name"); + String value = aipNodes.getAsStringOrNull("Value"); + if (key != null && value != null) { + if (attributes == null) { + attributes = new HashMap<>(); + } + attributes.put(key, value); + } + }); + nodeMap.getAsNodeMap("DesignatedProductClassification").ifPresent(dpcNodes -> { String className = dpcNodes.getAsStringOrNull("ClassName"); dpcNodes.getNode("ClassCode").map(ClassCode::fromNode).ifPresent(classCode -> From 74704bb2f83535cd8671ca0ce7cb7dda08afc74d Mon Sep 17 00:00:00 2001 From: jstaerk Date: Mon, 25 Nov 2024 18:04:12 +0100 Subject: [PATCH 15/22] original (invalid) version of cii and ubl version --- .../ZUGFeRD/ZF2ZInvoiceImporterTest.java | 1 + ...ased_onTest_EeISI_300_CENfullmodel.cii.xml | 76 +- ...ased_onTest_EeISI_300_CENfullmodel.ubl.xml | 727 +++++++++--------- ...sed_onTest_EeISI_300_CENfullmodel2.cii.xml | 353 --------- ...sed_onTest_EeISI_300_CENfullmodel2.ubl.xml | 349 --------- 5 files changed, 420 insertions(+), 1086 deletions(-) delete mode 100644 library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.cii.xml delete mode 100644 library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.ubl.xml diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java index 441d9a1d..40ee39de 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java @@ -396,6 +396,7 @@ this would test if for all elements/attributes ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(); + zii.doIgnoreCalculationErrors(); try { zii.fromXML(new String(Files.readAllBytes(inputCII.toPath()), StandardCharsets.UTF_8)); diff --git a/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel.cii.xml b/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel.cii.xml index 1b88d4d4..8b5bb189 100644 --- a/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel.cii.xml +++ b/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel.cii.xml @@ -1,8 +1,5 @@ - + BT-23 Business Process Type @@ -19,11 +16,11 @@ invoice note text - AAA + #AAA# invoice note text 2 - AAA + #AAA# @@ -35,9 +32,7 @@ - Item standar identifier - - + Item standar identifier Item seller's identifier Item buyer's identifier Item name @@ -98,9 +93,9 @@ false 1.00 - 100.00 + 1000.00 10.00 - 95 + 55 Invoice line allowance reason @@ -108,17 +103,18 @@ true 1.00 - 100.00 + 1000.00 10.00 AAA Invoice line charge reason - 100.00 + 1000.00 Line object identifier 130 + 6789 @@ -147,7 +143,7 @@ 0.00 - 100.00 + 1000.00 @@ -159,7 +155,7 @@ Seller name Seller additional legal information - + Seller legal identifier Seller trading name @@ -181,7 +177,7 @@ Seller country subdivision - Seller electronic address + Seller electronic address DE12345677 @@ -216,7 +212,7 @@ Buyer country subdivision - Buyer electronic address + Buyer electronic address IE394838894 @@ -256,7 +252,7 @@ rst 130 - AAA + 0090 456 @@ -315,32 +311,32 @@ IT1212341234123412 Payment account name - - - + BSCTCH22 + - 5.00 + 50.00 VAT - 100.00 + 1000.00 S - + 29 5.00 0.00 VAT Exemtion reason text - 100.00 + 1000.00 E - VATEX-EU-O + Exemption reason code 29 0.00 @@ -357,9 +353,9 @@ false 1.00 - 100.00 + 1000.00 10.00 - 95 + 55 Doc allowance reason text VAT @@ -372,7 +368,7 @@ true 1.00 - 100.00 + 1000.00 10.00 AAA Doc charge reason text @@ -390,16 +386,16 @@ Mandate reference identifier - 200.00 + 2000.00 10.00 10.00 - 200.00 - 5.00 - 4.60 + 2000.00 + 50.00 + 46.00 0.00 - 205.00 + 2050.00 0.00 - 205.00 + 2050.00 abc123 diff --git a/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel.ubl.xml b/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel.ubl.xml index 6aec88d9..b9b5abd7 100644 --- a/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel.ubl.xml +++ b/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel.ubl.xml @@ -1,365 +1,404 @@ - - urn:cen.eu:en16931:2017#compliant#urn:fdc:peppol.eu:2017:poacc:billing:3.0 - urn:fdc:peppol.eu:2017:poacc:billing:01:1.0 + + urn:cen.eu:en16931:2017 + BT-23 Business Process Type Test_EeISI_100 2018-11-12 2018-11-30 380 - #AAA#invoice note text - #AAA#invoice note text 2 + ##AAA##invoice note text + ##AAA##invoice note text 2 EUR NOK uvz 123 - 2018-11-12 - 2018-11-30 - - - abc - def - - - - abc123 - 2018-10-04 - - - - lmn - - - ghi - - - 789 - - - Supporting document ref - Supporting document descr - - ZGVmYXVsdA== - - External document location - - - - - rst - 130 - - - 456 - - - - Seller electronic address - - Seller identifier 1 - - - Seller identifier 2 - - - Seller trading name - - - Seller address line 1 - Seller address line 2 - Seller city - 12345 - Seller country subdivision - - Seller address line 3 - - - DE - - - - DE12345677 - - VAT - - - - DE49294093 - - FC - - - - Seller name - Seller additional legal information - - - Seller contact point - +41 345 654455 - seller@contact.de - - - - - - Buyer electronic address - - Buyer identifier - - - Buyer trading name - - - Buyer address line 1 - Buyer address line 2 - Buyer city - 34562 - Buyer country subdivision - - Buyer address line 3 - - - IE - - - - IE394838894 - - VAT - - - - Buyer name - Buyer legal registration identifier - - - Buyer contact point - +353 2948584 - buyer@contact.ie - - - - - - Payee identifier - - - Payee name - - - - - Tax representative name - - - Tax representative address line 1 - Tax representative address line 2 - Tax representative city - 23455 - Tax representative country subdivision - - Tax representative address line 3 - - - DE - - - - DE3949053 - - VAT - - - - - 2018-12-04 - - deliver location identifier - - Deliver to address line 1 - Deliver to address line 2 - Deliver to city - 98765 - Deliver to country subdivision - - Deliver to address line 3 - - - IE - - - - - - Deliver to party name - - - - - total amount - - - false - 95 - Doc allowance reason text - 1.00 - 10 - 1000 - - S - 5 - - VAT - - - - - true - AAA - Doc charge reason text - 1.00 - 10 - 1000 - - S - 5 - - VAT - - - - - 50 - - 1000 - 50 - - S - 5 - - VAT - - - - - 1000 - 0 - - E - 0 - VATEX-EU-O - Exemtion reason text - - VAT - - - - - - 46 - - - 200 - 200 - 205 - 10 - 10 - 0 - 205 - - - 1a - Invoice line note - 10 - 1000 - 6789 - 2018-11-12 2018-11-30 - - - 12345 - - - Line object identifier + 35 + + + abc + def + + + + abc123 + 2018-10-04 + + + + lmn + + + ghi + + + opq + + + 789 + + + rst 130 - - + + + Supporting document ref + Supporting document descr + + ZGVmYXVsdA== + + External document location + + + + + 456 + + + + Seller electronic address + + Seller identifier 1 + + + Seller identifier 2 + + + Bank assigned creditor identifier + + + Seller trading name + + + Seller address line 1 + Seller address line 2 + Seller city + 12345 + Seller country subdivision + + Seller address line 3 + + + DE + + + + DE12345677 + + VAT + + + + DE49294093 + + NOVAT + + + + Seller name + Seller legal identifier + Seller additional legal information + + + Seller contact point + +41 345 654455 + seller@contact.de + + + + + + Buyer electronic address + + 0190:Buyer identifier + + + Buyer trading name + + + Buyer address line 1 + Buyer address line 2 + Buyer city + 34562 + Buyer country subdivision + + Buyer address line 3 + + + IE + + + + IE394838894 + + VAT + + + + Buyer name + Buyer legal registration identifier + + + Buyer contact point + +353 2948584 + buyer@contact.ie + + + + + + Payee identifier + + + Payee name + + + Payee legal registration identifier + + + + + Tax representative name + + + Tax representative address line 1 + Tax representative address line 2 + Tax representative city + 23455 + Tax representative country subdivision + + Tax representative address line 3 + + + DE + + + + DE3949053 + + VAT + + + + + 2018-12-04 + + deliver location identifier + + Deliver to address line 1 + Deliver to address line 2 + Deliver to city + 98765 + Deliver to country subdivision + + Deliver to address line 3 + + + IE + + + + + + Deliver to party name + + + + + 4 + Remittance information + + 1234 + mandatory network id + Payment card holder name + + + IT1212341234123412 + Payment account name + + BSCTCH22 + + + + IT1212341234123413 + Payment account name 2 + + BSCTCH22 + + + + Mandate reference identifier + + Debited account identifier + + + + + total amount + + false - 95 - Invoice line allowance reason - 1.00 - 10 - 1000 - - + 55 + Doc allowance reason text + 1.0000 + 10.00 + 1000.00 + + S + 5.00 + + VAT + + + + true AAA - Invoice line charge reason - 1.00 - 10 - 1000 - - - Item description - Item name - - Item buyer's identifier - - - Item seller's identifier - - - Item standar identifier - - - IT - - - Item classification identifier0 - - - S - 5 - - VAT - - - - Color - Red - - - Size - L - - - - 10 - 1 + Doc charge reason text + 1.0000 + 10.00 + 1000.00 + + S + 5.00 + + VAT + + + + + 46.00 + + + 50.00 + + 1000.00 + 50.00 + + S + 5.00 + + VAT + + + + + 1000.00 + 0.00 + + E + 0.00 + Exemption reason code + Exemtion reason text + + VAT + + + + + + 2000.00 + 2000.00 + 2050.00 + 10.00 + 10.00 + 2050.00 + + + 1a + Invoice line note + 10.00000000 + 1000.00 + 6789 + + 2018-11-12 + 2018-11-30 + + + 12345 + + + Line object identifier + 130 + - false - 1 - 11 + false + 55 + Invoice line allowance reason + 1 + 10 + 1000 - + + true + AAA + Invoice line charge reason + 1 + 10 + 1000 + + + Item description + Item name + + Item buyer's identifier + + + Item seller's identifier + + + Item standar identifier + + + IT + + + Item classification identifier0 + + + S + 5.00 + + VAT + + + + Color + Red + + + Size + L + + + + 10.00 + 1.00 + + false + 1 + 11 + + - 1b - 10 - 1000 - - Item name 2 - - E - 0 - - VAT - - - - - 10 - + 1b + 10.00000000 + 1000.00 + + Item name 2 + + E + 0.00 + + VAT + + + + + 10.00 + - + diff --git a/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.cii.xml b/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.cii.xml deleted file mode 100644 index 94a81f4c..00000000 --- a/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.cii.xml +++ /dev/null @@ -1,353 +0,0 @@ - - - - - BT-23 Business Process Type - - - urn:cen.eu:en16931:2017 - - - - Test_EeISI_100 - 380 - - 20181112 - - - invoice note text - #AAA# - - - invoice note text 2 - #AAA# - - - - - - 1a - - Invoice line note - - - - Item standar identifier - Item seller's identifier - Item buyer's identifier - Item name - Item description - - Color - Red - - - Size - L - - - Item classification identifier0 - - - IT - - - - - 12345 - - - 11.00 - 1.00 - - - 10.00 - 1.00 - - - - 10.00 - - - - VAT - S - 5.00 - - - - 20181112 - - - 20181130 - - - - 1000.00 - - - Line object identifier - 130 - - - - 6789 - - - - - - 1b - - - Item name 2 - - - - 10.00 - - - - 10.00 - - - - VAT - E - 0.00 - - - 1000.00 - - - - - 123 - - Seller identifier 1 - Seller identifier 2 - Seller name - Seller additional legal information - - Seller legal identifier - Seller trading name - - - Seller contact point - - +41 345 654455 - - - seller@contact.de - - - - 12345 - Seller address line 1 - Seller address line 2 - Seller address line 3 - Seller city - DE - Seller country subdivision - - - Seller electronic address - - - DE12345677 - - - DE49294093 - - - - Buyer identifier - Buyer name - - Buyer legal registration identifier - Buyer trading name - - - Buyer contact point - - +353 2948584 - - - buyer@contact.ie - - - - 34562 - Buyer address line 1 - Buyer address line 2 - Buyer address line 3 - Buyer city - IE - Buyer country subdivision - - - Buyer electronic address - - - IE394838894 - - - - Tax representative name - - 23455 - Tax representative address line 1 - Tax representative address line 2 - Tax representative address line 3 - Tax representative city - DE - Tax representative country subdivision - - - DE3949053 - - - - def - - - abc - - - 789 - - - Supporting document ref - External document location - 916 - Supporting document descr - ZGVmYXVsdA== - - - rst - 130 - 0090 - - - 456 - Project reference - - - - - deliver location identifier - Deliver to party name - - 98765 - Deliver to address line 1 - Deliver to address line 2 - Deliver to address line 3 - Deliver to city - IE - Deliver to country subdivision - - - - - 20181204 - - - - lmn - - - ghi - - - - Bank assigned creditor identifier - Remittance information - NOK - EUR - - Payee identifier - Payee name - - Payee legal registration identifier - - - - 4 - SEPA - - 1234 - Payment card holder name - - - Debited account identifier - - - IT1212341234123412 - Payment account name - - - BSCTCH22 - - - IT1212341234123413 - Payment account name 2 - - - BSCTCH22 - - - - 50.00 - VAT - 1000.00 - S - 29 - 5.00 - - - 0.00 - VAT - Exemtion reason text - 1000.00 - E - Exemption reason code - 29 - 0.00 - - - - 20181112 - - - 20181130 - - - - total amount - - 20181130 - - Mandate reference identifier - - - 200.00 - 200.00 - 50.00 - 46.00 - 0.00 - 205.00 - 0.00 - 205.00 - - - abc123 - - 20181004 - - - - uvz - - - - diff --git a/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.ubl.xml b/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.ubl.xml deleted file mode 100644 index 1654b0ac..00000000 --- a/library/src/test/resources/not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel2.ubl.xml +++ /dev/null @@ -1,349 +0,0 @@ - - - urn:cen.eu:en16931:2017 - BT-23 Business Process Type - Test_EeISI_100 - 2018-11-12 - 2018-11-30 - 380 - ##AAA##invoice note text - ##AAA##invoice note text 2 - EUR - NOK - uvz - 123 - - 2018-11-12 - 2018-11-30 - 35 - - - abc - def - - - - abc123 - 2018-10-04 - - - - lmn - - - ghi - - - opq - - - 789 - - - rst - 130 - - - Supporting document ref - Supporting document descr - - ZGVmYXVsdA== - - External document location - - - - - 456 - - - - Seller electronic address - - Seller identifier 1 - - - Seller identifier 2 - - - Bank assigned creditor identifier - - - Seller trading name - - - Seller address line 1 - Seller address line 2 - Seller city - 12345 - Seller country subdivision - - Seller address line 3 - - - DE - - - - DE12345677 - - VAT - - - - DE49294093 - - NOVAT - - - - Seller name - Seller legal identifier - Seller additional legal information - - - Seller contact point - +41 345 654455 - seller@contact.de - - - - - - Buyer electronic address - - Buyer identifier - - - Buyer trading name - - - Buyer address line 1 - Buyer address line 2 - Buyer city - 34562 - Buyer country subdivision - - Buyer address line 3 - - - IE - - - - IE394838894 - - VAT - - - - Buyer name - Buyer legal registration identifier - - - Buyer contact point - +353 2948584 - buyer@contact.ie - - - - - - Payee identifier - - - Payee name - - - Payee legal registration identifier - - - - - Tax representative name - - - Tax representative address line 1 - Tax representative address line 2 - Tax representative city - 23455 - Tax representative country subdivision - - Tax representative address line 3 - - - DE - - - - DE3949053 - - VAT - - - - - 2018-12-04 - - deliver location identifier - - Deliver to address line 1 - Deliver to address line 2 - Deliver to city - 98765 - Deliver to country subdivision - - Deliver to address line 3 - - - IE - - - - - - Deliver to party name - - - - - 4 - Remittance information - - 1234 - mandatory network id - Payment card holder name - - - IT1212341234123412 - Payment account name - - BSCTCH22 - - - - IT1212341234123413 - Payment account name 2 - - BSCTCH22 - - - - Mandate reference identifier - - Debited account identifier - - - - - total amount - - - 50.00 - - 1000.00 - 50.00 - - S - 5.00 - - VAT - - - - - 1000.00 - 0.00 - - E - 0.00 - Exemption reason code - Exemtion reason text - - VAT - - - - - - 200.00 - 200.00 - 205.00 - 205.00 - - - 1a - Invoice line note - 10.00000000 - 1000.00 - 6789 - - 2018-11-12 - 2018-11-30 - - - 12345 - - - Line object identifier - 130 - - - Item description - Item name - - Item buyer's identifier - - - Item seller's identifier - - - Item standar identifier - - - IT - - - Item classification identifier0 - - - S - 5.00 - - VAT - - - - Color - Red - - - Size - L - - - - 10.00 - 1.00 - - - - - 1b - 10.00000000 - 100.00 - - Item name 2 - - E - 0.00 - - VAT - - - - - 10.00 - - - From f703e598424c68f258e6db5d3ae277e91ca56297 Mon Sep 17 00:00:00 2001 From: Bharti Date: Mon, 25 Nov 2024 18:18:49 +0100 Subject: [PATCH 16/22] UBL updates : adding description to item for ubl --- library/src/main/java/org/mustangproject/Item.java | 1 + library/src/main/java/org/mustangproject/Product.java | 8 ++++---- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/library/src/main/java/org/mustangproject/Item.java b/library/src/main/java/org/mustangproject/Item.java index d726ed08..7959950d 100644 --- a/library/src/main/java/org/mustangproject/Item.java +++ b/library/src/main/java/org/mustangproject/Item.java @@ -66,6 +66,7 @@ public class Item implements IZUGFeRDExportableItem { //and we additionally have vat% setProduct(new Product()); icnm.getAsString("Name").ifPresent(product::setName); + icnm.getAsString("Description").ifPresent(product::setDescription); icnm.getAsNodeMap("ClassifiedTaxCategory").flatMap(m -> m.getAsBigDecimal("Percent")) .ifPresent(product::setVATPercent); }); diff --git a/library/src/main/java/org/mustangproject/Product.java b/library/src/main/java/org/mustangproject/Product.java index 352d3368..ddbed336 100644 --- a/library/src/main/java/org/mustangproject/Product.java +++ b/library/src/main/java/org/mustangproject/Product.java @@ -82,13 +82,13 @@ public class Product implements IZUGFeRDExportableProduct { //UBL nodeMap.getAsNodeMap("AdditionalItemProperty").ifPresent(aipNodes -> { - String key = aipNodes.getAsStringOrNull("Name"); - String value = aipNodes.getAsStringOrNull("Value"); - if (key != null && value != null) { + String name = aipNodes.getAsStringOrNull("Name"); + String val = aipNodes.getAsStringOrNull("Value"); + if (name != null && val != null) { if (attributes == null) { attributes = new HashMap<>(); } - attributes.put(key, value); + attributes.put(name, val); } }); From 39f870bd7f551e6bb3c4b80284f5280442f78f78 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Mon, 25 Nov 2024 19:42:20 +0100 Subject: [PATCH 17/22] importing deliveryaddress --- .../ZUGFeRD/ZUGFeRDInvoiceImporter.java | 76 +++++++++++++++---- 1 file changed, 62 insertions(+), 14 deletions(-) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index 8932d50c..ef9dc0d8 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -11,6 +11,7 @@ import org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile; import org.mustangproject.*; import org.mustangproject.Exceptions.ArithmetricException; import org.mustangproject.Exceptions.StructureException; +import org.mustangproject.util.NodeMap; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.w3c.dom.Document; @@ -273,6 +274,9 @@ public class ZUGFeRDInvoiceImporter { } } + public void setID(String id) { + String ud=id; + } /*** * This will parse a XML into the given invoice object * @param zpp the invoice to be altered @@ -302,20 +306,64 @@ public class ZUGFeRDInvoiceImporter { } //UBL... - XPathExpression shipExUBL = xpath.compile("//*[local-name()=\"DeliveryLocation\"]"); - deliveryNodes = (NodeList) shipExUBL.evaluate(getDocument(), XPathConstants.NODESET); - if (deliveryNodes != null) { - String street, name, additionalStreet, city, postal, countrySubentity, line, country = null; - street = extractString("//*[local-name() = \"Address\"]/*[local-name() = \"StreetName\"]"); - additionalStreet = extractString("//*[local-name() = \"Address\"]/*[local-name() = \"AdditionalStreetName\"]"); - city = extractString("//*[local-name() = \"Address\"]/*[local-name() = \"CityName\"]"); - postal = extractString("//*[local-name() = \"Address\"]/*[local-name() = \"PostalZone\"]"); - countrySubentity = extractString("//*[local-name() = \"Address\"]/*[local-name() = \"CountrySubentity\"]"); - line = extractString("//*[local-name() = \"Address\"]//*[local-name() = \"AddressLine\"]/*[local-name() = \"Line\"]"); - country = extractString("//*[local-name() = \"Address\"]//*[local-name() = \"Country\"]/*[local-name() = \"IdentificationCode\"]"); - name = extractString("//*[local-name() = \"DeliveryParty\"]//*[local-name() = \"PartyName\"]/*[local-name() = \"Name\"]"); + XPathExpression shipExUBL = xpath.compile("//*[local-name()=\"Delivery\"]"); + Node deliveryNode = (Node) shipExUBL.evaluate(getDocument(), XPathConstants.NODE); - zpp.setDeliveryAddress(new TradeParty(deliveryNodes) + if (deliveryNode != null) { + TradeParty delivery=new TradeParty(); + NodeMap nodeMap = new NodeMap(deliveryNode).getAsNodeMap("DeliveryLocation").get(); + + if (nodeMap != null) { + nodeMap.getNode("ID").ifPresent(s -> { + SchemedID sID = new SchemedID().setScheme(s.getAttributes().getNamedItem("schemeID").getTextContent()).setId(s.getTextContent()); + delivery.addGlobalID(sID); + }); + nodeMap.getAsNodeMap("Address").ifPresent(s -> { + s.getAsString("StreetName").ifPresent(t -> delivery.setStreet(t)); + }); + nodeMap.getAsNodeMap("Address").ifPresent(s -> { + s.getAsString("AdditionalStreetName").ifPresent(t -> delivery.setAdditionalAddress(t)); + }); + nodeMap.getAsNodeMap("Address").ifPresent(s -> { + s.getAsString("CityName").ifPresent(t -> delivery.setLocation(t)); + }); + nodeMap.getAsNodeMap("Address").ifPresent(s -> { + s.getAsString("PostalZone").ifPresent(t -> delivery.setZIP(t)); + }); + nodeMap.getAsNodeMap("Address").ifPresent(s -> { + s.getAsNodeMap("Country").ifPresent(t -> t.getAsString("IdentificationCode").ifPresent(u -> delivery.setCountry(u))); + }); + nodeMap.getAsNodeMap("Address").ifPresent(s -> { + s.getAsNodeMap("AddressLine").ifPresent(t -> t.getAsString("Line").ifPresent(u -> delivery.setAdditionalAddressExtension(u))); + }); + nodeMap.getAsNodeMap("Address").ifPresent(s -> { + s.getAsString("AdditionalStreetName").ifPresent(t -> delivery.setAdditionalAddress(t)); + }); + nodeMap.getAsNodeMap("Address").ifPresent(s -> { + s.getAsString("AdditionalStreetName").ifPresent(t -> delivery.setAdditionalAddress(t)); + }); + } + + + NodeMap partyMap = new NodeMap(deliveryNode).getAsNodeMap("DeliveryParty").get(); + if (partyMap!=null) { + partyMap.getAsNodeMap("PartyName").ifPresent(s->{s.getAsString("Name").ifPresent(t->delivery.setName(t));}); + } + String street, name, additionalStreet, city, postal, countrySubentity, line, country = null; +/* + String idx = extractString("//*[local-name()=\"DeliveryLocation\"]/*[local-name() = \"ID\"]"); + street = extractString("//*[local-name()=\"DeliveryLocation\"]/*[local-name()=\"Address\"]/*[local-name()=\"StreetName\"]"); + additionalStreet = extractString("//*[local-name()=\"DeliveryLocation\"]/*[local-name() = \"Address\"]/*[local-name() = \"AdditionalStreetName\"]"); + city = extractString("//*[local-name()=\"DeliveryLocation\"]/*[local-name() = \"Address\"]/*[local-name() = \"CityName\"]"); + postal = extractString("//*[local-name()=\"DeliveryLocation\"]/*[local-name() = \"Address\"]/*[local-name() = \"PostalZone\"]"); + countrySubentity = extractString("//*[local-name()=\"DeliveryLocation\"]/*[local-name() = \"Address\"]/*[local-name() = \"CountrySubentity\"]"); + line = extractString("//*[local-name()=\"DeliveryLocation\"]/*[local-name() = \"Address\"]//*[local-name() = \"AddressLine\"]/*[local-name() = \"Line\"]"); + country = extractString("//*[local-name()=\"DeliveryLocation\"]/*[local-name() = \"Address\"]//*[local-name() = \"Country\"]/*[local-name() = \"IdentificationCode\"]"); + name = extractString("//*[local-name()=\"DeliveryLocation\"]/*[local-name() = \"DeliveryParty\"]//*[local-name() = \"PartyName\"]/*[local-name() = \"Name\"]"); +*/ + zpp.setDeliveryAddress(delivery); + /* + zpp.setDeliveryAddress(new TradeParty() .setStreet(street) .setAdditionalAddress(additionalStreet) .setLocation(city) @@ -324,7 +372,7 @@ public class ZUGFeRDInvoiceImporter { .setCountry(country) .setName(name) ); - +*/ } From 30022a061a5a1bfad61cb1d2fac841244c34e822 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Tue, 26 Nov 2024 09:46:34 +0100 Subject: [PATCH 18/22] no message --- library/src/main/java/org/mustangproject/Item.java | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/org/mustangproject/Item.java b/library/src/main/java/org/mustangproject/Item.java index 7959950d..1fa6ce75 100644 --- a/library/src/main/java/org/mustangproject/Item.java +++ b/library/src/main/java/org/mustangproject/Item.java @@ -64,9 +64,17 @@ public class Item implements IZUGFeRDExportableItem { // ubl //we need: name description unitcode //and we additionally have vat% + + // Bhartis homework 20241126:Streams https://www.youtube.com/watch?v=Lf01cBzmuXw and Lamdas https://www.youtube.com/watch?v=HCyx31NW8xg setProduct(new Product()); icnm.getAsString("Name").ifPresent(product::setName); icnm.getAsString("Description").ifPresent(product::setDescription); + + icnm.getAsNodeMap("SellersItemIdentification").ifPresent(SellersItemIdentification -> { + SellersItemIdentification.getAsString("ID").ifPresent(product::setSellerAssignedID); + }); +// icnm.getAsString("BuyerAssignedID").ifPresent(this::setBuyerAssignedID); + icnm.getAsNodeMap("ClassifiedTaxCategory").flatMap(m -> m.getAsBigDecimal("Percent")) .ifPresent(product::setVATPercent); }); @@ -98,7 +106,8 @@ public class Item implements IZUGFeRDExportableItem { .forEach(this::addReferencedDocument); }); - itemMap.getNode("SpecifiedTradeProduct").map(Product::new).ifPresent(this::setProduct); + itemMap.getNode("SpecifiedTradeProduct").map(Product::new).ifPresent(this::setProduct);//CII + itemMap.getNode("SpecifiedTradeProduct").map(Product::new).ifPresent(this::setProduct);//UBL // RequestedQuantity is for Order-X, BilledQuantity for FX and ZF itemMap.getAsNodeMap("SpecifiedLineTradeDelivery", "SpecifiedSupplyChainTradeDelivery") From 9f694d209b294d767fd4e4da9d1223d5a6ffbf5e Mon Sep 17 00:00:00 2001 From: Bharti Date: Wed, 27 Nov 2024 08:54:08 +0100 Subject: [PATCH 19/22] UBL updates --- .../main/java/org/mustangproject/Item.java | 23 +++++++++++++++++-- .../ZUGFeRD/ZUGFeRDInvoiceImporter.java | 14 +++++++++++ 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/org/mustangproject/Item.java b/library/src/main/java/org/mustangproject/Item.java index 1fa6ce75..3ddcf266 100644 --- a/library/src/main/java/org/mustangproject/Item.java +++ b/library/src/main/java/org/mustangproject/Item.java @@ -13,6 +13,8 @@ import java.math.BigDecimal; import java.math.RoundingMode; import java.util.ArrayList; import java.util.Date; +import java.util.HashMap; +import java.util.Map; /*** * describes any invoice line @@ -37,6 +39,7 @@ public class Item implements IZUGFeRDExportableItem { protected ArrayList additionalReference = null; protected ArrayList Allowances = new ArrayList<>(); protected ArrayList Charges = new ArrayList<>(); + //protected HashMap attributes = new HashMap<>(); /*** * default constructor @@ -65,7 +68,8 @@ public class Item implements IZUGFeRDExportableItem { //we need: name description unitcode //and we additionally have vat% - // Bhartis homework 20241126:Streams https://www.youtube.com/watch?v=Lf01cBzmuXw and Lamdas https://www.youtube.com/watch?v=HCyx31NW8xg + // Bharti's homework 20241126:Streams https://www.youtube.com/watch?v=Lf01cBzmuXw + // and Lambdas https://www.youtube.com/watch?v=HCyx31NW8xg setProduct(new Product()); icnm.getAsString("Name").ifPresent(product::setName); icnm.getAsString("Description").ifPresent(product::setDescription); @@ -73,7 +77,22 @@ public class Item implements IZUGFeRDExportableItem { icnm.getAsNodeMap("SellersItemIdentification").ifPresent(SellersItemIdentification -> { SellersItemIdentification.getAsString("ID").ifPresent(product::setSellerAssignedID); }); -// icnm.getAsString("BuyerAssignedID").ifPresent(this::setBuyerAssignedID); + + icnm.getAsNodeMap("BuyersItemIdentification").ifPresent(BuyersItemIdentification -> { + BuyersItemIdentification.getAsString("ID").ifPresent(product::setBuyerAssignedID); + }); + +// String name = icnm.getAsStringOrNull("Name"); +// String val = icnm.getAsStringOrNull("Value"); +// if (name != null && val != null) { +// if (attributes == null) { +// attributes = new HashMap<>(); +// } +// product.attributes.put(name, val); +// } + //icnm.getNode("AdditionalItemProperty").flatMap(n ->n.getAttributes()).ifPresent(product::setAttributes); + + icnm.getAsNodeMap("ClassifiedTaxCategory").flatMap(m -> m.getAsBigDecimal("Percent")) .ifPresent(product::setVATPercent); diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index ef9dc0d8..049dff20 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -637,7 +637,21 @@ public class ZUGFeRDInvoiceImporter { } } } +// if ((paymentMeansChilds.item(paymentTermChildIndex).getLocalName() != null) && (paymentTermChilds.item(paymentTermChildIndex).getLocalName().equals("DirectDebitMandateID"))) { +// directDebitMandateID = paymentTermChilds.item(paymentTermChildIndex).getTextContent(); +// } + if((paymentMeansChilds.item(meansChildIndex).getLocalName() != null) + && (paymentMeansChilds.item(meansChildIndex).getLocalName().equals("PaymentMandate"))){ + NodeList paymentMandateChilds = paymentMeansChilds.item(meansChildIndex).getChildNodes(); + for (int paymentMandateChildIndex = 0; paymentMandateChildIndex < paymentMandateChilds.getLength(); paymentMandateChildIndex++) { + if ((paymentMandateChilds.item(paymentMandateChildIndex).getLocalName() != null) && (paymentMandateChilds.item(paymentMandateChildIndex).getLocalName().equals("ID"))) { + directDebitMandateID = paymentMandateChilds.item(paymentMandateChildIndex).getTextContent(); + } + } + + } } + } zpp.setDueDate(dueDate).setDeliveryDate(deliveryDate).setIssueDate(issueDate).setSender(new TradeParty(SellerNodes)).setRecipient(new TradeParty(BuyerNodes)).setNumber(number).setDocumentCode(typeCode); From 914e8f1a6e1a3b48fae51e6723f2fdc538f57ed5 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Wed, 27 Nov 2024 11:47:56 +0100 Subject: [PATCH 20/22] working on legelorganisationname --- .../java/org/mustangproject/TradeParty.java | 190 ++++++++++-------- 1 file changed, 101 insertions(+), 89 deletions(-) diff --git a/library/src/main/java/org/mustangproject/TradeParty.java b/library/src/main/java/org/mustangproject/TradeParty.java index 42838984..7fe5ed43 100644 --- a/library/src/main/java/org/mustangproject/TradeParty.java +++ b/library/src/main/java/org/mustangproject/TradeParty.java @@ -17,7 +17,6 @@ import org.w3c.dom.NodeList; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonIgnoreProperties; -import static org.apache.fop.fonts.type1.AdobeStandardEncoding.a; /*** * A organisation, i.e. usually a company @@ -83,7 +82,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { if (currentNode.getLocalName().equals("DeliveryLocation")) { NodeList deliveryLocation = currentNode.getChildNodes(); for (int deliveryLocationIndex = 0; deliveryLocationIndex < deliveryLocation.getLength(); deliveryLocationIndex++) { - if (deliveryLocation.item(deliveryLocationIndex).getLocalName() != null){ + if (deliveryLocation.item(deliveryLocationIndex).getLocalName() != null) { if (deliveryLocation.item(deliveryLocationIndex).getLocalName().equals("ID")) { //Node currentNode = partyID.item(partyIDIndex); setID(deliveryLocation.item(deliveryLocationIndex).getTextContent()); @@ -122,13 +121,13 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } } if (party.item(partyIndex).getLocalName().equals("EndpointID")) { - Node currentNode = party.item(partyIndex); - if ((currentNode.getAttributes() != null && - (currentNode.getAttributes().getNamedItem("schemeID") != null)) - && (party.item(partyIndex).getAttributes().getNamedItem("schemeID").getNodeValue().equals("EM")) - ) { - setEmail(currentNode.getTextContent()); - } + Node currentNode = party.item(partyIndex); + if ((currentNode.getAttributes() != null && + (currentNode.getAttributes().getNamedItem("schemeID") != null)) + && (party.item(partyIndex).getAttributes().getNamedItem("schemeID").getNodeValue().equals("EM")) + ) { + setEmail(currentNode.getTextContent()); + } } @@ -148,8 +147,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { addGlobalID(sID); //&& ((currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0110") && currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0100")) - } - else{ + } else { setID(currentNode.getTextContent()); } @@ -164,17 +162,16 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { String CompanyId = null; for (int partyTaxSchemeIndex = 0; partyTaxSchemeIndex < partyTaxScheme.getLength(); partyTaxSchemeIndex++) { if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName() != null) { - if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName().equals("CompanyID")){ + if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName().equals("CompanyID")) { CompanyId = (partyTaxScheme.item(partyTaxSchemeIndex).getTextContent()); } - if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName().equals("TaxScheme")){ + if (partyTaxScheme.item(partyTaxSchemeIndex).getLocalName().equals("TaxScheme")) { NodeList taxSchemechilds = partyTaxScheme.item(partyTaxSchemeIndex).getChildNodes(); for (int taxSchemechildsIndex = 0; taxSchemechildsIndex < taxSchemechilds.getLength(); taxSchemechildsIndex++) { - if (taxSchemechilds.item(taxSchemechildsIndex).getLocalName() != null){ - if (taxSchemechilds.item(taxSchemechildsIndex).getTextContent().equals("FC") ||(taxSchemechilds.item(taxSchemechildsIndex).getTextContent().equals("NOVAT"))) { + if (taxSchemechilds.item(taxSchemechildsIndex).getLocalName() != null) { + if (taxSchemechilds.item(taxSchemechildsIndex).getTextContent().equals("FC") || (taxSchemechilds.item(taxSchemechildsIndex).getTextContent().equals("NOVAT"))) { setTaxID(CompanyId); - } - else{ + } else { setVATID(CompanyId); } } @@ -191,83 +188,98 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { so overwrite if one exists */ - if (currentTopElementName.equals("PartyLegalEntity")) { - NodeList legal = party.item(partyIndex).getChildNodes(); - for (int legalChildIndex = 0; legalChildIndex < legal.getLength(); legalChildIndex++) { - if (legal.item(legalChildIndex).getLocalName() != null) { - if (legal.item(legalChildIndex).getLocalName().equals("RegistrationName")) { - setName(legal.item(legalChildIndex).getTextContent()); + if (currentTopElementName.equals("PartyLegalEntity")) { + NodeList legal = party.item(partyIndex).getChildNodes(); + for (int legalChildIndex = 0; legalChildIndex < legal.getLength(); legalChildIndex++) { + if (legal.item(legalChildIndex).getLocalName() != null) { + LegalOrganisation lo = null; + if (legal.item(legalChildIndex).getLocalName().equals("RegistrationName")) { + if (lo == null) { + lo = new LegalOrganisation(); } - if (legal.item(legalChildIndex).getLocalName().equals("CompanyLegalForm")) { - setDescription(legal.item(legalChildIndex).getTextContent()); + lo.setTradingBusinessName(legal.item(legalChildIndex).getTextContent()); + } + if (legal.item(legalChildIndex).getLocalName().equals("CompanyID")) { + if (lo == null) { + lo = new LegalOrganisation(); + } + if (legal.item(legalChildIndex).getAttributes().getNamedItem("schemeID")!=null) { + SchemedID sid = new SchemedID(legal.item(legalChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue(), legal.item(legalChildIndex).getTextContent()); + lo.setSchemedID(sid); } } - } - } - - if (currentTopElementName.equals("PostalAddress")) { - - NodeList postal = party.item(partyIndex).getChildNodes(); - for (int postalChildIndex = 0; postalChildIndex < postal.getLength(); postalChildIndex++) { - if (postal.item(postalChildIndex).getLocalName() != null) { - - if (postal.item(postalChildIndex).getLocalName().equals("StreetName")) { - setStreet(postal.item(postalChildIndex).getTextContent()); - } - if (postal.item(postalChildIndex).getLocalName().equals("AdditionalStreetName")) { - setAdditionalAddress(postal.item(postalChildIndex).getTextContent()); - } - //unknow correspondence if (postal.item(postalChildIndex).getLocalName().equals("LineThree")) { - - - if (postal.item(postalChildIndex).getLocalName().equals("CityName")) { - setLocation(postal.item(postalChildIndex).getTextContent()); - } - if (postal.item(postalChildIndex).getLocalName().equals("PostalZone")) { - setZIP(postal.item(postalChildIndex).getTextContent()); - } - if (postal.item(postalChildIndex).getLocalName().equals("Country")) { - NodeList country = postal.item(postalChildIndex).getChildNodes(); - for (int countryIndex = 0; countryIndex < country.getLength(); countryIndex++) { - if (country.item(countryIndex).getLocalName() != null) { - - if (country.item(countryIndex).getLocalName().equals("IdentificationCode")) { - setCountry(country.item(countryIndex).getTextContent()); - } - - } - } - - - } - - if (postal.item(postalChildIndex).getLocalName().equals("AddressLine")) { - NodeList AddressLine = postal.item(postalChildIndex).getChildNodes(); - for (int lineIndex = 0; lineIndex < AddressLine.getLength(); lineIndex++) { - if (AddressLine.item(lineIndex).getLocalName() != null) { - - if (AddressLine.item(lineIndex).getLocalName().equals("Line")) { - setAdditionalAddressExtension(AddressLine.item(lineIndex).getTextContent()); - } - - } - } - } - if (postal.item(postalChildIndex).getLocalName().equals("Name")) { - setName(postal.item(postalChildIndex).getTextContent()); - } - + // we dont have that attribute yet in the legalorganisation: CompanyLegalForm + if (lo != null) { + setLegalOrganisation(lo); } + } } - - if (currentTopElementName.equals("Contact")) { - NodeList contact = party.item(partyIndex).getChildNodes(); - setContact(new Contact(contact)); - - } + } + + if (currentTopElementName.equals("PostalAddress")) { + + NodeList postal = party.item(partyIndex).getChildNodes(); + for (int postalChildIndex = 0; postalChildIndex < postal.getLength(); postalChildIndex++) { + if (postal.item(postalChildIndex).getLocalName() != null) { + + if (postal.item(postalChildIndex).getLocalName().equals("StreetName")) { + setStreet(postal.item(postalChildIndex).getTextContent()); + } + if (postal.item(postalChildIndex).getLocalName().equals("AdditionalStreetName")) { + setAdditionalAddress(postal.item(postalChildIndex).getTextContent()); + } + //unknow correspondence if (postal.item(postalChildIndex).getLocalName().equals("LineThree")) { + + + if (postal.item(postalChildIndex).getLocalName().equals("CityName")) { + setLocation(postal.item(postalChildIndex).getTextContent()); + } + if (postal.item(postalChildIndex).getLocalName().equals("PostalZone")) { + setZIP(postal.item(postalChildIndex).getTextContent()); + } + if (postal.item(postalChildIndex).getLocalName().equals("Country")) { + NodeList country = postal.item(postalChildIndex).getChildNodes(); + for (int countryIndex = 0; countryIndex < country.getLength(); countryIndex++) { + if (country.item(countryIndex).getLocalName() != null) { + + if (country.item(countryIndex).getLocalName().equals("IdentificationCode")) { + setCountry(country.item(countryIndex).getTextContent()); + } + + } + } + + + } + + if (postal.item(postalChildIndex).getLocalName().equals("AddressLine")) { + NodeList AddressLine = postal.item(postalChildIndex).getChildNodes(); + for (int lineIndex = 0; lineIndex < AddressLine.getLength(); lineIndex++) { + if (AddressLine.item(lineIndex).getLocalName() != null) { + + if (AddressLine.item(lineIndex).getLocalName().equals("Line")) { + setAdditionalAddressExtension(AddressLine.item(lineIndex).getTextContent()); + } + + } + } + } + if (postal.item(postalChildIndex).getLocalName().equals("Name")) { + setName(postal.item(postalChildIndex).getTextContent()); + } + + } + } + } + + if (currentTopElementName.equals("Contact")) { + NodeList contact = party.item(partyIndex).getChildNodes(); + setContact(new Contact(contact)); + } } + } } @@ -282,7 +294,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { NodeList contact = nodes.item(nodeIndex).getChildNodes(); setContact(new Contact(contact)); } - if(currentUBLChild.equals("PayeeParty")){ + if (currentUBLChild.equals("PayeeParty")) { NodeList payeeParty = nodes.item(nodeIndex).getChildNodes(); for (int payeePartyIndex = 0; payeePartyIndex < payeeParty.getLength(); payeePartyIndex++) { if (payeeParty.item(payeePartyIndex).getLocalName() != null) { @@ -302,8 +314,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { addGlobalID(sID); //&& ((currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0110") && currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0100")) - } - else{ + } else { setID(currentNode.getTextContent()); } @@ -600,6 +611,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { /** * primarily for invoiceimporter and JSON + * * @return the list of sepa mandates */ public List getDebitDetails() { From c099c9e138a4ceb104538ef015d05251f61f6c22 Mon Sep 17 00:00:00 2001 From: Bharti Date: Wed, 27 Nov 2024 12:17:18 +0100 Subject: [PATCH 21/22] UBL updates : adding back the sender.description --- library/src/main/java/org/mustangproject/TradeParty.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/library/src/main/java/org/mustangproject/TradeParty.java b/library/src/main/java/org/mustangproject/TradeParty.java index 7fe5ed43..f8a6f9e2 100644 --- a/library/src/main/java/org/mustangproject/TradeParty.java +++ b/library/src/main/java/org/mustangproject/TradeParty.java @@ -199,6 +199,9 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } lo.setTradingBusinessName(legal.item(legalChildIndex).getTextContent()); } + if (legal.item(legalChildIndex).getLocalName().equals("CompanyLegalForm")) { + setDescription(legal.item(legalChildIndex).getTextContent()); + } if (legal.item(legalChildIndex).getLocalName().equals("CompanyID")) { if (lo == null) { lo = new LegalOrganisation(); From 87d3fdec3f53740f5218a310115516ef6c078041 Mon Sep 17 00:00:00 2001 From: Bharti Date: Wed, 27 Nov 2024 19:53:31 +0100 Subject: [PATCH 22/22] UBL updates --- .../main/java/org/mustangproject/Item.java | 10 ++ .../main/java/org/mustangproject/Product.java | 2 +- .../java/org/mustangproject/TradeParty.java | 112 +++++++++--------- .../ZUGFeRD/ZUGFeRDInvoiceImporter.java | 3 +- 4 files changed, 70 insertions(+), 57 deletions(-) diff --git a/library/src/main/java/org/mustangproject/Item.java b/library/src/main/java/org/mustangproject/Item.java index 3ddcf266..2f6269b9 100644 --- a/library/src/main/java/org/mustangproject/Item.java +++ b/library/src/main/java/org/mustangproject/Item.java @@ -111,11 +111,21 @@ public class Item implements IZUGFeRDExportableItem { product.setUnit(icn.getAttributes().getNamedItem("unitCode").getNodeValue()); }); + itemMap.getAsNodeMap("OrderLineReference") + .flatMap(bordNodes -> bordNodes.getAsString("LineID")) + .ifPresent(this::addReferencedLineID); + + + + itemMap.getAllNodes("DocumentReference").map(ReferencedDocument::fromNode) + .forEach(this::addAdditionalReference); + itemMap.getAsNodeMap("SpecifiedLineTradeAgreement", "SpecifiedSupplyChainTradeAgreement").ifPresent(icnm -> { icnm.getAsNodeMap("BuyerOrderReferencedDocument") .flatMap(bordNodes -> bordNodes.getAsString("LineID")) .ifPresent(this::addReferencedLineID); + icnm.getAsNodeMap("NetPriceProductTradePrice").ifPresent(npptpNodes -> { npptpNodes.getAsBigDecimal("ChargeAmount").ifPresent(this::setPrice); npptpNodes.getAsBigDecimal("BasisQuantity").ifPresent(this::setBasisQuantity); diff --git a/library/src/main/java/org/mustangproject/Product.java b/library/src/main/java/org/mustangproject/Product.java index ddbed336..1537bae4 100644 --- a/library/src/main/java/org/mustangproject/Product.java +++ b/library/src/main/java/org/mustangproject/Product.java @@ -22,7 +22,7 @@ import java.util.Map; @JsonInclude(JsonInclude.Include.NON_EMPTY) public class Product implements IZUGFeRDExportableProduct { - protected String unit, name, sellerAssignedID, buyerAssignedID,ID; + protected String unit, name, sellerAssignedID, buyerAssignedID; protected String description=""; protected String taxExemptionReason=null; protected String taxCategoryCode=null; diff --git a/library/src/main/java/org/mustangproject/TradeParty.java b/library/src/main/java/org/mustangproject/TradeParty.java index f8a6f9e2..1ae7b2e9 100644 --- a/library/src/main/java/org/mustangproject/TradeParty.java +++ b/library/src/main/java/org/mustangproject/TradeParty.java @@ -130,31 +130,67 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } } +// if (party.item(partyIndex).getLocalName().equals("AccountingSupplierParty")) { +// NodeList payeeParty = party.item(partyIndex).getChildNodes(); +// for (int payeePartyIndex = 0; payeePartyIndex < payeeParty.getLength(); payeePartyIndex++) { +// if (payeeParty.item(payeePartyIndex).getLocalName() != null) { + if (currentTopElementName.equals("PartyIdentification")) { + NodeList partyID = party.item(partyIndex).getChildNodes(); + for (int partyIDIndex = 0; partyIDIndex < partyID.getLength(); partyIDIndex++) { + if (partyID.item(partyIDIndex).getLocalName() != null) { + if (partyID.item(partyIDIndex).getLocalName().equals("ID")) { + Node currentNode = partyID.item(partyIDIndex); + if ((currentNode.getAttributes() != null && + (currentNode.getAttributes().getNamedItem("schemeID") != null)) + ) { + //SchemedID gid = new SchemedID().setScheme(nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(nodes.item(nodeIndex).getTextContent()); + // addGlobalID(gid); + SchemedID sID = new SchemedID().setScheme(currentNode.getAttributes().getNamedItem("schemeID").getTextContent()).setId(currentNode.getTextContent()); + addGlobalID(sID); - if (currentTopElementName.equals("PartyIdentification")) { - NodeList partyID = party.item(partyIndex).getChildNodes(); - for (int partyIDIndex = 0; partyIDIndex < partyID.getLength(); partyIDIndex++) { - if (partyID.item(partyIDIndex).getLocalName() != null) { - if (partyID.item(partyIDIndex).getLocalName().equals("ID")) { - Node currentNode = partyID.item(partyIDIndex); + //&& ((currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0110") && currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0100")) + } +// else { +// setID(currentNode.getTextContent()); +// } - if ((currentNode.getAttributes() != null && - (currentNode.getAttributes().getNamedItem("schemeID") != null)) - ) { - //SchemedID gid = new SchemedID().setScheme(nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(nodes.item(nodeIndex).getTextContent()); - // addGlobalID(gid); - SchemedID sID = new SchemedID(currentNode.getAttributes().getNamedItem("schemeID").getTextContent(), currentNode.getTextContent()); - addGlobalID(sID); - - //&& ((currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0110") && currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0100")) - } else { - setID(currentNode.getTextContent()); + } + } } - } - } - } - } +// } +// } +// } + +// if (currentTopElementName.equals("AccountingCustomerParty")) { +// NodeList partyID = party.item(partyIndex).getChildNodes(); +// for (int partyIDIndex = 0; partyIDIndex < partyID.getLength(); partyIDIndex++) { +// if (partyID.item(partyIDIndex).getLocalName() != null) { +// if (partyID.item(partyIDIndex).getLocalName().equals("ID")) { +// Node currentNode = partyID.item(partyIDIndex); +// //setID(currentNode.getTextContent()); +// +// if ((currentNode.getAttributes() != null && +// (currentNode.getAttributes().getNamedItem("schemeID") != null)) +// ) { +// //SchemedID gid = new SchemedID().setScheme(nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(nodes.item(nodeIndex).getTextContent()); +// //addGlobalID(gid); +// //SchemedID sID = new SchemedID(currentNode.getAttributes().getNamedItem("schemeID").getTextContent(), currentNode.getTextContent()); +// //addGlobalID(sID); +// // SchemedID sID = new SchemedID().setScheme(deliveryLocation.item(deliveryLocationIndex).getAttributes().getNamedItem("schemeID").getTextContent()); +// // addGlobalID(sID); +// SchemedID sID = new SchemedID().setScheme(currentNode.getAttributes().getNamedItem("schemeID").getTextContent()).setId(currentNode.getTextContent()); +// addGlobalID(sID); +// +// //&& ((currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0110") && currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0100")) +// } else { +// setID(currentNode.getTextContent()); +// } +// +// } +// } +// } +// } if (currentTopElementName.equals("PartyTaxScheme")) { @@ -297,40 +333,6 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { NodeList contact = nodes.item(nodeIndex).getChildNodes(); setContact(new Contact(contact)); } - if (currentUBLChild.equals("PayeeParty")) { - NodeList payeeParty = nodes.item(nodeIndex).getChildNodes(); - for (int payeePartyIndex = 0; payeePartyIndex < payeeParty.getLength(); payeePartyIndex++) { - if (payeeParty.item(payeePartyIndex).getLocalName() != null) { - if (payeeParty.item(payeePartyIndex).getLocalName().equals("PartyIdentification")) { - NodeList partyID = payeeParty.item(payeePartyIndex).getChildNodes(); - for (int partyIDIndex = 0; partyIDIndex < partyID.getLength(); partyIDIndex++) { - if (partyID.item(partyIDIndex).getLocalName() != null) { - if (partyID.item(partyIDIndex).getLocalName().equals("ID")) { - Node currentNode = partyID.item(partyIDIndex); - - if ((currentNode.getAttributes() != null && - (currentNode.getAttributes().getNamedItem("schemeID") != null)) - ) { - //SchemedID gid = new SchemedID().setScheme(nodes.item(nodeIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(nodes.item(nodeIndex).getTextContent()); - // addGlobalID(gid); - SchemedID sID = new SchemedID(currentNode.getAttributes().getNamedItem("schemeID").getTextContent(), currentNode.getTextContent()); - addGlobalID(sID); - - //&& ((currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0110") && currentNode.getAttributes().getNamedItem("schemeID").getNodeValue().equals("0100")) - } else { - setID(currentNode.getTextContent()); - } - - } - } - } - } - - - } - } - - } } } } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index 049dff20..36bfaf23 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -305,6 +305,7 @@ public class ZUGFeRDInvoiceImporter { zpp.setDeliveryAddress(new TradeParty(deliveryNodes)); } + //UBL... XPathExpression shipExUBL = xpath.compile("//*[local-name()=\"Delivery\"]"); Node deliveryNode = (Node) shipExUBL.evaluate(getDocument(), XPathConstants.NODE); @@ -380,7 +381,7 @@ public class ZUGFeRDInvoiceImporter { xpr = xpath.compile("//*[local-name()=\"BuyerTradeParty\"]|//*[local-name()=\"AccountingCustomerParty\"]/*"); NodeList BuyerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); - xpr = xpath.compile("//*[local-name()=\"PayeeTradeParty\"]|//*[local-name()=\"PayeeParty\"]/*"); + xpr = xpath.compile("//*[local-name()=\"PayeeTradeParty\"]|//*[local-name()=\"PayeeParty\"]//*"); NodeList payeeNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); xpr = xpath.compile("//*[local-name()=\"ExchangedDocument\"]|//*[local-name()=\"HeaderExchangedDocument\"]");