From c63c77ae2dbc07f3716e2ece00ba075479aeb213 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Tue, 11 Dec 2012 21:36:27 +0000 Subject: [PATCH] Added balance sheet --- Site5/App_GlobalResources/Pages.Ledgers.resx | 40 ++++++ Site5/Master-v5.master | 2 +- Site5/Pages/v5/Ledgers/BalanceSheet.aspx | 117 ++++++++++++++++ Site5/Pages/v5/Ledgers/BalanceSheet.aspx.cs | 50 +++++++ .../v5/Ledgers/Json-BalanceSheetData.aspx | 1 + .../v5/Ledgers/Json-BalanceSheetData.aspx.cs | 127 ++++++++++++++++++ 6 files changed, 336 insertions(+), 1 deletion(-) create mode 100644 Site5/Pages/v5/Ledgers/BalanceSheet.aspx create mode 100644 Site5/Pages/v5/Ledgers/BalanceSheet.aspx.cs create mode 100644 Site5/Pages/v5/Ledgers/Json-BalanceSheetData.aspx create mode 100644 Site5/Pages/v5/Ledgers/Json-BalanceSheetData.aspx.cs diff --git a/Site5/App_GlobalResources/Pages.Ledgers.resx b/Site5/App_GlobalResources/Pages.Ledgers.resx index 90dc9def..d9199c09 100644 --- a/Site5/App_GlobalResources/Pages.Ledgers.resx +++ b/Site5/App_GlobalResources/Pages.Ledgers.resx @@ -117,6 +117,46 @@ System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + Account + + + Balance Sheet for {0}, + {0} is the organization name. The year follows immediately. + + + Current + + + BalanceSheet + Must ONLY contain A-Z, a-z characters - nothing accented! + + + End-XXXX + The XXXX is replaced with year number. + + + The Balance Sheet is an overview of assets and debts at a snapshot in time, and is used to see how results affect the overall financial health of the organization. You may also want to look at the <a href="ProfitLossStatement.aspx">profit-and-loss statement</a> which is the overview of income and expenditure. + + + Balance Sheet + + + Change Q1 + + + Change Q2 + + + Change Q3 + + + Change Q4 + + + Start-XXXX + The XXXX is replaced with year number. + Account diff --git a/Site5/Master-v5.master b/Site5/Master-v5.master index fbefdce0..f58060a8 100644 --- a/Site5/Master-v5.master +++ b/Site5/Master-v5.master @@ -179,7 +179,7 @@ - + diff --git a/Site5/Pages/v5/Ledgers/BalanceSheet.aspx b/Site5/Pages/v5/Ledgers/BalanceSheet.aspx new file mode 100644 index 00000000..ad818586 --- /dev/null +++ b/Site5/Pages/v5/Ledgers/BalanceSheet.aspx @@ -0,0 +1,117 @@ +<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="BalanceSheet.aspx.cs" Inherits="Pages_v5_Ledgers_BalanceSheet" %> + + + + + + + + + + + + +

 Loading

+ + + + + + + + + + + + +
——————
+ +
+ +

+ +
+
+ +
+
+ + +
+ diff --git a/Site5/Pages/v5/Ledgers/BalanceSheet.aspx.cs b/Site5/Pages/v5/Ledgers/BalanceSheet.aspx.cs new file mode 100644 index 00000000..f71cf469 --- /dev/null +++ b/Site5/Pages/v5/Ledgers/BalanceSheet.aspx.cs @@ -0,0 +1,50 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; +using System.Globalization; + +public partial class Pages_v5_Ledgers_BalanceSheet : PageV5Base +{ + protected void Page_Load(object sender, EventArgs e) + { + if (!this.CurrentOrganization.IsEconomyEnabled) + { + Response.Redirect("/Pages/v5/Finance/EconomyNotEnabled.aspx", true); + return; + } + + this.PageIcon = "iconshock-treasure"; + this.PageTitle = Resources.Pages.Ledgers.BalanceSheet_PageTitle; + this.InfoBoxLiteral = Resources.Pages.Ledgers.BalanceSheet_Info; + + if (!Page.IsPostBack) + { + int year = DateTime.Today.Year; + int firstFiscalYear = CurrentOrganization.FirstFiscalYear; + + while (year >= firstFiscalYear) + { + this.DropYears.Items.Add(year.ToString(CultureInfo.InvariantCulture)); + year--; + } + + Localize(); + } + } + + + private void Localize() + { + this.LabelContentHeader.Text = string.Format(Resources.Pages.Ledgers.BalanceSheet_ContentHeader, CurrentOrganization.Name); + this.LiteralHeaderQ1.Text = Resources.Pages.Ledgers.BalanceSheet_Q1; + this.LiteralHeaderQ2.Text = Resources.Pages.Ledgers.BalanceSheet_Q2; + this.LiteralHeaderQ3.Text = Resources.Pages.Ledgers.BalanceSheet_Q3; + this.LiteralHeaderQ4.Text = Resources.Pages.Ledgers.BalanceSheet_Q4; + this.LiteralHeaderYtd.Text = Resources.Pages.Ledgers.BalanceSheet_Current; + this.LiteralHeaderAccountName.Text = Resources.Pages.Ledgers.BalanceSheet_AccountName; + } + +} \ No newline at end of file diff --git a/Site5/Pages/v5/Ledgers/Json-BalanceSheetData.aspx b/Site5/Pages/v5/Ledgers/Json-BalanceSheetData.aspx new file mode 100644 index 00000000..9c18dd96 --- /dev/null +++ b/Site5/Pages/v5/Ledgers/Json-BalanceSheetData.aspx @@ -0,0 +1 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-BalanceSheetData.aspx.cs" Inherits="Pages_v5_Ledgers_Json_BalanceSheetData" %> diff --git a/Site5/Pages/v5/Ledgers/Json-BalanceSheetData.aspx.cs b/Site5/Pages/v5/Ledgers/Json-BalanceSheetData.aspx.cs new file mode 100644 index 00000000..0582c8ee --- /dev/null +++ b/Site5/Pages/v5/Ledgers/Json-BalanceSheetData.aspx.cs @@ -0,0 +1,127 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using System.Linq; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; +using Activizr.Basic.Enums; +using Activizr.Logic.Financial; +using Activizr.Logic.Pirates; +using Activizr.Logic.Security; +using Activizr.Logic.Structure; + +public partial class Pages_v5_Ledgers_Json_BalanceSheetData : System.Web.UI.Page +{ + protected void Page_Load(object sender, EventArgs e) + { + // Current authentication + + string identity = HttpContext.Current.User.Identity.Name; + string[] identityTokens = identity.Split(','); + + string userIdentityString = identityTokens[0]; + string organizationIdentityString = identityTokens[1]; + + int currentUserId = Convert.ToInt32(userIdentityString); + int currentOrganizationId = Convert.ToInt32(organizationIdentityString); + + Person currentUser = Person.FromIdentity(currentUserId); + Authority authority = currentUser.GetAuthority(); + Organization currentOrganization = Organization.FromIdentity(currentOrganizationId); + + // Get culture + + string cultureString = "en-US"; + HttpCookie cookie = Request.Cookies["PreferredCulture"]; + + if (cookie != null) + { + cultureString = cookie.Value; + } + + _renderCulture = new CultureInfo(cultureString); + + // Get current year + + _year = DateTime.Today.Year; + + string yearParameter = Request.QueryString["Year"]; + + if (!string.IsNullOrEmpty(yearParameter)) + { + _year = Int32.Parse(yearParameter); // will throw if non-numeric - don't matter for app + } + + YearlyReport report = YearlyReport.Create(currentOrganization, _year, FinancialAccountType.Balance); + + Response.ContentType = "application/json"; + + Response.Output.WriteLine(RecurseReport(report.ReportLines)); + + Response.End(); + } + + + private int _year = 2012; + private CultureInfo _renderCulture; + + + + private string RecurseReport(List reportLines) + { + List elements = new List(); + + foreach (YearlyReportLine line in reportLines) + { + string element = string.Format("\"id\":{0},\"name\":\"{1}\"", line.AccountId, + line.AccountName.Replace("\"", "'")); + + if (line.Children.Count > 0) + { + + element += ",\"lastYear\":" + + JsonDualString(line.AccountId, line.AccountTreeValues.PreviousYear, line.AccountValues.PreviousYear); + + for (int quarter = 1; quarter <= 4; quarter++) + { + element += string.Format(",\"q{0}\":", quarter) + + JsonDualString(line.AccountId, line.AccountTreeValues.Quarters[quarter - 1], line.AccountValues.Quarters[quarter - 1]); + } + + element += ",\"ytd\":" + + JsonDualString(line.AccountId, line.AccountTreeValues.ThisYear, line.AccountValues.ThisYear); + + + element += ",\"state\":\"closed\",\"children\":" + RecurseReport(line.Children); + } + else + { + element += string.Format(_renderCulture, ",\"lastYear\":\"{0:N0}\"", (double)line.AccountValues.PreviousYear / -100.0); + + for (int quarter = 1; quarter <= 4; quarter++) + { + element += string.Format(_renderCulture, ",\"q{0}\":\"{1:N0}\"", quarter, line.AccountValues.Quarters[quarter - 1] / -100.0); + } + + element += string.Format(_renderCulture, ",\"ytd\":\"{0:N0}\"", (double)line.AccountValues.ThisYear / -100.0); + } + + elements.Add("{" + element + "}"); + } + + return "[" + String.Join(",", elements.ToArray()) + "]"; + } + + + private string JsonDualString(int accountId, Int64 treeValue, Int64 singleValue) + { + if (treeValue != 0 && singleValue == 0) + { + return string.Format(_renderCulture, "\"Σ {1:N0} \"", accountId, treeValue / -100.00); + } + return string.Format(_renderCulture, "\"Σ {1:N0}{2:N0}\"", accountId, treeValue / -100.0, singleValue / -100.0); + } + + +} \ No newline at end of file