From 1fb4b94718fa2c120898ef31c0889ab656d02d89 Mon Sep 17 00:00:00 2001 From: ean Date: Thu, 16 Jan 2025 13:08:16 +0100 Subject: [PATCH] Item: add BillingSpecifiedPeriod parses SpecifiedLineTradeSettlement->BillingSpecifiedPeriod to detailedDeliveryPeriod also fix parser for multiple ApplicableProductCharacteristics --- library/src/main/java/org/mustangproject/Item.java | 6 ++++++ .../src/main/java/org/mustangproject/Product.java | 3 +-- .../ZUGFeRD/ZF2ZInvoiceImporterTest.java | 12 ++++++++++++ 3 files changed, 19 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/org/mustangproject/Item.java b/library/src/main/java/org/mustangproject/Item.java index 8fefa87f..94562ca5 100644 --- a/library/src/main/java/org/mustangproject/Item.java +++ b/library/src/main/java/org/mustangproject/Item.java @@ -206,6 +206,12 @@ public class Item implements IZUGFeRDExportableItem { } icnm.getAllNodes("AdditionalReferencedDocument").map(ReferencedDocument::fromNode).forEach(this::addAdditionalReference); + + icnm.getAsNodeMap("BillingSpecifiedPeriod").ifPresent(periodNode -> { + Date start = periodNode.getAsNodeMap("StartDateTime").flatMap(dateTimeNode -> dateTimeNode.getNode("DateTimeString")).map(dts -> XMLTools.tryDate(dts)).orElse(null); + Date end = periodNode.getAsNodeMap("EndDateTime").flatMap(dateTimeNode -> dateTimeNode.getNode("DateTimeString")).map(dts -> XMLTools.tryDate(dts)).orElse(null); + setDetailedDeliveryPeriod(start, end); + }); }); itemMap.getAsNodeMap("AssociatedDocumentLineDocument").ifPresent(adld -> { diff --git a/library/src/main/java/org/mustangproject/Product.java b/library/src/main/java/org/mustangproject/Product.java index 4bbde404..4f0397ee 100644 --- a/library/src/main/java/org/mustangproject/Product.java +++ b/library/src/main/java/org/mustangproject/Product.java @@ -69,7 +69,7 @@ public class Product implements IZUGFeRDExportableProduct { nodeMap.getAsString("Description").ifPresent(this::setDescription); - nodeMap.getAsNodeMap("ApplicableProductCharacteristic").ifPresent(apcNodes -> { + nodeMap.getAllNodes("ApplicableProductCharacteristic").map(NodeMap::new).forEach(apcNodes -> { // ApplicableProductCharacteristic is 0 .. unbounded String key = apcNodes.getAsStringOrNull("Description"); String value = apcNodes.getAsStringOrNull("Value"); if (key != null && value != null) { @@ -80,7 +80,6 @@ public class Product implements IZUGFeRDExportableProduct { } }); - //UBL nodeMap.getAsNodeMap("AdditionalItemProperty").ifPresent(aipNodes -> { String name = aipNodes.getAsStringOrNull("Name"); diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java index 02985e61..f20ff181 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java @@ -40,6 +40,7 @@ import java.nio.file.Paths; import java.text.ParseException; import java.text.SimpleDateFormat; import java.util.Arrays; +import java.util.Date; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @@ -492,6 +493,17 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { } @Test + public void testItemsBillingSpecifiedPeriod() throws FileNotFoundException, XPathExpressionException, ParseException { + File inputFile = getResourceAsFile("factur-x_invoicingPeriod.xml"); + ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(new FileInputStream(inputFile)); + + CalculatedInvoice invoice = new CalculatedInvoice(); + zii.extractInto(invoice); + assertEquals(3, invoice.getZFItems().length); + assertEquals(new Date(2022-1900, 8-1, 29), invoice.getZFItems()[0].getDetailedDeliveryPeriodFrom()); + assertEquals(new Date(2022-1900, 8-1, 31), invoice.getZFItems()[0].getDetailedDeliveryPeriodTo()); + } + public void testImportPositionIncludedNotes() throws FileNotFoundException, XPathExpressionException, ParseException { File inputFile = getResourceAsFile("ZTESTZUGFERD_1_INVDSS_012015738820PDF-1.pdf"); ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(new FileInputStream(inputFile));