Skip to content

Commit

Permalink
Exclude inactive investments for dashboard
Browse files Browse the repository at this point in the history
  • Loading branch information
praslnx8 committed Aug 15, 2024
1 parent 54c6a02 commit e0910ab
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 4 deletions.
4 changes: 4 additions & 0 deletions lib/domain/models/investment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,10 @@ class Investment {
return getPayments().lastOrNull?.createdOn ?? DateTime.now();
}

bool inActive() {
return transactions.any((element) => element.qty > 0) && qty == 0;
}

List<Payment> getPayments(
{final DateTime? till, bool considerFuturePayments = false}) {
final payments = transactions
Expand Down
3 changes: 3 additions & 0 deletions lib/ui/models/investment_vo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/pages/investments_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ class _InvestmentsPage extends PageState<InvestmentsViewState, InvestmentsPage,
{required final BuildContext context,
required final InvestmentVO investmentVO}) {
return Card(
color: investmentVO.qty == 0 ? Colors.grey : null,
color: investmentVO.inActive ? Colors.grey : null,
margin: const EdgeInsets.all(AppDimen.defaultPadding),
child: InkWell(
onTap: () => {
Expand Down
7 changes: 4 additions & 3 deletions lib/ui/presentation/dashboard_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ class DashboardPresenter extends Presenter<DashboardViewState> {
Map<int, double> irrComposition = {};
List<Payment> 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());
Expand Down Expand Up @@ -60,8 +61,8 @@ class DashboardPresenter extends Presenter<DashboardViewState> {
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);
});
});
}
Expand Down

0 comments on commit e0910ab

Please sign in to comment.