Skip to content

Commit

Permalink
Bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
praslnx8 committed Feb 10, 2024
1 parent 7a6024e commit 363868a
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 26 deletions.
4 changes: 0 additions & 4 deletions lib/api/apis/investment_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -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));
Expand Down Expand Up @@ -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,
Expand All @@ -82,7 +79,6 @@ class InvestmentApi {
investedAmount: Value(investedAmount),
investedOn: Value(investedOn),
value: Value(value),
valueUpdatedOn: Value(valueUpdatedOn),
irr: Value(irr),
maturityDate: Value(maturityDate)));
}
Expand Down
15 changes: 5 additions & 10 deletions lib/domain/models/investment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand Down Expand Up @@ -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);
Expand All @@ -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<Payment> 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');
}
Expand All @@ -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,
Expand Down
8 changes: 2 additions & 6 deletions lib/domain/services/investment_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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");
}
Expand All @@ -50,8 +49,7 @@ class InvestmentService {
investedOn: investedOn,
value: value,
maturityDate: maturityDate,
irr: irr,
valueUpdatedOn: valueUpdatedOn)
irr: irr)
.then((_) => {});
}

Expand Down Expand Up @@ -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
Expand All @@ -98,7 +95,6 @@ class InvestmentService {
investedAmount: investedAmount,
investedOn: investedOn,
value: value,
valueUpdatedOn: valueUpdatedOn,
irr: irr,
maturityDate: maturityDate,
riskLevel: riskLevel,
Expand Down
2 changes: 0 additions & 2 deletions lib/presentation/create_investment_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,6 @@ class CreateInvestmentPresenter extends Presenter<CreateInvestmentViewState> {
value: value,
investedAmount: investedAmount,
investedOn: investedOn,
valueUpdatedOn: DateTime.now(),
basketId: basketId,
riskLevel: riskLevel,
irr: irr,
Expand All @@ -63,7 +62,6 @@ class CreateInvestmentPresenter extends Presenter<CreateInvestmentViewState> {
investedAmount: investedAmount,
investedOn: investedOn,
value: value,
valueUpdatedOn: DateTime.now(),
basketId: basketId,
riskLevel: riskLevel,
irr: irr,
Expand Down
3 changes: 0 additions & 3 deletions lib/presentation/investments_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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,
Expand All @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/widgets/create_investment_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,7 @@ class _CreateInvestmentPage extends PageState<CreateInvestmentViewState,
controller: _investedOnController,
inputFormatters: [DateTextInputFormatter()],
decoration: const InputDecoration(
labelText: 'Date (DD/MM/YYYY)',
labelText: 'Invested Date',
border: OutlineInputBorder()),
),
],
Expand Down

0 comments on commit 363868a

Please sign in to comment.