Import IncludedNotes on invoice extraction

This commit is contained in:
Marco Lennartz
2024-11-13 23:04:59 +01:00
parent a7c9e221cb
commit 678d3ba6a1
3 changed files with 64 additions and 0 deletions

View File

@@ -352,6 +352,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(/*)");

View File

@@ -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");
}
}

Binary file not shown.