working on ubl import

This commit is contained in:
jstaerk
2023-09-11 08:09:10 +02:00
parent 4fe7c4bcee
commit fcb52431ba
13 changed files with 1441 additions and 16 deletions

View File

@@ -59,12 +59,175 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
}
protected void parseFromUBL(NodeList nodes) {
if (nodes.getLength() > 0) {
for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) {
//nodes.item(i).getTextContent())) {
Node currentItemNode = nodes.item(nodeIndex);
NodeList itemChilds = currentItemNode.getChildNodes();
for (int itemChildIndex = 0; itemChildIndex < itemChilds.getLength(); itemChildIndex++) {
if (itemChilds.item(itemChildIndex).getLocalName() != null) {
if (itemChilds.item(itemChildIndex).getLocalName().equals("Party")) {
NodeList party = itemChilds.item(itemChildIndex).getChildNodes();
for (int partyIndex = 0; partyIndex < party.getLength(); partyIndex++) {
if (party.item(partyIndex).getLocalName() != null) {
if (party.item(partyIndex).getLocalName().equals("PartyName")) {
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("Name")) {
setName(partyName.item(partyNameIndex).getTextContent());
}
}
}
}
if (party.item(partyIndex).getLocalName().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 (itemChilds.item(itemChildIndex).getLocalName().equals("GlobalID")) {
if (itemChilds.item(itemChildIndex).getAttributes().getNamedItem("schemeID") != null) {
SchemedID gid=new SchemedID().setScheme(itemChilds.item(itemChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue()).setId(itemChilds.item(itemChildIndex).getTextContent());
addGlobalID(gid);
}
}
if (itemChilds.item(itemChildIndex).getLocalName().equals("DefinedTradeContact")) {
NodeList contact = itemChilds.item(itemChildIndex).getChildNodes();
setContact(new Contact(contact));
}
if (itemChilds.item(itemChildIndex).getLocalName().equals("PostalTradeAddress")) {
NodeList postal = itemChilds.item(itemChildIndex).getChildNodes();
for (int postalChildIndex = 0; postalChildIndex < postal.getLength(); postalChildIndex++) {
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());
}
}
}
}
if (itemChilds.item(itemChildIndex).getLocalName().equals("SpecifiedTaxRegistration")) {
NodeList taxChilds = itemChilds.item(itemChildIndex).getChildNodes();
for (int taxChildIndex = 0; taxChildIndex < taxChilds.getLength(); taxChildIndex++) {
if (taxChilds.item(taxChildIndex).getLocalName() != null) {
if ((taxChilds.item(taxChildIndex).getLocalName().equals("ID"))) {
if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID") != null) {
Node firstChild = taxChilds.item(taxChildIndex).getFirstChild();
if (firstChild != null)
{
if (taxChilds.item(taxChildIndex).getAttributes()
.getNamedItem("schemeID").getNodeValue().equals("VA")) {
setVATID(firstChild.getNodeValue());
}
if (taxChilds.item(taxChildIndex).getAttributes()
.getNamedItem("schemeID").getNodeValue().equals("FC")) {
setTaxID(firstChild.getNodeValue());
}
}
}
}
}
}
}
}
}
}
}
}
/***
* XML parsing constructor
* @param nodes the nodelist returned e.g. from xpath
*/
public TradeParty(NodeList nodes) {
/**
* CII would be sth like
* <ram:SellerTradeParty>
* <ram:ID>LIEF-987654321</ram:ID>
* <ram:Name>Max Mustermann IT GmbH</ram:Name>
@@ -87,7 +250,37 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
* <ram:ID schemeID="VA">DE123456789</ram:ID>
* </ram:SpecifiedTaxRegistration>
* </ram:SellerTradeParty>
*/
* while UBL may be
* <cac:AccountingCustomerParty>
* <cac:Party>
* <cac:PartyName>
* <cbc:Name>Theodor Est</cbc:Name>
* </cac:PartyName>
* <cac:PostalAddress>
* <cbc:StreetName>Bahnstr. 42</cbc:StreetName>
* <cbc:AdditionalStreetName>Hinterhaus</cbc:AdditionalStreetName>
* <cbc:CityName>Spielkreis</cbc:CityName>
* <cbc:PostalZone>88802</cbc:PostalZone>
* <cac:AddressLine>
* <cbc:Line>Zweiter Stock</cbc:Line>
* </cac:AddressLine>
* <cac:Country>
* <cbc:IdentificationCode>DE</cbc:IdentificationCode>
* </cac:Country>
* </cac:PostalAddress>
* <cac:PartyTaxScheme>
* <cbc:CompanyID>DE999999999</cbc:CompanyID>
* <cac:TaxScheme>
* <cbc:ID>VAT</cbc:ID>
* </cac:TaxScheme>
* </cac:PartyTaxScheme>
* <cac:PartyLegalEntity>
* <cbc:RegistrationName>Theodor Est</cbc:RegistrationName>
* </cac:PartyLegalEntity>
* </cac:Party>
* </cac:AccountingCustomerParty>
*
* */
if (nodes.getLength() > 0) {
for (int nodeIndex = 0; nodeIndex < nodes.getLength(); nodeIndex++) {
@@ -97,6 +290,11 @@ public class TradeParty implements IZUGFeRDExportableTradeParty {
for (int itemChildIndex = 0; itemChildIndex < itemChilds.getLength(); itemChildIndex++) {
if (itemChilds.item(itemChildIndex).getLocalName() != null) {
if (itemChilds.item(itemChildIndex).getLocalName().equals("Party")) {
parseFromUBL(nodes);
return;
}
if (itemChilds.item(itemChildIndex).getLocalName().equals("Name")) {
setName(itemChilds.item(itemChildIndex).getTextContent());
}

View File

@@ -664,13 +664,14 @@ public class ZUGFeRDImporter {
throw new Exception("Not yet parsed");
}
final String head = getUTF8();
if (head.contains("<rsm:CrossIndustryDocument")) {
String rootNode=extractString("local-name(/*)");
if (rootNode.equals("CrossIndustryDocument")) {
return EStandard.zugferd;
} else if (head.contains("<CrossIndustryDocument")) {
return EStandard.zugferd;
} else if (head.contains("<urn:rsm:CrossIndustryInvoice") || head.contains("<rsm:CrossIndustryInvoice")) {
} else if (rootNode.equals("Invoice")) {
return EStandard.ubl;
} else if (rootNode.equals("CrossIndustryInvoice")) {
return EStandard.facturx;
} else if (head.contains("<SCRDMCCBDACIDAMessageStructure")) {
} else if (rootNode.equals("SCRDMCCBDACIDAMessageStructure")) {
return EStandard.despatchadvice;
} else if (head.contains("<rsm:SCRDMCCBDACIOMessageStructure")) {
return EStandard.orderx;

View File

@@ -67,15 +67,15 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
*/
XPathFactory xpathFact = XPathFactory.newInstance();
XPath xpath = xpathFact.newXPath();
XPathExpression xpr = xpath.compile("//*[local-name()=\"SellerTradeParty\"]");
XPathExpression xpr = xpath.compile("//*[local-name()=\"SellerTradeParty\"]|//*[local-name()=\"AccountingSupplierParty\"]");
NodeList SellerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
xpr = xpath.compile("//*[local-name()=\"BuyerTradeParty\"]");
xpr = xpath.compile("//*[local-name()=\"BuyerTradeParty\"]|//*[local-name()=\"AccountingCustomerParty\"]");
NodeList BuyerNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
xpr = xpath.compile("//*[local-name()=\"ExchangedDocument\"]|//*[local-name()=\"HeaderExchangedDocument\"]");
NodeList ExchangedDocumentNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
xpr = xpath.compile("//*[local-name()=\"GrandTotalAmount\"]");
xpr = xpath.compile("//*[local-name()=\"GrandTotalAmount\"]|//*[local-name()=\"PayableAmount\"]");
BigDecimal expectedGrandTotal = null;
NodeList totalNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
if (totalNodes.getLength() > 0) {
@@ -229,7 +229,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
}
//.addItem(new Item(new Product("Testprodukt","","C62",BigDecimal.ZERO),amount,new BigDecimal(1.0)))
zpp.setOwnOrganisationName(extractString("//*[local-name()=\"SellerTradeParty\"]/*[local-name()=\"Name\"]"));
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;
@@ -241,7 +241,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
zpp.setReferenceNumber(buyerReference);
}
xpr = xpath.compile("//*[local-name()=\"IncludedSupplyChainTradeLineItem\"]");
xpr = xpath.compile("//*[local-name()=\"IncludedSupplyChainTradeLineItem\"]|//*[local-name()=\"InvoiceLine\"]");
NodeList nodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
if (nodes.getLength() == 0) {
@@ -311,7 +311,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter {
}
if ((netChilds.item(netIndex).getLocalName() != null)
&& (netChilds.item(netIndex).getLocalName().equals("BasisQuantity"))) {
&& ((netChilds.item(netIndex).getLocalName().equals("BasisQuantity"))||(netChilds.item(netIndex).getLocalName().equals("InvoicedQuantity")))) {
basisQuantity = netChilds.item(netIndex).getTextContent();// ChargeAmount
}

Binary file not shown.