diff --git a/pkg/api/accounts.go b/pkg/api/accounts.go index f0bf9f41..1624dd02 100644 --- a/pkg/api/accounts.go +++ b/pkg/api/accounts.go @@ -154,7 +154,7 @@ func (a *AccountsApi) AccountCreateHandler(c *core.WebContext) (any, *errs.Error return nil, errs.ErrClientTimezoneOffsetInvalid } - if accountCreateReq.Category < models.ACCOUNT_CATEGORY_CASH || accountCreateReq.Category > models.ACCOUNT_CATEGORY_INVESTMENT { + if accountCreateReq.Category < models.ACCOUNT_CATEGORY_CASH || accountCreateReq.Category > models.ACCOUNT_CATEGORY_CERTIFICATE_OF_DEPOSIT { log.Warnf(c, "[accounts.AccountCreateHandler] account category invalid, category is %d", accountCreateReq.Category) return nil, errs.ErrAccountCategoryInvalid } @@ -288,7 +288,7 @@ func (a *AccountsApi) AccountModifyHandler(c *core.WebContext) (any, *errs.Error return nil, errs.NewIncompleteOrIncorrectSubmissionError(err) } - if accountModifyReq.Category < models.ACCOUNT_CATEGORY_CASH || accountModifyReq.Category > models.ACCOUNT_CATEGORY_INVESTMENT { + if accountModifyReq.Category < models.ACCOUNT_CATEGORY_CASH || accountModifyReq.Category > models.ACCOUNT_CATEGORY_CERTIFICATE_OF_DEPOSIT { log.Warnf(c, "[accounts.AccountModifyHandler] account category invalid, category is %d", accountModifyReq.Category) return nil, errs.ErrAccountCategoryInvalid } diff --git a/pkg/models/account.go b/pkg/models/account.go index 76dee610..e883b3f8 100644 --- a/pkg/models/account.go +++ b/pkg/models/account.go @@ -8,33 +8,39 @@ type AccountCategory byte // Account categories const ( - ACCOUNT_CATEGORY_CASH AccountCategory = 1 - ACCOUNT_CATEGORY_DEBIT_CARD AccountCategory = 2 - ACCOUNT_CATEGORY_CREDIT_CARD AccountCategory = 3 - ACCOUNT_CATEGORY_VIRTUAL AccountCategory = 4 - ACCOUNT_CATEGORY_DEBT AccountCategory = 5 - ACCOUNT_CATEGORY_RECEIVABLES AccountCategory = 6 - ACCOUNT_CATEGORY_INVESTMENT AccountCategory = 7 + ACCOUNT_CATEGORY_CASH AccountCategory = 1 + ACCOUNT_CATEGORY_CHECKING_ACCOUNT AccountCategory = 2 + ACCOUNT_CATEGORY_CREDIT_CARD AccountCategory = 3 + ACCOUNT_CATEGORY_VIRTUAL AccountCategory = 4 + ACCOUNT_CATEGORY_DEBT AccountCategory = 5 + ACCOUNT_CATEGORY_RECEIVABLES AccountCategory = 6 + ACCOUNT_CATEGORY_INVESTMENT AccountCategory = 7 + ACCOUNT_CATEGORY_SAVINGS_ACCOUNT AccountCategory = 8 + ACCOUNT_CATEGORY_CERTIFICATE_OF_DEPOSIT AccountCategory = 9 ) var assetAccountCategory = map[AccountCategory]bool{ - ACCOUNT_CATEGORY_CASH: true, - ACCOUNT_CATEGORY_DEBIT_CARD: true, - ACCOUNT_CATEGORY_CREDIT_CARD: false, - ACCOUNT_CATEGORY_VIRTUAL: true, - ACCOUNT_CATEGORY_DEBT: false, - ACCOUNT_CATEGORY_RECEIVABLES: true, - ACCOUNT_CATEGORY_INVESTMENT: true, + ACCOUNT_CATEGORY_CASH: true, + ACCOUNT_CATEGORY_CHECKING_ACCOUNT: true, + ACCOUNT_CATEGORY_CREDIT_CARD: false, + ACCOUNT_CATEGORY_VIRTUAL: true, + ACCOUNT_CATEGORY_DEBT: false, + ACCOUNT_CATEGORY_RECEIVABLES: true, + ACCOUNT_CATEGORY_INVESTMENT: true, + ACCOUNT_CATEGORY_SAVINGS_ACCOUNT: true, + ACCOUNT_CATEGORY_CERTIFICATE_OF_DEPOSIT: true, } var liabilityAccountCategory = map[AccountCategory]bool{ - ACCOUNT_CATEGORY_CASH: false, - ACCOUNT_CATEGORY_DEBIT_CARD: false, - ACCOUNT_CATEGORY_CREDIT_CARD: true, - ACCOUNT_CATEGORY_VIRTUAL: false, - ACCOUNT_CATEGORY_DEBT: true, - ACCOUNT_CATEGORY_RECEIVABLES: false, - ACCOUNT_CATEGORY_INVESTMENT: false, + ACCOUNT_CATEGORY_CASH: false, + ACCOUNT_CATEGORY_CHECKING_ACCOUNT: false, + ACCOUNT_CATEGORY_CREDIT_CARD: true, + ACCOUNT_CATEGORY_VIRTUAL: false, + ACCOUNT_CATEGORY_DEBT: true, + ACCOUNT_CATEGORY_RECEIVABLES: false, + ACCOUNT_CATEGORY_INVESTMENT: false, + ACCOUNT_CATEGORY_SAVINGS_ACCOUNT: false, + ACCOUNT_CATEGORY_CERTIFICATE_OF_DEPOSIT: false, } // AccountType represents account type diff --git a/pkg/models/account_test.go b/pkg/models/account_test.go index 5682cee7..458d95f4 100644 --- a/pkg/models/account_test.go +++ b/pkg/models/account_test.go @@ -11,7 +11,7 @@ func TestAccountInfoResponseSliceLess(t *testing.T) { var accountRespSlice AccountInfoResponseSlice accountRespSlice = append(accountRespSlice, &AccountInfoResponse{ Id: 1, - Category: ACCOUNT_CATEGORY_DEBIT_CARD, + Category: ACCOUNT_CATEGORY_CHECKING_ACCOUNT, DisplayOrder: int32(1), }) accountRespSlice = append(accountRespSlice, &AccountInfoResponse{ diff --git a/src/consts/account.js b/src/consts/account.js index 550cd73b..77dc2969 100644 --- a/src/consts/account.js +++ b/src/consts/account.js @@ -6,7 +6,12 @@ const allAccountCategories = [ }, { id: 2, - name: 'Debit Card', + name: 'Checking Account', + defaultAccountIconId: '100' + }, + { + id: 8, + name: 'Savings Account', defaultAccountIconId: '100' }, { @@ -29,6 +34,11 @@ const allAccountCategories = [ name: 'Receivables', defaultAccountIconId: '700' }, + { + id: 9, + name: 'Certificate of Deposit', + defaultAccountIconId: '110' + }, { id: 7, name: 'Investment Account', diff --git a/src/lib/account.js b/src/lib/account.js index e17ce2fd..e4bcb87a 100644 --- a/src/lib/account.js +++ b/src/lib/account.js @@ -100,7 +100,7 @@ export function getSubAccountCurrencies(account, showHidden, subAccountId) { return subAccountCurrencies; } -export function getCategorizedAccounts(allAccounts) { +export function getCategorizedAccountsMap(allAccounts) { const ret = {}; for (let i = 0; i < allAccounts.length; i++) { @@ -128,8 +128,26 @@ export function getCategorizedAccounts(allAccounts) { return ret; } +export function getCategorizedAccounts(allAccounts) { + const ret = []; + const categorizedAccounts = getCategorizedAccountsMap(allAccounts); + + for (let i = 0; i < accountConstants.allCategories.length; i++) { + const category = accountConstants.allCategories[i]; + + if (!categorizedAccounts[category.id]) { + continue; + } + + const accountCategory = categorizedAccounts[category.id]; + ret.push(accountCategory); + } + + return ret; +} + export function getCategorizedAccountsWithVisibleCount(categorizedAccounts) { - const ret = {}; + const ret = []; for (let i = 0; i < accountConstants.allCategories.length; i++) { const accountCategory = accountConstants.allCategories[i]; @@ -181,7 +199,7 @@ export function getCategorizedAccountsWithVisibleCount(categorizedAccounts) { } if (allAccounts.length > 0) { - ret[accountCategory.id] = { + ret.push({ category: accountCategory.id, name: accountCategory.name, icon: accountCategory.defaultAccountIconId, @@ -191,7 +209,7 @@ export function getCategorizedAccountsWithVisibleCount(categorizedAccounts) { allSubAccounts: allSubAccounts, allVisibleSubAccountCounts: allVisibleSubAccountCounts, allFirstVisibleSubAccountIndexes: allFirstVisibleSubAccountIndexes - }; + }); } } diff --git a/src/lib/i18n.js b/src/lib/i18n.js index 356c3218..c934555e 100644 --- a/src/lib/i18n.js +++ b/src/lib/i18n.js @@ -55,7 +55,7 @@ import { } from './currency.js'; import { - getCategorizedAccounts, + getCategorizedAccountsMap, getAllFilteredAccountsBalance } from './account.js'; @@ -1280,14 +1280,17 @@ function getEnableDisableOptions(translateFn) { } function getCategorizedAccountsWithDisplayBalance(allVisibleAccounts, showAccountBalance, defaultCurrency, userStore, settingsStore, exchangeRatesStore, translateFn) { - const categorizedAccounts = copyObjectTo(getCategorizedAccounts(allVisibleAccounts), {}); + const ret = []; + const categorizedAccounts = copyObjectTo(getCategorizedAccountsMap(allVisibleAccounts), {}); - for (let category in categorizedAccounts) { - if (!Object.prototype.hasOwnProperty.call(categorizedAccounts, category)) { + for (let i = 0; i < accountConstants.allCategories.length; i++) { + const category = accountConstants.allCategories[i]; + + if (!categorizedAccounts[category.id]) { continue; } - const accountCategory = categorizedAccounts[category]; + const accountCategory = categorizedAccounts[category.id]; if (accountCategory.accounts) { for (let i = 0; i < accountCategory.accounts.length; i++) { @@ -1339,9 +1342,11 @@ function getCategorizedAccountsWithDisplayBalance(allVisibleAccounts, showAccoun } else { accountCategory.displayBalance = '***'; } + + ret.push(accountCategory); } - return categorizedAccounts; + return ret; } function joinMultiText(textArray, translateFn) { diff --git a/src/locales/en.json b/src/locales/en.json index 5e275a96..bb301c7b 100644 --- a/src/locales/en.json +++ b/src/locales/en.json @@ -1395,12 +1395,14 @@ "Income": "Income", "Transfer": "Transfer", "Cash": "Cash", - "Debit Card": "Debit Card", + "Checking Account": "Checking Account", "Credit Card": "Credit Card", "Virtual Account": "Virtual Account", "Debt Account": "Debt Account", "Receivables": "Receivables", "Investment Account": "Investment Account", + "Savings Account": "Savings Account", + "Certificate of Deposit": "Certificate of Deposit", "Balance": "Balance", "Unable to retrieve account list": "Unable to retrieve account list", "Account list is up to date": "Account list is up to date", diff --git a/src/locales/zh_Hans.json b/src/locales/zh_Hans.json index b618aa84..ffacfb69 100644 --- a/src/locales/zh_Hans.json +++ b/src/locales/zh_Hans.json @@ -1395,12 +1395,14 @@ "Income": "收入", "Transfer": "转账", "Cash": "现金", - "Debit Card": "借记卡", + "Checking Account": "借记账户", "Credit Card": "信用卡", "Virtual Account": "虚拟账户", "Debt Account": "负债账户", "Receivables": "应收款项", "Investment Account": "投资账户", + "Savings Account": "储蓄账户", + "Certificate of Deposit": "定期存款", "Balance": "余额", "Unable to retrieve account list": "无法获取账户列表", "Account list is up to date": "账户列表已是最新", diff --git a/src/stores/account.js b/src/stores/account.js index dbf6ea93..02037019 100644 --- a/src/stores/account.js +++ b/src/stores/account.js @@ -10,7 +10,7 @@ import colorConstants from '@/consts/color.js'; import services from '@/lib/services.js'; import logger from '@/lib/logger.js'; import { isNumber, isEquals } from '@/lib/common.js'; -import { getCategorizedAccounts, getAllFilteredAccountsBalance } from '@/lib/account.js'; +import { getCategorizedAccountsMap, getAllFilteredAccountsBalance } from '@/lib/account.js'; function loadAccountList(state, accounts) { state.allAccounts = accounts; @@ -28,7 +28,7 @@ function loadAccountList(state, accounts) { } } - state.allCategorizedAccounts = getCategorizedAccounts(accounts); + state.allCategorizedAccounts = getCategorizedAccountsMap(accounts); } function addAccountToAccountList(state, account) { @@ -56,7 +56,7 @@ function addAccountToAccountList(state, account) { const accountList = state.allCategorizedAccounts[account.category].accounts; accountList.push(account); } else { - state.allCategorizedAccounts = getCategorizedAccounts(state.allAccounts); + state.allCategorizedAccounts = getCategorizedAccountsMap(state.allAccounts); } } diff --git a/src/views/desktop/accounts/ListPage.vue b/src/views/desktop/accounts/ListPage.vue index 2d9201f5..c0203df1 100644 --- a/src/views/desktop/accounts/ListPage.vue +++ b/src/views/desktop/accounts/ListPage.vue @@ -47,7 +47,7 @@ - +