Merge pull request #554 from marco-lennartz/read-includedNotes-invoice
Import IncludedNotes on invoice extraction
This commit is contained in:
@@ -354,6 +354,34 @@ public class ZUGFeRDInvoiceImporter {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
List<IncludedNote> 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(/*)");
|
String rootNode = extractString("local-name(/*)");
|
||||||
|
|||||||
@@ -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<IncludedNote> 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");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
BIN
library/src/test/resources/EN16931_Einfach.pdf
Executable file
BIN
library/src/test/resources/EN16931_Einfach.pdf
Executable file
Binary file not shown.
Reference in New Issue
Block a user