mirror of
https://github.com/mayswind/ezbookkeeping.git
synced 2026-05-18 16:54:25 +08:00
code refactor
This commit is contained in:
@@ -15,6 +15,26 @@ const (
|
|||||||
ACCOUNT_CATEGORY_INVESTMENT AccountCategory = 7
|
ACCOUNT_CATEGORY_INVESTMENT AccountCategory = 7
|
||||||
)
|
)
|
||||||
|
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
|
||||||
|
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,
|
||||||
|
}
|
||||||
|
|
||||||
type AccountType byte
|
type AccountType byte
|
||||||
|
|
||||||
const (
|
const (
|
||||||
@@ -98,6 +118,8 @@ type AccountInfoResponse struct {
|
|||||||
Balance int64 `json:"balance"`
|
Balance int64 `json:"balance"`
|
||||||
Comment string `json:"comment"`
|
Comment string `json:"comment"`
|
||||||
DisplayOrder int `json:"displayOrder"`
|
DisplayOrder int `json:"displayOrder"`
|
||||||
|
IsAsset bool `json:"isAsset,omitempty"`
|
||||||
|
IsLiability bool `json:"isLiability,omitempty"`
|
||||||
Hidden bool `json:"hidden"`
|
Hidden bool `json:"hidden"`
|
||||||
SubAccounts AccountInfoResponseSlice `json:"subAccounts,omitempty"`
|
SubAccounts AccountInfoResponseSlice `json:"subAccounts,omitempty"`
|
||||||
}
|
}
|
||||||
@@ -115,6 +137,8 @@ func (a *Account) ToAccountInfoResponse() *AccountInfoResponse {
|
|||||||
Balance: a.Balance,
|
Balance: a.Balance,
|
||||||
Comment: a.Comment,
|
Comment: a.Comment,
|
||||||
DisplayOrder: a.DisplayOrder,
|
DisplayOrder: a.DisplayOrder,
|
||||||
|
IsAsset: AssetAccountCategory[a.Category],
|
||||||
|
IsLiability: LiabilityAccountCategory[a.Category],
|
||||||
Hidden: a.Hidden,
|
Hidden: a.Hidden,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,43 +2,36 @@ const allAccountCategories = [
|
|||||||
{
|
{
|
||||||
id: 1,
|
id: 1,
|
||||||
name: 'Cash',
|
name: 'Cash',
|
||||||
isAsset: true,
|
|
||||||
defaultAccountIconId: '1'
|
defaultAccountIconId: '1'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 2,
|
id: 2,
|
||||||
name: 'Debit Card',
|
name: 'Debit Card',
|
||||||
isAsset: true,
|
|
||||||
defaultAccountIconId: '100'
|
defaultAccountIconId: '100'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 3,
|
id: 3,
|
||||||
name: 'Credit Card',
|
name: 'Credit Card',
|
||||||
isLiability: true,
|
|
||||||
defaultAccountIconId: '100'
|
defaultAccountIconId: '100'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 4,
|
id: 4,
|
||||||
name: 'Virtual Account',
|
name: 'Virtual Account',
|
||||||
isAsset: true,
|
|
||||||
defaultAccountIconId: '500'
|
defaultAccountIconId: '500'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 5,
|
id: 5,
|
||||||
name: 'Debt Account',
|
name: 'Debt Account',
|
||||||
isLiability: true,
|
|
||||||
defaultAccountIconId: '600'
|
defaultAccountIconId: '600'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 6,
|
id: 6,
|
||||||
name: 'Receivables',
|
name: 'Receivables',
|
||||||
isAsset: true,
|
|
||||||
defaultAccountIconId: '700'
|
defaultAccountIconId: '700'
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
id: 7,
|
id: 7,
|
||||||
name: 'Investment Account',
|
name: 'Investment Account',
|
||||||
isAsset: true,
|
|
||||||
defaultAccountIconId: '800'
|
defaultAccountIconId: '800'
|
||||||
}
|
}
|
||||||
];
|
];
|
||||||
|
|||||||
+8
-3
@@ -106,21 +106,21 @@ function getAccountByAccountId(categorizedAccounts, accountId) {
|
|||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getAllFilteredAccountsBalance(categorizedAccounts, accountCategoryFilter) {
|
function getAllFilteredAccountsBalance(categorizedAccounts, accountFilter) {
|
||||||
const allAccountCategories = accountConstants.allCategories;
|
const allAccountCategories = accountConstants.allCategories;
|
||||||
const ret = [];
|
const ret = [];
|
||||||
|
|
||||||
for (let categoryIdx = 0; categoryIdx < allAccountCategories.length; categoryIdx++) {
|
for (let categoryIdx = 0; categoryIdx < allAccountCategories.length; categoryIdx++) {
|
||||||
const accountCategory = allAccountCategories[categoryIdx];
|
const accountCategory = allAccountCategories[categoryIdx];
|
||||||
|
|
||||||
if (!accountCategoryFilter(accountCategory) || !categorizedAccounts[accountCategory.id]) {
|
if (!categorizedAccounts[accountCategory.id]) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let accountIdx = 0; accountIdx < categorizedAccounts[accountCategory.id].length; accountIdx++) {
|
for (let accountIdx = 0; accountIdx < categorizedAccounts[accountCategory.id].length; accountIdx++) {
|
||||||
const account = categorizedAccounts[accountCategory.id][accountIdx];
|
const account = categorizedAccounts[accountCategory.id][accountIdx];
|
||||||
|
|
||||||
if (account.hidden) {
|
if (account.hidden || !accountFilter(account)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -132,6 +132,11 @@ function getAllFilteredAccountsBalance(categorizedAccounts, accountCategoryFilte
|
|||||||
} else if (account.type === accountConstants.allAccountTypes.MultiSubAccounts) {
|
} else if (account.type === accountConstants.allAccountTypes.MultiSubAccounts) {
|
||||||
for (let subAccountIdx = 0; subAccountIdx < account.subAccounts.length; subAccountIdx++) {
|
for (let subAccountIdx = 0; subAccountIdx < account.subAccounts.length; subAccountIdx++) {
|
||||||
const subAccount = account.subAccounts[subAccountIdx];
|
const subAccount = account.subAccounts[subAccountIdx];
|
||||||
|
|
||||||
|
if (subAccount.hidden || !accountFilter(subAccount)) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
ret.push({
|
ret.push({
|
||||||
balance: subAccount.balance,
|
balance: subAccount.balance,
|
||||||
currency: subAccount.currency
|
currency: subAccount.currency
|
||||||
|
|||||||
@@ -243,7 +243,7 @@ export default {
|
|||||||
return '***';
|
return '***';
|
||||||
}
|
}
|
||||||
|
|
||||||
const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.accounts, category => category.isAsset);
|
const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.accounts, account => account.isAsset);
|
||||||
let totalAssets = 0;
|
let totalAssets = 0;
|
||||||
let hasUnCalculatedAmount = false;
|
let hasUnCalculatedAmount = false;
|
||||||
|
|
||||||
@@ -273,7 +273,7 @@ export default {
|
|||||||
return '***';
|
return '***';
|
||||||
}
|
}
|
||||||
|
|
||||||
const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.accounts, category => category.isLiability);
|
const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.accounts, account => account.isLiability);
|
||||||
let totalLiabilities = 0;
|
let totalLiabilities = 0;
|
||||||
let hasUnCalculatedAmount = false;
|
let hasUnCalculatedAmount = false;
|
||||||
|
|
||||||
@@ -404,7 +404,7 @@ export default {
|
|||||||
return '***';
|
return '***';
|
||||||
}
|
}
|
||||||
|
|
||||||
const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.accounts, category => category.id === accountCategory.id);
|
const accountsBalance = this.$utilities.getAllFilteredAccountsBalance(this.accounts, account => account.category === accountCategory.id);
|
||||||
let totalBalance = 0;
|
let totalBalance = 0;
|
||||||
let hasUnCalculatedAmount = false;
|
let hasUnCalculatedAmount = false;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user