From 00e68389ce7de750e6017f0b8f3bc72d1f11369e Mon Sep 17 00:00:00 2001 From: jstaerk Date: Tue, 10 May 2022 20:33:16 +0200 Subject: [PATCH] corrected import of CIDA delivery advices --- .../ZUGFeRD/ZUGFeRDImporter.java | 27 ++++++++++++++----- .../ZUGFeRD/ZUGFeRDInvoiceImporter.java | 12 +++++++-- .../org/mustangproject/ZUGFeRD/DXTest.java | 6 ++--- 3 files changed, 33 insertions(+), 12 deletions(-) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java index 21615e52..92dced87 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDImporter.java @@ -44,6 +44,7 @@ import org.apache.pdfbox.pdmodel.PDEmbeddedFilesNameTreeNode; import org.apache.pdfbox.pdmodel.common.PDNameTreeNode; import org.apache.pdfbox.pdmodel.common.filespecification.PDComplexFileSpecification; import org.apache.pdfbox.pdmodel.common.filespecification.PDEmbeddedFile; +import org.mustangproject.EStandard; import org.mustangproject.Item; import org.mustangproject.Product; import org.w3c.dom.Document; @@ -633,11 +634,28 @@ public class ZUGFeRDImporter { } - public int getVersion() throws Exception { + public EStandard getStandard() throws Exception { if (!containsMeta) { throw new Exception("Not yet parsed"); } if (getUTF8().contains(" lineItemNodes = new ArrayList<>(); NodeList nl = null; try { - if (getVersion() == 1) { - nl = getNodeListByPath("//*[local-name() = 'CrossIndustryDocument']//*[local-name() = 'SpecifiedSupplyChainTradeTransaction']//*[local-name() = 'IncludedSupplyChainTradeLineItem']"); - } else { - nl = getNodeListByPath("//*[local-name() = 'CrossIndustryInvoice']//*[local-name() = 'SupplyChainTradeTransaction']//*[local-name() = 'IncludedSupplyChainTradeLineItem']"); - } + nl = getNodeListByPath("//*[local-name() = 'IncludedSupplyChainTradeLineItem']"); + } catch (final Exception e) { Logger.getLogger(ZUGFeRDImporter.class.getName()).log(Level.SEVERE, null, e); } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index 5c4aea81..0fa236a8 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -216,7 +216,7 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter { if ((itemChilds.item(itemChildIndex).getLocalName() != null) && (itemChilds.item(itemChildIndex).getLocalName().equals("SpecifiedLineTradeDelivery"))) { NodeList tradeLineChilds = itemChilds.item(itemChildIndex).getChildNodes(); for (int tradeLineChildIndex = 0; tradeLineChildIndex < tradeLineChilds.getLength(); tradeLineChildIndex++) { - if ((tradeLineChilds.item(tradeLineChildIndex).getLocalName() != null) && (tradeLineChilds.item(tradeLineChildIndex).getLocalName().equals("BilledQuantity")||tradeLineChilds.item(tradeLineChildIndex).getLocalName().equals("RequestedQuantity"))) { + if ((tradeLineChilds.item(tradeLineChildIndex).getLocalName() != null) && (tradeLineChilds.item(tradeLineChildIndex).getLocalName().equals("BilledQuantity")||tradeLineChilds.item(tradeLineChildIndex).getLocalName().equals("RequestedQuantity")||tradeLineChilds.item(tradeLineChildIndex).getLocalName().equals("DespatchedQuantity"))) { //RequestedQuantity is for Order-X, BilledQuantity for FX and ZF quantity = tradeLineChilds.item(tradeLineChildIndex).getTextContent(); unitCode = tradeLineChilds.item(tradeLineChildIndex).getAttributes().getNamedItem("unitCode").getNodeValue(); @@ -336,7 +336,15 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter { TransactionCalculator tc = new TransactionCalculator(zpp); String expectedStringTotalGross = tc.getGrandTotal().toPlainString(); - if ((!expectedStringTotalGross.equals(XMLTools.nDigitFormat(expectedGrandTotal, 2)))&&(!ignoreCalculationErrors)) { + EStandard whichType; + try { + whichType=getStandard(); + } catch(Exception e) { + throw new ParseException("Could not find out if it's an invoice, order, or delivery advice", 0); + + } + + if ((whichType!=EStandard.despatchadvice) && ((!expectedStringTotalGross.equals(XMLTools.nDigitFormat(expectedGrandTotal, 2)))&&(!ignoreCalculationErrors))) { throw new ParseException("Could not reproduce the invoice, this could mean that it could not be read properly", 0); } } diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/DXTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/DXTest.java index b62937f3..5dfc37f7 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/DXTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/DXTest.java @@ -278,7 +278,7 @@ public class DXTest extends MustangReaderTestCase implements IExportableTransact .load(SOURCE_PDF)) { oe.setTransaction(this); String theXML = new String(oe.getProvider().getXML(), StandardCharsets.UTF_8); - assertTrue(theXML.contains("220")); assertTrue(zi.getUTF8().contains("")); assertFalse(zi.getUTF8().contains("EUR")); - assertTrue(zi.getUTF8().contains("USD"));//currency should be USD, test for #150 - // Now also check the "invoice"Importer - assertEquals("496.00", zi.getAmount()); + assertEquals(zi.getLineItemList().size(),3); assertEquals(zi.getHolder(), getOwnOrganisationName()); ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(TARGET_PDF); try {