Skip to content

Commit

Permalink
Allow negative transaction value to indicate selling the investment s…
Browse files Browse the repository at this point in the history
…tocks
  • Loading branch information
praslnx8 committed Aug 7, 2024
1 parent b0da574 commit 33d4f92
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 16 deletions.
12 changes: 6 additions & 6 deletions lib/api/db/app_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,7 @@ class InvestmentTable extends Table {
RealColumn get irr => real().nullable().named('IRR')();

DateTimeColumn get maturityDate =>
dateTime().nullable().named('MATURITY_DATE').check(maturityDate.isNull() |
maturityDate.isBiggerThanValue(DateTime.now()))();
dateTime().nullable().named('MATURITY_DATE')();

DateTimeColumn get valueUpdatedDate =>
dateTime().nullable().named('VALUE_UPDATED_DATE')();
Expand All @@ -59,7 +58,7 @@ class TransactionTable extends Table {
integer().nullable().named('SIP_ID').references(SipTable, #id)();

RealColumn get amount =>
real().named('AMOUNT').check(amount.isBiggerThanValue(0))();
real().named('AMOUNT').check(amount.isNotValue(0))();

RealColumn get qty => real().named('QTY').withDefault(const Constant(0))();

Expand Down Expand Up @@ -119,8 +118,7 @@ class GoalTable extends Table {
real().named('INFLATION').check(inflation.isBetweenValues(1, 100))();

DateTimeColumn get maturityDate => dateTime()
.named('MATURITY_DATE')
.check(maturityDate.isBiggerThanValue(DateTime.now()))();
.named('MATURITY_DATE')();

TextColumn get importance => textEnum<GoalImportance>().named('IMPORTANCE')();
}
Expand Down Expand Up @@ -355,7 +353,9 @@ class AppDatabase extends _$AppDatabase {
var tableName = entry.key;
var tableDataList = entry.value;

print("Updating table $tableName");
for (var tableData in tableDataList) {
print("Inserting $tableData");
final String columnsString =
tableData.keys.where((key) => tableData[key] != null).join(', ');
final String valuesString = tableData.keys
Expand All @@ -378,7 +378,7 @@ class AppDatabase extends _$AppDatabase {
} else if (value is bool) {
return Variable.withBool(value);
} else {
throw Exception('Unknown type $value');
return Variable.withString("");
}
}).toList(),
);
Expand Down
12 changes: 3 additions & 9 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.

Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,6 @@ class CreateTransactionViewState {
SingleEvent<void>? onTransactionLoaded;

bool isValid() {
return amount > 0;
return amount != 0;
}
}
1 change: 1 addition & 0 deletions lib/ui/presentation/investments_presenter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class InvestmentsPresenter extends Presenter<InvestmentsViewState> {
.get()
.then((investments) => investments
.map((investment) => InvestmentVO.from(investment: investment))
.where((element) => element.qty > 0)
.toList())
.then((investmentVOs) {
investmentVOs.sort((a, b) => a.currentValue > b.currentValue ? -1 : 1);
Expand Down

0 comments on commit 33d4f92

Please sign in to comment.