working on line total

This commit is contained in:
jstaerk
2024-11-25 16:08:53 +01:00
parent c5f5581aa8
commit ec7f842e13
4 changed files with 36 additions and 8 deletions

View File

@@ -1,4 +1,4 @@
2.16.0
2.15.1
=======
- #566
- have a bean contructor for direct debit

View File

@@ -12,10 +12,12 @@ import java.math.BigDecimal;
public class CalculatedInvoice extends Invoice implements Serializable {
protected BigDecimal grandTotal=null;
protected BigDecimal lineTotalAmount=null;
public void calculate() {
TransactionCalculator tc=new TransactionCalculator(this);
grandTotal=tc.getGrandTotal();
lineTotalAmount=tc.getValue();
}
public BigDecimal getGrandTotal() {
if (grandTotal==null) {
@@ -27,4 +29,15 @@ public class CalculatedInvoice extends Invoice implements Serializable {
grandTotal=grand;
return this;
}
public BigDecimal getLineTotalAmount() {
if (lineTotalAmount==null) {
calculate();
}
return lineTotalAmount;
}
public CalculatedInvoice setLineTotalAmount(BigDecimal total) {
lineTotalAmount=total;
return this;
}
}

View File

@@ -330,6 +330,15 @@ public class ZUGFeRDInvoiceImporter {
zpp.setTotalPrepaidAmount(new BigDecimal(XMLTools.trimOrNull(prepaidNodes.item(0))));
}
xpr = xpath.compile("//*[local-name()=\"SpecifiedTradeSettlementHeaderMonetarySummation\"]/*[local-name()=\"LineTotalAmount\"]|//*[local-name()=\"LegalMonetaryTotal\"]/*[local-name()=\"LineExtensionAmount\"]");
NodeList lineTotalNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
if (lineTotalNodes.getLength() > 0) {
if (zpp instanceof CalculatedInvoice) {
((CalculatedInvoice) zpp).setLineTotalAmount(new BigDecimal(XMLTools.trimOrNull(lineTotalNodes.item(0))));
}
}
Date issueDate = null;
Date dueDate = null;
Date deliveryDate = null;
@@ -628,9 +637,9 @@ public class ZUGFeRDInvoiceImporter {
xpr = xpath.compile("//*[local-name()=\"BuyerReference\"]");
String buyerReference = null;
prepaidNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
if (prepaidNodes.getLength() > 0) {
buyerReference = XMLTools.trimOrNull(prepaidNodes.item(0));
lineTotalNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
if (lineTotalNodes.getLength() > 0) {
buyerReference = XMLTools.trimOrNull(lineTotalNodes.item(0));
}
if (buyerReference != null) {
zpp.setReferenceNumber(buyerReference);

View File

@@ -384,13 +384,19 @@ public class ZF2ZInvoiceImporterTest extends ResourceCase {
ZUGFeRDInvoiceImporter importer = new ZUGFeRDInvoiceImporter();
importer.doIgnoreCalculationErrors();
importer.setInputStream(inputStream);
Invoice invoice = importer.extractInvoice();
CalculatedInvoice invoice = new CalculatedInvoice();
importer.extractInto(invoice);
boolean isBD=invoice.getTotalPrepaidAmount() instanceof BigDecimal;
assertTrue(isBD);
BigDecimal expected=new BigDecimal(50);
BigDecimal expectedPrepaid=new BigDecimal(50);
BigDecimal expectedLineTotal=new BigDecimal("180.76");
if (isBD) {
BigDecimal amread=invoice.getTotalPrepaidAmount();
assertTrue(amread.compareTo(expected) == 0);
BigDecimal amline=invoice.getLineTotalAmount();
assertTrue(amread.compareTo(expectedPrepaid) == 0);
assertTrue(amline.compareTo(expectedLineTotal) == 0);
}
}