diff --git a/library/src/main/java/org/mustangproject/TradeParty.java b/library/src/main/java/org/mustangproject/TradeParty.java index 5f14b322..7a979763 100644 --- a/library/src/main/java/org/mustangproject/TradeParty.java +++ b/library/src/main/java/org/mustangproject/TradeParty.java @@ -23,7 +23,7 @@ import com.fasterxml.jackson.annotation.JsonIgnoreProperties; @JsonInclude(JsonInclude.Include.NON_EMPTY) public class TradeParty implements IZUGFeRDExportableTradeParty { - protected String name, zip, street, location, country; + protected String name, zip, street, location, taxScheme; protected String taxID = null, vatID = null; protected String ID = null; protected String description = null; @@ -58,7 +58,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { this.street = street; this.zip = zip; this.location = location; - this.country = country; + this.taxScheme = country; } @@ -90,22 +90,47 @@ 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")) { setTaxID(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("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++) { @@ -113,6 +138,9 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { if (legal.item(legalChildIndex).getLocalName().equals("RegistrationName")) { setName(legal.item(legalChildIndex).getTextContent()); } + if (legal.item(legalChildIndex).getLocalName().equals("CompanyLegalForm")) { + setDescription(legal.item(legalChildIndex).getTextContent()); + } } } } @@ -225,26 +253,27 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { } - if (currentUBLChild.equals("SpecifiedTaxRegistration")) { + 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("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).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()); } - if (taxChilds.item(taxChildIndex).getAttributes().getNamedItem("schemeID").getNodeValue().equals("FC")) { - setTaxID(firstChild.getNodeValue()); +// 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()); + } } } } } } } - } } } @@ -671,7 +700,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { @Override public String getCountry() { - return country; + return taxScheme; } /*** @@ -680,7 +709,7 @@ public class TradeParty implements IZUGFeRDExportableTradeParty { * @return fluent setter */ public TradeParty setCountry(String country) { - this.country = country; + this.taxScheme = country; return this; } diff --git a/validator/src/main/java/org/mustangproject/validator/XMLValidator.java b/validator/src/main/java/org/mustangproject/validator/XMLValidator.java index 4392448e..c2124b87 100644 --- a/validator/src/main/java/org/mustangproject/validator/XMLValidator.java +++ b/validator/src/main/java/org/mustangproject/validator/XMLValidator.java @@ -269,13 +269,13 @@ public class XMLValidator extends Validator { // saxon java net.sf.saxon.Transform -o tcdl2.0.tsdtf.sch.tmp.xsl -s // tcdl2.0.tsdtf.sch iso_svrl.xsl - } else if (root.getLocalName().equalsIgnoreCase("Invoice")) { + } else if (root.getLocalName().equalsIgnoreCase("Invoice") || root.getLocalName().equalsIgnoreCase("CreditNote") ) { context.setGeneration("2"); context.setFormat("UBL"); isXRechnung = context.getProfile().contains("xrechnung"); // UBL LOGGER.debug("UBL"); - validateSchema(zfXML.getBytes(StandardCharsets.UTF_8), "UBL_21/maindoc/UBL-Invoice-2.1.xsd", 18, EPart.fx); + validateSchema(zfXML.getBytes(StandardCharsets.UTF_8), "UBL_21/maindoc/UBL-"+root.getLocalName()+"-2.1.xsd", 18, EPart.fx); xsltFilename = "/xslt/en16931schematron/EN16931-UBL-validation.xslt"; mainSchematronSectionErrorTypeCode=24; diff --git a/validator/src/test/java/org/mustangproject/validator/XMLValidatorTest.java b/validator/src/test/java/org/mustangproject/validator/XMLValidatorTest.java index 8b6022f5..5477b25c 100644 --- a/validator/src/test/java/org/mustangproject/validator/XMLValidatorTest.java +++ b/validator/src/test/java/org/mustangproject/validator/XMLValidatorTest.java @@ -298,6 +298,22 @@ public class XMLValidatorTest extends ResourceCase { noExceptions = false; } assertTrue(noExceptions); + tempFile = getResourceAsFile("ubl-tc434-creditnote1.xml"); + try { + xv.setFilename(tempFile.getAbsolutePath()); + xv.validate(); + + Source source = Input.fromString("" + xv.getXMLResult() + "").build(); + String content = xpath.evaluate("/validation/summary/@status", source); + assertEquals("valid", content); + + + } catch (IrrecoverableValidationError e) { + + noExceptions = false; + } + assertTrue(noExceptions); + } diff --git a/validator/src/test/resources/ubl-tc434-creditnote1.xml b/validator/src/test/resources/ubl-tc434-creditnote1.xml new file mode 100644 index 00000000..b9380fb3 --- /dev/null +++ b/validator/src/test/resources/ubl-tc434-creditnote1.xml @@ -0,0 +1,136 @@ + + + + urn:cen.eu:en16931:2017 + urn:fdc:peppol.eu:2017:poacc:billing:01:1.0 + 018304 / 28865 + 2019-09-23 + 381 + EUR + 018304 / 28865 + + 2019-02-01 + 2019-02-28 + + + + 0000000196 + + My Supplier Company N.V. + + + De Grote Meir 22 + ANTWERPEN + 2000 + + BE + + + + BE0000000196 + + VAT + + + + My Supplier Company + 0000000196 + + + john.doole@mysuppliercompany.be + + + + + + 0000000295 + + My Customer Company S.A. + + + Boulevard Sint Michel 53 + BRUXELLES + 1000 + + BE + + + + BE0000000295 + + VAT + + + + My Customer Company + 0000000295 + + + pete.smith@mycustomercompany.be + + + + + 1 + 010676609538 + + BE91000000143476 + + BPOTBEB1 + + + + + 0.00 + + 100.11 + 0.00 + + E + 0.00 + Taxes are not applicable + + VAT + + + + + + 100.11 + 100.11 + 100.11 + 100.11 + + + 1 + 1.00 + 100.11 + + Exonération du versement du PP + Exonération du versement du PP + + V55 + + + E + 0.00 + + VAT + + + + 2 + Contributions - précompte professionnel + + + + 100.11 + + +