mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 08:44:25 +08:00
code refactor
This commit is contained in:
@@ -2,82 +2,6 @@ import { AccountType, AccountCategory } from '@/core/account.ts';
|
||||
import { PARENT_ACCOUNT_CURRENCY_PLACEHOLDER } from '@/consts/currency.ts';
|
||||
import { type AccountBalance, type CategorizedAccount, type AccountCategoriesWithVisibleCount, Account } from '@/models/account.ts';
|
||||
|
||||
export function getAccountOrSubAccountId(account: Account, subAccountId: string): string | null {
|
||||
if (account.type === AccountType.SingleAccount.type) {
|
||||
return account.id;
|
||||
} else if (account.type === AccountType.MultiSubAccounts.type && !subAccountId) {
|
||||
return account.id;
|
||||
} else if (account.type === AccountType.MultiSubAccounts.type && subAccountId) {
|
||||
if (!account.childrenAccounts || !account.childrenAccounts.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (let i = 0; i < account.childrenAccounts.length; i++) {
|
||||
const subAccount = account.childrenAccounts[i];
|
||||
|
||||
if (subAccountId && subAccountId === subAccount.id) {
|
||||
return subAccount.id;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function getAccountOrSubAccountComment(account: Account, subAccountId: string): string | null {
|
||||
if (account.type === AccountType.SingleAccount.type) {
|
||||
return account.comment;
|
||||
} else if (account.type === AccountType.MultiSubAccounts.type && !subAccountId) {
|
||||
return account.comment;
|
||||
} else if (account.type === AccountType.MultiSubAccounts.type && subAccountId) {
|
||||
if (!account.childrenAccounts || !account.childrenAccounts.length) {
|
||||
return null;
|
||||
}
|
||||
|
||||
for (let i = 0; i < account.childrenAccounts.length; i++) {
|
||||
const subAccount = account.childrenAccounts[i];
|
||||
|
||||
if (subAccountId && subAccountId === subAccount.id) {
|
||||
return subAccount.comment;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
} else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function getSubAccountCurrencies(account: Account, showHidden: boolean, subAccountId: string): string[] {
|
||||
if (!account.childrenAccounts || !account.childrenAccounts.length) {
|
||||
return [];
|
||||
}
|
||||
|
||||
const subAccountCurrenciesMap: Record<string, boolean> = {};
|
||||
const subAccountCurrencies: string[] = [];
|
||||
|
||||
for (let i = 0; i < account.childrenAccounts.length; i++) {
|
||||
const subAccount = account.childrenAccounts[i];
|
||||
|
||||
if (!showHidden && subAccount.hidden) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (subAccountId && subAccountId === subAccount.id) {
|
||||
return [subAccount.currency];
|
||||
} else {
|
||||
if (!subAccountCurrenciesMap[subAccount.currency]) {
|
||||
subAccountCurrenciesMap[subAccount.currency] = true;
|
||||
subAccountCurrencies.push(subAccount.currency);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return subAccountCurrencies;
|
||||
}
|
||||
|
||||
export function getCategorizedAccountsMap(allAccounts: Account[]): Record<number, CategorizedAccount> {
|
||||
const ret: Record<number, CategorizedAccount> = {};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user