be able to parse minimal invoices
This commit is contained in:
@@ -0,0 +1,30 @@
|
||||
// Copyright (c) 2023 Jochen Stärk, see LICENSE file
|
||||
package org.mustangproject;
|
||||
|
||||
|
||||
import org.mustangproject.ZUGFeRD.TransactionCalculator;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.Serializable;
|
||||
import java.math.BigDecimal;
|
||||
|
||||
public class CalculatedInvoice extends Invoice implements Serializable {
|
||||
|
||||
protected BigDecimal grandTotal=null;
|
||||
|
||||
public void calculate() {
|
||||
TransactionCalculator tc=new TransactionCalculator(this);
|
||||
grandTotal=tc.getGrandTotal();
|
||||
}
|
||||
public BigDecimal getGrandTotal() {
|
||||
if (grandTotal==null) {
|
||||
calculate();
|
||||
}
|
||||
return grandTotal;
|
||||
}
|
||||
public CalculatedInvoice setGrandTotal(BigDecimal grand) {
|
||||
grandTotal=grand;
|
||||
return this;
|
||||
}
|
||||
}
|
||||
@@ -394,9 +394,7 @@ public class ZUGFeRDImporter extends ZUGFeRDInvoiceImporter {
|
||||
*/
|
||||
public String getAmount() {
|
||||
|
||||
TransactionCalculator ic=new TransactionCalculator(importedInvoice);
|
||||
|
||||
return ic.getGrandTotal().toPlainString();
|
||||
return importedInvoice.getGrandTotal().toPlainString();
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ public class ZUGFeRDInvoiceImporter {
|
||||
*/
|
||||
protected boolean parseAutomatically = true;
|
||||
protected Integer version;
|
||||
protected Invoice importedInvoice = null;
|
||||
protected CalculatedInvoice importedInvoice = null;
|
||||
protected boolean recalcPrice = false;
|
||||
protected boolean ignoreCalculationErrors = false;
|
||||
protected ArrayList<FileAttachment> fileAttachments = new ArrayList<>();
|
||||
@@ -239,7 +239,7 @@ public class ZUGFeRDInvoiceImporter {
|
||||
document = builder.parse(is);
|
||||
if (parseAutomatically) {
|
||||
try {
|
||||
importedInvoice = new Invoice();
|
||||
importedInvoice = new CalculatedInvoice();
|
||||
extractInto(importedInvoice);
|
||||
} catch (XPathExpressionException e) {
|
||||
throw new RuntimeException(e);
|
||||
@@ -281,6 +281,12 @@ public class ZUGFeRDInvoiceImporter {
|
||||
NodeList totalNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
|
||||
if (totalNodes.getLength() > 0) {
|
||||
expectedGrandTotal = new BigDecimal(totalNodes.item(0).getTextContent());
|
||||
if (zpp instanceof CalculatedInvoice) {
|
||||
// usually we would re-calculate the invoice to get expectedGrandTotal
|
||||
// however, for "minimal" invoices or other invoices without lines
|
||||
// this will not work
|
||||
((CalculatedInvoice) zpp).setGrandTotal(expectedGrandTotal);
|
||||
}
|
||||
}
|
||||
|
||||
Date issueDate = null;
|
||||
|
||||
@@ -136,7 +136,7 @@ public class ProfilesMinimumBasicWLTest extends TestCase {
|
||||
ZUGFeRDImporter zi = new ZUGFeRDImporter(TARGET_PDF_FX_MINIMUM);
|
||||
|
||||
// Reading ZUGFeRD
|
||||
assertEquals("145.37",zi.getAmount());
|
||||
assertEquals("146.37",zi.getAmount());
|
||||
// assertEquals(zi.getBIC(), ownBIC);
|
||||
// assertEquals(zi.getIBAN(), ownIBAN);
|
||||
assertEquals(ownOrgName, zi.getHolder());
|
||||
|
||||
Reference in New Issue
Block a user