-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
137 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
@startuml | ||
|
||
class Basket { | ||
- id: Int | ||
- name: String | ||
- description: String | ||
} | ||
|
||
class Investment { | ||
- id: Int | ||
- name: String | ||
- description: String | ||
- basketId: Int | ||
- currentValue: Real | ||
- riskLevel: String | ||
- irr: Real | ||
- currentValueUpdatedOn: DateTime | ||
- maturityDate: DateTime | ||
} | ||
|
||
class Transaction { | ||
- id: Int | ||
- investmentId: Int | ||
- sipId: Int | ||
- amount: Real | ||
- description: String | ||
- amountInvestedOn: DateTime | ||
} | ||
|
||
class Sip { | ||
- id: Int | ||
- investmentId: Int | ||
- amount: Real | ||
- description: String | ||
- startDate: DateTime | ||
- endDate: DateTime | ||
- frequency: Real | ||
- executedTill: DateTime | ||
} | ||
|
||
class Goal { | ||
- id: Int | ||
- name: String | ||
- description: String | ||
- amount: Real | ||
- date: DateTime | ||
- inflation: Real | ||
- targetAmount: Real | ||
- targetDate: DateTime | ||
- importance: String | ||
} | ||
|
||
Basket "1" -- "0..*" Investment : contains | ||
Investment "1" -- "0..*" Transaction : contains | ||
Investment "1" -- "0..*" Sip : contains | ||
Goal "1" -- "*..*" Investment : contains | ||
|
||
@enduml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
enum SipFrequency { | ||
daily, | ||
weekly, | ||
biweekly, | ||
monthly, | ||
yearly, | ||
} |
41 changes: 41 additions & 0 deletions
41
lib/domain/usecases/perform_sip_transactions_use_case.dart
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:wealth_wave/api/apis/investment_api.dart'; | ||
|
||
class PerformSipTransactionsUseCase { | ||
final InvestmentApi _investmentApi; | ||
|
||
PerformSipTransactionsUseCase({final InvestmentApi? investmentApi}) | ||
: _investmentApi = investmentApi ?? InvestmentApi(); | ||
|
||
Future<void> performSipTransactions() async { | ||
return _investmentApi.getSips().then((sips) { | ||
for (var sip in sips) { | ||
if (sip.startDate.isBefore(DateTime.now())) { | ||
var diff = sip.startDate.difference(DateTime.now()).inDays; | ||
var frequency = sip.frequency; | ||
if (diff > frequency) { | ||
for (DateTime i = sip.startDate; | ||
i.isBefore(DateTime.now()); | ||
i.add(Duration(days: frequency.toInt()))) { | ||
_investmentApi | ||
.createTransaction( | ||
investmentId: sip.investmentId, | ||
description: 'SIP', | ||
amount: sip.amount, | ||
date: sip.startDate) | ||
.await; | ||
} | ||
} | ||
|
||
_investmentApi | ||
.createTransaction( | ||
investmentId: sip.investmentId, | ||
amount: sip.amount, | ||
date: sip.startDate) | ||
.then((_) => _investmentApi.updateSip( | ||
id: sip.id, | ||
startDate: sip.startDate.add(Duration(days: 30)))); | ||
} | ||
} | ||
}); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters