Skip to content

Commit

Permalink
Add qty at transaction
Browse files Browse the repository at this point in the history
  • Loading branch information
praslnx8 committed Apr 28, 2024
1 parent 4cfc719 commit a73ebcf
Show file tree
Hide file tree
Showing 11 changed files with 191 additions and 95 deletions.
3 changes: 0 additions & 3 deletions lib/api/apis/investment_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ class InvestmentApi {
required final int? basketId,
required final RiskLevel riskLevel,
required final double? value,
required final double? qty,
required final DateTime? valueUpdatedOn,
required final double? irr,
required final DateTime? maturityDate,
Expand All @@ -23,7 +22,6 @@ class InvestmentApi {
description: Value(description),
basketId: Value(basketId),
value: Value(value),
qty: Value(qty),
irr: Value(irr),
maturityDate: Value(maturityDate),
valueUpdatedOn: Value(valueUpdatedOn),
Expand Down Expand Up @@ -77,7 +75,6 @@ class InvestmentApi {
basketId: Value(basketId),
riskLevel: Value(riskLevel),
value: Value(value),
qty: Value(qty),
valueUpdatedOn: Value(valueUpdatedOn),
irr: Value(irr),
maturityDate: Value(maturityDate)));
Expand Down
4 changes: 4 additions & 0 deletions lib/api/apis/transaction_api.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,15 @@ class TransactionApi {
{required final int investmentId,
required final String? description,
required final double amount,
required final double qty,
required final DateTime createdOn,
final int? sipId}) async {
return _db.into(_db.transactionTable).insert(
TransactionTableCompanion.insert(
investmentId: investmentId,
description: Value(description),
amount: amount,
qty: Value(qty),
sipId: Value(sipId),
createdOn: createdOn));
}
Expand Down Expand Up @@ -55,13 +57,15 @@ class TransactionApi {
required final int investmentId,
required final String? description,
required final double amount,
required final double qty,
required final DateTime createdOn,
final int? sipId}) async {
return (_db.update(_db.transactionTable)..where((t) => t.id.equals(id)))
.write(TransactionTableCompanion(
investmentId: Value(investmentId),
description: Value(description),
amount: Value(amount),
qty: Value(qty),
createdOn: Value(createdOn),
sipId: Value(sipId),
));
Expand Down
12 changes: 8 additions & 4 deletions lib/api/db/app_database.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,6 @@ class InvestmentTable extends Table {

RealColumn get value => real().nullable().named('VALUE')();

RealColumn get qty => real().nullable().named('QTY')();

DateTimeColumn get valueUpdatedOn =>
dateTime().nullable().named('VALUE_UPDATED_ON')();

Expand Down Expand Up @@ -63,6 +61,8 @@ class TransactionTable extends Table {
RealColumn get amount =>
real().named('AMOUNT').check(amount.isBiggerThanValue(0))();

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

DateTimeColumn get createdOn => dateTime().named('CREATED_ON')();
}

Expand Down Expand Up @@ -167,6 +167,9 @@ abstract class InvestmentEnrichedView extends View {
distinct: true,
filter: transaction.investmentId.equalsExp(investment.id));

Expression<double> get qty => transaction.qty
.sum(filter: transaction.investmentId.equalsExp(investment.id));

Expression<int> get totalSips => sip.id
.count(distinct: true, filter: sip.investmentId.equalsExp(investment.id));

Expand All @@ -182,14 +185,14 @@ abstract class InvestmentEnrichedView extends View {
investment.riskLevel,
investment.maturityDate,
investment.irr,
investment.qty,
investment.value,
investment.valueUpdatedOn,
basketId,
basketName,
totalTransactions,
totalSips,
taggedGoals
taggedGoals,
qty
]).from(investment).join([
leftOuterJoin(basket, basket.id.equalsExp(investment.basketId)),
leftOuterJoin(
Expand Down Expand Up @@ -222,6 +225,7 @@ abstract class TransactionEnrichedView extends View {
transaction.investmentId,
transaction.sipId,
transaction.amount,
transaction.qty,
transaction.createdOn,
investmentName,
sipDescription,
Expand Down
Loading

0 comments on commit a73ebcf

Please sign in to comment.