From 4799f9586818dc783b106e7cd59846afaafe3444 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Mon, 2 Dec 2024 10:42:05 +0100 Subject: [PATCH 1/2] import docuemtne level included notes in ubl --- .../ZUGFeRD/ZUGFeRDInvoiceImporter.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index 12504210..5eabd0a4 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -306,8 +306,18 @@ public class ZUGFeRDInvoiceImporter { zpp.setDeliveryAddress(new TradeParty(deliveryNodes)); } + List includedNotes = new ArrayList<>(); //UBL... + XPathExpression UBLNotesEx = xpath.compile("/*[local-name()=\"Invoice\"]/*[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++) { + includedNotes.add(IncludedNote.generalNote(UBLNotesNd.item(nodeIndex).getTextContent())); + } + zpp.addNotes(includedNotes); + } + XPathExpression shipExUBL = xpath.compile("//*[local-name()=\"Delivery\"]"); Node deliveryNode = (Node) shipExUBL.evaluate(getDocument(), XPathConstants.NODE); @@ -473,6 +483,7 @@ public class ZUGFeRDInvoiceImporter { Date dueDate = null; Date deliveryDate = null; String despatchAdviceReferencedDocument = null; + for (int i = 0; i < ExchangedDocumentNodes.getLength(); i++) { Node exchangedDocumentNode = ExchangedDocumentNodes.item(i); NodeList exchangedDocumentChilds = exchangedDocumentNode.getChildNodes(); @@ -493,7 +504,6 @@ public class ZUGFeRDInvoiceImporter { } } } - List includedNotes = new ArrayList<>(); if ((item.getLocalName() != null) && (item.getLocalName().equals("IncludedNote"))) { String subjectCode = ""; String content = null; From db3be5fbadc74febb943145b11e89575de692fa2 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Mon, 2 Dec 2024 11:02:58 +0100 Subject: [PATCH 2/2] remove test --- .../ZUGFeRD/ZF2ZInvoiceImporterTest.java | 55 ------------------- 1 file changed, 55 deletions(-) diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java index 3472af79..5b8155ea 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java @@ -390,61 +390,6 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { } - /* -this would test if for all elements/attributes - */ - - public void testEEISI_300_cii_Import() throws XPathExpressionException, ParseException { - boolean hasExceptions = false; - File inputCII = getResourceAsFile("not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel.cii.xml"); - File inputUBL = getResourceAsFile("not_validating_full_invoice_based_onTest_EeISI_300_CENfullmodel.ubl.xml"); - - - ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(); - zii.doIgnoreCalculationErrors(); - try { - zii.fromXML(new String(Files.readAllBytes(inputCII.toPath()), StandardCharsets.UTF_8)); - - } catch (IOException e) { - hasExceptions = true; - } - - Invoice invoiceUBL = null; - invoiceUBL = zii.extractInvoice(); - - try { - zii.ignoreCalculationErrors=true; - zii.fromXML(new String(Files.readAllBytes(inputUBL.toPath()), StandardCharsets.UTF_8)); - - } catch (IOException e) { - hasExceptions = true; - } - - Invoice invoiceCII = null; - try { - invoiceCII = zii.extractInvoice(); - ObjectMapper mapper = new ObjectMapper(); - String ubl=mapper.writeValueAsString(invoiceUBL).replace("," ,"\n"); - String cii=mapper.writeValueAsString(invoiceCII).replace("," ,"\n"); - - assertEquals(cii,ubl); - - - /* - Seller contact point - +41 345 654455 - seller@contact.de);*/ - } catch (XPathExpressionException | ParseException e) { - hasExceptions = true; - } catch (JsonProcessingException e) { - throw new RuntimeException(e); - } - assertFalse(hasExceptions); - -// TransactionCalculator tc = new TransactionCalculator(invoiceCII); -// assertEquals(new BigDecimal("205.00"), tc.getGrandTotal()); - - } @Test public void testImportPrepaid() throws XPathExpressionException, ParseException {