public static JsonAccountData GetAccountData(int accountId) { AuthenticationData authData = GetAuthenticationDataAndCulture(); FinancialAccount account = FinancialAccount.FromIdentity(accountId); if (account.OrganizationId != authData.CurrentOrganization.Identity) { throw new UnauthorizedAccessException("A million nopes"); } FinancialAccounts accountTree = account.GetTree(); int year = DateTime.Today.Year; JsonAccountData result = new JsonAccountData(); result.AccountName = account.Name; result.ParentAccountId = account.ParentIdentity; result.ParentAccountName = account.ParentFinancialAccountId == 0 ? Global.ResourceManager.GetString("Financial_" + account.AccountType) : account.Parent.Name; result.Expensable = account.Expensable; result.Administrative = account.Administrative; result.Active = account.Active; result.Open = account.Open; result.AccountOwnerName = account.OwnerPersonId != 0 ? account.Owner.Name : Global.Global_NoOwner; result.AccountOwnerAvatarUrl = account.OwnerPersonId != 0 ? account.Owner.GetSecureAvatarLink(24) : "/Images/Icons/iconshock-warning-24px.png"; result.Budget = (accountTree.GetBudgetSumCents(year) / 100L).ToString("N0", CultureInfo.CurrentCulture); if (account.AccountType == FinancialAccountType.Asset || account.AccountType == FinancialAccountType.Debt) { result.Balance = (accountTree.GetDeltaCents(new DateTime(1900, 1, 1), new DateTime(year + 1, 1, 1)) / 100L).ToString ( "N0"); result.InitialBalance = ((accountTree.GetDeltaCents(new DateTime(1900, 1, 1), new DateTime(authData.CurrentOrganization.FirstFiscalYear, 1, 1)) / 100.0).ToString("N2")); } else { result.Balance = (-accountTree.GetDeltaCents(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1)) / 100L) .ToString( "N0"); result.InitialBalance = "N/A"; // unused } result.CurrencyCode = account.Organization.Currency.DisplayCode; return(result); }
public static JsonAccountData GetAccountData(int accountId) { AuthenticationData authData = GetAuthenticationDataAndCulture(); FinancialAccount account = FinancialAccount.FromIdentity(accountId); if (account.OrganizationId != authData.CurrentOrganization.Identity) { throw new UnauthorizedAccessException("A million nopes"); } FinancialAccounts accountTree = account.GetTree(); int year = DateTime.Today.Year; JsonAccountData result = new JsonAccountData(); result.AccountName = account.Name; result.ParentAccountId = account.ParentIdentity; result.ParentAccountName = account.ParentFinancialAccountId == 0 ? Resources.Global.ResourceManager.GetString("Financial_" + account.AccountType.ToString()) : account.Parent.Name; result.Expensable = account.Expensable; result.Administrative = account.Administrative; result.Open = account.Open; result.AccountOwnerName = account.OwnerPersonId != 0 ? account.Owner.Name : Resources.Global.Global_NoOwner; result.AccountOwnerAvatarUrl = account.OwnerPersonId != 0 ? account.Owner.GetSecureAvatarLink(24) : "/Images/Icons/iconshock-warning-24px.png"; result.Budget = (accountTree.GetBudgetSumCents(year)/100L).ToString("N0"); if (account.AccountType == FinancialAccountType.Asset || account.AccountType == FinancialAccountType.Debt) { result.Balance = (accountTree.GetDeltaCents(new DateTime(1900, 1, 1), new DateTime(year + 1, 1, 1))/100L).ToString("N0"); } else { result.Balance = (-accountTree.GetDeltaCents(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1)) / 100L).ToString("N0"); } return result; }