diff --git a/lib/ui/reports/reports_screen.dart b/lib/ui/reports/reports_screen.dart index 46af53a56..f419bcdd3 100644 --- a/lib/ui/reports/reports_screen.dart +++ b/lib/ui/reports/reports_screen.dart @@ -279,7 +279,7 @@ class _ReportDataTableState extends State { children: [ DataTable( columns: reportResult.totalColumns(context), - rows: [], + rows: reportResult.totalRows(context), ), ], ), @@ -718,6 +718,40 @@ class ReportResult { ) ]; } + + List totalRows(BuildContext context) { + final rows = []; + + final Map> totals = {}; + + for (var i = 0; i < data.length; i++) { + final row = data[i]; + final cells = [ + DataCell(Text('')), + DataCell(Text('')), + ]; + for (var j = 0; j < row.length; j++) { + final cell = row[j]; + final column = columns[j]; + if (getReportColumnType(column) == ReportColumnType.number) { + cells.add(DataCell(cell.renderWidget(context, column))); + final String currencyId = (cell as ReportNumberValue).currencyId; + + if (!totals.containsKey(currencyId)) { + totals[currencyId] = {'count': 0}; + } + if (!totals[currencyId].containsKey(column)) { + totals[currencyId][column] = 0; + } + totals[currencyId][column] += cell.value; + } + } + rows.add(DataRow(cells: cells)); + } + + print('## TOTALS: $totals'); + return rows; + } } abstract class ReportElement {