From e0910abb8436d891fcfd03cefa213e70ba9602f9 Mon Sep 17 00:00:00 2001 From: Prasanna Anbazhagan Date: Thu, 15 Aug 2024 11:53:31 +0530 Subject: [PATCH] Exclude inactive investments for dashboard --- lib/domain/models/investment.dart | 4 ++++ lib/ui/models/investment_vo.dart | 3 +++ lib/ui/pages/investments_page.dart | 2 +- lib/ui/presentation/dashboard_presenter.dart | 7 ++++--- 4 files changed, 12 insertions(+), 4 deletions(-) diff --git a/lib/domain/models/investment.dart b/lib/domain/models/investment.dart index 7ec0af6..e4875a2 100644 --- a/lib/domain/models/investment.dart +++ b/lib/domain/models/investment.dart @@ -53,6 +53,10 @@ class Investment { return getPayments().lastOrNull?.createdOn ?? DateTime.now(); } + bool inActive() { + return transactions.any((element) => element.qty > 0) && qty == 0; + } + List getPayments( {final DateTime? till, bool considerFuturePayments = false}) { final payments = transactions diff --git a/lib/ui/models/investment_vo.dart b/lib/ui/models/investment_vo.dart index d768971..473fd3a 100644 --- a/lib/ui/models/investment_vo.dart +++ b/lib/ui/models/investment_vo.dart @@ -13,6 +13,7 @@ class InvestmentVO { final double currentValue; final DateTime? valueUpdatedDate; final double qty; + final bool inActive; final double valuePerQty; final DateTime? maturityDate; final int? basketId; @@ -37,6 +38,7 @@ class InvestmentVO { required this.currentValue, required this.valueUpdatedDate, required this.qty, + required this.inActive, required this.valuePerQty, required this.maturityDate, required this.transactions, @@ -53,6 +55,7 @@ class InvestmentVO { investedValue: investment.getTotalInvestedAmount(), currentValue: investment.getValue(), valueUpdatedDate: investment.valueUpdatedOn, + inActive: investment.inActive(), qty: investment.qty ?? 1, valuePerQty: investment.getValuePerUnit(), basketId: investment.basketId, diff --git a/lib/ui/pages/investments_page.dart b/lib/ui/pages/investments_page.dart index b244766..0d419ff 100644 --- a/lib/ui/pages/investments_page.dart +++ b/lib/ui/pages/investments_page.dart @@ -119,7 +119,7 @@ class _InvestmentsPage extends PageState { diff --git a/lib/ui/presentation/dashboard_presenter.dart b/lib/ui/presentation/dashboard_presenter.dart index 8ea7fcc..aabe7e0 100644 --- a/lib/ui/presentation/dashboard_presenter.dart +++ b/lib/ui/presentation/dashboard_presenter.dart @@ -26,7 +26,8 @@ class DashboardPresenter extends Presenter { Map irrComposition = {}; List payments = []; - for (var investment in investments) { + var activeInvestments = investments.where((investment) => !investment.inActive()).toList(); + for (var investment in activeInvestments) { double investmentValue = investment.getValueOn(date: DateTime.now()); double investedAmount = investment.getTotalInvestedAmount(till: DateTime.now()); @@ -60,8 +61,8 @@ class DashboardPresenter extends Presenter { viewState.valueOverTime = _getValueOverTime(investments); viewState.investmentOverTime = _getInvestmentOverTime(investments); viewState.overallIRR = overallIRR; - viewState.basketIrr = _calculateBasketIRR(investments); - viewState.irrGroups = _calculateIRRGroups(investments); + viewState.basketIrr = _calculateBasketIRR(activeInvestments); + viewState.irrGroups = _calculateIRRGroups(activeInvestments); }); }); }