From 8c7a2c322d0d4f17ff667d6d0873836a04ce0dc7 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Tue, 14 Jan 2025 07:05:46 +0100 Subject: [PATCH] closes #678 --- History.md | 1 + .../ZUGFeRD/ZUGFeRDInvoiceImporter.java | 13 +++++----- .../ZUGFeRD/ZF2ZInvoiceImporterTest.java | 24 ++++++++++++++++++- 3 files changed, 31 insertions(+), 7 deletions(-) diff --git a/History.md b/History.md index 701106d8..f02bc608 100644 --- a/History.md +++ b/History.md @@ -1,3 +1,4 @@ +- #678 2.16.0 ======= diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index de66b35d..b9d3f5c1 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -309,7 +309,7 @@ public class ZUGFeRDInvoiceImporter { List includedNotes = new ArrayList<>(); //UBL... - XPathExpression UBLNotesEx = xpath.compile("/*[local-name()=\"Invoice\"]/*[local-name()=\"Note\"]"); + XPathExpression UBLNotesEx = xpath.compile("/*[local-name()=\"Invoice\" or local-name()=\"CreditNote\"]/*[local-name()=\"Note\"]"); NodeList UBLNotesNd = (NodeList) UBLNotesEx.evaluate(getDocument(), XPathConstants.NODESET); if ((UBLNotesNd != null) && (UBLNotesNd.getLength() > 0)) { for (int nodeIndex = 0; nodeIndex < UBLNotesNd.getLength(); nodeIndex++) { @@ -556,15 +556,16 @@ public class ZUGFeRDInvoiceImporter { } zpp.addNotes(includedNotes); String rootNode = extractString("local-name(/*)"); - if (rootNode.equals("Invoice")) { + if (rootNode.equals("Invoice")||rootNode.equals("CreditNote")) { // UBL... - number = extractString("//*[local-name()=\"Invoice\"]/*[local-name()=\"ID\"]").trim(); - typeCode = extractString("//*[local-name()=\"Invoice\"]/*[local-name()=\"InvoiceTypeCode\"]").trim(); - String issueDateStr = extractString("//*[local-name()=\"Invoice\"]/*[local-name()=\"IssueDate\"]").trim(); + // //*[local-name()="Invoice" or local-name()="CreditNote"] + number = extractString("/*[local-name()=\"Invoice\" or local-name()=\"CreditNote\"]/*[local-name()=\"ID\"]").trim(); + typeCode = extractString("/*[local-name()=\"Invoice\" or local-name()=\"CreditNote\"]/*[local-name()=\"InvoiceTypeCode\"]").trim(); + String issueDateStr = extractString("/*[local-name()=\"Invoice\" or local-name()=\"CreditNote\"]/*[local-name()=\"IssueDate\"]").trim(); if (issueDateStr.length()>0) { issueDate = new SimpleDateFormat("yyyy-MM-dd").parse(issueDateStr); } - String dueDt = extractString("//*[local-name()=\"Invoice\"]/*[local-name()=\"DueDate\"]").trim(); + String dueDt = extractString("/*[local-name()=\"Invoice\" or local-name()=\"CreditNote\"]/*[local-name()=\"DueDate\"]").trim(); if (dueDt.length() > 0) { dueDate = new SimpleDateFormat("yyyy-MM-dd").parse(dueDt); } diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java index 49c5ce78..11daecf0 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java @@ -375,7 +375,7 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { } - public void testImportMinimum() { + public void testImportMinimum() { File CIIinputFile = getResourceAsFile("cii/facturFrMinimum.xml"); try { ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(new FileInputStream(CIIinputFile)); @@ -394,6 +394,28 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { } + } + + public void testImportUBLCreditnote() { // Confirm some basics also work with UBL credit notes + File CIIinputFile = getResourceAsFile("ubl/UBL-CreditNote-2.1-Example.ubl.xml"); + try { + ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(new FileInputStream(CIIinputFile)); + + + CalculatedInvoice i = new CalculatedInvoice(); + zii.extractInto(i); + assertEquals("TOSL108", i.getNumber()); + assertEquals("729", i.getGrandTotal().toString()); + + } catch (IOException e) { + fail("IOException not expected"); + } catch (XPathExpressionException e) { + throw new RuntimeException(e); + } catch (ParseException e) { + throw new RuntimeException(e); + } + + }