Skip to content

Commit

Permalink
save commit
Browse files Browse the repository at this point in the history
  • Loading branch information
praslnx8 committed Jan 20, 2024
1 parent 52e8d74 commit 8d590c3
Show file tree
Hide file tree
Showing 6 changed files with 56 additions and 41 deletions.
8 changes: 4 additions & 4 deletions lib/api/apis/goal_investment_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ class GoalInvestmentApi {
Future<int> create(
{required final int goalId,
required final int investmentId,
required final double split}) async {
required final double splitPercentage}) async {
return _db.into(_db.goalInvestmentTable).insert(
GoalInvestmentTableCompanion.insert(
goalId: goalId, investmentId: investmentId, split: split));
goalId: goalId, investmentId: investmentId, splitPercentage: splitPercentage));
}

Future<List<GoalInvestmentDO>> getBy(
Expand All @@ -38,12 +38,12 @@ class GoalInvestmentApi {
{required final int id,
required final int goalId,
required final int investmentId,
required final double split}) async {
required final double splitPercentage}) async {
return (_db.update(_db.goalInvestmentTable)..where((t) => t.id.equals(id)))
.write(GoalInvestmentTableCompanion(
investmentId: Value(investmentId),
goalId: Value(goalId),
split: Value(split)));
splitPercentage: Value(splitPercentage)));
}

Future<int> deleteBy(
Expand Down
2 changes: 1 addition & 1 deletion lib/api/db/app_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ class GoalInvestmentTable extends Table {
IntColumn get investmentId =>
integer().named('INVESTMENT_ID').references(GoalTable, #id)();

RealColumn get split => real().named('SPLIT')();
RealColumn get splitPercentage => real().named('SPLIT_PERCENTAGE')();
}

@DataClassName('InvestmentEnrichedDO')
Expand Down
52 changes: 26 additions & 26 deletions lib/api/db/app_database.g.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 18 additions & 7 deletions lib/domain/models/goal.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:wealth_wave/api/db/app_database.dart';
import 'package:wealth_wave/contract/goal_importance.dart';
import 'package:wealth_wave/domain/models/investment.dart';
import 'package:wealth_wave/domain/models/irr_calculator.dart';
import 'package:wealth_wave/utils/utils.dart';

class Goal {
final int id;
Expand Down Expand Up @@ -44,7 +45,7 @@ class Goal {
.then((investmentDO) =>
Investment.from(investmentDO: investmentDO))
.then((investment) =>
MapEntry(investment, goalInvestment.split)))))
MapEntry(investment, goalInvestment.splitPercentage)))))
.then((entries) => Map.fromEntries(entries));
}

Expand All @@ -57,8 +58,10 @@ class Goal {
.then((investmentDO) =>
Investment.from(investmentDO: investmentDO))
.then((investment) => investment.getTotalInvestedAmount())
.then((amount) => amount * goalInvestment.split))))
.then((amounts) => amounts.isNotEmpty ? amounts.reduce((value, element) => value + element): 0);
.then((amount) => amount * goalInvestment.splitPercentage))))
.then((amounts) => amounts.isNotEmpty
? amounts.reduce((value, element) => value + element)
: 0);
}

Future<double> getMaturityAmount() {
Expand All @@ -79,14 +82,18 @@ class Goal {
Investment.from(investmentDO: investmentDO))
.then((investment) => investment.getValueOn(
date: maturityDate, considerFuturePayments: true))
.then((amount) => amount * goalInvestment.split))))
.then((amounts) => amounts.isNotEmpty ? amounts.reduce((value, element) => value + element): 0);
.then((amount) => calculatePercentageOfValue(
value: amount,
percentage: goalInvestment.splitPercentage)))))
.then((amounts) => amounts.isNotEmpty
? amounts.reduce((value, element) => value + element)
: 0);
}

Future<void> tagInvestment(
{required final int investmentId, required final double split}) async {
return _goalInvestmentApi
.create(goalId: id, investmentId: investmentId, split: split)
.create(goalId: id, investmentId: investmentId, splitPercentage: split)
.then((goalInvestmentDO) => {});
}

Expand All @@ -95,7 +102,11 @@ class Goal {
required final int investmentId,
required final double split}) async {
return _goalInvestmentApi
.update(id: id, goalId: id, investmentId: investmentId, split: split)
.update(
id: id,
goalId: id,
investmentId: investmentId,
splitPercentage: split)
.then((goalInvestmentDO) => {});
}

Expand Down
6 changes: 3 additions & 3 deletions lib/domain/models/investment.dart
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ class Investment {
(goalInvestment) => _goalApi
.getBy(id: goalInvestment.goalId)
.then((goalDO) => Goal.from(goalDO: goalDO))
.then((goal) => MapEntry(goal, goalInvestment.split)))))
.then((goal) => MapEntry(goal, goalInvestment.splitPercentage)))))
.then((entries) => Map.fromEntries(entries));
}

Expand Down Expand Up @@ -211,7 +211,7 @@ class Investment {
Future<void> tagGoal(
{required final int goalId, required final double split}) async {
return _goalInvestmentApi
.create(goalId: goalId, investmentId: id, split: split)
.create(goalId: goalId, investmentId: id, splitPercentage: split)
.then((goalInvestmentDO) => {});
}

Expand All @@ -220,7 +220,7 @@ class Investment {
required final int goalId,
required final double split}) async {
return _goalInvestmentApi
.update(id: id, goalId: goalId, investmentId: id, split: split)
.update(id: id, goalId: goalId, investmentId: id, splitPercentage: split)
.then((goalInvestmentDO) => {});
}

Expand Down
4 changes: 4 additions & 0 deletions lib/utils/utils.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
double calculatePercentageOfValue(
{required final double value, required final double percentage}) {
return value * percentage / 100;
}

0 comments on commit 8d590c3

Please sign in to comment.