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 - #566
- have a bean contructor for direct debit - have a bean contructor for direct debit

View File

@@ -11,11 +11,13 @@ import java.math.BigDecimal;
public class CalculatedInvoice extends Invoice implements Serializable { public class CalculatedInvoice extends Invoice implements Serializable {
protected BigDecimal grandTotal=null; protected BigDecimal grandTotal=null;
protected BigDecimal lineTotalAmount=null;
public void calculate() { public void calculate() {
TransactionCalculator tc=new TransactionCalculator(this); TransactionCalculator tc=new TransactionCalculator(this);
grandTotal=tc.getGrandTotal(); grandTotal=tc.getGrandTotal();
lineTotalAmount=tc.getValue();
} }
public BigDecimal getGrandTotal() { public BigDecimal getGrandTotal() {
if (grandTotal==null) { if (grandTotal==null) {
@@ -27,4 +29,15 @@ public class CalculatedInvoice extends Invoice implements Serializable {
grandTotal=grand; grandTotal=grand;
return this; 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)))); 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 issueDate = null;
Date dueDate = null; Date dueDate = null;
Date deliveryDate = null; Date deliveryDate = null;
@@ -628,9 +637,9 @@ public class ZUGFeRDInvoiceImporter {
xpr = xpath.compile("//*[local-name()=\"BuyerReference\"]"); xpr = xpath.compile("//*[local-name()=\"BuyerReference\"]");
String buyerReference = null; String buyerReference = null;
prepaidNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET); lineTotalNodes = (NodeList) xpr.evaluate(getDocument(), XPathConstants.NODESET);
if (prepaidNodes.getLength() > 0) { if (lineTotalNodes.getLength() > 0) {
buyerReference = XMLTools.trimOrNull(prepaidNodes.item(0)); buyerReference = XMLTools.trimOrNull(lineTotalNodes.item(0));
} }
if (buyerReference != null) { if (buyerReference != null) {
zpp.setReferenceNumber(buyerReference); zpp.setReferenceNumber(buyerReference);

View File

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