Skip to content

Commit

Permalink
Merge pull request #173 from gioisco/fix/account-exclusion-recurring-…
Browse files Browse the repository at this point in the history
…transactions

Fix for Account Exclusion Issue Due to Recurring Transactions
  • Loading branch information
mikev-cw authored Nov 4, 2024
2 parents 5afebcf + ff929d2 commit b9514db
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions lib/model/bank_account.dart
Original file line number Diff line number Diff line change
Expand Up @@ -149,8 +149,8 @@ class BankAccountMethods extends SossoldiDatabase {
final db = await database;

final orderByASC = '${BankAccountFields.createdAt} ASC';
final where =
'${BankAccountFields.active} = 1 AND (${TransactionFields.recurring} = 0 OR ${TransactionFields.recurring} is NULL)';
final where = '${BankAccountFields.active} = 1 ';
final recurringFilter = '(t.${TransactionFields.recurring} = 0 OR t.${TransactionFields.recurring} IS NULL)';

final result = await db.rawQuery('''
SELECT b.*, (b.${BankAccountFields.startingValue} +
Expand All @@ -160,7 +160,10 @@ class BankAccountMethods extends SossoldiDatabase {
ELSE 0 END)
) as ${BankAccountFields.total}
FROM $bankAccountTable as b
LEFT JOIN "$transactionTable" as t ON t.${TransactionFields.idBankAccount} = b.${BankAccountFields.id} OR t.${TransactionFields.idBankAccountTransfer} = b.${BankAccountFields.id}
LEFT JOIN "$transactionTable" as t
ON (t.${TransactionFields.idBankAccount} = b.${BankAccountFields.id} OR
t.${TransactionFields.idBankAccountTransfer} = b.${BankAccountFields.id})
AND $recurringFilter
WHERE $where
GROUP BY b.${BankAccountFields.id}
ORDER BY $orderByASC
Expand Down

0 comments on commit b9514db

Please sign in to comment.