diff --git a/packages/server/src/services/Banking/BankAccounts/GetBankAccountSummary.ts b/packages/server/src/services/Banking/BankAccounts/GetBankAccountSummary.ts index b8c173dab..29c68abb6 100644 --- a/packages/server/src/services/Banking/BankAccounts/GetBankAccountSummary.ts +++ b/packages/server/src/services/Banking/BankAccounts/GetBankAccountSummary.ts @@ -1,6 +1,7 @@ import { Inject, Service } from 'typedi'; import { initialize } from 'objection'; import HasTenancyService from '@/services/Tenancy/TenancyService'; +import { UncategorizedTransactionTransformer } from '@/services/Cashflow/UncategorizedTransactionTransformer'; @Service() export class GetBankAccountSummary { @@ -69,14 +70,27 @@ export class GetBankAccountSummary { q.first(); }); + const excludedTransactionsCount = + await UncategorizedCashflowTransaction.query().onBuild((q) => { + q.where('accountId', bankAccountId); + q.modify('excluded'); + + // Count the results. + q.count('uncategorized_cashflow_transactions.id as total'); + q.first(); + }); + const totalUncategorizedTransactions = uncategorizedTranasctionsCount?.total || 0; const totalRecognizedTransactions = recognizedTransactionsCount?.total || 0; + const totalExcludedTransactions = excludedTransactionsCount?.total || 0; + return { name: bankAccount.name, totalUncategorizedTransactions, totalRecognizedTransactions, + totalExcludedTransactions, }; } } diff --git a/packages/webapp/src/containers/CashFlow/AccountTransactions/AccountTransactionsFilterTabs.tsx b/packages/webapp/src/containers/CashFlow/AccountTransactions/AccountTransactionsFilterTabs.tsx index c2d40059d..3cd798feb 100644 --- a/packages/webapp/src/containers/CashFlow/AccountTransactions/AccountTransactionsFilterTabs.tsx +++ b/packages/webapp/src/containers/CashFlow/AccountTransactions/AccountTransactionsFilterTabs.tsx @@ -1,4 +1,5 @@ // @ts-nocheck +import { useMemo } from 'react'; import styled from 'styled-components'; import { ContentTabs } from '@/components/ContentTabs/ContentTabs'; import { useAccountTransactionsContext } from './AccountTransactionsProvider'; @@ -8,15 +9,19 @@ const AccountContentTabs = styled(ContentTabs)` `; export function AccountTransactionsFilterTabs() { - const { filterTab, setFilterTab, currentAccount } = + const { filterTab, setFilterTab, bankAccountMetaSummary, currentAccount } = useAccountTransactionsContext(); const handleChange = (value) => { setFilterTab(value); }; - const hasUncategorizedTransx = Boolean( - currentAccount.uncategorized_transactions, + // Detarmines whether show the uncategorized transactions tab. + const hasUncategorizedTransx = useMemo( + () => + bankAccountMetaSummary?.totalUncategorizedTransactions > 0 || + bankAccountMetaSummary?.totalExcludedTransactions > 0, + [bankAccountMetaSummary], ); return (