fix: Should not show the excluded transactions in recognized transactions

This commit is contained in:
Ahmed Bouhuolia
2024-08-05 21:11:15 +02:00
parent 64c0732e5f
commit f6350d3d61
2 changed files with 25 additions and 18 deletions

View File

@@ -31,17 +31,21 @@ export class GetBankAccountSummary {
.findById(bankAccountId) .findById(bankAccountId)
.throwIfNotFound(); .throwIfNotFound();
const commonQuery = (q) => {
// Include just the given account.
q.where('accountId', bankAccountId);
// Only the not excluded.
q.modify('notExcluded');
// Only the not categorized.
q.modify('notCategorized');
};
// Retrieves the uncategorized transactions count of the given bank account. // Retrieves the uncategorized transactions count of the given bank account.
const uncategorizedTranasctionsCount = const uncategorizedTranasctionsCount =
await UncategorizedCashflowTransaction.query().onBuild((q) => { await UncategorizedCashflowTransaction.query().onBuild((q) => {
// Include just the given account. commonQuery(q);
q.where('accountId', bankAccountId);
// Only the not excluded.
q.modify('notExcluded');
// Only the not categorized.
q.modify('notCategorized');
// Only the not matched bank transactions. // Only the not matched bank transactions.
q.withGraphJoined('matchedBankTransactions'); q.withGraphJoined('matchedBankTransactions');
@@ -52,16 +56,18 @@ export class GetBankAccountSummary {
q.first(); q.first();
}); });
// Retrieves the recognized transactions count of the given bank account. // Retrives the recognized transactions count.
const recognizedTransactionsCount = await RecognizedBankTransaction.query() const recognizedTransactionsCount =
.whereExists( await UncategorizedCashflowTransaction.query().onBuild((q) => {
UncategorizedCashflowTransaction.query().where( commonQuery(q);
'accountId',
bankAccountId q.withGraphJoined('recognizedTransaction');
) q.whereNotNull('recognizedTransaction.id');
)
.count('id as total') // Count the results.
.first(); q.count('uncategorized_cashflow_transactions.id as total');
q.first();
});
const totalUncategorizedTransactions = const totalUncategorizedTransactions =
uncategorizedTranasctionsCount?.total || 0; uncategorizedTranasctionsCount?.total || 0;

View File

@@ -34,6 +34,7 @@ export class GetRecognizedTransactionsService {
q.withGraphFetched('recognizedTransaction.assignAccount'); q.withGraphFetched('recognizedTransaction.assignAccount');
q.withGraphFetched('recognizedTransaction.bankRule'); q.withGraphFetched('recognizedTransaction.bankRule');
q.whereNotNull('recognizedTransactionId'); q.whereNotNull('recognizedTransactionId');
q.modify('notExcluded');
if (_filter.accountId) { if (_filter.accountId) {
q.where('accountId', _filter.accountId); q.where('accountId', _filter.accountId);