diff --git a/lib/data/models/entities.dart b/lib/data/models/entities.dart index abcde5395..05fc450cd 100644 --- a/lib/data/models/entities.dart +++ b/lib/data/models/entities.dart @@ -38,6 +38,7 @@ class EntityType extends EnumClass { static const EntityType gatewayToken = _$gatewayToken; static const EntityType invoiceItem = _$invoiceItem; static const EntityType design = _$design; + // STARTER: entity type - do not remove comment static const EntityType quoteItem = _$quoteItem; static const EntityType contact = _$contact; @@ -228,6 +229,12 @@ abstract class BaseEntity implements SelectableEntity { ReportBoolValue getReportBool({bool value}) => ReportBoolValue(entityId: id, entityType: entityType, value: value); + ReportAgeValue getReportAge({int value, String currencyId}) => ReportAgeValue( + entityType: entityType, + entityId: id, + value: value, + currencyId: currencyId); + ReportNumberValue getReportNumber( {double value, String currencyId, diff --git a/lib/ui/reports/aging_report.dart b/lib/ui/reports/aging_report.dart index ff27cc4db..36e2ff6e9 100644 --- a/lib/ui/reports/aging_report.dart +++ b/lib/ui/reports/aging_report.dart @@ -131,11 +131,8 @@ ReportResult agingReport( if (value.runtimeType == bool) { row.add(invoice.getReportBool(value: value)); } else if (column == AgingReportFields.age) { - row.add(invoice.getReportNumber( - value: value, - // TODO figure out why this line is needed - currencyId: client.settings.currencyId, - formatNumberType: FormatNumberType.int)); + row.add(invoice.getReportAge( + value: value.round(), currencyId: client.settings.currencyId)); } else if (value.runtimeType == double || value.runtimeType == int) { row.add(invoice.getReportNumber( value: value, currencyId: client.settings.currencyId)); diff --git a/lib/ui/reports/report_charts.dart b/lib/ui/reports/report_charts.dart index b2c045930..dfa0afa90 100644 --- a/lib/ui/reports/report_charts.dart +++ b/lib/ui/reports/report_charts.dart @@ -43,6 +43,9 @@ class ReportCharts extends StatelessWidget { Widget child; switch (getReportColumnType(reportState.group, context)) { + case ReportColumnType.age: + child = SizedBox(); + break; case ReportColumnType.string: case ReportColumnType.bool: child = charts.BarChart( diff --git a/lib/ui/reports/reports_screen.dart b/lib/ui/reports/reports_screen.dart index 3dc4b77a5..230044b45 100644 --- a/lib/ui/reports/reports_screen.dart +++ b/lib/ui/reports/reports_screen.dart @@ -474,6 +474,7 @@ enum ReportColumnType { date, number, bool, + age, } ReportColumnType getReportColumnType(String column, BuildContext context) { @@ -496,6 +497,8 @@ ReportColumnType getReportColumnType(String column, BuildContext context) { return ReportColumnType.dateTime; } else if (['date', 'due_date'].contains(column)) { return ReportColumnType.date; + } else if (column == 'age') { + return ReportColumnType.age; } else if ([ 'balance', 'paid_to_date', @@ -509,7 +512,6 @@ ReportColumnType getReportColumnType(String column, BuildContext context) { 'tax_rate', 'tax_amount', 'tax_paid', - 'age', 'payment_amount' ].contains(column)) { return ReportColumnType.number; @@ -789,7 +791,7 @@ class ReportResult { ], )) else - if (column == 'age') + if (getReportColumnType(column, context) == ReportColumnType.age) DataCell(AppDropdownButton( value: (textEditingControllers[column].text ?? '') .isNotEmpty && @@ -1063,7 +1065,8 @@ class ReportResult { onSort: onSortCallback, ), for (String column in columns) - if (getReportColumnType(column, context) == ReportColumnType.number) + if ([ReportColumnType.number, ReportColumnType.age,].contains( + getReportColumnType(column, context))) DataColumn( label: Text( localization.lookup(column), @@ -1090,8 +1093,14 @@ class ReportResult { for (var j = 0; j < row.length; j++) { final cell = row[j]; final column = columns[j]; - if (cell is ReportNumberValue) { - final String currencyId = cell.currencyId; + + if (cell is ReportNumberValue || cell is ReportAgeValue) { + String currencyId; + if (cell is ReportNumberValue) { + currencyId = cell.currencyId; + } else if (cell is ReportAgeValue) { + currencyId = cell.currencyId; + } if (!totals.containsKey(currencyId)) { totals[currencyId] = {'count': 0}; @@ -1213,6 +1222,27 @@ class ReportStringValue extends ReportElement { } } +class ReportAgeValue extends ReportElement { + ReportAgeValue({ + @required dynamic value, + @required EntityType entityType, + @required String entityId, + @required this.currencyId, + }) : super(value: value, entityType: entityType, entityId: entityId); + + final String currencyId; + + @override + Widget renderWidget(BuildContext context, String column) { + return Text(renderText(context, column)); + } + + @override + String renderText(BuildContext context, String column) { + return '$value'; + } +} + class ReportNumberValue extends ReportElement { ReportNumberValue({ dynamic value,