using System; using Activizr.Logic.Financial; using Activizr.Logic.Pirates; using Membership = Activizr.Logic.Pirates.Membership; namespace Controls.v4.Financial { public partial class ListBudgets : System.Web.UI.UserControl { 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 = ""; 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 += "\r\n"; } if (!budgetFound) { literal += "\r\n"; } literal += "\r\n"; literal += "
"; if (multipleOrgs) { literal += Server.HtmlEncode(account.Organization.NameShort) + " - "; } literal += "" + Server.HtmlEncode(account.Name) + " "; literal += Server.HtmlEncode(remaining.ToString("N2")); literal += " of "; literal += Server.HtmlEncode(budget.ToString("N2")); literal += " ("; if (budget != 0.0) { literal += (remaining/(decimal) budget).ToString("P0"); } else { literal += "--%"; } literal += " left)
No budget allocated to you (yet?) for " + year.ToString() + ".
 
Allocate funds...
"; this.LiteralBudgetData.Text = literal; } else { this.LiteralBudgetData.Text = "You own no budgets."; } } public Person Person { get { return this.person; } set { this.person = value; } } private Person person; } }