Skip to content

Commit

Permalink
use the account / transaction category filter of the statistics page …
Browse files Browse the repository at this point in the history
…when navigating from the statistics page to the transaction list page
  • Loading branch information
mayswind committed Jul 7, 2024
1 parent dad3f10 commit d0e8419
Show file tree
Hide file tree
Showing 4 changed files with 91 additions and 1 deletion.
29 changes: 29 additions & 0 deletions src/lib/account.js
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,35 @@ export function getAllFilteredAccountsBalance(categorizedAccounts, accountFilter

return ret;
}

export function getFinalAccountIdsByFilteredAccountIds(allAccountsMap, filteredAccountIds) {
let finalAccountIds = '';

if (!allAccountsMap) {
return finalAccountIds;
}

for (let accountId in allAccountsMap) {
if (!Object.prototype.hasOwnProperty.call(allAccountsMap, accountId)) {
continue;
}

const account = allAccountsMap[accountId];

if (filteredAccountIds && !isAccountOrSubAccountsAllChecked(account, filteredAccountIds)) {
continue;
}

if (finalAccountIds.length > 0) {
finalAccountIds += ',';
}

finalAccountIds += account.id;
}

return finalAccountIds;
}

export function getUnifiedSelectedAccountsCurrencyOrDefaultCurrency(allAccounts, selectedAccountIds, defaultCurrency) {
if (!selectedAccountIds) {
return defaultCurrency;
Expand Down
28 changes: 28 additions & 0 deletions src/lib/category.js
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,34 @@ export function allVisiblePrimaryTransactionCategoriesByType(allTransactionCateg
return allVisibleCategories[type.toString()].visibleCategories;
}

export function getFinalCategoryIdsByFilteredCategoryIds(allTransactionCategoriesMap, filteredCategoryIds) {
let finalCategoryIds = '';

if (!allTransactionCategoriesMap) {
return finalCategoryIds;
}

for (let categoryId in allTransactionCategoriesMap) {
if (!Object.prototype.hasOwnProperty.call(allTransactionCategoriesMap, categoryId)) {
continue;
}

const category = allTransactionCategoriesMap[categoryId];

if (filteredCategoryIds && !isCategoryOrSubCategoriesAllChecked(category, filteredCategoryIds)) {
continue;
}

if (finalCategoryIds.length > 0) {
finalCategoryIds += ',';
}

finalCategoryIds += category.id;
}

return finalCategoryIds;
}

export function isSubCategoryIdAvailable(categories, categoryId) {
if (!categories || !categories.length) {
return false;
Expand Down
16 changes: 16 additions & 0 deletions src/lib/common.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,22 @@ export function isEquals(obj1, obj2) {
}
}

export function isObjectEmpty(obj) {
if (!obj) {
return true;
}

for (let field in obj) {
if (!Object.prototype.hasOwnProperty.call(obj, field)) {
continue;
}

return false;
}

return true;
}

export function getObjectOwnFieldCount(object) {
let count = 0;

Expand Down
19 changes: 18 additions & 1 deletion src/stores/statistics.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,20 @@ import logger from '@/lib/logger.js';
import {
isEquals,
isNumber,
isObject,
isYearMonth,
isObject
isObjectEmpty
} from '@/lib/common.js';
import {
getYearAndMonthFromUnixTime,
getDateRangeByDateType
} from '@/lib/datetime.js';
import {
getFinalAccountIdsByFilteredAccountIds
} from '@/lib/account.js';
import {
getFinalCategoryIdsByFilteredCategoryIds
} from '@/lib/category.js';
import {
sortStatisticsItems
} from '@/lib/statistics.js';
Expand Down Expand Up @@ -736,6 +743,8 @@ export const useStatisticsStore = defineStore('statistics', {
}
},
getTransactionListPageParams(analysisType, item, dateRange) {
const accountsStore = useAccountsStore();
const transactionCategoriesStore = useTransactionCategoriesStore();
const querys = [];

if (this.transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.IncomeByAccount.type
Expand All @@ -755,11 +764,19 @@ export const useStatisticsStore = defineStore('statistics', {
|| this.transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.AccountTotalAssets.type
|| this.transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.AccountTotalLiabilities.type) {
querys.push('accountIds=' + item.id);

if (!isObjectEmpty(this.transactionStatisticsFilter.filterCategoryIds)) {
querys.push('categoryIds=' + getFinalCategoryIdsByFilteredCategoryIds(transactionCategoriesStore.allTransactionCategoriesMap, this.transactionStatisticsFilter.filterCategoryIds));
}
} else if (this.transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.IncomeByPrimaryCategory.type
|| this.transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.IncomeBySecondaryCategory.type
|| this.transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.ExpenseByPrimaryCategory.type
|| this.transactionStatisticsFilter.chartDataType === statisticsConstants.allChartDataTypes.ExpenseBySecondaryCategory.type) {
querys.push('categoryIds=' + item.id);

if (!isObjectEmpty(this.transactionStatisticsFilter.filterAccountIds)) {
querys.push('accountIds=' + getFinalAccountIdsByFilteredAccountIds(accountsStore.allAccountsMap, this.transactionStatisticsFilter.filterAccountIds));
}
}

if (analysisType === statisticsConstants.allAnalysisTypes.CategoricalAnalysis
Expand Down

0 comments on commit d0e8419

Please sign in to comment.