mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 16:54:25 +08:00
support changing account category order
This commit is contained in:
+15
-12
@@ -48,7 +48,7 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
}
|
||||
}
|
||||
|
||||
return Account.sortAccounts(allAccountsList, allAccountsMap.value);
|
||||
return Account.sortAccounts(allAccountsList, settingsStore.accountCategoryDisplayOrders, allAccountsMap.value);
|
||||
});
|
||||
|
||||
const allMixedPlainAccounts = computed<Account[]>(() => {
|
||||
@@ -68,7 +68,7 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
}
|
||||
}
|
||||
|
||||
return Account.sortAccounts(allAccountsList, allAccountsMap.value);
|
||||
return Account.sortAccounts(allAccountsList, settingsStore.accountCategoryDisplayOrders, allAccountsMap.value);
|
||||
});
|
||||
|
||||
const allVisiblePlainAccounts = computed<Account[]>(() => {
|
||||
@@ -95,7 +95,7 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
}
|
||||
}
|
||||
|
||||
return Account.sortAccounts(allVisibleAccounts, allAccountsMap.value);
|
||||
return Account.sortAccounts(allVisibleAccounts, settingsStore.accountCategoryDisplayOrders, allAccountsMap.value);
|
||||
});
|
||||
|
||||
const allAvailableAccountsCount = computed<number>(() => {
|
||||
@@ -148,8 +148,10 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
if (newAccountCategory) {
|
||||
for (const [account, index] of itemAndIndex(allAccounts.value)) {
|
||||
const accountCategory = AccountCategory.valueOf(account.category);
|
||||
const accountCategoryDisplayOrder = settingsStore.accountCategoryDisplayOrders[accountCategory?.type ?? 0] || Number.MAX_SAFE_INTEGER;
|
||||
const newAccountCategoryDisplayOrder = settingsStore.accountCategoryDisplayOrders[newAccountCategory.type] || Number.MAX_SAFE_INTEGER;
|
||||
|
||||
if (accountCategory && accountCategory.displayOrder > newAccountCategory.displayOrder) {
|
||||
if (accountCategory && accountCategoryDisplayOrder > newAccountCategoryDisplayOrder) {
|
||||
insertIndexToAllList = index;
|
||||
break;
|
||||
}
|
||||
@@ -457,8 +459,8 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
return DISPLAY_HIDDEN_AMOUNT;
|
||||
}
|
||||
|
||||
const accountsBalance = getAllFilteredAccountsBalance(allCategorizedAccountsMap.value, account =>
|
||||
!(account.type === AccountType.SingleAccount.type && settingsStore.appSettings.totalAmountExcludeAccountIds[account.id])
|
||||
const accountsBalance = getAllFilteredAccountsBalance(allCategorizedAccountsMap.value, settingsStore.appSettings.accountCategoryOrders,
|
||||
account => !(account.type === AccountType.SingleAccount.type && settingsStore.appSettings.totalAmountExcludeAccountIds[account.id])
|
||||
);
|
||||
let netAssets = 0;
|
||||
let hasUnCalculatedAmount = false;
|
||||
@@ -493,8 +495,8 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
return DISPLAY_HIDDEN_AMOUNT;
|
||||
}
|
||||
|
||||
const accountsBalance = getAllFilteredAccountsBalance(allCategorizedAccountsMap.value, account =>
|
||||
(account.isAsset || false) && !(account.type === AccountType.SingleAccount.type && settingsStore.appSettings.totalAmountExcludeAccountIds[account.id])
|
||||
const accountsBalance = getAllFilteredAccountsBalance(allCategorizedAccountsMap.value, settingsStore.appSettings.accountCategoryOrders,
|
||||
account => (account.isAsset || false) && !(account.type === AccountType.SingleAccount.type && settingsStore.appSettings.totalAmountExcludeAccountIds[account.id])
|
||||
);
|
||||
let totalAssets = 0;
|
||||
let hasUnCalculatedAmount = false;
|
||||
@@ -529,8 +531,8 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
return DISPLAY_HIDDEN_AMOUNT;
|
||||
}
|
||||
|
||||
const accountsBalance = getAllFilteredAccountsBalance(allCategorizedAccountsMap.value, account =>
|
||||
(account.isLiability || false) && !(account.type === AccountType.SingleAccount.type && settingsStore.appSettings.totalAmountExcludeAccountIds[account.id])
|
||||
const accountsBalance = getAllFilteredAccountsBalance(allCategorizedAccountsMap.value, settingsStore.appSettings.accountCategoryOrders,
|
||||
account => (account.isLiability || false) && !(account.type === AccountType.SingleAccount.type && settingsStore.appSettings.totalAmountExcludeAccountIds[account.id])
|
||||
);
|
||||
let totalLiabilities = 0;
|
||||
let hasUnCalculatedAmount = false;
|
||||
@@ -565,7 +567,8 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
return DISPLAY_HIDDEN_AMOUNT;
|
||||
}
|
||||
|
||||
const accountsBalance = getAllFilteredAccountsBalance(allCategorizedAccountsMap.value, account => account.category === accountCategory.type);
|
||||
const accountsBalance = getAllFilteredAccountsBalance(allCategorizedAccountsMap.value, settingsStore.appSettings.accountCategoryOrders,
|
||||
account => account.category === accountCategory.type);
|
||||
let totalBalance = 0;
|
||||
let hasUnCalculatedAmount = false;
|
||||
|
||||
@@ -775,7 +778,7 @@ export const useAccountsStore = defineStore('accounts', () => {
|
||||
updateAccountListInvalidState(false);
|
||||
}
|
||||
|
||||
const accounts = Account.sortAccounts(Account.ofMulti(data.result));
|
||||
const accounts = Account.sortAccounts(Account.ofMulti(data.result), settingsStore.accountCategoryDisplayOrders);
|
||||
|
||||
if (force && data.result && isEquals(allAccounts.value, accounts)) {
|
||||
reject({ message: 'Account list is up to date', isUpToDate: true });
|
||||
|
||||
@@ -296,23 +296,25 @@ export const useExplorersStore = defineStore('explorers', () => {
|
||||
};
|
||||
} else if (dimension === TransactionExplorerDataDimension.SourceAccount) {
|
||||
const primaryAccount = accountsStore.allAccountsMap[transaction.sourceAccount.parentId] ?? transaction.sourceAccount;
|
||||
const primaryAccountCategoryDisplayOrder: number = settingsStore.accountCategoryDisplayOrders[primaryAccount.category] || Number.MAX_SAFE_INTEGER;
|
||||
|
||||
return {
|
||||
categoryName: transaction.sourceAccountName || 'Unknown',
|
||||
categoryNameNeedI18n: !transaction.sourceAccountName,
|
||||
categoryId: transaction.sourceAccountId || 'unknown',
|
||||
categoryIdType: TransactionExplorerDimensionType.Account,
|
||||
categoryDisplayOrders: [primaryAccount.category, primaryAccount.displayOrder, transaction.sourceAccount.displayOrder]
|
||||
categoryDisplayOrders: [primaryAccountCategoryDisplayOrder, primaryAccount.displayOrder, transaction.sourceAccount.displayOrder]
|
||||
};
|
||||
} else if (dimension === TransactionExplorerDataDimension.SourceAccountCategory) {
|
||||
const accountCategory = AccountCategory.valueOf(transaction.sourceAccount.category);
|
||||
const accountCategoryDisplayOrder: number = settingsStore.accountCategoryDisplayOrders[accountCategory?.type ?? 0] || Number.MAX_SAFE_INTEGER;
|
||||
|
||||
return {
|
||||
categoryName: accountCategory?.name || 'Unknown',
|
||||
categoryNameNeedI18n: true,
|
||||
categoryId: accountCategory?.type.toString(10) || 'unknown',
|
||||
categoryIdType: TransactionExplorerDimensionType.Other,
|
||||
categoryDisplayOrders: [accountCategory ? accountCategory.type : 0]
|
||||
categoryDisplayOrders: [accountCategoryDisplayOrder]
|
||||
};
|
||||
} else if (dimension === TransactionExplorerDataDimension.SourceAccountCurrency) {
|
||||
return {
|
||||
@@ -324,23 +326,25 @@ export const useExplorersStore = defineStore('explorers', () => {
|
||||
};
|
||||
} else if (dimension === TransactionExplorerDataDimension.DestinationAccount) {
|
||||
const primaryAccount = accountsStore.allAccountsMap[transaction.destinationAccount?.parentId ?? ''] ?? transaction.destinationAccount;
|
||||
const primaryAccountCategoryDisplayOrder: number = settingsStore.accountCategoryDisplayOrders[primaryAccount?.category || 0] || Number.MAX_SAFE_INTEGER;
|
||||
|
||||
return {
|
||||
categoryName: transaction.type === TransactionType.Transfer ? (transaction.destinationAccountName || 'Unknown') : 'None',
|
||||
categoryNameNeedI18n: transaction.type !== TransactionType.Transfer || !transaction.destinationAccountName,
|
||||
categoryId: transaction.type === TransactionType.Transfer ? (transaction.destinationAccountId || 'unknown') : 'none',
|
||||
categoryIdType: TransactionExplorerDimensionType.Account,
|
||||
categoryDisplayOrders: transaction.type === TransactionType.Transfer && primaryAccount && transaction.destinationAccount ? [primaryAccount.category, primaryAccount.displayOrder, transaction.destinationAccount.displayOrder] : [0]
|
||||
categoryDisplayOrders: transaction.type === TransactionType.Transfer && primaryAccount && transaction.destinationAccount ? [primaryAccountCategoryDisplayOrder, primaryAccount.displayOrder, transaction.destinationAccount.displayOrder] : [0]
|
||||
};
|
||||
} else if (dimension === TransactionExplorerDataDimension.DestinationAccountCategory) {
|
||||
const accountCategory = transaction.type === TransactionType.Transfer && transaction.destinationAccount ? AccountCategory.valueOf(transaction.destinationAccount.category) : undefined;
|
||||
const accountCategoryDisplayOrder: number = settingsStore.accountCategoryDisplayOrders[accountCategory?.type ?? 0] || Number.MAX_SAFE_INTEGER;
|
||||
|
||||
return {
|
||||
categoryName: transaction.type === TransactionType.Transfer ? (accountCategory?.name || 'Unknown') : 'None',
|
||||
categoryNameNeedI18n: true,
|
||||
categoryId: transaction.type === TransactionType.Transfer ? (accountCategory?.name || 'unknown') : 'none',
|
||||
categoryIdType: TransactionExplorerDimensionType.Other,
|
||||
categoryDisplayOrders: transaction.type === TransactionType.Transfer ? [accountCategory?.type || 0] : [0]
|
||||
categoryDisplayOrders: transaction.type === TransactionType.Transfer ? [accountCategoryDisplayOrder] : [0]
|
||||
};
|
||||
} else if (dimension === TransactionExplorerDataDimension.DestinationAccountCurrency) {
|
||||
return {
|
||||
|
||||
@@ -15,6 +15,9 @@ import {
|
||||
ALL_ALLOWED_CLOUD_SYNC_APP_SETTING_KEY_TYPES
|
||||
} from '@/core/setting.ts';
|
||||
|
||||
|
||||
import { AccountCategory } from '@/core/account.ts';
|
||||
|
||||
import {
|
||||
isObject,
|
||||
isString,
|
||||
@@ -41,6 +44,8 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
|
||||
const enableApplicationCloudSync = computed<boolean>(() => getObjectOwnFieldCount(syncedAppSettings.value) > 0);
|
||||
|
||||
const accountCategoryDisplayOrders = computed<Record<number, number>>(() => AccountCategory.allDisplayOrders(appSettings.value.accountCategoryOrders));
|
||||
|
||||
function updateApplicationSettingsValueAndAppSettingsFromCloudSetting(key: string, value: string | number | boolean | Record<string, boolean>): void {
|
||||
const keyItems = key.split('.');
|
||||
const keyFirstPart = keyItems[0] as string;
|
||||
@@ -265,6 +270,12 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
updateUserApplicationCloudSettingValue('totalAmountExcludeAccountIds', value);
|
||||
}
|
||||
|
||||
function setAccountCategoryOrders(value: string): void {
|
||||
updateApplicationSettingsValue('accountCategoryOrders', value);
|
||||
appSettings.value.accountCategoryOrders = value;
|
||||
updateUserApplicationCloudSettingValue('accountCategoryOrders', value);
|
||||
}
|
||||
|
||||
function setHideCategoriesWithoutAccounts(value: boolean): void {
|
||||
updateApplicationSettingsValue('hideCategoriesWithoutAccounts', value);
|
||||
appSettings.value.hideCategoriesWithoutAccounts = value;
|
||||
@@ -459,6 +470,7 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
localeDefaultSettings,
|
||||
// computed states
|
||||
enableApplicationCloudSync,
|
||||
accountCategoryDisplayOrders,
|
||||
// functions
|
||||
// -- Basic Settings
|
||||
setTheme,
|
||||
@@ -491,6 +503,7 @@ export const useSettingsStore = defineStore('settings', () => {
|
||||
setShowTagInInsightsExplorerPage,
|
||||
// -- Account List Page
|
||||
setTotalAmountExcludeAccountIds,
|
||||
setAccountCategoryOrders,
|
||||
setHideCategoriesWithoutAccounts,
|
||||
// -- Exchange Rates Data Page
|
||||
setCurrencySortByInExchangeRatesPage,
|
||||
|
||||
@@ -284,6 +284,7 @@ export const useStatisticsStore = defineStore('statistics', () => {
|
||||
totalExpense += item.amountInDefaultCurrency;
|
||||
}
|
||||
|
||||
const primaryAccountCategoryDisplayOrder = settingsStore.accountCategoryDisplayOrders[item.primaryAccount.category] || Number.MAX_SAFE_INTEGER;
|
||||
const incomeByAccountKey = `${TransactionCategoricalOverviewAnalysisDataItemType.IncomeByAccount}:${item.account.id}`;
|
||||
const expenseByAccountKey = `${TransactionCategoricalOverviewAnalysisDataItemType.ExpenseByAccount}:${item.account.id}`;
|
||||
let incomeByAccountItem: TransactionCategoricalOverviewAnalysisDataItem | undefined = allDataItemsMap[incomeByAccountKey];
|
||||
@@ -294,7 +295,7 @@ export const useStatisticsStore = defineStore('statistics', () => {
|
||||
item.account.id,
|
||||
item.account.name,
|
||||
TransactionCategoricalOverviewAnalysisDataItemType.IncomeByAccount,
|
||||
[item.primaryAccount.category, item.primaryAccount.displayOrder, item.account.displayOrder],
|
||||
[primaryAccountCategoryDisplayOrder, item.primaryAccount.displayOrder, item.account.displayOrder],
|
||||
item.primaryAccount.hidden || item.account.hidden);
|
||||
allDataItemsMap[incomeByAccountKey] = incomeByAccountItem;
|
||||
allIncomeByAccountDataItems.push(incomeByAccountItem);
|
||||
@@ -305,7 +306,7 @@ export const useStatisticsStore = defineStore('statistics', () => {
|
||||
item.account.id,
|
||||
item.account.name,
|
||||
TransactionCategoricalOverviewAnalysisDataItemType.ExpenseByAccount,
|
||||
[item.primaryAccount.category, item.primaryAccount.displayOrder, item.account.displayOrder],
|
||||
[primaryAccountCategoryDisplayOrder, item.primaryAccount.displayOrder, item.account.displayOrder],
|
||||
item.primaryAccount.hidden || item.account.hidden);
|
||||
allDataItemsMap[expenseByAccountKey] = expenseByAccountItem;
|
||||
allExpenseByAccountDataItems.push(expenseByAccountItem);
|
||||
@@ -404,11 +405,12 @@ export const useStatisticsStore = defineStore('statistics', () => {
|
||||
let transferToAccountItem: TransactionCategoricalOverviewAnalysisDataItem | undefined = allDataItemsMap[transferToAccountKey];
|
||||
|
||||
if (!transferToAccountItem) {
|
||||
const relatedPrimaryAccountCategoryDisplayOrder = settingsStore.accountCategoryDisplayOrders[item.relatedPrimaryAccount.category] || Number.MAX_SAFE_INTEGER;
|
||||
transferToAccountItem = createNewTransactionCategoricalOverviewAnalysisDataItem(
|
||||
item.relatedAccount.id,
|
||||
item.relatedAccount.name,
|
||||
TransactionCategoricalOverviewAnalysisDataItemType.ExpenseByAccount,
|
||||
[item.relatedPrimaryAccount.category, item.relatedPrimaryAccount.displayOrder, item.relatedAccount.displayOrder],
|
||||
[relatedPrimaryAccountCategoryDisplayOrder, item.relatedPrimaryAccount.displayOrder, item.relatedAccount.displayOrder],
|
||||
item.relatedPrimaryAccount.hidden || item.relatedAccount.hidden);
|
||||
allDataItemsMap[transferToAccountKey] = transferToAccountItem;
|
||||
allExpenseByAccountDataItems.push(transferToAccountItem);
|
||||
@@ -543,6 +545,8 @@ export const useStatisticsStore = defineStore('statistics', () => {
|
||||
primaryAccount = account;
|
||||
}
|
||||
|
||||
const primaryAccountCategoryDisplayOrder = settingsStore.accountCategoryDisplayOrders[primaryAccount.category] || Number.MAX_SAFE_INTEGER;
|
||||
|
||||
let amount = account.balance;
|
||||
|
||||
if (account.currency !== userStore.currentUserDefaultCurrency) {
|
||||
@@ -566,7 +570,7 @@ export const useStatisticsStore = defineStore('statistics', () => {
|
||||
icon: account.icon || DEFAULT_ACCOUNT_ICON.icon,
|
||||
color: account.color || DEFAULT_ACCOUNT_COLOR,
|
||||
hidden: primaryAccount.hidden || account.hidden,
|
||||
displayOrders: [primaryAccount.category, primaryAccount.displayOrder, account.displayOrder],
|
||||
displayOrders: [primaryAccountCategoryDisplayOrder, primaryAccount.displayOrder, account.displayOrder],
|
||||
totalAmount: amount
|
||||
};
|
||||
|
||||
@@ -888,6 +892,8 @@ export const useStatisticsStore = defineStore('statistics', () => {
|
||||
if (data) {
|
||||
data.totalAmount += amount;
|
||||
} else {
|
||||
const primaryAccountCategoryDisplayOrder = settingsStore.accountCategoryDisplayOrders[item.primaryAccount.category] || Number.MAX_SAFE_INTEGER;
|
||||
|
||||
data = {
|
||||
name: item.account.name,
|
||||
type: 'account',
|
||||
@@ -895,7 +901,7 @@ export const useStatisticsStore = defineStore('statistics', () => {
|
||||
icon: item.account.icon || DEFAULT_ACCOUNT_ICON.icon,
|
||||
color: item.account.color || DEFAULT_ACCOUNT_COLOR,
|
||||
hidden: item.primaryAccount.hidden || item.account.hidden,
|
||||
displayOrders: [item.primaryAccount.category, item.primaryAccount.displayOrder, item.account.displayOrder],
|
||||
displayOrders: [primaryAccountCategoryDisplayOrder, item.primaryAccount.displayOrder, item.account.displayOrder],
|
||||
totalAmount: amount,
|
||||
items: []
|
||||
};
|
||||
@@ -1131,6 +1137,8 @@ export const useStatisticsStore = defineStore('statistics', () => {
|
||||
if (data) {
|
||||
data.totalAmount += item.amountInDefaultCurrency;
|
||||
} else {
|
||||
const primaryAccountCategoryDisplayOrder = settingsStore.accountCategoryDisplayOrders[item.primaryAccount.category] || Number.MAX_SAFE_INTEGER;
|
||||
|
||||
data = {
|
||||
name: item.account.name,
|
||||
type: 'account',
|
||||
@@ -1138,7 +1146,7 @@ export const useStatisticsStore = defineStore('statistics', () => {
|
||||
icon: item.account.icon || DEFAULT_ACCOUNT_ICON.icon,
|
||||
color: item.account.color || DEFAULT_ACCOUNT_COLOR,
|
||||
hidden: item.primaryAccount.hidden || item.account.hidden,
|
||||
displayOrders: [item.primaryAccount.category, item.primaryAccount.displayOrder, item.account.displayOrder],
|
||||
displayOrders: [primaryAccountCategoryDisplayOrder, item.primaryAccount.displayOrder, item.account.displayOrder],
|
||||
totalAmount: item.amountInDefaultCurrency
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user