From c162f058fb443a356639139bede81cc043ebc6b9 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Thu, 9 Jan 2025 07:20:02 +0100 Subject: [PATCH 1/3] working on first functionality --- .../main/java/org/mustangproject/Item.java | 16 ++++++++++++ .../ZUGFeRD/ZF2ZInvoiceImporterTest.java | 26 +++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/library/src/main/java/org/mustangproject/Item.java b/library/src/main/java/org/mustangproject/Item.java index 4641a0e3..3f302d63 100644 --- a/library/src/main/java/org/mustangproject/Item.java +++ b/library/src/main/java/org/mustangproject/Item.java @@ -172,6 +172,22 @@ public class Item implements IZUGFeRDExportableItem { icnm.getAsNodeMap("ApplicableTradeTax") .flatMap(cnm -> cnm.getAsBigDecimal("RateApplicablePercent", "ApplicablePercent")) .ifPresent(product::setVATPercent); + icnm.getAsNodeMap("SpecifiedTradeAllowanceCharge").ifPresent(stac -> { + stac.getAsNodeMap("ChargeIndicator").ifPresent(ci -> { + String isChargeString=ci.getAsString("Indicator").get(); + String percentString=stac.getAsStringOrNull("CalculationPercent"); + String reason=stac.getAsStringOrNull("Reason"); + Allowance izac=null; + if (isChargeString.equalsIgnoreCase("false")) { + izac = new Allowance(); + } + + izac.setPercent(new BigDecimal(percentString)); + izac.setReason(reason); + addAllowance(izac); + }); + + }); if (recalcPrice && !BigDecimal.ZERO.equals(quantity)) { icnm.getAsNodeMap("SpecifiedTradeSettlementLineMonetarySummation") diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java index 75aa5324..17c1e15b 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java @@ -103,6 +103,32 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { } + + public void testTheInvoiceImport() { + + ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter("C:\\Users\\jstaerk\\workspace\\XMLExamples\\zfdiverses\\20250108_\\xmlDieWirLesenSollten.xml"); + + boolean hasExceptions = false; + Invoice invoice = null; + try { + invoice = zii.extractInvoice(); + } catch (XPathExpressionException | ParseException e) { + hasExceptions = true; + } + assertFalse(hasExceptions); + // Reading ZUGFeRD + + TransactionCalculator tc = new TransactionCalculator(invoice); + assertEquals(new BigDecimal("0.00"), tc.getDuePayable()); + assertEquals(new BigDecimal("0.00"), tc.getGrandTotal()); + + + // name street location zip country, contact name phone email, total amount + + } + + + public void testInvoiceImportUBL() { From b4aa73317084b2d6accfe5bf90694c26e7a3f276 Mon Sep 17 00:00:00 2001 From: jstaerk Date: Fri, 10 Jan 2025 08:06:54 +0100 Subject: [PATCH 2/3] use calculated price after allowances/charges and do focus on document level allowances/charges for document level allowance/charge processing only --- .../main/java/org/mustangproject/ZUGFeRD/LineCalculator.java | 2 +- .../java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/LineCalculator.java b/library/src/main/java/org/mustangproject/ZUGFeRD/LineCalculator.java index e319ec73..d17ccfec 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/LineCalculator.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/LineCalculator.java @@ -55,7 +55,7 @@ public class LineCalculator { BigDecimal basisQuantity = currentItem.getBasisQuantity().compareTo(BigDecimal.ZERO) == 0 ? BigDecimal.ONE.setScale(4) : currentItem.getBasisQuantity(); - itemTotalNetAmount = quantity.multiply(getPrice()).divide(basisQuantity, 18, RoundingMode.HALF_UP) + itemTotalNetAmount = quantity.multiply(price).divide(basisQuantity, 18, RoundingMode.HALF_UP) .subtract(allowanceItemTotal).setScale(2, RoundingMode.HALF_UP); itemTotalVATAmount = itemTotalNetAmount.multiply(multiplicator); } diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index 0417990d..de66b35d 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -897,7 +897,7 @@ public class ZUGFeRDInvoiceImporter { // be read, // so the invoice remains arithmetically correct // -> parse document level charges+allowances - xpr = xpath.compile("//*[local-name()=\"SpecifiedTradeAllowanceCharge\"]|//*[local-name()=\"AllowanceCharge\"]");//CII and UBL + xpr = xpath.compile("//*[local-name()=\"ApplicableHeaderTradeSettlement\"]/*[local-name()=\"SpecifiedTradeAllowanceCharge\"]|/*[local-name()=\"AllowanceCharge\"]");//CII and UBL NodeList chargeNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); for (int i = 0; i < chargeNodes.getLength(); i++) { NodeList chargeNodeChilds = chargeNodes.item(i).getChildNodes(); From 6f63c85b149b0a6c130ea3e37193744030387a1e Mon Sep 17 00:00:00 2001 From: jstaerk Date: Fri, 10 Jan 2025 10:39:12 +0100 Subject: [PATCH 3/3] also allow item allowances --- History.md | 4 ++- .../main/java/org/mustangproject/Item.java | 16 +++++++++--- .../ZUGFeRD/ZF2ZInvoiceImporterTest.java | 26 ------------------- 3 files changed, 16 insertions(+), 30 deletions(-) diff --git a/History.md b/History.md index a829860d..98dfa6da 100644 --- a/History.md +++ b/History.md @@ -8,7 +8,9 @@ allow to add includedNotes with type - 631 multiple invoice referenced documents - 629 - 630 #296 #565 -- +- 648 +- 651 +- 652 2.15.2 ======= diff --git a/library/src/main/java/org/mustangproject/Item.java b/library/src/main/java/org/mustangproject/Item.java index 3f302d63..8fefa87f 100644 --- a/library/src/main/java/org/mustangproject/Item.java +++ b/library/src/main/java/org/mustangproject/Item.java @@ -176,15 +176,25 @@ public class Item implements IZUGFeRDExportableItem { stac.getAsNodeMap("ChargeIndicator").ifPresent(ci -> { String isChargeString=ci.getAsString("Indicator").get(); String percentString=stac.getAsStringOrNull("CalculationPercent"); + String amountString=stac.getAsStringOrNull("ActualAmount"); String reason=stac.getAsStringOrNull("Reason"); - Allowance izac=null; + Charge izac= new Charge(); if (isChargeString.equalsIgnoreCase("false")) { izac = new Allowance(); + } else { + izac = new Charge(); + } + if (amountString!=null) { + izac.setTotalAmount(new BigDecimal(amountString)); } - izac.setPercent(new BigDecimal(percentString)); izac.setReason(reason); - addAllowance(izac); + + if (isChargeString.equalsIgnoreCase("false")) { + addAllowance(izac); + } else { + addCharge(izac); + } }); }); diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java index 17c1e15b..49c5ce78 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/ZF2ZInvoiceImporterTest.java @@ -40,7 +40,6 @@ 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; @@ -104,31 +103,6 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase { } - public void testTheInvoiceImport() { - - ZUGFeRDInvoiceImporter zii = new ZUGFeRDInvoiceImporter("C:\\Users\\jstaerk\\workspace\\XMLExamples\\zfdiverses\\20250108_\\xmlDieWirLesenSollten.xml"); - - boolean hasExceptions = false; - Invoice invoice = null; - try { - invoice = zii.extractInvoice(); - } catch (XPathExpressionException | ParseException e) { - hasExceptions = true; - } - assertFalse(hasExceptions); - // Reading ZUGFeRD - - TransactionCalculator tc = new TransactionCalculator(invoice); - assertEquals(new BigDecimal("0.00"), tc.getDuePayable()); - assertEquals(new BigDecimal("0.00"), tc.getGrandTotal()); - - - // name street location zip country, contact name phone email, total amount - - } - - - public void testInvoiceImportUBL() {