moneygo/js/utils.js

34 lines
1.2 KiB
JavaScript
Raw Permalink Normal View History

2016-10-05 13:36:47 -04:00
const recursiveAccountDisplayInfo = function(account, account_map, accountChildren, prefix) {
2015-08-05 21:25:25 -04:00
var name = prefix + account.Name;
var accounts = [{AccountId: account.AccountId, Name: name}];
2016-10-05 13:36:47 -04:00
for (var i = 0; i < accountChildren[account.AccountId].length; i++)
accounts = accounts.concat(recursiveAccountDisplayInfo(account_map[accountChildren[account.AccountId][i]], account_map, accountChildren, name + "/"));
2015-08-05 21:25:25 -04:00
return accounts
};
2016-10-05 13:36:47 -04:00
const getAccountDisplayList = function(account_map, accountChildren, includeRoot, rootName) {
2015-08-05 21:25:25 -04:00
var accounts = []
if (includeRoot)
accounts.push({AccountId: -1, Name: rootName});
2016-10-05 13:36:47 -04:00
for (var accountId in account_map) {
if (account_map.hasOwnProperty(accountId) &&
account_map[accountId].isRootAccount())
accounts = accounts.concat(recursiveAccountDisplayInfo(account_map[accountId], account_map, accountChildren, ""));
2015-08-05 21:25:25 -04:00
}
return accounts;
};
const getAccountDisplayName = function(account, account_map) {
var name = account.Name;
while (account.ParentAccountId >= 0) {
account = account_map[account.ParentAccountId];
name = account.Name + "/" + name;
}
return name;
};
module.exports = {
getAccountDisplayList: getAccountDisplayList,
getAccountDisplayName: getAccountDisplayName
};