protected void PopulateGrid() { FinancialAccounts allAccounts = FinancialAccounts.ForOrganization(Organization.PPSE); Dictionary <int, bool> accountIsParent = new Dictionary <int, bool>(); FinancialAccounts resultAccounts = new FinancialAccounts(); foreach (FinancialAccount account in allAccounts) { if (account.AccountType == FinancialAccountType.Income || account.AccountType == FinancialAccountType.Cost) { resultAccounts.Add(account); if (account.ParentIdentity != 0) { } } } // Add expansion headers this.GridBudgetAccounts.DataSource = resultAccounts; PopulateLookups(resultAccounts); }
private Dictionary <int, Int64> GetAttestationRights() { // Right now, this function is quite primitive. At some point in the future, it needs to take into // account that a budget may have several attesters. Right now, it just loops over all accounts and // checks the owner. Dictionary <int, Int64> result = new Dictionary <int, Int64>(); FinancialAccounts accounts = FinancialAccounts.ForOrganization(CurrentOrganization); foreach (FinancialAccount account in accounts) { if (account.OwnerPersonId == CurrentUser.Identity) { if (account.AccountType == FinancialAccountType.Cost) { result[account.Identity] = account.GetBudgetCentsRemaining(); } else { result[account.Identity] = 1; // any value } } } 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); }
static private Dictionary <int, bool> GetAttestationRights() { AuthenticationData authData = GetAuthenticationDataAndCulture(); // Right now, this function is quite primitive. At some point in the future, it needs to take into // account that a budget may have several attesters. Right now, it just loops over all accounts and // checks the owner. Dictionary <int, bool> result = new Dictionary <int, bool>(); FinancialAccounts accounts = FinancialAccounts.ForOrganization(authData.CurrentOrganization); foreach (FinancialAccount account in accounts) { if (account.OwnerPersonId == authData.CurrentUser.Identity || (account.OwnerPersonId == 0 && authData.Authority.HasAccess(new Access(authData.CurrentOrganization, AccessAspect.Administration)))) { if (account.AccountType == FinancialAccountType.Cost) { result[account.Identity] = true; } } } return(result); }
private static void OnMondayMorning() { try { // Detect and log any forex difference exceeding 100 cents. FinancialAccounts allAccounts = FinancialAccounts.GetAll(); // across ALL ORGS! foreach (FinancialAccount account in allAccounts) { // For every account, if it's based on foreign currency, check for forex gains/losses if (account.ForeignCurrency != null) { account.CheckForexProfitLoss(); } } } catch (Exception e) { ExceptionMail.Send(e, true); if (testMode) { Console.WriteLine(e.ToString()); } } }
protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { PopulateGrid(); } if (Assembly.GetAssembly(typeof(ScriptManager)).FullName.IndexOf("3.5") != -1) { this.GridBudgetAccounts.MasterTableView.FilterExpression = @"it[""ParentFinancialAccountId""] = 0"; } else { this.GridBudgetAccounts.MasterTableView.FilterExpression = "ParentFinancialAccountId=0"; } FinancialAccounts testAccounts = FinancialAccounts.FromBankTransactionTag("BG 472-5107"); if (testAccounts.Count != 1) { this.LabelTest.Text = testAccounts.Count.ToString() + " accounts returned"; } this.LabelTest.Text = testAccounts[0].Name + " (" + testAccounts[0].AssignedGeography.Name + ")"; }
protected void Page_Load(object sender, EventArgs e) { if (!this.CurrentOrganization.IsEconomyEnabled) { Response.Redirect("/Pages/v5/Financial/EconomyNotEnabled.aspx", true); return; } this.PageIcon = "iconshock-treasure"; this.PageTitle = Resources.Pages.Ledgers.ResyncExternalAccount_PageTitle; this.InfoBoxLiteral = Resources.Pages.Ledgers.ResyncExternalAccount_Info; if (!Page.IsPostBack) { this.DropAccounts.Items.Add(new ListItem(Resources.Global.Global_SelectOne, "0")); FinancialAccounts accounts = FinancialAccounts.ForOrganization(this.CurrentOrganization, FinancialAccountType.Asset); foreach (FinancialAccount account in accounts) { // TODO: COnstruct import settings for accounts if (this.CurrentOrganization.Name == "Piratpartiet SE" && account.Identity == 1) { this.DropAccounts.Items.Add(new ListItem(account.Name + " (SE/SEB)", account.Identity.ToString(CultureInfo.InvariantCulture))); } } Localize(); } }
private void Populate(FinancialAccounts accounts) { // We still need a real f*****g tree structure. Dictionary <int, FinancialAccounts> lookup = new Dictionary <int, FinancialAccounts>(); foreach (FinancialAccount account in accounts) { if (!lookup.ContainsKey(account.ParentIdentity)) { lookup[account.ParentIdentity] = new FinancialAccounts(); } lookup[account.ParentIdentity].Add(account); } RadTreeNodeCollection collection = RecursiveAdd(lookup, accounts[0].ParentIdentity); foreach (RadTreeNode subnode in collection) { Tree.Nodes.Add(subnode); } //Tree.Nodes[0].Expanded = true; //Tree.Nodes[0].Selected = true; }
private void ExecuteSaveAccountCommand() { try { SelectedFinancialAccount.BankName = SelectedBank.DisplayName; var isNewObject = SelectedFinancialAccount.Id; var stat = _financialAccountService.InsertOrUpdate(SelectedFinancialAccount); if (string.IsNullOrEmpty(stat)) { if (isNewObject == 0) { FinancialAccounts.Insert(0, SelectedFinancialAccount); } } else { MessageBox.Show("Got Problem while saving, try again..." + Environment.NewLine + stat, "save error", MessageBoxButton.OK, MessageBoxImage.Error); } } catch (Exception exception) { MessageBox.Show("Got Problem while saving, try again..." + Environment.NewLine + exception.Message, "save error", MessageBoxButton.OK, MessageBoxImage.Error); } }
private void InitSuballocation(bool setData) { this.TextThisAccountBudget.Text = (_account.GetBudgetCents(_year) / 100).ToString("N0", new CultureInfo(_account.Organization.DefaultCountry.Culture)); this.LabelThisAccountName.Text = _account.Name; this.TextThisAccountBudget.Style[HtmlTextWriterStyle.TextAlign] = "right"; this.TextThisAccountBudget.Style[HtmlTextWriterStyle.Width] = "150px"; FinancialAccounts accounts = _account.Children; AccountBudgetLines childData = new AccountBudgetLines(); foreach (FinancialAccount account in accounts) { childData.Add(new AccountBudgetLine(account, _year)); } _initializingBudgets = setData; this.RepeaterAccountNames.DataSource = childData; this.RepeaterAccountNames.DataBind(); this.RepeaterBudgetTextBoxes.DataSource = childData; this.RepeaterBudgetTextBoxes.DataBind(); this.RepeaterBudgetOwners.DataSource = childData; this.RepeaterBudgetOwners.DataBind(); this.ButtonReallocate.Enabled = accounts.Count > 0 ? true : false; // this.TooltipManager.TargetControls.Add(this.LabelThisAccountOwner.ClientID, "1", true); }
private void Populate(FinancialAccounts accounts) { // We still need a real f*****g tree structure. Dictionary<int, FinancialAccounts> lookup = new Dictionary<int, FinancialAccounts>(); foreach (FinancialAccount account in accounts) { if (!lookup.ContainsKey(account.ParentIdentity)) { lookup[account.ParentIdentity] = new FinancialAccounts(); } lookup[account.ParentIdentity].Add(account); } RadTreeNodeCollection collection = RecursiveAdd(lookup, accounts[0].ParentIdentity); foreach (RadTreeNode subnode in collection) { Tree.Nodes.Add(subnode); } //Tree.Nodes[0].Expanded = true; //Tree.Nodes[0].Selected = true; }
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); }
protected void Page_Load(object sender, EventArgs e) { _authenticationData = GetAuthenticationDataAndCulture(); _year = DateTime.Today.Year; if (!_authenticationData.CurrentUser.HasAccess(new Access(_authenticationData.CurrentOrganization, AccessAspect.Bookkeeping, AccessType.Read))) { throw new UnauthorizedAccessException(); } // TODO: Get and cache account tree and account balances Response.ContentType = "application/json"; string response = string.Empty; PopulateLookups(FinancialAccounts.ForOrganization(_authenticationData.CurrentOrganization)); _hashedAccounts = FinancialAccounts.GetHashedAccounts(_authenticationData.CurrentOrganization); response += GetAccountGroup(FinancialAccountType.Asset, Resources.Pages.Ledgers.BalanceSheet_Assets) + ","; response += GetAccountGroup(FinancialAccountType.Debt, Resources.Pages.Ledgers.BalanceSheet_Debt) + ","; response += GetAccountGroup(FinancialAccountType.Income, Resources.Pages.Ledgers.ProfitLossStatement_Income) + ","; response += GetAccountGroup(FinancialAccountType.Cost, Resources.Pages.Ledgers.ProfitLossStatement_Costs); Response.Output.WriteLine("[" + response + "]"); Response.End(); }
protected void Page_Load(object sender, EventArgs e) { this._authenticationData = GetAuthenticationDataAndCulture(); this._year = DateTime.Today.Year; if ( !this._authenticationData.CurrentUser.HasAccess(new Access( this._authenticationData.CurrentOrganization, AccessAspect.Bookkeeping, AccessType.Read))) { throw new UnauthorizedAccessException(); } // TODO: Get and cache account tree and account balances Response.ContentType = "application/json"; string response = string.Empty; PopulateLookups(FinancialAccounts.ForOrganization(this._authenticationData.CurrentOrganization)); this._hashedAccounts = FinancialAccounts.GetHashedAccounts(this._authenticationData.CurrentOrganization); this._resultAccountId = this._authenticationData.CurrentOrganization.FinancialAccounts.CostsYearlyResult.Identity; response += GetAccountGroup(FinancialAccountType.Asset, Resources.Global.Financial_Asset) + ","; response += GetAccountGroup(FinancialAccountType.Debt, Resources.Global.Financial_Debt) + ","; response += GetAccountGroup(FinancialAccountType.Income, Resources.Global.Financial_Income) + ","; response += GetAccountGroup(FinancialAccountType.Cost, Resources.Global.Financial_Cost); Response.Output.WriteLine("[" + response + "]"); Response.End(); }
private FinancialAccounts GetRootLevelResultAccounts() { Organization org = this.CurrentOrganization; if (org == null && Page.IsPostBack) { // If we're being called from Page_Init to create controls just to catch events, then this.CurrentOrganization won't be set. // We need to create it temporarily from a hidden field: org = Organization.FromIdentity(Int32.Parse(Request["ctl00$PlaceHolderMain$HiddenInitOrganizationId"])); } FinancialAccount yearlyResult = org.FinancialAccounts.CostsYearlyResult; FinancialAccounts allAccounts = FinancialAccounts.ForOrganization(org, FinancialAccountType.Result); // Select root accounts FinancialAccounts accounts = new FinancialAccounts(); foreach (FinancialAccount account in allAccounts) { if (account.ParentFinancialAccountId == 0 && account.Identity != yearlyResult.Identity) { accounts.Add(account); } } return(accounts); }
protected void Page_Load(object sender, EventArgs e) { this.PageAccessRequired = new Access(this.CurrentOrganization, AccessAspect.Bookkeeping, AccessType.Write); this.HiddenInitOrganizationId.Value = this.CurrentOrganization.Identity.ToString(); this.PageIcon = "iconshock-moneybag"; this.PageTitle = Resources.Pages.Ledgers.SetRootBudgets_PageTitle; if (!Page.IsPostBack) { FinancialAccounts accounts = GetRootLevelResultAccounts(); int currentYear = DateTime.Today.Year; _year = currentYear; do { this.DropYears.Items.Add(new ListItem(currentYear.ToString())); currentYear--; } while (accounts[0].GetTree().GetBudgetSumCents(currentYear) > 0); this.DropYears.SelectedIndex = 0; this.RepeaterAccountNames.DataSource = accounts; this.RepeaterAccountNames.DataBind(); this.RepeaterAccountBudgets.DataSource = accounts; this.RepeaterAccountBudgets.DataBind(); this.RepeaterAccountActuals.DataSource = accounts; this.RepeaterAccountActuals.DataBind(); UpdateYearlyResult(accounts); this.LabelRootBudgetHeader.Text = String.Format(Resources.Pages.Ledgers.SetRootBudgets_PageHeader, this.CurrentOrganization.Name); this.LabelAccountHeader.Text = Resources.Global.Financial_BookkeepingAccountShort; this.LabelYearlyResultLabel.Text = Resources.Global.Financial_YearlyResult; this.ButtonSetBudgets.Text = Resources.Pages.Ledgers.SetRootBudgets_SetNewBudgets; this.LabelBudgetOwnerHeader.Text = Resources.Pages.Ledgers.SetRootBudgets_BudgetOwnerHeader; this.LabelSidebarActions.Text = Resources.Global.Sidebar_Actions; this.LabelSidebarInfo.Text = Resources.Global.Sidebar_Information; this.LabelSidebarTodo.Text = Resources.Global.Sidebar_Todo; this.LabelDashboardInfo.Text = Resources.Pages.Ledgers.SetRootBudgets_Info; LocalizeActualsHeader(); } else { _year = Int32.Parse(DropYears.SelectedItem.Text); } this.DropYears.Style[HtmlTextWriterStyle.FontWeight] = "bold"; this.ButtonSetBudgets.Style[HtmlTextWriterStyle.MarginTop] = "4px"; this.ButtonSetBudgets.Style[HtmlTextWriterStyle.MarginBottom] = "5px"; this.ButtonSetBudgets.Style[HtmlTextWriterStyle.Padding] = "1px"; // RebindTooltips(); }
protected void ButtonSetBudgets_Click(object sender, EventArgs e) { foreach (RepeaterItem repeaterItem in this.RepeaterAccountBudgets.Items) { HiddenField hiddenAccountId = (HiddenField)repeaterItem.FindControl("HiddenAccountId"); TextBox textBudget = (TextBox)repeaterItem.FindControl("TextBudget"); FinancialAccount account = FinancialAccount.FromIdentity(Int32.Parse(hiddenAccountId.Value)); // TODO: Possible race condition here, fix with HiddenField Int64 newBudgetAmount = Int64.Parse(textBudget.Text.Replace(",", "").Replace(" ", ""), Thread.CurrentThread.CurrentCulture); // TODO: May throw -- catch and send error message Int64 currentBudgetAmount = account.GetTree().GetBudgetSumCents(_year) / 100; // Set the new amount to the difference between the single budget of this account and the intended amount if (newBudgetAmount != currentBudgetAmount) { account.SetBudgetCents(_year, account.GetBudgetCents(_year) + (newBudgetAmount - currentBudgetAmount) * 100); } } // After updating budgets, rebind repeater FinancialAccounts accounts = GetRootLevelResultAccounts(); UpdateYearlyResult(accounts); this.RepeaterAccountBudgets.DataSource = accounts; this.RepeaterAccountBudgets.DataBind(); }
public static string GetInactiveAccountCount() { AuthenticationData authData = GetAuthenticationDataAndCulture(); int inactiveAccountCount = FinancialAccounts.ForOrganization(authData.CurrentOrganization).Count(account => !account.Active); return(inactiveAccountCount.ToString("N0")); }
public ActionResult DeleteConfirmed(int id) { FinancialAccounts financialAccounts = db.FinancialAccounts.Find(id); db.FinancialAccounts.Remove(financialAccounts); db.SaveChanges(); return(RedirectToAction("Index")); }
private void PopulateControls() { FinancialAccounts accounts = FinancialAccounts.ForOwner(_currentUser); this.DropBudgets.Items.Clear(); this.DropYears.Items.Clear(); foreach (FinancialAccount account in accounts) { this.DropBudgets.Items.Add(new ListItem(account.Name + " / " + account.Organization.Name, account.Identity.ToString())); } bool selectedBudget = false; string accountParameterString = Request.QueryString["AccountId"]; if (!String.IsNullOrEmpty(accountParameterString)) { int accountId = Int32.Parse(accountParameterString); if (FinancialAccount.FromIdentity(accountId).OwnerPersonId == _currentUser.Identity) { this.DropBudgets.SelectedValue = accountId.ToString(); } else if (_currentUser.Identity == 1 && System.Diagnostics.Debugger.IsAttached) // DEBUG { FinancialAccount account = FinancialAccount.FromIdentity(accountId); this.DropBudgets.Items.Add(new ListItem(account.Name + " / " + account.Organization.Name, account.Identity.ToString())); this.DropBudgets.SelectedValue = accountId.ToString(); } } ViewState[this.ClientID + "_BudgetId"] = this.DropBudgets.SelectedValue; _account = FinancialAccount.FromIdentity(Int32.Parse(this.DropBudgets.SelectedValue)); this.HiddenInitBudgetId.Value = _account.Identity.ToString(); int yearStart = DateTime.Today.Year - 1; if (DateTime.Today.Month <= 6) { yearStart--; } for (int yearIndex = 0; yearIndex < 3; yearIndex++) { this.DropYears.Items.Add((yearStart + yearIndex).ToString()); } this.DropYears.SelectedValue = DateTime.Today.Year.ToString(); _year = DateTime.Today.Year; ViewState[this.ClientID + "_Year"] = this.DropYears.SelectedValue; this.HiddenInitYear.Value = this.DropYears.SelectedValue; PopulateBudgetData(); }
// This function is a bit of black magic. // It makes sure that all the accounts are populated with their respective values. In order to // summarize the values for every subtree, it 1) sorts the accounts in an order so that a // parents always comes before a child, 2) calculates the values for all accounts, // 3) iterates in reverse order and adds every account's values to the parent account, if there is one. private void PopulateLookups(FinancialAccounts accounts) { singleLookups = new Dictionary <int, decimal> [6]; treeLookups = new Dictionary <int, decimal> [6]; for (int index = 0; index < 6; index++) { treeLookups[index] = new Dictionary <int, decimal>(); singleLookups[index] = new Dictionary <int, decimal>(); } int year = 2010; DateTime[] quarterBoundaries = { new DateTime(year, 1, 1), new DateTime(year, 3, 1), new DateTime(year, 6, 1), new DateTime(year, 9, 1), new DateTime(year + 1, 1, 1) }; // 1) Actually, the accounts are already sorted. Or are supposed to be, anyway, // since FinancialAccounts.ForOrganization gets the _tree_ rather than the flat list. // 2) Add all values to the accounts. foreach (FinancialAccount account in accounts) { // Find this year's inbound singleLookups [0][account.Identity] = account.GetDelta(new DateTime(year - 1, 1, 1), new DateTime(year, 1, 1)); // Find quarter diffs for (int quarter = 0; quarter < 4; quarter++) { singleLookups[quarter + 1][account.Identity] = account.GetDelta(quarterBoundaries[quarter], quarterBoundaries[quarter + 1]); } // Find outbound singleLookups [5][account.Identity] = account.GetDelta(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1)); // copy to treeLookups for (int index = 0; index < 6; index++) { treeLookups[index][account.Identity] = singleLookups[index][account.Identity]; } } // 3) Add all children's values to parents for (int index = 0; index < 6; index++) { AddChildrenValuesToParents(treeLookups[index], accounts); } // Done. }
protected void Page_Load(object sender, EventArgs e) { if (!CurrentOrganization.IsEconomyEnabled) { Response.Redirect("/Pages/v5/Financial/EconomyNotEnabled.aspx", true); return; } if (!Page.IsPostBack) { // Localize PageIcon = "iconshock-openbook"; this.BoxTitle.Text = PageTitle = Resources.Pages.Ledgers.AccountPlan_PageTitle; InfoBoxLiteral = Resources.Pages.Ledgers.AccountPlan_Info; this.LiteralExpensesBudgetsAreNegative.Text = Resources.Pages.Ledgers.AccountPlan_ExpensesBudgetsAreNegative; this.LiteralDebtBalancesAreNegative.Text = Resources.Pages.Ledgers.AccountPlan_DebtBalancesAreNegative; this.LiteralHeaderAccountName.Text = Resources.Pages.Ledgers.AccountPlan_Header_AccountName; this.LiteralHeaderBalance.Text = Resources.Pages.Ledgers.AccountPlan_Header_Balance; this.LiteralHeaderBudget.Text = Resources.Pages.Ledgers.AccountPlan_Header_Budget; this.LiteralHeaderEdit.Text = Resources.Pages.Ledgers.AccountPlan_Header_Edit; this.LiteralHeaderEditingAccount.Text = Resources.Pages.Ledgers.AccountPlan_Edit_Header; this.LiteralHeaderFlags.Text = Resources.Pages.Ledgers.AccountPlan_Header_Flags; this.LiteralHeaderOwner.Text = Global.Global_Owner; this.LiteralLabelAccountName.Text = Resources.Pages.Ledgers.AccountPlan_Edit_AccountName; this.LiteralLabelActiveLong.Text = Resources.Pages.Ledgers.AccountPlan_Edit_ActiveLong; this.LiteralLabelActiveShort.Text = Resources.Pages.Ledgers.AccountPlan_Edit_ActiveShort; this.LiteralLabelAdministrativeLong.Text = Resources.Pages.Ledgers.AccountPlan_Edit_AdministrativeLong; this.LiteralLabelAdministrativeShort.Text = Resources.Pages.Ledgers.AccountPlan_Edit_AdministrativeShort; this.LiteralLabelBudgetBalance.Text = Resources.Pages.Ledgers.AccountPlan_Edit_BudgetBalance; this.LiteralLabelExpensableLong.Text = Resources.Pages.Ledgers.AccountPlan_Edit_ExpensableLong; this.LiteralLabelExpensableShort.Text = Resources.Pages.Ledgers.AccountPlan_Edit_ExpensableShort; this.LiteralLabelFileUploadProfile.Text = Resources.Pages.Ledgers.AccountPlan_Edit_FileUploadProfile; this.LiteralLabelHeaderAutomation.Text = Resources.Pages.Ledgers.AccountPlan_Edit_HeaderAutomation; this.LiteralLabelHeaderConfiguration.Text = Resources.Pages.Ledgers.AccountPlan_Edit_HeaderConfiguration; this.LiteralLabelHeaderDailyOperations.Text = Resources.Pages.Ledgers.AccountPlan_Edit_HeaderDailyOperations; this.LiteralLabelOwner.Text = Global.Global_Owner; this.LiteralLabelParent.Text = Resources.Pages.Ledgers.AccountPlan_Edit_Parent; this.LiteralLabelInitialAmount.Text = String.Format(Resources.Pages.Ledgers.AccountPlan_Edit_InitialBalance, CurrentOrganization.FirstFiscalYear, CurrentOrganization.Currency.DisplayCode); FinancialAccounts organizationAccounts = FinancialAccounts.ForOrganization(this.CurrentOrganization); int inactiveCount = organizationAccounts.Count(account => !account.Active); this.LabelSidebarOptions.Text = Resources.Global.Sidebar_Options; this.LabelOptionsShowInactive.Text = String.Format(Resources.Pages.Ledgers.AccountPlan_Options_ShowInactive, inactiveCount); } PageAccessRequired = new Access(CurrentOrganization, AccessAspect.Bookkeeping, AccessType.Write); DbVersionRequired = 2; // Account reparenting RegisterControl(EasyUIControl.DataGrid | EasyUIControl.Tree); RegisterControl(IncludedControl.SwitchButton); }
protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "application/json"; // Is this stuff in cache already? string cacheKey = "ExpensableBudgets-Json-" + this.CurrentOrganization.Identity.ToString((CultureInfo.InvariantCulture)); string accountsJson = (string) Cache[cacheKey]; if (accountsJson != null) { Response.Output.WriteLine(accountsJson); Response.End(); return; } // Not in cache. Construct. // Get accounts FinancialAccounts accounts = this.CurrentOrganization.FinancialAccounts.ExpensableBudgets; // Build tree (there should be a template for this) Dictionary<int, List<FinancialAccount>> treeMap = new Dictionary<int, List<FinancialAccount>>(); foreach (FinancialAccount account in accounts) { if (!treeMap.ContainsKey(account.ParentIdentity)) { treeMap[account.ParentIdentity] = new List<FinancialAccount>(); } treeMap[account.ParentIdentity].Add(account); } int renderRootNodeId = 0; if (treeMap[0].Count == 1) { // assume there's a master root like "Costs"; bypass it renderRootNodeId = treeMap[0][0].Identity; } accountsJson = RecurseTreeMap(treeMap, renderRootNodeId); Cache.Insert(cacheKey, accountsJson, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero); // cache lasts for five minutes, no sliding expiration Response.Output.WriteLine(accountsJson); Response.End(); }
private void PopulateAccounts(int organizationId) { FinancialAccounts accounts = FinancialAccounts.ForOrganization(Organization.FromIdentity(organizationId)); this.DropAccounts.Items.Add(new ListItem("-- None --", "0")); foreach (FinancialAccount account in accounts) { this.DropAccounts.Items.Add(new ListItem("[" + account.AccountType.ToString().Substring(0, 1) + "] " + account.Name, account.Identity.ToString())); } }
private void PopulateAccounts(int organizationId) { FinancialAccounts accounts = FinancialAccounts.ForOrganization(Organization.FromIdentity(organizationId)); this.DropAccounts.Items.Add(new ListItem("-- Select account --", "0")); foreach (FinancialAccount account in accounts) { this.DropAccounts.Items.Add(new ListItem(account.Name, account.Identity.ToString())); } }
protected void Page_Load(object sender, EventArgs e) { Response.ContentType = "application/json"; FinancialAccountType accountType = (FinancialAccountType)(Enum.Parse(typeof(FinancialAccountType), Request.QueryString["AccountType"])); string accountsJson = string.Empty; int excludeId = -1; string excludeIdString = Request.QueryString["ExcludeId"]; if (!String.IsNullOrEmpty(excludeIdString)) { excludeId = Int32.Parse(excludeIdString); } // Get accounts FinancialAccounts accounts = FinancialAccounts.ForOrganization(this.CurrentOrganization, accountType); // Build tree (there should be a template for this) Dictionary <int, List <FinancialAccount> > treeMap = new Dictionary <int, List <FinancialAccount> >(); foreach (FinancialAccount account in accounts) { if (account.Identity == excludeId) { continue; } if (!treeMap.ContainsKey(account.ParentIdentity)) { treeMap[account.ParentIdentity] = new List <FinancialAccount>(); } treeMap[account.ParentIdentity].Add(account); } if (treeMap.ContainsKey(0)) { accountsJson = RecurseTreeMap(treeMap, 0); } accountsJson = "[{\"id\":\"0\",\"text\":\"" + JsonSanitize(Resources.Global.ResourceManager.GetString("Financial_" + accountType.ToString())) + "\",\"state\":\"open\",\"children\":" + accountsJson + "}]"; Response.Output.WriteLine(accountsJson); Response.End(); }
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); }
// This function is a bit of black magic. // It makes sure that all the accounts are populated with their respective values. In order to // summarize the values for every subtree, it 1) sorts the accounts in an order so that a // parents always comes before a child, 2) calculates the values for all accounts, // 3) iterates in reverse order and adds every account's values to the parent account, if there is one. private void PopulateLookups(FinancialAccounts accounts) { balanceInboundLookup = new Dictionary <int, decimal>(); diffQuarterLookups = new Dictionary <int, decimal> [4]; for (int quarterIndex = 0; quarterIndex < 4; quarterIndex++) { diffQuarterLookups[quarterIndex] = new Dictionary <int, decimal>(); } balanceOutboundLookup = new Dictionary <int, decimal>(); int year = 2010; DateTime[] quarterBoundaries = { new DateTime(year, 1, 1), new DateTime(year, 3, 1), new DateTime(year, 6, 1), new DateTime(year, 9, 1), new DateTime(year + 1, 1, 1) }; // 1) Actually, the accounts are already sorted. Or are supposed to be, anyway, // since FinancialAccounts.ForOrganization gets the _tree_ rather than the flat list. // 2) Add all values to the accounts. foreach (FinancialAccount account in accounts) { // Find this year's inbound balanceInboundLookup [account.Identity] = account.GetDelta(new DateTime(2006, 1, 1), new DateTime(year, 1, 1)); // Find quarter diffs for (int quarter = 0; quarter < 4; quarter++) { diffQuarterLookups[quarter][account.Identity] = account.GetDelta(quarterBoundaries[quarter], quarterBoundaries[quarter + 1]); } // Find outbound balanceOutboundLookup [account.Identity] = account.GetDelta(new DateTime(2006, 1, 1), new DateTime(year + 1, 1, 1)); } // 3) Add all children's values to parents AddChildrenValuesToParents(balanceInboundLookup, accounts); AddChildrenValuesToParents(diffQuarterLookups[0], accounts); AddChildrenValuesToParents(diffQuarterLookups[1], accounts); AddChildrenValuesToParents(diffQuarterLookups[2], accounts); AddChildrenValuesToParents(diffQuarterLookups[3], accounts); AddChildrenValuesToParents(balanceOutboundLookup, accounts); // Done. }
public ActionResult Edit([Bind(Include = "Id,Name,Balance,ReconciledBalance,HouseholdId")] FinancialAccounts financialAccounts) { if (ModelState.IsValid) { db.Entry(financialAccounts).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.HouseholdId = new SelectList(db.Households, "Id", "Name", financialAccounts.HouseholdId); return(View(financialAccounts)); }
private void PopulateLookups(FinancialAccounts accounts) { singleLookups = new Dictionary <int, decimal> [5]; treeLookups = new Dictionary <int, decimal> [5]; for (int index = 0; index < 5; index++) { treeLookups[index] = new Dictionary <int, decimal>(); singleLookups[index] = new Dictionary <int, decimal>(); } // 1) Actually, the accounts are already sorted. Or are supposed to be, anyway, // since FinancialAccounts.ForOrganization gets the _tree_ rather than the flat list. // 2) Add all values to the accounts. int year = DateTime.Today.Year; foreach (FinancialAccount account in accounts) { // Find budget last year singleLookups [(int)ColumnType.LastYearBudget][account.Identity] = (decimal)account.GetBudget(year - 1); // Find budget this year singleLookups [(int)ColumnType.ThisYearBudget][account.Identity] = (decimal)account.GetBudget(year); // Find last year's actuals (sign reversed) singleLookups [(int)ColumnType.LastYearActuals][account.Identity] = -account.GetDelta(new DateTime(year - 1, 1, 1), new DateTime(year, 1, 1)); // Find actuals (sign reversed) singleLookups [(int)ColumnType.ThisYearActuals][account.Identity] = -account.GetDelta(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1)); // copy to treeLookups for (int index = 1; index < 5; index++) { treeLookups[index][account.Identity] = singleLookups[index][account.Identity]; } } // 3) Add all children's values to parents for (int index = 1; index < 5; index++) { AddChildrenValuesToParents(treeLookups[index], accounts); } // Done. }
private void PopulateLookups(FinancialAccounts accounts) { this._singleBalanceLookup = new Dictionary <int, Int64>(); this._treeBalanceLookup = new Dictionary <int, Int64>(); this._singleBudgetLookup = new Dictionary <int, Int64>(); this._treeBudgetLookup = new Dictionary <int, Int64>(); // 1) Actually, the accounts are already sorted. Or are supposed to be, anyway, // since FinancialAccounts.ForOrganization gets the _tree_ rather than the flat list. // 2) Add all values to the accounts. foreach (FinancialAccount account in accounts) { // Get current balances // TODO: There must be a more optimized way to do this, like with a database optimization. This // is a HORRIBLY expensive operation, as it performs one complex database query PER ACCOUNT. if (account.AccountType == FinancialAccountType.Cost || account.AccountType == FinancialAccountType.Income) { this._singleBalanceLookup[account.Identity] = -account.GetDeltaCents(new DateTime(this._year, 1, 1), new DateTime(this._year + 1, 1, 1)); this._singleBudgetLookup[account.Identity] = account.GetBudgetCents(this._year); } else if (account.AccountType == FinancialAccountType.Asset || account.AccountType == FinancialAccountType.Debt) { this._singleBalanceLookup[account.Identity] = account.GetDeltaCents(new DateTime(1900, 1, 1), new DateTime(this._year + 1, 1, 1)); this._singleBudgetLookup[account.Identity] = 0; // balance accounts don't have budgets } else { throw new InvalidOperationException("Account with invalid type encountered - " + account.AccountType); } // copy to treeLookups this._treeBalanceLookup[account.Identity] = this._singleBalanceLookup[account.Identity]; this._treeBudgetLookup[account.Identity] = this._singleBudgetLookup[account.Identity]; } // 3) Add all children's values to parents AddChildrenValuesToParents(this._treeBalanceLookup, accounts); AddChildrenValuesToParents(this._treeBudgetLookup, accounts); // Done. }
private void PopulateLedger() { FinancialAccounts accounts = new FinancialAccounts(); if (this.RadioAllAccounts.Checked) { accounts = FinancialAccounts.ForOrganization( Organization.FromIdentity(Int32.Parse(this.DropOrganizations.SelectedValue))); } else if (this.RadioAccountGroup.Checked) { accounts = FinancialAccounts.ForOrganization( Organization.FromIdentity(Int32.Parse(this.DropOrganizations.SelectedValue)), (FinancialAccountType) Int32.Parse(this.DropAccountGroups.SelectedValue)); } else if (this.RadioSpecificAccount.Checked) { accounts.Add(this.DropAccounts.SelectedFinancialAccount); } Ledger.Accounts = accounts; Ledger.DateStart = (DateTime)this.DateStart.SelectedDate; Ledger.DateEnd = (DateTime)this.DateEnd.SelectedDate; Ledger.MaxAmount = 1.0e12m; // catches all transactions -- if not, PW is kind of outscaled if (this.RadioCreditingTransactions.Checked) { Ledger.MaxAmount = 0.0m; } else if (this.RadioCreditingTransactionsLarge.Checked) { Ledger.MaxAmount = -1000.0m; } Ledger.Populate(); }
private FinancialAccounts GetRootLevelResultAccounts() { Organization org = this.CurrentOrganization; if (org == null && Page.IsPostBack) { // If we're being called from Page_Init to create controls just to catch events, then this.CurrentOrganization won't be set. // We need to create it temporarily from a hidden field: org = Organization.FromIdentity(Int32.Parse(Request["ctl00$PlaceHolderMain$HiddenInitOrganizationId"])); } FinancialAccount yearlyResult = org.FinancialAccounts.CostsYearlyResult; FinancialAccounts allAccounts = FinancialAccounts.ForOrganization(org, FinancialAccountType.Result); // Select root accounts FinancialAccounts accounts = new FinancialAccounts(); foreach (FinancialAccount account in allAccounts) { if (account.ParentFinancialAccountId == 0 && account.Identity != yearlyResult.Identity) { accounts.Add(account); } } return accounts; }
protected void PopulateGrid () { FinancialAccounts allAccounts = FinancialAccounts.ForOrganization(Organization.PPSE); FinancialAccounts volatileAccounts = new FinancialAccounts(); foreach (FinancialAccount account in allAccounts) { if (account.AccountType == FinancialAccountType.Cost || account.AccountType == FinancialAccountType.Income) { volatileAccounts.Add(account); } } this.GridBudgetAccounts.DataSource = volatileAccounts; PopulateLookups(volatileAccounts); }
private void AddChildrenValuesToParents (Dictionary<int,decimal> lookup, FinancialAccounts accounts) { // Iterate backwards and add any value to its parent's value, as they are sorted in tree order. for (int index = accounts.Count - 1; index >= 0; index--) { int parentFinancialAccountId = accounts[index].ParentFinancialAccountId; int accountId = accounts[index].Identity; if (parentFinancialAccountId != 0) { lookup[parentFinancialAccountId] += lookup[accountId]; } } }
// This function is a bit of black magic. // It makes sure that all the accounts are populated with their respective values. In order to // summarize the values for every subtree, it 1) sorts the accounts in an order so that a // parents always comes before a child, 2) calculates the values for all accounts, // 3) iterates in reverse order and adds every account's values to the parent account, if there is one. private void PopulateLookups(FinancialAccounts accounts) { balanceInboundLookup = new Dictionary<int, decimal>(); diffQuarterLookups = new Dictionary<int, decimal> [4]; for (int quarterIndex = 0; quarterIndex < 4; quarterIndex++ ) { diffQuarterLookups[quarterIndex] = new Dictionary<int, decimal>(); } balanceOutboundLookup = new Dictionary<int, decimal>(); int year = 2010; DateTime[] quarterBoundaries = { new DateTime(year, 1, 1), new DateTime(year, 3, 1), new DateTime(year, 6, 1), new DateTime(year, 9, 1), new DateTime(year + 1, 1, 1) }; // 1) Actually, the accounts are already sorted. Or are supposed to be, anyway, // since FinancialAccounts.ForOrganization gets the _tree_ rather than the flat list. // 2) Add all values to the accounts. foreach (FinancialAccount account in accounts) { // Find this year's inbound balanceInboundLookup [account.Identity] = account.GetDelta(new DateTime(2006, 1, 1), new DateTime(year, 1, 1)); // Find quarter diffs for (int quarter = 0; quarter < 4; quarter++) { diffQuarterLookups[quarter][account.Identity] = account.GetDelta(quarterBoundaries[quarter], quarterBoundaries[quarter+1]); } // Find outbound balanceOutboundLookup [account.Identity] = account.GetDelta(new DateTime(2006, 1, 1), new DateTime(year + 1, 1, 1)); } // 3) Add all children's values to parents AddChildrenValuesToParents(balanceInboundLookup, accounts); AddChildrenValuesToParents(diffQuarterLookups[0], accounts); AddChildrenValuesToParents(diffQuarterLookups[1], accounts); AddChildrenValuesToParents(diffQuarterLookups[2], accounts); AddChildrenValuesToParents(diffQuarterLookups[3], accounts); AddChildrenValuesToParents(balanceOutboundLookup, accounts); // Done. }
protected void PopulateGrid () { FinancialAccounts allAccounts = FinancialAccounts.ForOrganization(Organization.PPSE); FinancialAccounts balanceAccounts = new FinancialAccounts(); foreach (FinancialAccount account in allAccounts) { if (account.AccountType == FinancialAccountType.Asset || account.AccountType == FinancialAccountType.Debt) { balanceAccounts.Add(account); } } // Add main headers this.GridBudgetAccounts.DataSource = balanceAccounts; PopulateLookups(balanceAccounts); }
private void PopulateLookups(FinancialAccounts accounts) { singleLookups = new Dictionary<int, decimal>[5]; treeLookups = new Dictionary<int, decimal>[5]; for (int index = 0; index < 5; index++) { treeLookups[index] = new Dictionary<int, decimal>(); singleLookups[index] = new Dictionary<int, decimal>(); } // 1) Actually, the accounts are already sorted. Or are supposed to be, anyway, // since FinancialAccounts.ForOrganization gets the _tree_ rather than the flat list. // 2) Add all values to the accounts. int year = DateTime.Today.Year; foreach (FinancialAccount account in accounts) { // Find budget last year singleLookups [(int) ColumnType.LastYearBudget][account.Identity] = (decimal) account.GetBudget(year-1); // Find budget this year singleLookups [(int) ColumnType.ThisYearBudget][account.Identity] = (decimal) account.GetBudget(year); // Find last year's actuals (sign reversed) singleLookups [(int) ColumnType.LastYearActuals][account.Identity] = -account.GetDelta(new DateTime(year - 1, 1, 1), new DateTime(year, 1, 1)); // Find actuals (sign reversed) singleLookups [(int) ColumnType.ThisYearActuals][account.Identity] = -account.GetDelta(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1)); // copy to treeLookups for (int index = 1; index < 5; index++) { treeLookups[index][account.Identity] = singleLookups[index][account.Identity]; } } // 3) Add all children's values to parents for (int index = 1; index < 5; index++) { AddChildrenValuesToParents(treeLookups[index], accounts); } // Done. }
// This function is a bit of black magic. // It makes sure that all the accounts are populated with their respective values. In order to // summarize the values for every subtree, it 1) sorts the accounts in an order so that a // parents always comes before a child, 2) calculates the values for all accounts, // 3) iterates in reverse order and adds every account's values to the parent account, if there is one. private void PopulateLookups(FinancialAccounts accounts) { singleLookups = new Dictionary<int, decimal>[6]; treeLookups = new Dictionary<int, decimal>[6]; for (int index = 0; index < 6; index++ ) { treeLookups[index] = new Dictionary<int, decimal>(); singleLookups[index] = new Dictionary<int, decimal>(); } int year = 2010; DateTime[] quarterBoundaries = { new DateTime(year, 1, 1), new DateTime(year, 3, 1), new DateTime(year, 6, 1), new DateTime(year, 9, 1), new DateTime(year + 1, 1, 1) }; // 1) Actually, the accounts are already sorted. Or are supposed to be, anyway, // since FinancialAccounts.ForOrganization gets the _tree_ rather than the flat list. // 2) Add all values to the accounts. foreach (FinancialAccount account in accounts) { // Find this year's inbound singleLookups [0][account.Identity] = account.GetDelta(new DateTime(year-1, 1, 1), new DateTime(year, 1, 1)); // Find quarter diffs for (int quarter = 0; quarter < 4; quarter++) { singleLookups[quarter+1][account.Identity] = account.GetDelta(quarterBoundaries[quarter], quarterBoundaries[quarter+1]); } // Find outbound singleLookups [5][account.Identity] = account.GetDelta(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1)); // copy to treeLookups for (int index=0; index < 6; index++) { treeLookups[index][account.Identity] = singleLookups[index][account.Identity]; } } // 3) Add all children's values to parents for (int index = 0; index < 6; index++) { AddChildrenValuesToParents(treeLookups[index], accounts); } // Done. }
private void PopulateOrderedList(FinancialAccounts orderedList, int renderNodeId) { foreach (FinancialAccount account in _treeMap[renderNodeId]) { orderedList.Add(account); if (_treeMap.ContainsKey(account.Identity)) { PopulateOrderedList(orderedList, account.Identity); // recursive call } } }
protected void UpdateYearlyResult(FinancialAccounts rootAccounts) { Int64 budgetSum = 0; Int64 actualSum = 0; foreach (FinancialAccount account in rootAccounts) { budgetSum += account.GetTree().GetBudgetSumCents(_year)/100; actualSum -= (account.GetTree().GetDeltaCents(new DateTime(_year,1,1), new DateTime(_year+1, 1, 1))+50)/100; // negative: results accounts are sign reversed } this.TextYearlyResult.Text = String.Format("{0:N0}", budgetSum); this.TextYearlyResult.Style[HtmlTextWriterStyle.Width] = "80px"; this.TextYearlyResult.Style[HtmlTextWriterStyle.TextAlign] = "right"; this.LabelYearlyResultActuals.Text = String.Format("{0:N0}", actualSum); }
public static YearlyReport Create (Organization organization, int year, FinancialAccountType accountType) { YearlyReport report = new YearlyReport(); report.Organization = organization; report.Year = year; report._accountType = accountType; // Get accounts FinancialAccounts accounts = FinancialAccounts.ForOrganization(organization, accountType); // Remove unwanted accounts FinancialAccount resultsAccount = organization.FinancialAccounts.CostsYearlyResult; foreach (FinancialAccount account in accounts) { // For now, just remove the "results" account. TODO: Remove inactive accounts, too. if (account.Identity == resultsAccount.Identity) { accounts.Remove(account); break; } } // Build tree (there should be a template for this) report._treeMap = new Dictionary<int, List<FinancialAccount>>(); foreach (FinancialAccount account in accounts) { if (!report._treeMap.ContainsKey(account.ParentIdentity)) { report._treeMap[account.ParentIdentity] = new List<FinancialAccount>(); } report._treeMap[account.ParentIdentity].Add(account); } FinancialAccounts orderedList = new FinancialAccounts(); // This list is guaranteed to have parents before children report.PopulateOrderedList(orderedList, 0); // recursively add nodes parents-first report.PopulateLookups(orderedList); // populate the lookup tables for results per account report.PopulateTotals(); report.ReportLines = new List<YearlyReportLine>(); report.RecurseAddLines(report.ReportLines, 0); // Aggregate accounts, if appropriate if (report._treeMap[0].Count > 3) { // regroup list report.AggregateAccounts(); } return report; }
protected void Page_Load(object sender, EventArgs e) { FinancialAccounts allOwned = new FinancialAccounts(); Memberships memberships = this.person.GetMemberships(); int orgOwned = 0; bool multipleOrgs = false; foreach (Membership membership in memberships) { FinancialAccounts orgAccounts = FinancialAccounts.ForOrganization(membership.Organization); foreach (FinancialAccount account in orgAccounts) { if (account.OwnerPersonId == this.person.Identity) { allOwned.Add(account); if (orgOwned == 0 || orgOwned == membership.OrganizationId) { orgOwned = membership.OrganizationId; } else { multipleOrgs = true; } } } } if (allOwned.Count > 0) { string literal = "<span style=\"line-height:150%\"><table border=\"0\" cellspacing=\"0\" width=\"100%\">"; int year = DateTime.Today.Year; DateTime now = DateTime.Now; DateTime jan1 = new DateTime(year, 1, 1); bool budgetFound = false; foreach (FinancialAccount account in allOwned) { double budget = -account.GetBudget(year); decimal spent = account.GetDelta(jan1, now); decimal remaining = (decimal) budget - spent; if (budget == 0.0 && spent == 0.0m) { continue; // not interesting } budgetFound = true; literal += "<tr><td>"; if (multipleOrgs) { literal += Server.HtmlEncode(account.Organization.NameShort) + " - "; } literal += "<a href=\"/Pages/v4/Financial/ManageBudget.aspx?AccountId=" + account.Identity + "\">" + Server.HtmlEncode(account.Name) + "</a> </td><td align=\"right\">"; literal += Server.HtmlEncode(remaining.ToString("N2")); literal += "</td><td> of </td><td align=\"right\">"; literal += Server.HtmlEncode(budget.ToString("N2")); literal += "</td><td align=\"right\"> ("; if (budget != 0.0) { literal += (remaining/(decimal) budget).ToString("P0"); } else { literal += "--%"; } literal += " left)</td><tr>\r\n"; } if (!budgetFound) { literal += "<tr><td>No budget allocated to you (yet?) for " + year.ToString() + ".</td></tr>\r\n"; } literal += "<tr><td> </td></tr><tr><td colspan=\"5\" align=\"right\"><a href=\"/Pages/v4/Financial/AllocateFunds.aspx\">Allocate funds...</a></td></tr>\r\n"; literal += "</table></span>"; this.LiteralBudgetData.Text = literal; } else { this.LiteralBudgetData.Text = "You own no budgets."; } }
protected void PopulateGrid () { FinancialAccounts allAccounts = FinancialAccounts.ForOrganization(Organization.PPSE); Dictionary<int, bool> accountIsParent = new Dictionary<int, bool>(); FinancialAccounts resultAccounts = new FinancialAccounts(); foreach (FinancialAccount account in allAccounts) { if (account.AccountType == FinancialAccountType.Income || account.AccountType == FinancialAccountType.Cost) { resultAccounts.Add(account); if (account.ParentIdentity != 0) { } } } // Add expansion headers this.GridBudgetAccounts.DataSource = resultAccounts; PopulateLookups(resultAccounts); }
private void PopulateLookups(FinancialAccounts accounts) { _singleLookups = new Dictionary<int, Int64>[6]; _treeLookups = new Dictionary<int, Int64>[6]; for (int index = 0; index < 6; index++) { _treeLookups[index] = new Dictionary<int, Int64>(); _singleLookups[index] = new Dictionary<int, Int64>(); } DateTime[] quarterBoundaries = { new DateTime(this.Year, 1, 1), new DateTime(this.Year, 3, 1), new DateTime(this.Year, 6, 1), new DateTime(this.Year, 9, 1), new DateTime(this.Year + 1, 1, 1) }; // 1) Actually, the accounts are already sorted. Or are supposed to be, anyway, // since FinancialAccounts.ForOrganization gets the _tree_ rather than the flat list. // 2) Add all values to the accounts. foreach (FinancialAccount account in accounts) { // Find this year's inbound if (_accountType == FinancialAccountType.Result) { _singleLookups[0][account.Identity] = account.GetDeltaCents(new DateTime(this.Year - 1, 1, 1), new DateTime(this.Year, 1, 1)); } else if (_accountType == FinancialAccountType.Balance) { _singleLookups[0][account.Identity] = account.GetDeltaCents(new DateTime(1900, 1, 1), new DateTime(this.Year, 1, 1)); } else { throw new InvalidOperationException("Can only calculate yearly reports for balance or P&L statements"); } // Find quarter diffs for (int quarter = 0; quarter < 4; quarter++) { _singleLookups[quarter + 1][account.Identity] = account.GetDeltaCents(quarterBoundaries[quarter], quarterBoundaries[quarter + 1]); } // Find outbound if (_accountType == FinancialAccountType.Result) { _singleLookups[5][account.Identity] = account.GetDeltaCents(new DateTime(this.Year, 1, 1), new DateTime(this.Year + 1, 1, 1)); } else if (_accountType == FinancialAccountType.Balance) { _singleLookups[5][account.Identity] = account.GetDeltaCents(new DateTime(1900, 1, 1), new DateTime(this.Year + 1, 1, 1)); } else { throw new InvalidOperationException("Can only calculate yearly reports for balance or P&L statements"); } // copy to treeLookups for (int index = 0; index < 6; index++) { _treeLookups[index][account.Identity] = _singleLookups[index][account.Identity]; } } // 3) Add all children's values to parents for (int index = 0; index < 6; index++) { AddChildrenValuesToParents(_treeLookups[index], accounts); } // Done. }