From ce9378c43f3ca5597e613babce566012f8b40a22 Mon Sep 17 00:00:00 2001 From: MaysWind Date: Sun, 7 Sep 2025 13:57:07 +0800 Subject: [PATCH] support filtering accounts and transaction categories for overview in home page (#209) --- pkg/api/transactions.go | 21 ++++- pkg/models/transaction.go | 2 + pkg/models/user_app_cloud_setting.go | 6 +- pkg/services/transactions.go | 42 ++++++++- src/core/setting.ts | 6 ++ src/lib/common.ts | 16 ++++ src/lib/services.ts | 14 ++- src/locales/de.json | 2 + src/locales/en.json | 2 + src/locales/es.json | 2 + src/locales/it.json | 2 + src/locales/ja.json | 2 + src/locales/nl.json | 2 + src/locales/pt_BR.json | 2 + src/locales/ru.json | 2 + src/locales/uk.json | 2 + src/locales/vi.json | 2 + src/locales/zh_Hans.json | 2 + src/locales/zh_Hant.json | 2 + src/stores/overview.ts | 58 +++++++++++- src/stores/setting.ts | 14 +++ .../settings/AccountFilterSettingPageBase.ts | 14 ++- .../base/settings/AppCloudSyncPageBase.ts | 4 +- .../base/settings/AppSettingsPageBase.ts | 94 +++++++++++++++++-- .../settings/CategoryFilterSettingPageBase.ts | 12 ++- src/views/desktop/HomePage.vue | 20 ++-- .../app/settings/tabs/AppBasicSettingTab.vue | 68 +++++++++++++- .../cards/AccountFilterSettingsCard.vue | 7 +- .../cards/CategoryFilterSettingsCard.vue | 7 +- src/views/mobile/HomePage.vue | 28 +++--- .../settings/AccountFilterSettingsPage.vue | 7 +- .../settings/CategoryFilterSettingsPage.vue | 7 +- .../mobile/settings/PageSettingsPage.vue | 41 +++++++- 33 files changed, 459 insertions(+), 53 deletions(-) diff --git a/pkg/api/transactions.go b/pkg/api/transactions.go index 7efbb289..10456ed9 100644 --- a/pkg/api/transactions.go +++ b/pkg/api/transactions.go @@ -549,6 +549,25 @@ func (a *TransactionsApi) TransactionAmountsHandler(c *core.WebContext) (any, *e return nil, errs.ErrQueryItemsTooMuch } + excludeAccountIds := make([]int64, 0) + excludeCategoryIds := make([]int64, 0) + + if transactionAmountsReq.ExcludeAccountIds != "" { + excludeAccountIds, err = utils.StringArrayToInt64Array(strings.Split(transactionAmountsReq.ExcludeAccountIds, ",")) + + if err != nil { + return nil, errs.ErrAccountIdInvalid + } + } + + if transactionAmountsReq.ExcludeCategoryIds != "" { + excludeCategoryIds, err = utils.StringArrayToInt64Array(strings.Split(transactionAmountsReq.ExcludeCategoryIds, ",")) + + if err != nil { + return nil, errs.ErrTransactionCategoryIdInvalid + } + } + utcOffset, err := c.GetClientTimezoneOffset() if err != nil { @@ -571,7 +590,7 @@ func (a *TransactionsApi) TransactionAmountsHandler(c *core.WebContext) (any, *e for i := 0; i < len(requestItems); i++ { requestItem := requestItems[i] - incomeAmounts, expenseAmounts, err := a.transactions.GetAccountsTotalIncomeAndExpense(c, uid, requestItem.StartTime, requestItem.EndTime, utcOffset, transactionAmountsReq.UseTransactionTimezone) + incomeAmounts, expenseAmounts, err := a.transactions.GetAccountsTotalIncomeAndExpense(c, uid, requestItem.StartTime, requestItem.EndTime, excludeAccountIds, excludeCategoryIds, utcOffset, transactionAmountsReq.UseTransactionTimezone) if err != nil { log.Errorf(c, "[transactions.TransactionAmountsHandler] failed to get transaction amounts item for user \"uid:%d\", because %s", uid, err.Error()) diff --git a/pkg/models/transaction.go b/pkg/models/transaction.go index 7f427535..64bce9bf 100644 --- a/pkg/models/transaction.go +++ b/pkg/models/transaction.go @@ -258,6 +258,8 @@ type TransactionStatisticTrendsRequest struct { // TransactionAmountsRequest represents all parameters of transaction amounts request type TransactionAmountsRequest struct { Query string `form:"query"` + ExcludeAccountIds string `form:"exclude_account_ids"` + ExcludeCategoryIds string `form:"exclude_category_ids"` UseTransactionTimezone bool `form:"use_transaction_timezone"` } diff --git a/pkg/models/user_app_cloud_setting.go b/pkg/models/user_app_cloud_setting.go index ea6e69a2..6698a6ac 100644 --- a/pkg/models/user_app_cloud_setting.go +++ b/pkg/models/user_app_cloud_setting.go @@ -17,8 +17,10 @@ var ALL_ALLOWED_CLOUD_SYNC_APP_SETTING_KEY_TYPES = map[string]UserApplicationClo // Basic Settings "showAccountBalance": USER_APPLICATION_CLOUD_SETTING_TYPE_BOOLEAN, // Overview Page - "showAmountInHomePage": USER_APPLICATION_CLOUD_SETTING_TYPE_BOOLEAN, - "timezoneUsedForStatisticsInHomePage": USER_APPLICATION_CLOUD_SETTING_TYPE_NUMBER, + "showAmountInHomePage": USER_APPLICATION_CLOUD_SETTING_TYPE_BOOLEAN, + "timezoneUsedForStatisticsInHomePage": USER_APPLICATION_CLOUD_SETTING_TYPE_NUMBER, + "overviewAccountFilterInHomePage": USER_APPLICATION_CLOUD_SETTING_TYPE_STRING_BOOLEAN_MAP, + "overviewTransactionCategoryFilterInHomePage": USER_APPLICATION_CLOUD_SETTING_TYPE_STRING_BOOLEAN_MAP, // Transaction List Page "itemsCountInTransactionListPage": USER_APPLICATION_CLOUD_SETTING_TYPE_NUMBER, "showTotalAmountInTransactionListPage": USER_APPLICATION_CLOUD_SETTING_TYPE_BOOLEAN, diff --git a/pkg/services/transactions.go b/pkg/services/transactions.go index c84ec85b..d802f5dd 100644 --- a/pkg/services/transactions.go +++ b/pkg/services/transactions.go @@ -1422,7 +1422,7 @@ func (s *TransactionService) GetRelatedTransferTransaction(originalTransaction * } // GetAccountsTotalIncomeAndExpense returns the every accounts total income and expense amount by specific date range -func (s *TransactionService) GetAccountsTotalIncomeAndExpense(c core.Context, uid int64, startUnixTime int64, endUnixTime int64, utcOffset int16, useTransactionTimezone bool) (map[int64]int64, map[int64]int64, error) { +func (s *TransactionService) GetAccountsTotalIncomeAndExpense(c core.Context, uid int64, startUnixTime int64, endUnixTime int64, excludeAccountIds []int64, excludeCategoryIds []int64, utcOffset int16, useTransactionTimezone bool) (map[int64]int64, map[int64]int64, error) { if uid <= 0 { return nil, nil, errs.ErrUserIdInvalid } @@ -1437,13 +1437,49 @@ func (s *TransactionService) GetAccountsTotalIncomeAndExpense(c core.Context, ui startTransactionTime := utils.GetMinTransactionTimeFromUnixTime(startUnixTime) endTransactionTime := utils.GetMaxTransactionTimeFromUnixTime(endUnixTime) - condition := "uid=? AND deleted=? AND (type=? OR type=?) AND transaction_time>=? AND transaction_time<=?" - conditionParams := make([]any, 0, 4) + condition := "uid=? AND deleted=? AND (type=? OR type=?)" + conditionParams := make([]any, 0, 4+len(excludeAccountIds)+len(excludeCategoryIds)) conditionParams = append(conditionParams, uid) conditionParams = append(conditionParams, false) conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_INCOME) conditionParams = append(conditionParams, models.TRANSACTION_DB_TYPE_EXPENSE) + if len(excludeAccountIds) > 0 { + var accountIdsCondition strings.Builder + accountIdConditionParams := make([]any, 0, len(excludeAccountIds)) + + for i := 0; i < len(excludeAccountIds); i++ { + if i > 0 { + accountIdsCondition.WriteString(",") + } + + accountIdsCondition.WriteString("?") + accountIdConditionParams = append(accountIdConditionParams, excludeAccountIds[i]) + } + + condition = condition + " AND account_id NOT IN (" + accountIdsCondition.String() + ")" + conditionParams = append(conditionParams, accountIdConditionParams...) + } + + if len(excludeCategoryIds) > 0 { + var categoryIdsCondition strings.Builder + categoryIdConditionParams := make([]any, 0, len(excludeCategoryIds)) + + for i := 0; i < len(excludeCategoryIds); i++ { + if i > 0 { + categoryIdsCondition.WriteString(",") + } + + categoryIdsCondition.WriteString("?") + categoryIdConditionParams = append(categoryIdConditionParams, excludeCategoryIds[i]) + } + + condition = condition + " AND category_id NOT IN (" + categoryIdsCondition.String() + ")" + conditionParams = append(conditionParams, categoryIdConditionParams...) + } + + condition = condition + " AND transaction_time>=? AND transaction_time<=?" + minTransactionTime := startTransactionTime maxTransactionTime := endTransactionTime var allTransactions []*models.Transaction diff --git a/src/core/setting.ts b/src/core/setting.ts index 23700c15..d3969f1f 100644 --- a/src/core/setting.ts +++ b/src/core/setting.ts @@ -37,6 +37,8 @@ export interface ApplicationSettings extends BaseApplicationSetting { // Overview Page showAmountInHomePage: boolean; timezoneUsedForStatisticsInHomePage: number; + overviewAccountFilterInHomePage: Record; + overviewTransactionCategoryFilterInHomePage: Record; // Transaction List Page itemsCountInTransactionListPage: number; showTotalAmountInTransactionListPage: boolean; @@ -95,6 +97,8 @@ export const ALL_ALLOWED_CLOUD_SYNC_APP_SETTING_KEY_TYPES: Record(object: Record, value: T): string[] { + const ret: string[] = []; + + for (const field in object) { + if (!Object.prototype.hasOwnProperty.call(object, field)) { + continue; + } + + if (object[field] === value) { + ret.push(field); + } + } + + return ret; +} + export function arrayItemToObjectField(array: string[], value: T): Record { const ret: Record = {}; diff --git a/src/lib/services.ts b/src/lib/services.ts index a0c941a1..93b0a9fe 100644 --- a/src/lib/services.ts +++ b/src/lib/services.ts @@ -471,9 +471,19 @@ export default { return axios.get>(`v1/transactions/statistics/trends.json?use_transaction_timezone=${req.useTransactionTimezone}` + (queryParams.length ? '&' + queryParams.join('&') : '')); }, - getTransactionAmounts: (params: TransactionAmountsRequestParams): ApiResponsePromise => { + getTransactionAmounts: (params: TransactionAmountsRequestParams, excludeAccountIds: string[], excludeCategoryIds: string[]): ApiResponsePromise => { const req = TransactionAmountsRequest.of(params); - return axios.get>(`v1/transactions/amounts.json?${req.buildQuery()}`); + let queryParams = req.buildQuery(); + + if (excludeAccountIds && excludeAccountIds.length) { + queryParams = queryParams + `&exclude_account_ids=${excludeAccountIds.join(',')}`; + } + + if (excludeCategoryIds && excludeCategoryIds.length) { + queryParams = queryParams + `&exclude_category_ids=${excludeCategoryIds.join(',')}`; + } + + return axios.get>(`v1/transactions/amounts.json?${queryParams}`); }, getTransaction: ({ id, withPictures }: { id: string, withPictures: boolean | undefined }): ApiResponsePromise => { if (!isDefined(withPictures)) { diff --git a/src/locales/de.json b/src/locales/de.json index abdee05e..a323eeed 100644 --- a/src/locales/de.json +++ b/src/locales/de.json @@ -1962,6 +1962,8 @@ "Show Add Transaction Button": "Show Add Transaction Button", "Overview Page": "Übersichtsseite", "Timezone Used for Statistics": "Zeitzone für Statistiken", + "Accounts Included in Overview Statistics": "Accounts Included in Overview Statistics", + "Transaction Categories Included in Overview Statistics": "Transaction Categories Included in Overview Statistics", "Timezone Type": "Zeitzonentyp", "Application Timezone": "Anwendungszeitzone", "Transaction List Page": "Transaktionslisten-Seite", diff --git a/src/locales/en.json b/src/locales/en.json index 5b2ceb0a..b8dec6f2 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1962,6 +1962,8 @@ "Show Add Transaction Button": "Show Add Transaction Button", "Overview Page": "Overview Page", "Timezone Used for Statistics": "Timezone Used for Statistics", + "Accounts Included in Overview Statistics": "Accounts Included in Overview Statistics", + "Transaction Categories Included in Overview Statistics": "Transaction Categories Included in Overview Statistics", "Timezone Type": "Timezone Type", "Application Timezone": "Application Timezone", "Transaction List Page": "Transaction List Page", diff --git a/src/locales/es.json b/src/locales/es.json index 3c48188b..b79f6a4f 100644 --- a/src/locales/es.json +++ b/src/locales/es.json @@ -1962,6 +1962,8 @@ "Show Add Transaction Button": "Show Add Transaction Button", "Overview Page": "Página de descripción general", "Timezone Used for Statistics": "Zona horaria utilizada para estadísticas", + "Accounts Included in Overview Statistics": "Accounts Included in Overview Statistics", + "Transaction Categories Included in Overview Statistics": "Transaction Categories Included in Overview Statistics", "Timezone Type": "Tipo de zona horaria", "Application Timezone": "Zona horaria de la aplicación", "Transaction List Page": "Página de lista de transacciones", diff --git a/src/locales/it.json b/src/locales/it.json index 3ebdb5e8..fc1aa36d 100644 --- a/src/locales/it.json +++ b/src/locales/it.json @@ -1962,6 +1962,8 @@ "Show Add Transaction Button": "Mostra pulsante Aggiungi transazione", "Overview Page": "Pagina panoramica", "Timezone Used for Statistics": "Fuso orario utilizzato per le statistiche", + "Accounts Included in Overview Statistics": "Accounts Included in Overview Statistics", + "Transaction Categories Included in Overview Statistics": "Transaction Categories Included in Overview Statistics", "Timezone Type": "Tipo fuso orario", "Application Timezone": "Fuso orario applicazione", "Transaction List Page": "Pagina elenco transazioni", diff --git a/src/locales/ja.json b/src/locales/ja.json index 8822757b..83f12f6c 100644 --- a/src/locales/ja.json +++ b/src/locales/ja.json @@ -1962,6 +1962,8 @@ "Show Add Transaction Button": "Show Add Transaction Button", "Overview Page": "概要ページ", "Timezone Used for Statistics": "統計に使用されるタイムゾーン", + "Accounts Included in Overview Statistics": "Accounts Included in Overview Statistics", + "Transaction Categories Included in Overview Statistics": "Transaction Categories Included in Overview Statistics", "Timezone Type": "タイムゾーンタイプ", "Application Timezone": "アプリのタイムゾーン", "Transaction List Page": "取引リストページ", diff --git a/src/locales/nl.json b/src/locales/nl.json index af072ef8..200899eb 100644 --- a/src/locales/nl.json +++ b/src/locales/nl.json @@ -1962,6 +1962,8 @@ "Show Add Transaction Button": "Knop ‘Transactie toevoegen’ tonen", "Overview Page": "Overzichtspagina", "Timezone Used for Statistics": "Tijdzone gebruikt voor statistieken", + "Accounts Included in Overview Statistics": "Accounts Included in Overview Statistics", + "Transaction Categories Included in Overview Statistics": "Transaction Categories Included in Overview Statistics", "Timezone Type": "Tijdzonetype", "Application Timezone": "Applicatietijdzone", "Transaction List Page": "Transactielijstpagina", diff --git a/src/locales/pt_BR.json b/src/locales/pt_BR.json index 009b4489..48ba4b67 100644 --- a/src/locales/pt_BR.json +++ b/src/locales/pt_BR.json @@ -1962,6 +1962,8 @@ "Show Add Transaction Button": "Mostrar Botão de Adicionar Transação", "Overview Page": "Página de Visão Geral", "Timezone Used for Statistics": "Fuso Horário Usado para Estatísticas", + "Accounts Included in Overview Statistics": "Accounts Included in Overview Statistics", + "Transaction Categories Included in Overview Statistics": "Transaction Categories Included in Overview Statistics", "Timezone Type": "Tipo de Fuso Horário", "Application Timezone": "Fuso Horário do Aplicativo", "Transaction List Page": "Página de Lista de Transações", diff --git a/src/locales/ru.json b/src/locales/ru.json index 723c8646..4f4b42ce 100644 --- a/src/locales/ru.json +++ b/src/locales/ru.json @@ -1962,6 +1962,8 @@ "Show Add Transaction Button": "Show Add Transaction Button", "Overview Page": "Страница обзора", "Timezone Used for Statistics": "Часовой пояс, используемый для статистики", + "Accounts Included in Overview Statistics": "Accounts Included in Overview Statistics", + "Transaction Categories Included in Overview Statistics": "Transaction Categories Included in Overview Statistics", "Timezone Type": "Тип часового пояса", "Application Timezone": "Часовой пояс приложения", "Transaction List Page": "Страница списка транзакций", diff --git a/src/locales/uk.json b/src/locales/uk.json index de8b2aa3..7e799688 100644 --- a/src/locales/uk.json +++ b/src/locales/uk.json @@ -1962,6 +1962,8 @@ "Show Add Transaction Button": "Показати кнопку додавання транзакції", "Overview Page": "Сторінка огляду", "Timezone Used for Statistics": "Часовий пояс для статистики", + "Accounts Included in Overview Statistics": "Accounts Included in Overview Statistics", + "Transaction Categories Included in Overview Statistics": "Transaction Categories Included in Overview Statistics", "Timezone Type": "Тип часового поясу", "Application Timezone": "Часовий пояс застосунку", "Transaction List Page": "Сторінка списку транзакцій", diff --git a/src/locales/vi.json b/src/locales/vi.json index 1ac81407..ca7ea181 100644 --- a/src/locales/vi.json +++ b/src/locales/vi.json @@ -1962,6 +1962,8 @@ "Show Add Transaction Button": "Show Add Transaction Button", "Overview Page": "Trang tổng quan", "Timezone Used for Statistics": "Múi giờ được sử dụng cho thống kê", + "Accounts Included in Overview Statistics": "Accounts Included in Overview Statistics", + "Transaction Categories Included in Overview Statistics": "Transaction Categories Included in Overview Statistics", "Timezone Type": "Loại múi giờ", "Application Timezone": "Múi giờ ứng dụng", "Transaction List Page": "Trang danh sách giao dịch", diff --git a/src/locales/zh_Hans.json b/src/locales/zh_Hans.json index 16270db4..d2a28f6a 100644 --- a/src/locales/zh_Hans.json +++ b/src/locales/zh_Hans.json @@ -1962,6 +1962,8 @@ "Show Add Transaction Button": "显示添加交易按钮", "Overview Page": "总览页面", "Timezone Used for Statistics": "统计时使用的时区", + "Accounts Included in Overview Statistics": "总览统计中包含的账户", + "Transaction Categories Included in Overview Statistics": "总览统计中包含的交易分类", "Timezone Type": "时区类型", "Application Timezone": "应用时区", "Transaction List Page": "交易列表页面", diff --git a/src/locales/zh_Hant.json b/src/locales/zh_Hant.json index 63ebc947..50b23d28 100644 --- a/src/locales/zh_Hant.json +++ b/src/locales/zh_Hant.json @@ -1962,6 +1962,8 @@ "Show Add Transaction Button": "顯示新增交易按鈕", "Overview Page": "總覽頁面", "Timezone Used for Statistics": "統計使用的時區", + "Accounts Included in Overview Statistics": "概覽統計中包含的帳戶", + "Transaction Categories Included in Overview Statistics": "概覽統計中包含的交易分類", "Timezone Type": "時區類型", "Application Timezone": "應用程式時區", "Transaction List Page": "交易清單頁面", diff --git a/src/stores/overview.ts b/src/stores/overview.ts index b4cbad14..e1ace787 100644 --- a/src/stores/overview.ts +++ b/src/stores/overview.ts @@ -3,10 +3,14 @@ import { defineStore } from 'pinia'; import { useSettingsStore } from './setting.ts'; import { useUserStore } from './user.ts'; +import { useAccountsStore } from './account.ts'; +import { useTransactionCategoriesStore } from './transactionCategory.ts'; import { useExchangeRatesStore } from './exchangeRates.ts'; -import type { WritableStartEndTime } from '@/core/datetime.ts'; +import { type WritableStartEndTime, DateRange } from '@/core/datetime.ts'; import { TimezoneTypeForStatistics } from '@/core/timezone.ts'; +import type { TransactionType } from '@/core/transaction.ts'; + import type { TransactionAmountsRequestType, TransactionAmountsRequestParams, @@ -15,7 +19,13 @@ import type { } from '@/models/transaction.ts'; import { ALL_TRANSACTION_AMOUNTS_REQUEST_TYPE } from '@/models/transaction.ts'; -import { isNumber, isEquals } from '@/lib/common.ts'; +import { + isDefined, + isNumber, + isEquals, + isObjectEmpty, + objectFieldWithValueToArrayItem +} from '@/lib/common.ts'; import { getUnixTimeBeforeUnixTime, getTodayFirstUnixTime, @@ -27,6 +37,8 @@ import { getThisYearFirstUnixTime, getThisYearLastUnixTime } from '@/lib/datetime.ts'; +import { getFinalAccountIdsByFilteredAccountIds } from '@/lib/account.ts'; +import { getFinalCategoryIdsByFilteredCategoryIds } from '@/lib/category.ts'; import logger from '@/lib/logger.ts'; import services from '@/lib/services.ts'; @@ -100,6 +112,8 @@ interface TransactionOverviewOptions { export const useOverviewStore = defineStore('overview', () => { const settingsStore = useSettingsStore(); const userStore = useUserStore(); + const accountsStore = useAccountsStore(); + const transactionCategoriesStore = useTransactionCategoriesStore(); const exchangeRatesStore = useExchangeRatesStore(); const transactionDataRange = ref(getTransactionDateRange()); @@ -287,8 +301,11 @@ export const useOverviewStore = defineStore('overview', () => { requestParams.monthBeforeLast10Months = transactionDataRange.value.monthBeforeLast10Months; } + const excludeAccountIds: string[] = objectFieldWithValueToArrayItem(settingsStore.appSettings.overviewAccountFilterInHomePage, true); + const excludeCategoryIds: string[] = objectFieldWithValueToArrayItem(settingsStore.appSettings.overviewTransactionCategoryFilterInHomePage, true); + return new Promise((resolve, reject) => { - services.getTransactionAmounts(requestParams).then(response => { + services.getTransactionAmounts(requestParams, excludeAccountIds, excludeCategoryIds).then(response => { const data = response.data; if (!data || !data.success || !data.result) { @@ -327,6 +344,38 @@ export const useOverviewStore = defineStore('overview', () => { }); } + function getTransactionListPageParams({ type, dateType, minTime, maxTime }: { type?: TransactionType, dateType?: number, minTime?: number, maxTime?: number }): string { + const querys: string[] = []; + + if (isDefined(type)) { + querys.push('type=' + type); + } + + if (isDefined(dateType)) { + querys.push('dateType=' + dateType); + + if (dateType === DateRange.Custom.type) { + if (isNumber(minTime) && minTime > 0) { + querys.push('minTime=' + minTime); + } + + if (isNumber(maxTime) && maxTime > 0) { + querys.push('maxTime=' + maxTime); + } + } + } + + if (!isObjectEmpty(settingsStore.appSettings.overviewTransactionCategoryFilterInHomePage)) { + querys.push('categoryIds=' + getFinalCategoryIdsByFilteredCategoryIds(transactionCategoriesStore.allTransactionCategoriesMap, settingsStore.appSettings.overviewTransactionCategoryFilterInHomePage)); + } + + if (!isObjectEmpty(settingsStore.appSettings.overviewAccountFilterInHomePage)) { + querys.push('accountIds=' + getFinalAccountIdsByFilteredAccountIds(accountsStore.allAccountsMap, settingsStore.appSettings.overviewAccountFilterInHomePage)); + } + + return querys.join('&'); + } + return { // states transactionDataRange, @@ -338,6 +387,7 @@ export const useOverviewStore = defineStore('overview', () => { // functions updateTransactionOverviewInvalidState, resetTransactionOverview, - loadTransactionOverview + loadTransactionOverview, + getTransactionListPageParams }; }); diff --git a/src/stores/setting.ts b/src/stores/setting.ts index 60cc7a67..19143954 100644 --- a/src/stores/setting.ts +++ b/src/stores/setting.ts @@ -182,6 +182,18 @@ export const useSettingsStore = defineStore('settings', () => { updateUserApplicationCloudSettingValue('timezoneUsedForStatisticsInHomePage', value); } + function setOverviewAccountFilterInHomePage(value: Record): void { + updateApplicationSettingsValue('overviewAccountFilterInHomePage', value); + appSettings.value.overviewAccountFilterInHomePage = value; + updateUserApplicationCloudSettingValue('overviewAccountFilterInHomePage', value); + } + + function setOverviewTransactionCategoryFilterInHomePage(value: Record): void { + updateApplicationSettingsValue('overviewTransactionCategoryFilterInHomePage', value); + appSettings.value.overviewTransactionCategoryFilterInHomePage = value; + updateUserApplicationCloudSettingValue('overviewTransactionCategoryFilterInHomePage', value); + } + // Transaction List Page function setItemsCountInTransactionListPage(value: number): void { updateApplicationSettingsValue('itemsCountInTransactionListPage', value); @@ -428,6 +440,8 @@ export const useSettingsStore = defineStore('settings', () => { // -- Overview Page setShowAmountInHomePage, setTimezoneUsedForStatisticsInHomePage, + setOverviewAccountFilterInHomePage, + setOverviewTransactionCategoryFilterInHomePage, // -- Transaction List Page setItemsCountInTransactionListPage, setShowTotalAmountInTransactionListPage, diff --git a/src/views/base/settings/AccountFilterSettingPageBase.ts b/src/views/base/settings/AccountFilterSettingPageBase.ts index a09a2200..9e34ccc2 100644 --- a/src/views/base/settings/AccountFilterSettingPageBase.ts +++ b/src/views/base/settings/AccountFilterSettingPageBase.ts @@ -4,6 +4,7 @@ import { useSettingsStore } from '@/stores/setting.ts'; import { useAccountsStore } from '@/stores/account.ts'; import { useTransactionsStore } from '@/stores/transaction.ts'; import { useStatisticsStore } from '@/stores/statistics.ts'; +import { useOverviewStore } from '@/stores/overview.ts'; import type { Account, AccountCategoriesWithVisibleCount } from '@/models/account.ts'; @@ -13,11 +14,14 @@ import { isAccountOrSubAccountsAllChecked } from '@/lib/account.ts'; -export function useAccountFilterSettingPageBase(type?: string) { +export type AccountFilterType = 'statisticsDefault' | 'statisticsCurrent' | 'homePageOverview' | 'transactionListCurrent' | 'accountListTotalAmount'; + +export function useAccountFilterSettingPageBase(type?: AccountFilterType) { const settingsStore = useSettingsStore(); const accountsStore = useAccountsStore(); const transactionsStore = useTransactionsStore(); const statisticsStore = useStatisticsStore(); + const overviewStore = useOverviewStore(); const loading = ref(true); const showHidden = ref(false); @@ -40,7 +44,7 @@ export function useAccountFilterSettingPageBase(type?: string) { }); const allowHiddenAccount = computed(() => { - return type === 'statisticsDefault' || type === 'statisticsCurrent' || type === 'transactionListCurrent'; + return type === 'statisticsDefault' || type === 'statisticsCurrent' || type === 'homePageOverview' || type === 'transactionListCurrent'; }); const allCategorizedAccounts = computed(() => getCategorizedAccountsWithVisibleCount(accountsStore.allCategorizedAccountsMap)); @@ -85,6 +89,9 @@ export function useAccountFilterSettingPageBase(type?: string) { } else if (type === 'statisticsCurrent') { filterAccountIds.value = Object.assign(allAccountIds, statisticsStore.transactionStatisticsFilter.filterAccountIds); return true; + } else if (type === 'homePageOverview') { + filterAccountIds.value = Object.assign(allAccountIds, settingsStore.appSettings.overviewAccountFilterInHomePage); + return true; } else if (type === 'transactionListCurrent') { for (const accountId in transactionsStore.allFilterAccountIds) { if (!Object.prototype.hasOwnProperty.call(transactionsStore.allFilterAccountIds, accountId)) { @@ -146,6 +153,9 @@ export function useAccountFilterSettingPageBase(type?: string) { changed = statisticsStore.updateTransactionStatisticsFilter({ filterAccountIds: filteredAccountIds }); + } else if (type === 'homePageOverview') { + settingsStore.setOverviewAccountFilterInHomePage(filteredAccountIds); + overviewStore.updateTransactionOverviewInvalidState(true); } else if (type === 'transactionListCurrent') { changed = transactionsStore.updateTransactionListFilter({ accountIds: isAllSelected ? '' : finalAccountIds diff --git a/src/views/base/settings/AppCloudSyncPageBase.ts b/src/views/base/settings/AppCloudSyncPageBase.ts index 5a70c00e..293c2e0e 100644 --- a/src/views/base/settings/AppCloudSyncPageBase.ts +++ b/src/views/base/settings/AppCloudSyncPageBase.ts @@ -28,7 +28,9 @@ export const ALL_APPLICATION_CLOUD_SETTINGS: CategorizedApplicationCloudSettingI categoryName: 'Overview Page', items: [ { settingKey: 'showAmountInHomePage', settingName: 'Show Amount', mobile: true, desktop: true }, - { settingKey: 'timezoneUsedForStatisticsInHomePage', settingName: 'Timezone Used for Statistics', mobile: true, desktop: true } + { settingKey: 'timezoneUsedForStatisticsInHomePage', settingName: 'Timezone Used for Statistics', mobile: true, desktop: true }, + { settingKey: 'overviewAccountFilterInHomePage', settingName: 'Accounts Included in Overview Statistics', mobile: true, desktop: true }, + { settingKey: 'overviewTransactionCategoryFilterInHomePage', settingName: 'Transaction Categories Included in Overview Statistics', mobile: true, desktop: true } ] }, { diff --git a/src/views/base/settings/AppSettingsPageBase.ts b/src/views/base/settings/AppSettingsPageBase.ts index 0d831302..3dc6f566 100644 --- a/src/views/base/settings/AppSettingsPageBase.ts +++ b/src/views/base/settings/AppSettingsPageBase.ts @@ -5,11 +5,16 @@ import { useI18n } from '@/locales/helpers.ts'; import { useSettingsStore } from '@/stores/setting.ts'; import { useAccountsStore } from '@/stores/account.ts'; import { useTransactionsStore } from '@/stores/transaction.ts'; +import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts'; import { useOverviewStore } from '@/stores/overview.ts'; import { useStatisticsStore } from '@/stores/statistics.ts'; import type { NameValue, TypeAndDisplayName } from '@/core/base.ts'; import type { LocalizedTimezoneInfo } from '@/core/timezone.ts'; +import { CategoryType } from '@/core/category.ts'; +import type { Account } from '@/models/account.ts'; + +import { isObjectEmpty } from '@/lib/common.ts'; export function useAppSettingPageBase() { const { tt, getAllTimezones, getAllTimezoneTypesUsedForStatistics, getAllCurrencySortingTypes, setTimeZone } = useI18n(); @@ -17,10 +22,12 @@ export function useAppSettingPageBase() { const settingsStore = useSettingsStore(); const accountsStore = useAccountsStore(); const transactionsStore = useTransactionsStore(); + const transactionCategoriesStore = useTransactionCategoriesStore(); const overviewStore = useOverviewStore(); const statisticsStore = useStatisticsStore(); const loadingAccounts = ref(false); + const loadingTransactionCategories = ref(false); const allThemes = computed(() => { return [ @@ -42,7 +49,9 @@ export function useAppSettingPageBase() { ]; }); + const hasAnyAccount = computed(() => accountsStore.allPlainAccounts.length > 0); const hasAnyVisibleAccount = computed(() => accountsStore.allVisibleAccountsCount > 0); + const hasAnyTransactionCategory = computed(() => !isObjectEmpty(transactionCategoriesStore.allTransactionCategoriesMap)); const timeZone = computed({ get: () => settingsStore.appSettings.timeZone, @@ -114,12 +123,26 @@ export function useAppSettingPageBase() { set: (value: number) => settingsStore.setCurrencySortByInExchangeRatesPage(value) }); + const accountsIncludedInHomePageOverviewDisplayContent = computed(() => { + const excludeAccountIds = settingsStore.appSettings.overviewAccountFilterInHomePage; + return getIncludedAccountsDisplayContent(excludeAccountIds, accountsStore.allPlainAccounts); + }); + const accountsIncludedInTotalDisplayContent = computed(() => { - if (loadingAccounts.value || !accountsStore.allVisiblePlainAccounts || !accountsStore.allVisiblePlainAccounts.length) { + const excludeAccountIds = settingsStore.appSettings.totalAmountExcludeAccountIds; + return getIncludedAccountsDisplayContent(excludeAccountIds, accountsStore.allVisiblePlainAccounts); + }); + + const transactionCategoriesIncludedInHomePageOverviewDisplayContent = computed(() => { + const excludeAccountIds = settingsStore.appSettings.overviewTransactionCategoryFilterInHomePage; + return getIncludedTransactionCategoriesDisplayContent(excludeAccountIds); + }); + + function getIncludedAccountsDisplayContent(excludeAccountIds: Record, allAccounts: Account[]): string { + if (loadingAccounts.value || !allAccounts || !allAccounts.length) { return ''; } - const excludeAccountIds = settingsStore.appSettings.totalAmountExcludeAccountIds; let hasExcludeAccount = false; for (const accountId in excludeAccountIds) { @@ -137,27 +160,76 @@ export function useAppSettingPageBase() { return tt('All'); } - let allVisibleAccountExcluded = true; + let allAccountExcluded = true; - for (let i = 0; i < accountsStore.allVisiblePlainAccounts.length; i++) { - const account = accountsStore.allVisiblePlainAccounts[i]; + for (let i = 0; i < allAccounts.length; i++) { + const account = allAccounts[i]; if (!excludeAccountIds[account.id]) { - allVisibleAccountExcluded = false; + allAccountExcluded = false; break; } } - if (allVisibleAccountExcluded) { + if (allAccountExcluded) { return tt('None'); } return tt('Partial'); - }); + } + + function getIncludedTransactionCategoriesDisplayContent(excludeTransactionCategoryIds: Record): string { + if (loadingTransactionCategories.value || !transactionCategoriesStore.allTransactionCategoriesMap) { + return ''; + } + + let hasExcludeTransactionCategory = false; + + for (const transactionCategoryId in excludeTransactionCategoryIds) { + if (!Object.prototype.hasOwnProperty.call(excludeTransactionCategoryIds, transactionCategoryId)) { + continue; + } + + if (excludeTransactionCategoryIds[transactionCategoryId] && transactionCategoriesStore.allTransactionCategoriesMap[transactionCategoryId]) { + hasExcludeTransactionCategory = true; + break; + } + } + + if (!hasExcludeTransactionCategory) { + return tt('All'); + } + + let allTransactionCategoryExcluded = true; + + for (const transactionCategoryId in transactionCategoriesStore.allTransactionCategoriesMap) { + if (!Object.prototype.hasOwnProperty.call(transactionCategoriesStore.allTransactionCategoriesMap, transactionCategoryId)) { + continue; + } + + const transactionCategory = transactionCategoriesStore.allTransactionCategoriesMap[transactionCategoryId]; + + if (transactionCategory.type !== CategoryType.Income && transactionCategory.type !== CategoryType.Expense) { + continue; + } + + if (!excludeTransactionCategoryIds[transactionCategory.id]) { + allTransactionCategoryExcluded = false; + break; + } + } + + if (allTransactionCategoryExcluded) { + return tt('None'); + } + + return tt('Partial'); + } return { // states loadingAccounts, + loadingTransactionCategories, // computed states allThemes, allTimezones, @@ -165,7 +237,9 @@ export function useAppSettingPageBase() { allCurrencySortingTypes, allAutoSaveTransactionDraftTypes, timeZone, + hasAnyAccount, hasAnyVisibleAccount, + hasAnyTransactionCategory, isAutoUpdateExchangeRatesData, showAccountBalance, showAmountInHomePage, @@ -176,6 +250,8 @@ export function useAppSettingPageBase() { autoSaveTransactionDraft, isAutoGetCurrentGeoLocation, currencySortByInExchangeRatesPage, - accountsIncludedInTotalDisplayContent + accountsIncludedInHomePageOverviewDisplayContent, + accountsIncludedInTotalDisplayContent, + transactionCategoriesIncludedInHomePageOverviewDisplayContent }; } diff --git a/src/views/base/settings/CategoryFilterSettingPageBase.ts b/src/views/base/settings/CategoryFilterSettingPageBase.ts index e7533fb9..180dedf5 100644 --- a/src/views/base/settings/CategoryFilterSettingPageBase.ts +++ b/src/views/base/settings/CategoryFilterSettingPageBase.ts @@ -6,6 +6,7 @@ import { useSettingsStore } from '@/stores/setting.ts'; import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts'; import { useTransactionsStore } from '@/stores/transaction.ts'; import { useStatisticsStore } from '@/stores/statistics.ts'; +import { useOverviewStore } from '@/stores/overview.ts'; import { CategoryType } from '@/core/category.ts'; import type { TransactionCategory, TransactionCategoriesWithVisibleCount } from '@/models/transaction_category.ts'; @@ -21,13 +22,16 @@ import { isCategoryOrSubCategoriesAllChecked } from '@/lib/category.ts'; -export function useCategoryFilterSettingPageBase(type?: string, allowCategoryTypesStr?: string) { +export type CategoryFilterType = 'statisticsDefault' | 'statisticsCurrent' | 'homePageOverview' | 'transactionListCurrent'; + +export function useCategoryFilterSettingPageBase(type?: CategoryFilterType, allowCategoryTypesStr?: string) { const { tt } = useI18n(); const settingsStore = useSettingsStore(); const transactionCategoriesStore = useTransactionCategoriesStore(); const transactionsStore = useTransactionsStore(); const statisticsStore = useStatisticsStore(); + const overviewStore = useOverviewStore(); const allowCategoryTypes: Record | undefined = allowCategoryTypesStr ? arrayItemToObjectField(allowCategoryTypesStr.split(','), true) : undefined; @@ -100,6 +104,9 @@ export function useCategoryFilterSettingPageBase(type?: string, allowCategoryTyp } else if (type === 'statisticsCurrent') { filterCategoryIds.value = Object.assign(allCategoryIds, statisticsStore.transactionStatisticsFilter.filterCategoryIds); return true; + } else if (type === 'homePageOverview') { + filterCategoryIds.value = Object.assign(allCategoryIds, settingsStore.appSettings.overviewTransactionCategoryFilterInHomePage); + return true; } else if (type === 'transactionListCurrent') { for (const categoryId in transactionsStore.allFilterCategoryIds) { if (!Object.prototype.hasOwnProperty.call(transactionsStore.allFilterCategoryIds, categoryId)) { @@ -157,6 +164,9 @@ export function useCategoryFilterSettingPageBase(type?: string, allowCategoryTyp changed = statisticsStore.updateTransactionStatisticsFilter({ filterCategoryIds: filteredCategoryIds }); + } else if (type === 'homePageOverview') { + settingsStore.setOverviewTransactionCategoryFilterInHomePage(filteredCategoryIds); + overviewStore.updateTransactionOverviewInvalidState(true); } else if (type === 'transactionListCurrent') { changed = transactionsStore.updateTransactionListFilter({ categoryIds: isAllSelected ? '' : finalCategoryIds diff --git a/src/views/desktop/HomePage.vue b/src/views/desktop/HomePage.vue index ab704387..c9970fb6 100644 --- a/src/views/desktop/HomePage.vue +++ b/src/views/desktop/HomePage.vue @@ -34,7 +34,7 @@ {{ transactionOverview && transactionOverview.thisMonth ? getDisplayIncomeAmount(transactionOverview.thisMonth) : '-' }} - {{ tt('View Details') }} + {{ tt('View Details') }} @@ -135,7 +135,7 @@ :datetime="displayDateRange?.thisWeek?.startTime + '-' + displayDateRange?.thisWeek?.endTime" > @@ -151,7 +151,7 @@ :datetime="displayDateRange?.thisMonth?.startTime + '-' + displayDateRange?.thisMonth?.endTime" > @@ -167,7 +167,7 @@ :datetime="displayDateRange?.thisYear?.displayTime || ''" > @@ -199,6 +199,7 @@ import { useI18n } from '@/locales/helpers.ts'; import { useHomePageBase } from '@/views/base/HomePageBase.ts'; import { useAccountsStore } from '@/stores/account.ts'; +import { useTransactionCategoriesStore } from '@/stores/transactionCategory.ts'; import { useOverviewStore } from '@/stores/overview.ts'; import { type NumeralSystem } from '@/core/numeral.ts'; @@ -242,6 +243,7 @@ const { } = useHomePageBase(); const accountsStore = useAccountsStore(); +const transactionCategoriesStore = useTransactionCategoriesStore(); const overviewStore = useOverviewStore(); const snackbar = useTemplateRef('snackbar'); @@ -258,7 +260,12 @@ function clickMonthlyIncomeOrExpense(e: MonthlyIncomeAndExpenseCardClickEvent): const maxTime = getUnixTimeBeforeUnixTime(getUnixTimeAfterUnixTime(minTime, 1, 'months'), 1, 'seconds'); const type = e.transactionType; - router.push(`/transaction/list?type=${type}&dateType=${DateRange.Custom.type}&maxTime=${maxTime}&minTime=${minTime}`); + router.push(`/transaction/list?${overviewStore.getTransactionListPageParams({ + type: type, + dateType: DateRange.Custom.type, + minTime: minTime, + maxTime: maxTime + })}`); } const monthlyIncomeAndExpenseData = computed(() => { @@ -298,6 +305,7 @@ function reload(force: boolean): void { const promises = [ accountsStore.loadAllAccounts({ force: false }), + transactionCategoriesStore.loadAllCategories({ force: false }), overviewStore.loadTransactionOverview({ force: force, loadLast11Months: true }) ]; diff --git a/src/views/desktop/app/settings/tabs/AppBasicSettingTab.vue b/src/views/desktop/app/settings/tabs/AppBasicSettingTab.vue index 24dc8d8f..cf43120d 100644 --- a/src/views/desktop/app/settings/tabs/AppBasicSettingTab.vue +++ b/src/views/desktop/app/settings/tabs/AppBasicSettingTab.vue @@ -110,6 +110,38 @@ v-model="timezoneUsedForStatisticsInHomePage" /> + + + + + + + + @@ -241,6 +273,16 @@ + + + + + + + + @@ -252,6 +294,7 @@