From edbdd904128a236e952b2b4cec55389c1fe9b574 Mon Sep 17 00:00:00 2001 From: Prasanna Anbazhagan Date: Sat, 30 Mar 2024 14:04:34 +0530 Subject: [PATCH] Fix Investment future value calculation logic --- lib/domain/models/investment.dart | 6 +++--- lib/ui/pages/dashboard_page.dart | 11 +++++++---- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/lib/domain/models/investment.dart b/lib/domain/models/investment.dart index 9e62a22..bc228f7 100644 --- a/lib/domain/models/investment.dart +++ b/lib/domain/models/investment.dart @@ -65,12 +65,10 @@ class Investment { ? maturityDate : date; - final payments = getPayments( - till: futureDate, considerFuturePayments: considerFuturePayments); - final value = this.value; final irr = this.irr; if (value != null) { + final payments = getPayments(till: DateTime.now()); final irr = IRRCalculator().calculateIRR( payments: payments, value: value, valueUpdatedOn: DateTime.now()); return IRRCalculator().calculateValueOnIRR( @@ -79,6 +77,8 @@ class Investment { currentValue: value, currentValueUpdatedOn: DateTime.now()); } else if (irr != null) { + final payments = getPayments( + till: futureDate, considerFuturePayments: considerFuturePayments); return IRRCalculator().calculateFutureValueOnIRR( payments: payments, irr: irr, futureDate: futureDate); } else { diff --git a/lib/ui/pages/dashboard_page.dart b/lib/ui/pages/dashboard_page.dart index 18c4bc2..b5d0906 100644 --- a/lib/ui/pages/dashboard_page.dart +++ b/lib/ui/pages/dashboard_page.dart @@ -42,24 +42,27 @@ class _DashboardPage mainAxisAlignment: MainAxisAlignment.start, children: [ Text('Progress:', style: Theme.of(context).textTheme.titleMedium), + const SizedBox(height: AppDimen.minPadding), _buildInvestmentProgress( investedAmount: snapshot.invested, valueOfInvestment: snapshot.currentValue, irr: snapshot.overallIRR), + const SizedBox(height: AppDimen.defaultPadding), Text('Basket Composition:', style: Theme.of(context).textTheme.titleMedium), const SizedBox(height: AppDimen.minPadding), _buildBarChart(snapshot.basketComposition.entries.toList()), + const SizedBox(height: AppDimen.defaultPadding), Text('Risk Composition:', style: Theme.of(context).textTheme.titleMedium), const SizedBox(height: AppDimen.minPadding), _buildPieChart(snapshot.riskComposition), - const SizedBox(height: AppDimen.minPadding), - Text('IRR Composition:', + const SizedBox(height: AppDimen.defaultPadding), + Text('Basket IRR:', style: Theme.of(context).textTheme.titleMedium), const SizedBox(height: AppDimen.minPadding), _buildIrrContribution(data: snapshot.basketIrr.entries.toList()), - const SizedBox(height: AppDimen.minPadding), + const SizedBox(height: AppDimen.defaultPadding), Text('Investment Over Time:', style: Theme.of(context).textTheme.titleMedium), const SizedBox(height: AppDimen.minPadding), @@ -178,7 +181,7 @@ class _DashboardPage return SfCartesianChart( primaryXAxis: const CategoryAxis(), series: [ - ColumnSeries( + BarSeries( dataSource: contribution, xValueMapper: (data, _) => data.key, yValueMapper: (data, _) => data.value,