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,9 +31,7 @@ export class GetBankAccountSummary {
.findById(bankAccountId) .findById(bankAccountId)
.throwIfNotFound(); .throwIfNotFound();
// Retrieves the uncategorized transactions count of the given bank account. const commonQuery = (q) => {
const uncategorizedTranasctionsCount =
await UncategorizedCashflowTransaction.query().onBuild((q) => {
// Include just the given account. // Include just the given account.
q.where('accountId', bankAccountId); q.where('accountId', bankAccountId);
@@ -42,6 +40,12 @@ export class GetBankAccountSummary {
// Only the not categorized. // Only the not categorized.
q.modify('notCategorized'); q.modify('notCategorized');
};
// Retrieves the uncategorized transactions count of the given bank account.
const uncategorizedTranasctionsCount =
await UncategorizedCashflowTransaction.query().onBuild((q) => {
commonQuery(q);
// 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);