From 4bcc8a0a2b162c68870ba9e2c8e33328b5db482a Mon Sep 17 00:00:00 2001 From: Prasanna Anbazhagan Date: Mon, 15 Jan 2024 07:07:38 +0530 Subject: [PATCH] save commit --- docs/class.puml | 58 +++++++++++++++++++ lib/contract/sip_frequency.dart | 7 +++ .../perform_sip_transactions_use_case.dart | 41 +++++++++++++ lib/ui/widgets/create_investment_dialog.dart | 49 ++++++++++------ 4 files changed, 137 insertions(+), 18 deletions(-) create mode 100644 docs/class.puml create mode 100644 lib/contract/sip_frequency.dart create mode 100644 lib/domain/usecases/perform_sip_transactions_use_case.dart diff --git a/docs/class.puml b/docs/class.puml new file mode 100644 index 0000000..5482578 --- /dev/null +++ b/docs/class.puml @@ -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 \ No newline at end of file diff --git a/lib/contract/sip_frequency.dart b/lib/contract/sip_frequency.dart new file mode 100644 index 0000000..de77bfd --- /dev/null +++ b/lib/contract/sip_frequency.dart @@ -0,0 +1,7 @@ +enum SipFrequency { + daily, + weekly, + biweekly, + monthly, + yearly, +} diff --git a/lib/domain/usecases/perform_sip_transactions_use_case.dart b/lib/domain/usecases/perform_sip_transactions_use_case.dart new file mode 100644 index 0000000..505e760 --- /dev/null +++ b/lib/domain/usecases/perform_sip_transactions_use_case.dart @@ -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 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)))); + } + } + }); + } +} diff --git a/lib/ui/widgets/create_investment_dialog.dart b/lib/ui/widgets/create_investment_dialog.dart index 0f0fa78..474b355 100644 --- a/lib/ui/widgets/create_investment_dialog.dart +++ b/lib/ui/widgets/create_investment_dialog.dart @@ -102,24 +102,37 @@ class _CreateInvestmentPage extends PageState( decoration: const InputDecoration(