Support charting invoice age in reports
This commit is contained in:
parent
70cd5d2b8b
commit
f40043f8e2
|
|
@ -42,7 +42,7 @@ abstract class ReportsUIState
|
||||||
|
|
||||||
BuiltMap<String, String> get filters;
|
BuiltMap<String, String> get filters;
|
||||||
|
|
||||||
bool get isGroupByFIltered =>
|
bool get isGroupByFiltered =>
|
||||||
filters.containsKey(group) && filters[group].isNotEmpty;
|
filters.containsKey(group) && filters[group].isNotEmpty;
|
||||||
|
|
||||||
static Serializer<ReportsUIState> get serializer =>
|
static Serializer<ReportsUIState> get serializer =>
|
||||||
|
|
|
||||||
|
|
@ -46,10 +46,13 @@ class ReportCharts extends StatelessWidget {
|
||||||
Widget child;
|
Widget child;
|
||||||
final columnType = getReportColumnType(reportState.group, context);
|
final columnType = getReportColumnType(reportState.group, context);
|
||||||
|
|
||||||
|
print('## DATA: ${viewModel.groupTotals.totals}');
|
||||||
|
|
||||||
switch (columnType) {
|
switch (columnType) {
|
||||||
case ReportColumnType.age:
|
|
||||||
case ReportColumnType.string:
|
case ReportColumnType.string:
|
||||||
case ReportColumnType.bool:
|
case ReportColumnType.bool:
|
||||||
|
case ReportColumnType.number:
|
||||||
|
case ReportColumnType.age:
|
||||||
child = charts.BarChart(
|
child = charts.BarChart(
|
||||||
[
|
[
|
||||||
charts.Series<dynamic, String>(
|
charts.Series<dynamic, String>(
|
||||||
|
|
@ -61,13 +64,13 @@ class ReportCharts extends StatelessWidget {
|
||||||
? localization.lookup(item['name'])
|
? localization.lookup(item['name'])
|
||||||
: item['name'],
|
: item['name'],
|
||||||
measureFn: (dynamic item, _) => item['value'],
|
measureFn: (dynamic item, _) => item['value'],
|
||||||
data: viewModel.groupTotals.rows
|
data: viewModel.groupTotals.rows.map((key) {
|
||||||
.map((key) => {
|
return {
|
||||||
'name': key,
|
'name': key,
|
||||||
'value': viewModel.groupTotals.totals[key]
|
'value': viewModel.groupTotals.totals[key]
|
||||||
[reportState.chart]
|
[reportState.chart]
|
||||||
})
|
};
|
||||||
.toList())
|
}).toList())
|
||||||
],
|
],
|
||||||
animate: true,
|
animate: true,
|
||||||
primaryMeasureAxis: numericAxis,
|
primaryMeasureAxis: numericAxis,
|
||||||
|
|
@ -88,13 +91,13 @@ class ReportCharts extends StatelessWidget {
|
||||||
charts.ColorUtil.fromDartColor(state.accentColor),
|
charts.ColorUtil.fromDartColor(state.accentColor),
|
||||||
domainFn: (dynamic item, _) => DateTime.tryParse(item['name']),
|
domainFn: (dynamic item, _) => DateTime.tryParse(item['name']),
|
||||||
measureFn: (dynamic item, _) => item['value'],
|
measureFn: (dynamic item, _) => item['value'],
|
||||||
data: keys
|
data: keys.map((key) {
|
||||||
.map((key) => {
|
return {
|
||||||
'name': key,
|
'name': key,
|
||||||
'value': viewModel.groupTotals.totals[key]
|
'value': viewModel.groupTotals.totals[key]
|
||||||
[reportState.chart]
|
[reportState.chart]
|
||||||
})
|
};
|
||||||
.toList())
|
}).toList())
|
||||||
],
|
],
|
||||||
animate: true,
|
animate: true,
|
||||||
primaryMeasureAxis: numericAxis,
|
primaryMeasureAxis: numericAxis,
|
||||||
|
|
@ -108,7 +111,6 @@ class ReportCharts extends StatelessWidget {
|
||||||
*/
|
*/
|
||||||
);
|
);
|
||||||
break;
|
break;
|
||||||
case ReportColumnType.number:
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return child == null
|
return child == null
|
||||||
|
|
|
||||||
|
|
@ -164,8 +164,9 @@ class ReportsScreen extends StatelessWidget {
|
||||||
},
|
},
|
||||||
items: reportResult.columns
|
items: reportResult.columns
|
||||||
.where((column) =>
|
.where((column) =>
|
||||||
getReportColumnType(column, context) ==
|
[ReportColumnType.number, ReportColumnType.age,].contains(
|
||||||
ReportColumnType.number)
|
getReportColumnType(column, context))
|
||||||
|
)
|
||||||
.map((column) =>
|
.map((column) =>
|
||||||
DropdownMenuItem(
|
DropdownMenuItem(
|
||||||
child: Text(localization.lookup(column)),
|
child: Text(localization.lookup(column)),
|
||||||
|
|
@ -576,7 +577,7 @@ class ReportDataTableSource extends DataTableSource {
|
||||||
int get rowCount {
|
int get rowCount {
|
||||||
final reportState = viewModel.reportState;
|
final reportState = viewModel.reportState;
|
||||||
|
|
||||||
if (reportState.group.isEmpty || reportState.isGroupByFIltered) {
|
if (reportState.group.isEmpty || reportState.isGroupByFiltered) {
|
||||||
return viewModel.reportResult.data.length + 1;
|
return viewModel.reportResult.data.length + 1;
|
||||||
} else {
|
} else {
|
||||||
return viewModel.groupTotals.totals.length + 1;
|
return viewModel.groupTotals.totals.length + 1;
|
||||||
|
|
@ -1014,7 +1015,7 @@ class ReportResult {
|
||||||
final groupBy = reportState.group;
|
final groupBy = reportState.group;
|
||||||
final sorted = sortedColumns(reportState);
|
final sorted = sortedColumns(reportState);
|
||||||
|
|
||||||
if (groupBy.isEmpty || reportState.isGroupByFIltered) {
|
if (groupBy.isEmpty || reportState.isGroupByFiltered) {
|
||||||
final row = data[index - 1];
|
final row = data[index - 1];
|
||||||
final cells = <DataCell>[];
|
final cells = <DataCell>[];
|
||||||
for (var j = 0; j < row.length; j++) {
|
for (var j = 0; j < row.length; j++) {
|
||||||
|
|
@ -1054,9 +1055,11 @@ class ReportResult {
|
||||||
value = group;
|
value = group;
|
||||||
}
|
}
|
||||||
value = value + ' (' + values['count'].floor().toString() + ')';
|
value = value + ' (' + values['count'].floor().toString() + ')';
|
||||||
} else if (columnType ==
|
} else if (columnType == ReportColumnType.number) {
|
||||||
ReportColumnType.number) {
|
|
||||||
value = formatNumber(values[column], context);
|
value = formatNumber(values[column], context);
|
||||||
|
} else if (columnType == ReportColumnType.age) {
|
||||||
|
value = formatNumber(
|
||||||
|
values[column], context, formatNumberType: FormatNumberType.int);
|
||||||
}
|
}
|
||||||
cells.add(DataCell(Text(value), onTap: () {
|
cells.add(DataCell(Text(value), onTap: () {
|
||||||
if (group.isEmpty) {
|
if (group.isEmpty) {
|
||||||
|
|
|
||||||
|
|
@ -309,7 +309,7 @@ class ReportsScreenVM {
|
||||||
final reportState = state.uiState.reportsUIState;
|
final reportState = state.uiState.reportsUIState;
|
||||||
String csvData = '';
|
String csvData = '';
|
||||||
|
|
||||||
if (reportState.group.isEmpty || reportState.isGroupByFIltered) {
|
if (reportState.group.isEmpty || reportState.isGroupByFiltered) {
|
||||||
reportResult.columns.forEach((column) {
|
reportResult.columns.forEach((column) {
|
||||||
csvData += '${localization.lookup(column)},';
|
csvData += '${localization.lookup(column)},';
|
||||||
});
|
});
|
||||||
|
|
@ -446,7 +446,7 @@ GroupTotals calculateReportTotals({
|
||||||
if (column == reportState.group) {
|
if (column == reportState.group) {
|
||||||
totals['$group']['count'] += 1;
|
totals['$group']['count'] += 1;
|
||||||
}
|
}
|
||||||
if (cell is ReportNumberValue) {
|
if (cell is ReportNumberValue || cell is ReportAgeValue) {
|
||||||
if (!totals['$group'].containsKey(column)) {
|
if (!totals['$group'].containsKey(column)) {
|
||||||
totals['$group'][column] = 0;
|
totals['$group'][column] = 0;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue