// create Map with summaries
Map<Double, InvoicePositionSummary> calculatedSummaries =
new HashMap<Double, InvoicePositionSummary>(5);
calculatedSummaries.put(Globals.DOUBLE_022,
new InvoicePositionSummary(Globals.DOUBLE_022));
calculatedSummaries.put(Globals.DOUBLE_007,
new InvoicePositionSummary(Globals.DOUBLE_007));
calculatedSummaries.put(Globals.DOUBLE_003,
new InvoicePositionSummary(Globals.DOUBLE_003));
calculatedSummaries.put(Globals.DOUBLE_0,
new InvoicePositionSummary(Globals.DOUBLE_0));
// position with 'total' aggregates
InvoicePositionSummary ip1 = new InvoicePositionSummary(Globals.DOUBLE_1);
calculatedSummaries.put(Globals.DOUBLE_1, ip1);
invoice.setCalculatedSummaries(calculatedSummaries);
if (invoice.getInvoicePositions() != null) {
for (InvoicePosition pos : invoice.getInvoicePositions()) {
if (logger.isDebugEnabled()) {
logger.debug("recalculateInvoice(Invoice) - iterate through invoicePositions - pos=" + pos);
}
Double percentTax = pos.getTax().getValue();
if (logger.isDebugEnabled()) {
logger.debug("recalculateInvoice(Invoice) - iterate through invoicePositions - percentTax=" + percentTax);
}
InvoicePositionSummary posFromMap =
(InvoicePositionSummary) calculatedSummaries.get(percentTax);
if (logger.isDebugEnabled()) {
logger.debug("recalculateInvoice(Invoice) - iterate through invoicePositions - before add - posFromMap=" + posFromMap);
logger.debug("recalculateInvoice(Invoice) - iterate through invoicePositions - before add - ip1=" + ip1);
}
if (posFromMap != null) {
posFromMap.addValueNetto(pos.getValueNetto());
posFromMap.addSum(pos.getSum());
posFromMap.addTotal(pos.getTotal());
}
ip1.addValueNetto(pos.getValueNetto());
ip1.addSum(pos.getSum());
ip1.addTotal(pos.getTotal());