Merge branch 'master' of github.com:ZUGFeRD/mustangproject

This commit is contained in:
jstaerk
2025-02-11 13:36:41 +01:00
3 changed files with 40 additions and 23 deletions

View File

@@ -191,10 +191,10 @@ public class Item implements IZUGFeRDExportableItem {
izac.setTotalAmount(new BigDecimal(amountString)); izac.setTotalAmount(new BigDecimal(amountString));
} }
if(percentString!=null) { if(percentString!=null) {
izac.setPercent(new BigDecimal(percentString)); izac.setPercent(new BigDecimal(percentString));
} }
if(reason!=null) { if(reason!=null) {
izac.setReason(reason); izac.setReason(reason);
} }
if (isChargeString.equalsIgnoreCase("false")) { if (isChargeString.equalsIgnoreCase("false")) {
@@ -213,6 +213,12 @@ public class Item implements IZUGFeRDExportableItem {
} }
icnm.getAllNodes("AdditionalReferencedDocument").map(ReferencedDocument::fromNode).forEach(this::addAdditionalReference); 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 -> { itemMap.getAsNodeMap("AssociatedDocumentLineDocument").ifPresent(adld -> {

View File

@@ -69,7 +69,7 @@ public class Product implements IZUGFeRDExportableProduct {
nodeMap.getAsString("Description").ifPresent(this::setDescription); 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 key = apcNodes.getAsStringOrNull("Description");
String value = apcNodes.getAsStringOrNull("Value"); String value = apcNodes.getAsStringOrNull("Value");
if (key != null && value != null) { if (key != null && value != null) {
@@ -80,7 +80,6 @@ public class Product implements IZUGFeRDExportableProduct {
} }
}); });
//UBL //UBL
nodeMap.getAsNodeMap("AdditionalItemProperty").ifPresent(aipNodes -> { nodeMap.getAsNodeMap("AdditionalItemProperty").ifPresent(aipNodes -> {
String name = aipNodes.getAsStringOrNull("Name"); String name = aipNodes.getAsStringOrNull("Name");

View File

@@ -40,6 +40,7 @@ import java.nio.file.Paths;
import java.text.ParseException; import java.text.ParseException;
import java.text.SimpleDateFormat; import java.text.SimpleDateFormat;
import java.util.Arrays; import java.util.Arrays;
import java.util.Date;
import java.util.List; import java.util.List;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@@ -125,8 +126,8 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
// Reading ZUGFeRD // Reading ZUGFeRD
assertEquals("Bei Spiel GmbH", invoice.getOwnOrganisationName()); assertEquals("Bei Spiel GmbH", invoice.getOwnOrganisationName());
assertEquals(3, invoice.getZFItems().length); assertEquals(3, invoice.getZFItems().length);
assertEquals(invoice.getZFItems()[0].getNotesWithSubjectCode().get(0).getContent(), "Something"); assertEquals(invoice.getZFItems()[0].getNotesWithSubjectCode().get(0).getContent(),"Something");
assertEquals(invoice.getZFItems()[0].getNotesWithSubjectCode().size(), 1); assertEquals(invoice.getZFItems()[0].getNotesWithSubjectCode().size(),1);
assertEquals("400", invoice.getZFItems()[1].getQuantity().toString()); assertEquals("400", invoice.getZFItems()[1].getQuantity().toString());
assertEquals("Zahlbar ohne Abzug bis zum 30.05.2017", invoice.getPaymentTermDescription()); assertEquals("Zahlbar ohne Abzug bis zum 30.05.2017", invoice.getPaymentTermDescription());
assertEquals("AB321", invoice.getReferenceNumber()); assertEquals("AB321", invoice.getReferenceNumber());
@@ -305,10 +306,10 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
ZUGFeRDImporter zii = new ZUGFeRDImporter(); ZUGFeRDImporter zii = new ZUGFeRDImporter();
int version = -1; int version=-1;
try { try {
zii.fromXML(new String(Files.readAllBytes(Paths.get("./target/testout-XR-Edge.xml")), StandardCharsets.UTF_8)); zii.fromXML(new String(Files.readAllBytes(Paths.get("./target/testout-XR-Edge.xml")), StandardCharsets.UTF_8));
version = zii.getVersion(); version=zii.getVersion();
} catch (IOException e) { } catch (IOException e) {
hasExceptions = true; hasExceptions = true;
} catch (Exception e) { } catch (Exception e) {
@@ -327,9 +328,9 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
TransactionCalculator tc = new TransactionCalculator(invoice); TransactionCalculator tc = new TransactionCalculator(invoice);
assertEquals(new BigDecimal("1.00"), tc.getGrandTotal()); assertEquals(new BigDecimal("1.00"), tc.getGrandTotal());
assertEquals(version, 2); assertEquals(version,2);
assertTrue(new BigDecimal("1").compareTo(invoice.getZFItems()[0].getQuantity()) == 0); assertTrue(new BigDecimal("1").compareTo(invoice.getZFItems()[0].getQuantity()) == 0);
LineCalculator lc = new LineCalculator(invoice.getZFItems()[0]); LineCalculator lc=new LineCalculator(invoice.getZFItems()[0]);
assertTrue(new BigDecimal("1").compareTo(lc.getItemTotalNetAmount()) == 0); assertTrue(new BigDecimal("1").compareTo(lc.getItemTotalNetAmount()) == 0);
assertEquals("Z", invoice.getZFItems()[0].getProduct().getTaxCategoryCode()); assertEquals("Z", invoice.getZFItems()[0].getProduct().getTaxCategoryCode());
@@ -483,15 +484,15 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
CalculatedInvoice invoice = new CalculatedInvoice(); CalculatedInvoice invoice = new CalculatedInvoice();
importer.extractInto(invoice); importer.extractInto(invoice);
boolean isBD = invoice.getTotalPrepaidAmount() instanceof BigDecimal; boolean isBD=invoice.getTotalPrepaidAmount() instanceof BigDecimal;
assertTrue(isBD); assertTrue(isBD);
BigDecimal expectedPrepaid = new BigDecimal(50); BigDecimal expectedPrepaid=new BigDecimal(50);
BigDecimal expectedLineTotal = new BigDecimal("180.76"); BigDecimal expectedLineTotal=new BigDecimal("180.76");
BigDecimal expectedDue = new BigDecimal("147.65"); BigDecimal expectedDue=new BigDecimal("147.65");
if (isBD) { if (isBD) {
BigDecimal amread = invoice.getTotalPrepaidAmount(); BigDecimal amread=invoice.getTotalPrepaidAmount();
BigDecimal importedLineTotal = invoice.getLineTotalAmount(); BigDecimal importedLineTotal=invoice.getLineTotalAmount();
BigDecimal importedDuePayable = invoice.getDuePayable(); BigDecimal importedDuePayable=invoice.getDuePayable();
assertTrue(amread.compareTo(expectedPrepaid) == 0); assertTrue(amread.compareTo(expectedPrepaid) == 0);
assertTrue(importedLineTotal.compareTo(expectedLineTotal) == 0); assertTrue(importedLineTotal.compareTo(expectedLineTotal) == 0);
assertTrue(importedDuePayable.compareTo(expectedDue) == 0); assertTrue(importedDuePayable.compareTo(expectedDue) == 0);
@@ -528,23 +529,34 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
ZUGFeRDInvoiceImporter importer = new ZUGFeRDInvoiceImporter(new FileInputStream(inputFile)); ZUGFeRDInvoiceImporter importer = new ZUGFeRDInvoiceImporter(new FileInputStream(inputFile));
Invoice invoice = importer.extractInvoice(); Invoice invoice = importer.extractInvoice();
assertEquals(1, invoice.getRecipient().getBankDetails().size()); assertEquals(1,invoice.getRecipient().getBankDetails().size());
// IBAN belongs to recipient in invoice with sepa debit // IBAN belongs to recipient in invoice with sepa debit
assertEquals("DE21860000000086001055", invoice.getRecipient().getBankDetails().get(0).getIBAN()); assertEquals("DE21860000000086001055",invoice.getRecipient().getBankDetails().get(0).getIBAN());
assertEquals(0, invoice.getSender().getBankDetails().size()); assertEquals(0,invoice.getSender().getBankDetails().size());
inputFile = getResourceAsFile("factur-x.xml"); inputFile = getResourceAsFile("factur-x.xml");
importer = new ZUGFeRDInvoiceImporter(new FileInputStream(inputFile)); importer = new ZUGFeRDInvoiceImporter(new FileInputStream(inputFile));
invoice = importer.extractInvoice(); invoice = importer.extractInvoice();
assertEquals(1, invoice.getSender().getBankDetails().size()); assertEquals(1,invoice.getSender().getBankDetails().size());
// IBAN belongs to sender in normal invoice // IBAN belongs to sender in normal invoice
assertEquals("DE88200800000970375700", invoice.getSender().getBankDetails().get(0).getIBAN()); assertEquals("DE88200800000970375700",invoice.getSender().getBankDetails().get(0).getIBAN());
assertEquals(0, invoice.getRecipient().getBankDetails().size()); assertEquals(0,invoice.getRecipient().getBankDetails().size());
} }
@Test @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 { public void testImportPositionIncludedNotes() throws FileNotFoundException, XPathExpressionException, ParseException {
File inputFile = getResourceAsFile("ZTESTZUGFERD_1_INVDSS_012015738820PDF-1.pdf"); File inputFile = getResourceAsFile("ZTESTZUGFERD_1_INVDSS_012015738820PDF-1.pdf");
ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(new FileInputStream(inputFile)); ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter(new FileInputStream(inputFile));