Skip to content

Commit

Permalink
save commit
Browse files Browse the repository at this point in the history
  • Loading branch information
praslnx8 committed Jan 15, 2024
1 parent 751d259 commit 4bcc8a0
Show file tree
Hide file tree
Showing 4 changed files with 137 additions and 18 deletions.
58 changes: 58 additions & 0 deletions docs/class.puml
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
7 changes: 7 additions & 0 deletions lib/contract/sip_frequency.dart
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 lib/domain/usecases/perform_sip_transactions_use_case.dart
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))));
}
}
});
}
}
49 changes: 31 additions & 18 deletions lib/ui/widgets/create_investment_dialog.dart
Original file line number Diff line number Diff line change
Expand Up @@ -102,24 +102,37 @@ class _CreateInvestmentPage extends PageState<CreateInvestmentViewState,
labelText: 'Desctiption', border: OutlineInputBorder()),
),
const SizedBox(height: AppDimen.defaultPadding),
TextFormField(
textInputAction: TextInputAction.next,
controller: _valueController,
keyboardType: TextInputType.number,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
decoration: const InputDecoration(
labelText: 'Value', border: OutlineInputBorder()),
),
const SizedBox(height: AppDimen.defaultPadding),
TextFormField(
textInputAction: TextInputAction.next,
controller: _valueUpdatedDateController,
inputFormatters: [
FilteringTextInputFormatter.deny(RegExp(r'[^0-9\-]'))
],
decoration: const InputDecoration(
labelText: 'Date (DD-MM-YYYY)', border: OutlineInputBorder()),
),
Container(
decoration: BoxDecoration(
border: Border.all(color: Theme.of(context).dividerColor),
borderRadius: BorderRadius.circular(AppDimen.defaultPadding)),
child: Padding(
padding: const EdgeInsets.all(AppDimen.minPadding),
child: Column(
children: [
TextFormField(
textInputAction: TextInputAction.next,
controller: _valueController,
keyboardType: TextInputType.number,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
decoration: const InputDecoration(
labelText: 'Current Value',
border: OutlineInputBorder()),
),
const SizedBox(height: AppDimen.minPadding),
const Text('Or'),
const SizedBox(height: AppDimen.minPadding),
TextFormField(
textInputAction: TextInputAction.next,
controller: _valueController,
keyboardType: TextInputType.number,
inputFormatters: [FilteringTextInputFormatter.digitsOnly],
decoration: const InputDecoration(
labelText: 'IRR %', border: OutlineInputBorder()),
)
],
),
)),
const SizedBox(height: AppDimen.defaultPadding),
DropdownButtonFormField<int>(
decoration: const InputDecoration(
Expand Down

0 comments on commit 4bcc8a0

Please sign in to comment.