From 363868ad9be7bd925115e06afdef6dda460e0180 Mon Sep 17 00:00:00 2001 From: Prasanna Anbazhagan Date: Sat, 10 Feb 2024 09:57:05 +0530 Subject: [PATCH] Bug fix --- lib/api/apis/investment_api.dart | 4 ---- lib/domain/models/investment.dart | 15 +++++---------- lib/domain/services/investment_service.dart | 8 ++------ lib/presentation/create_investment_presenter.dart | 2 -- lib/presentation/investments_presenter.dart | 3 --- lib/ui/widgets/create_investment_dialog.dart | 2 +- 6 files changed, 8 insertions(+), 26 deletions(-) diff --git a/lib/api/apis/investment_api.dart b/lib/api/apis/investment_api.dart index 4c5ee36..7550508 100644 --- a/lib/api/apis/investment_api.dart +++ b/lib/api/apis/investment_api.dart @@ -15,7 +15,6 @@ class InvestmentApi { required final double? investedAmount, required final DateTime? investedOn, required final double? value, - required final DateTime? valueUpdatedOn, required final double? irr, required final DateTime? maturityDate, }) async { @@ -26,7 +25,6 @@ class InvestmentApi { investedAmount: Value(investedAmount), investedOn: Value(investedOn), value: Value(value), - valueUpdatedOn: Value(valueUpdatedOn), irr: Value(irr), maturityDate: Value(maturityDate), riskLevel: riskLevel)); @@ -67,7 +65,6 @@ class InvestmentApi { required final double? investedAmount, required final DateTime? investedOn, required final double? value, - required final DateTime? valueUpdatedOn, required final double? irr, required final DateTime? maturityDate, required final RiskLevel riskLevel, @@ -82,7 +79,6 @@ class InvestmentApi { investedAmount: Value(investedAmount), investedOn: Value(investedOn), value: Value(value), - valueUpdatedOn: Value(valueUpdatedOn), irr: Value(irr), maturityDate: Value(maturityDate))); } diff --git a/lib/domain/models/investment.dart b/lib/domain/models/investment.dart index 90060bb..6dec9e0 100644 --- a/lib/domain/models/investment.dart +++ b/lib/domain/models/investment.dart @@ -14,7 +14,6 @@ class Investment { final double? irr; final double? investedAmount; final DateTime? investedOn; - final DateTime? valueUpdatedOn; final DateTime? maturityDate; final int? basketId; final String? basketName; @@ -31,7 +30,6 @@ class Investment { required this.investedAmount, required this.investedOn, required this.value, - required this.valueUpdatedOn, required this.basketId, required this.maturityDate, required this.basketName, @@ -75,16 +73,15 @@ class Investment { till: futureDate, considerFuturePayments: considerFuturePayments); final value = this.value; - final valueUpdatedOn = this.valueUpdatedOn; final irr = this.irr; - if (value != null && valueUpdatedOn != null) { + if (value != null) { final irr = IRRCalculator().calculateIRR( - payments: payments, value: value, valueUpdatedOn: valueUpdatedOn); + payments: payments, value: value, valueUpdatedOn: DateTime.now()); return IRRCalculator().calculateValueOnIRR( irr: irr, futureDate: futureDate, currentValue: value, - currentValueUpdatedOn: valueUpdatedOn); + currentValueUpdatedOn: DateTime.now()); } else if (irr != null) { return IRRCalculator().calculateFutureValueOnIRR( payments: payments, irr: irr, date: futureDate); @@ -96,14 +93,13 @@ class Investment { double getIRR() { final irr = this.irr; final value = this.value; - final valueUpdatedOn = this.valueUpdatedOn; if (irr != null) { return irr; - } else if (value != null && valueUpdatedOn != null) { + } else if (value != null) { final List payments = getPayments(till: DateTime.now()); return IRRCalculator().calculateIRR( - payments: payments, value: value, valueUpdatedOn: valueUpdatedOn); + payments: payments, value: value, valueUpdatedOn: DateTime.now()); } else { throw Exception('Value and IRR are null'); } @@ -122,7 +118,6 @@ class Investment { riskLevel: investmentDO.riskLevel, irr: investmentDO.irr, value: investmentDO.value, - valueUpdatedOn: investmentDO.valueUpdatedOn, basketId: investmentDO.basketId, maturityDate: investmentDO.maturityDate, basketName: investmentDO.basketName, diff --git a/lib/domain/services/investment_service.dart b/lib/domain/services/investment_service.dart index 29af593..e202f0f 100644 --- a/lib/domain/services/investment_service.dart +++ b/lib/domain/services/investment_service.dart @@ -31,11 +31,10 @@ class InvestmentService { required final double? investedAmount, required final DateTime? investedOn, required final double? value, - required final DateTime? valueUpdatedOn, required final double? irr, required final DateTime? maturityDate}) async { if ((irr == null || irr <= 0) && - (value == null || value <= 0 || valueUpdatedOn == null)) { + (value == null || value <= 0)) { throw Exception( "Either IRR or Value and Value Updated On must be provided"); } @@ -50,8 +49,7 @@ class InvestmentService { investedOn: investedOn, value: value, maturityDate: maturityDate, - irr: irr, - valueUpdatedOn: valueUpdatedOn) + irr: irr) .then((_) => {}); } @@ -87,7 +85,6 @@ class InvestmentService { required final DateTime? investedOn, required final RiskLevel riskLevel, required final double? value, - required final DateTime? valueUpdatedOn, required final double? irr, required final DateTime? maturityDate}) { return _investmentApi @@ -98,7 +95,6 @@ class InvestmentService { investedAmount: investedAmount, investedOn: investedOn, value: value, - valueUpdatedOn: valueUpdatedOn, irr: irr, maturityDate: maturityDate, riskLevel: riskLevel, diff --git a/lib/presentation/create_investment_presenter.dart b/lib/presentation/create_investment_presenter.dart index ef82069..d696026 100644 --- a/lib/presentation/create_investment_presenter.dart +++ b/lib/presentation/create_investment_presenter.dart @@ -48,7 +48,6 @@ class CreateInvestmentPresenter extends Presenter { value: value, investedAmount: investedAmount, investedOn: investedOn, - valueUpdatedOn: DateTime.now(), basketId: basketId, riskLevel: riskLevel, irr: irr, @@ -63,7 +62,6 @@ class CreateInvestmentPresenter extends Presenter { investedAmount: investedAmount, investedOn: investedOn, value: value, - valueUpdatedOn: DateTime.now(), basketId: basketId, riskLevel: riskLevel, irr: irr, diff --git a/lib/presentation/investments_presenter.dart b/lib/presentation/investments_presenter.dart index dc2b3c8..185d00c 100644 --- a/lib/presentation/investments_presenter.dart +++ b/lib/presentation/investments_presenter.dart @@ -43,7 +43,6 @@ class InvestmentVO { final double irr; final double investedValue; final double currentValue; - final DateTime? valueUpdatedOn; final DateTime? maturityDate; final int? basketId; final String? basketName; @@ -61,7 +60,6 @@ class InvestmentVO { required this.description, required this.riskLevel, required this.irr, - required this.valueUpdatedOn, required this.basketId, required this.basketName, required this.investedValue, @@ -80,7 +78,6 @@ class InvestmentVO { irr: investment.getIRR(), investedValue: investment.getTotalInvestedAmount(), currentValue: investment.getValueOn(date: DateTime.now()), - valueUpdatedOn: investment.valueUpdatedOn, basketId: investment.basketId, basketName: investment.basketName, transactions: investment.transactions, diff --git a/lib/ui/widgets/create_investment_dialog.dart b/lib/ui/widgets/create_investment_dialog.dart index 04b5b64..1edad1d 100644 --- a/lib/ui/widgets/create_investment_dialog.dart +++ b/lib/ui/widgets/create_investment_dialog.dart @@ -301,7 +301,7 @@ class _CreateInvestmentPage extends PageState