diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index 5c9ee429..5103fe4f 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -352,6 +352,34 @@ public class ZUGFeRDInvoiceImporter { } } } + List includedNotes = new ArrayList<>(); + if ((item.getLocalName() != null) && (item.getLocalName().equals("IncludedNote"))) { + String subjectCode = ""; + String content = null; + NodeList includedNodeChilds = item.getChildNodes(); + for (int issueDateChildIndex = 0; issueDateChildIndex < includedNodeChilds.getLength(); issueDateChildIndex++) { + if ((includedNodeChilds.item(issueDateChildIndex).getLocalName() != null) + && (includedNodeChilds.item(issueDateChildIndex).getLocalName().equals("Content"))) { + content = XMLTools.trimOrNull(includedNodeChilds.item(issueDateChildIndex)); + } + if ((includedNodeChilds.item(issueDateChildIndex).getLocalName() != null) + && (includedNodeChilds.item(issueDateChildIndex).getLocalName().equals("SubjectCode"))) { + subjectCode = XMLTools.trimOrNull(includedNodeChilds.item(issueDateChildIndex)); + } + } + switch (subjectCode){ + case "AAI": includedNotes.add(IncludedNote.generalNote(content)); break; + case "REG": includedNotes.add(IncludedNote.regulatoryNote(content)); break; + case "ABL": includedNotes.add(IncludedNote.legalNote(content)); break; + case "CUS": includedNotes.add(IncludedNote.customsNote(content)); break; + case "SUR": includedNotes.add(IncludedNote.sellerNote(content)); break; + case "TXD": includedNotes.add(IncludedNote.taxNote(content)); break; + case "ACY": includedNotes.add(IncludedNote.introductionNote(content)); break; + case "AAK": includedNotes.add(IncludedNote.discountBonusNote(content)); break; + default: includedNotes.add(IncludedNote.unspecifiedNote(content)); break; + } + } + zpp.addNotes(includedNotes); } } String rootNode = extractString("local-name(/*)"); diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporterTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporterTest.java new file mode 100644 index 00000000..de482946 --- /dev/null +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporterTest.java @@ -0,0 +1,36 @@ +package org.mustangproject.ZUGFeRD; + +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.InputStream; +import java.text.ParseException; +import java.util.List; +import javax.xml.xpath.XPathExpressionException; +import org.junit.jupiter.api.Test; +import org.mustangproject.IncludedNote; +import org.mustangproject.Invoice; +import org.mustangproject.SubjectCode; + +class ZUGFeRDInvoiceImporterTest { + + @Test + void testImportIncludedNotes() throws XPathExpressionException, ParseException { + InputStream inputStream = this.getClass() + .getResourceAsStream("/EN16931_Einfach.pdf"); + ZUGFeRDInvoiceImporter importer = new ZUGFeRDInvoiceImporter(inputStream); + Invoice invoice = importer.extractInvoice(); + List notesWithSubjectCode = invoice.getNotesWithSubjectCode(); + assertThat(notesWithSubjectCode).hasSize(2); + assertThat(notesWithSubjectCode.get(0).getSubjectCode()).isNull(); + assertThat(notesWithSubjectCode.get(0).getContent()).isEqualTo("Rechnung gemäß Bestellung vom 01.11.2024."); + assertThat(notesWithSubjectCode.get(1).getSubjectCode()).isEqualTo(SubjectCode.REG); + assertThat(notesWithSubjectCode.get(1).getContent()).isEqualTo("Lieferant GmbH\t\t\t\t\n" + + "Lieferantenstraße 20\t\t\t\t\n" + + "80333 München\t\t\t\t\n" + + "Deutschland\t\t\t\t\n" + + "Geschäftsführer: Hans Muster\n" + + "Handelsregisternummer: H A 123"); + + } + +} diff --git a/library/src/test/resources/EN16931_Einfach.pdf b/library/src/test/resources/EN16931_Einfach.pdf new file mode 100755 index 00000000..802b7282 Binary files /dev/null and b/library/src/test/resources/EN16931_Einfach.pdf differ