From 25392195f604f975d5a7496d8b6adbf1c24e1127 Mon Sep 17 00:00:00 2001 From: Bharti Date: Thu, 21 Nov 2024 15:39:00 +0100 Subject: [PATCH] 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));