Skip to content

Commit

Permalink
Fixed error with summary row
Browse files Browse the repository at this point in the history
  • Loading branch information
yamelsenih committed Oct 15, 2024
1 parent 5ffa890 commit 8819723
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions src/main/java/org/spin/report_engine/data/SummaryHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.stream.Collectors;

import org.spin.report_engine.format.PrintFormatItem;
Expand All @@ -37,9 +38,9 @@ public class SummaryHandler {
private SummaryHandler(List<PrintFormatItem> printFormatItems) {
groupedItems = printFormatItems.stream().filter(item -> item.isGroupBy()).sorted(Comparator.comparing(PrintFormatItem::getSortSequence)).collect(Collectors.toList());
summarizedItems = printFormatItems.stream().filter(printItem -> {
if(printItem.isHideGrandTotal()) {
return false;
}
// if(printItem.isHideGrandTotal()) {
// return false;
// }
return printItem.isAveraged() || printItem.isCounted() || printItem.isMaxCalc() || printItem.isMinCalc() || printItem.isSummarized() || printItem.isVarianceCalc();
}).collect(Collectors.toList());
summary = new HashMap<Integer, Map<Row, Map<Integer, SummaryFunction>>>();
Expand Down Expand Up @@ -110,16 +111,24 @@ public Map<Integer, Map<Row, Map<Integer, SummaryFunction>>> getSummary() {

public List<Row> getAsRows() {
List<Row> rows = new ArrayList<Row>();
AtomicBoolean isFirst = new AtomicBoolean(true);
groupedItems.forEach(groupItem -> {
Map<Row, Map<Integer, SummaryFunction>> groupTotals = Optional.ofNullable(summary.get(groupItem.getPrintFormatItemId())).orElse(new HashMap<Row, Map<Integer,SummaryFunction>>());
groupTotals.keySet().forEach(groupValueRow -> {
Map<Integer, SummaryFunction> summaryValue = groupTotals.get(groupValueRow);
summarizedItems.forEach(sumItem -> {
summarizedItems.stream().filter(printItem -> {
if(printItem.isHideGrandTotal() && isFirst.get()) {
return false;
}
return true;
})
.forEach(sumItem -> {
SummaryFunction function = summaryValue.get(sumItem.getPrintFormatItemId());
groupValueRow.withCell(sumItem.getPrintFormatItemId(), Cell.newInstance().withValue(function.getValue(SummaryFunction.F_SUM)).withFunction(function));
});
rows.add(groupValueRow.withSummaryRow(true));
});
isFirst.set(false);
});
return rows;
}
Expand Down

0 comments on commit 8819723

Please sign in to comment.