diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/TransactionCalculator.java b/library/src/main/java/org/mustangproject/ZUGFeRD/TransactionCalculator.java index 4d9382ea..1e1f757f 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/TransactionCalculator.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/TransactionCalculator.java @@ -39,8 +39,8 @@ public class TransactionCalculator implements IAbsoluteValueProvider { } /*** - * the invoice total with VAT, corrected by prepaid amount, allowances and - * charges + * the invoice total with VAT, allowances and + * charges, WITHOUT considering prepaid amount * * @return the invoice total including taxes */ diff --git a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java index 54174335..e330853b 100644 --- a/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java +++ b/library/src/main/java/org/mustangproject/ZUGFeRD/ZUGFeRDInvoiceImporter.java @@ -10,6 +10,7 @@ import java.util.ArrayList; import java.util.Base64; import java.util.Date; import java.util.List; +import java.util.Objects; import javax.xml.xpath.XPath; import javax.xml.xpath.XPathConstants; @@ -88,6 +89,12 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter { expectedGrandTotal = new BigDecimal(totalNodes.item(0).getTextContent()); } + xpr = xpath.compile("//*[local-name()=\"PrepaidAmount\"]"); + NodeList prepaidNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); + if (prepaidNodes.getLength() > 0) { + zpp.setTotalPrepaidAmount(new BigDecimal(prepaidNodes.item(0).getTextContent())); + } + Date issueDate = null; Date dueDate = null; Date deliveryDate = null; @@ -307,9 +314,9 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter { xpr = xpath.compile("//*[local-name()=\"BuyerReference\"]"); String buyerReference = null; - totalNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); - if (totalNodes.getLength() > 0) { - buyerReference = totalNodes.item(0).getTextContent(); + prepaidNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); + if (prepaidNodes.getLength() > 0) { + buyerReference = prepaidNodes.item(0).getTextContent(); } if (buyerReference != null) { zpp.setReferenceNumber(buyerReference); @@ -409,7 +416,8 @@ public class ZUGFeRDInvoiceImporter extends ZUGFeRDImporter { } TransactionCalculator tc = new TransactionCalculator(zpp); - String expectedStringTotalGross = tc.getGrandTotal().toPlainString(); + String expectedStringTotalGross = tc.getGrandTotal() + .subtract(Objects.requireNonNullElse(zpp.getTotalPrepaidAmount(), BigDecimal.ZERO)).toPlainString(); EStandard whichType; try { whichType = getStandard(); diff --git a/library/src/test/java/org/mustangproject/ZUGFeRD/UBLTest.java b/library/src/test/java/org/mustangproject/ZUGFeRD/UBLTest.java index 7dba9fdf..31d1ec12 100644 --- a/library/src/test/java/org/mustangproject/ZUGFeRD/UBLTest.java +++ b/library/src/test/java/org/mustangproject/ZUGFeRD/UBLTest.java @@ -123,6 +123,23 @@ public class UBLTest extends ResourceCase { } + public void testEdgeInvoiceImportUBL2() { + File UBLinputFile = getResourceAsFile("ubl/04.01a-INVOICE_ubl.xml"); + boolean hasExceptions = false; + + ZUGFeRDInvoiceImporter zii = null; + Invoice invoice = null; + try { + zii = new ZUGFeRDInvoiceImporter(new FileInputStream(UBLinputFile)); + invoice = zii.extractInvoice(); + } catch (XPathExpressionException | ParseException | FileNotFoundException e) { + e.printStackTrace(); + hasExceptions = true; + } + assertFalse(hasExceptions); + + assertEquals(new BigDecimal("10000.0"), invoice.getTotalPrepaidAmount()); + } /* public void testInvoiceImportOtherUBL() { diff --git a/library/src/test/resources/ubl/04.01a-INVOICE_ubl.xml b/library/src/test/resources/ubl/04.01a-INVOICE_ubl.xml new file mode 100644 index 00000000..e0014a4d --- /dev/null +++ b/library/src/test/resources/ubl/04.01a-INVOICE_ubl.xml @@ -0,0 +1,388 @@ + + urn:cen.eu:en16931:2017#compliant#urn:xoev-de:kosit:standard:xrechnung_2.2#conformant#urn:xoev-de:kosit:extension:xrechnung_2.2 + 12345 + 2019-05-15 + 380 + EUR + 12345678-12345-83 + + 2019-02-01 + 2019-05-07 + + + 123 + + + + + M. Meier Handwerk GbR + + + Hauptstraße 2 + Musterstadt + 12345 + + DE + + + + DE/12/345/67890 + + VAT + + + + M. Meier Handwerk GbR + 1122334455 + + + M. Meier Handwerk GbR + 010/12345 + info@m-meier.de + + + + + + + 345LA5324 + + + Dorfplatz 3 + Musterort + 54321 + + DE + + + + Beispielkunde + + + + + 31 + + DE091111222233334444 + + + + Zahlbar innerhalb 14 Tagen nach Erhalt der Rechnung. + + + 2382 + + 12536.84 + 2382 + + S + 19 + + VAT + + + + + + 12536.84 + 12536.84 + 14918.84 + 10000.0 + 4918.84 + + + 1 + 1 + 818.04 + + Sanitär und Zubehör + + S + 19 + + VAT + + + + + 818.04 + 1 + + + 1 1 + 1 + 335.79 + + Demontage Sanitär + + S + 19 + + VAT + + + + + 335.79 + 1 + + + 1 1 1 + 149 + 193.70 + + Demontage TW-Rohrleitung DN 12-25 + + S + 19 + + VAT + + + + + 1.30 + 1 + + + + 1 1 2 + 32.50 + 48.75 + + Demontage SML DN 100 + + S + 19 + + VAT + + + + + 1.50 + 1 + + + + 1 1 3 + 71.80 + 93.34 + + Demontage AW-Rohrleitungen Kunststoff PP bis DN100 + + S + 19 + + VAT + + + + + 1.30 + 1 + + + + + 1 2 + 1 + 482.25 + + Abwasserleitungen und Zubehör + + S + 19 + + VAT + + + + + 482.25 + 1 + + + 1 2 1 + 9.5 + 99.75 + + Abwasserleitung HT-PP DN 100 + + S + 19 + + VAT + + + + + 10.50 + 1 + + + + 1 2 2 + 45.0 + 382.50 + + Abwasserleitung HT-PP DN 50 + + S + 19 + + VAT + + + + + 8.50 + 1 + + + + + + 2 + 1 + 11718.8 + + Heizung und Zubehör + + S + 19 + + VAT + + + + + 11718.8 + 1 + + + 2 1 + 1 + 1324 + + Demontage Heizung + + S + 19 + + VAT + + + + + 1324 + 1 + + + 2 1 1 + 20 + 700 + + Entleeren der Heizungsanlage, teilnetz + + S + 19 + + VAT + + + + + 35 + 1 + + + + 2 1 2 + 52 + 624 + + Demontage Flachheizkörpers + + S + 19 + + VAT + + + + + 12 + 1 + + + + + 2 2 + 1 + 10394.8 + + Heizflächen und Zubehör + + S + 19 + + VAT + + + + + 10394.8 + 1 + + + 2 2 1 + 52 + 10202.4 + + Flachheizkörper Stahl profiliert Seitent. H 300mm L -500mm Typ22 + + S + 19 + + VAT + + + + + 196.20 + 1 + + + + 2 2 2 + 104 + 192.4 + + Einzelrosette aus Kunststoff, weiß + + S + 19 + + VAT + + + + + 1.85 + 1 + + + + + \ No newline at end of file