From d3ec7a6769c2996e1a30e681427cbefcae07f3e8 Mon Sep 17 00:00:00 2001 From: Hillel Coren Date: Mon, 30 Oct 2023 23:20:49 +0200 Subject: [PATCH] Feature Request: Report (Invoice) -> Group by Date (Quarterly #569 --- lib/constants.dart | 1 + lib/ui/reports/reports_screen.dart | 4 ++++ lib/ui/reports/reports_screen_vm.dart | 13 +++++++++++++ lib/utils/i18n.dart | 6 ++++++ 4 files changed, 24 insertions(+) diff --git a/lib/constants.dart b/lib/constants.dart index a083a0d9c..2722e3861 100644 --- a/lib/constants.dart +++ b/lib/constants.dart @@ -737,6 +737,7 @@ const String kTaxRegionAustralia = 'AU'; const String kReportGroupDay = 'day'; const String kReportGroupWeek = 'week'; const String kReportGroupMonth = 'month'; +const String kReportGroupQuarter = 'quarter'; const String kReportGroupYear = 'year'; const int kModuleRecurringInvoices = 1; diff --git a/lib/ui/reports/reports_screen.dart b/lib/ui/reports/reports_screen.dart index 1eca0d777..5b9ced148 100644 --- a/lib/ui/reports/reports_screen.dart +++ b/lib/ui/reports/reports_screen.dart @@ -190,6 +190,10 @@ class ReportsScreen extends StatelessWidget { child: Text(localization.month), value: kReportGroupMonth, ), + DropdownMenuItem( + child: Text(localization.quarter), + value: kReportGroupQuarter, + ), DropdownMenuItem( child: Text(localization.year), value: kReportGroupYear, diff --git a/lib/ui/reports/reports_screen_vm.dart b/lib/ui/reports/reports_screen_vm.dart index 1cac3fb70..58ef63657 100644 --- a/lib/ui/reports/reports_screen_vm.dart +++ b/lib/ui/reports/reports_screen_vm.dart @@ -652,6 +652,19 @@ GroupTotals calculateReportTotals({ group = group.substring(0, 4) + '-01-01'; } else if (reportState.subgroup == kReportGroupMonth) { group = group.substring(0, 7) + '-01'; + } else if (reportState.subgroup == kReportGroupQuarter) { + final parts = group.split('-'); + final month = parseInt(parts[1]) ?? 0; + group = parts[0] + '-'; + if (month <= 3) { + group += '01-01'; + } else if (month <= 6) { + group += '04-01'; + } else if (month <= 9) { + group += '07-01'; + } else { + group += '10-01'; + } } else if (reportState.subgroup == kReportGroupWeek) { final date = DateTime.parse(group); final dateWeek = diff --git a/lib/utils/i18n.dart b/lib/utils/i18n.dart index df43c4791..723bbbe9e 100644 --- a/lib/utils/i18n.dart +++ b/lib/utils/i18n.dart @@ -18,6 +18,7 @@ mixin LocalizationsProvider on LocaleCodeAware { static final Map> _localizedValues = { 'en': { // STARTER: lang key - do not remove comment + 'quarter': 'Quarter', 'item_description': 'Item Description', 'task_item': 'Task Item', 'record_state': 'Record State', @@ -109940,6 +109941,11 @@ mixin LocalizationsProvider on LocaleCodeAware { _localizedValues[localeCode]!['task_item'] ?? _localizedValues['en']!['task_item']!; + String get quarter => + _localizedValues[localeCode]!['quarter'] ?? + _localizedValues['en']!['quarter']!; + + // STARTER: lang field - do not remove comment String lookup(String? key) {