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); }
protected void DropYear_SelectedIndexChanged(object sender, EventArgs e) { int year = Int32.Parse(this.DropYear.SelectedValue); if (year < 2000) { return; } FinancialAccounts balanceAccounts = FinancialAccounts.ForOrganization(CurrentOrganization, FinancialAccountType.Balance); FinancialAccounts resultAccounts = FinancialAccounts.ForOrganization(CurrentOrganization, FinancialAccountType.Result); FinancialAccount ownCapital = CurrentOrganization.FinancialAccounts.DebtsEquity; FinancialAccount resultAsNoted = CurrentOrganization.FinancialAccounts.CostsYearlyResult; FinancialAccounts balancesWithoutCapital = FinancialAccounts.ForOrganization(CurrentOrganization, FinancialAccountType.Balance); balancesWithoutCapital.Remove(ownCapital); FinancialAccounts resultAccountsWithoutNotedResult = FinancialAccounts.ForOrganization(CurrentOrganization, FinancialAccountType.Result); resultAccountsWithoutNotedResult.Remove(CurrentOrganization.FinancialAccounts.CostsYearlyResult); Currency currency = CurrentOrganization.DefaultCountry.Currency; this.LabelResultsAll.Text = String.Format("{0} {1:N2}", currency.Code, resultAccounts.GetDeltaCents(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1)) / 100.0); this.LabelResultsNoted.Text = String.Format("{0} {1:N2}", currency.Code, resultAsNoted.GetDeltaCents(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1)) / 100.0); this.LabelEoyBalance.Text = String.Format("{0} {1:N2}", currency.Code, balanceAccounts.GetDeltaCents(new DateTime(1900, 1, 1), new DateTime(year + 1, 1, 1)) / 100.0); Int64 endOfLastYearCapital = ownCapital.GetDeltaCents(new DateTime(1900, 1, 1), new DateTime(year, 1, 1)); Int64 endOfSelectedYearCapital = ownCapital.GetDeltaCents(new DateTime(1900, 1, 1), new DateTime(year + 1, 1, 1)); this.LabelEolyOwnCapital.Text = String.Format("{0} {1:N2}", currency.Code, endOfLastYearCapital / 100.0); this.LabelEocyOwnCapital.Text = String.Format("{0} {1:N2}", currency.Code, endOfSelectedYearCapital / 100.0); this.LabelOwnCapitalDiff.Text = String.Format("{0} {1:N2}", currency.Code, (endOfSelectedYearCapital - endOfLastYearCapital) / 100.0); this.LabelOwnCapitalDelta.Text = String.Format("{0} {1:N2}", currency.Code, ownCapital.GetDeltaCents(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1)) / 100.0); }
private BudgetData GetBudgetData(int budgetId, int year) { FinancialAccount account = FinancialAccount.FromIdentity(budgetId); double budget = -account.GetBudget(year); Int64 actualCents = account.GetDeltaCents(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1)); double actual = actualCents / 100.0; // Get suballocated FinancialAccounts accountTree = account.GetTree(); double budgetTotal = -accountTree.GetBudgetSum(year); Int64 deltaTotalCents = accountTree.GetDeltaCents(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1)); double deltaTotal = deltaTotalCents / 100.0; BudgetData result = new BudgetData(); result.AccountName = account.Name; if (budgetTotal > 0.0) { result.PercentActual = actual / budgetTotal * 100.0; result.PercentSuballocated = (budgetTotal - budget) / budgetTotal * 100.0; result.PercentSuballocatedUsed = (deltaTotal - actual) / budgetTotal * 100.0; } return(result); }
public Int64 GetProfitLossCents(int year = 0) { if (year == 0) { year = DateTime.UtcNow.Year; } FinancialAccounts allPLAccounts = Swarmops.Logic.Financial.FinancialAccounts.ForOrganization(this, FinancialAccountType.Result); DateTime thisYearStart = new DateTime(year, 1, 1); DateTime thisYearEnd = new DateTime(year + 1, 1, 1); return(-allPLAccounts.GetDeltaCents(thisYearStart, thisYearEnd)); // negative because of accounting of P&L accounts }
public static AjaxCallAccountData 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.ThisAndBelow(); int year = DateTime.Today.Year; AjaxCallAccountData result = new AjaxCallAccountData(); if (account.ParentIdentity == 0) { // if this is a root account, put it under the category root node, which has negative the type id result.ParentAccountId = -(int)account.AccountType; } else { result.ParentAccountId = account.ParentIdentity; } result.AccountName = account.Name; 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.AutomationData = GetAccountAutomationData(account.AutomationProfileId); if (result.AutomationData.AutomationEnabled && result.AutomationData.NonPresentationCurrency) { Currency foreignCurrency = Currency.FromCode(result.AutomationData.AutomationCurrencyCode); result.AutomationData.AutomationCurrencyCode = foreignCurrency.DisplayCode; account.ForeignCurrency = foreignCurrency; } else { result.CurrencyCode = authData.CurrentOrganization.Currency.DisplayCode; } return(result); }