diff --git a/Logic/Financial/AnnualReport.cs b/Logic/Financial/AnnualReport.cs index 0a50f121..98fed8b8 100644 --- a/Logic/Financial/AnnualReport.cs +++ b/Logic/Financial/AnnualReport.cs @@ -150,6 +150,7 @@ namespace Swarmops.Logic.Financial } aggregateLine.AccountTreeValues.ThisYear += reportLine.AccountTreeValues.ThisYear; + aggregateLine.AccountTreeValues.ThisYearBudget += reportLine.AccountTreeValues.ThisYearBudget; } } @@ -162,7 +163,8 @@ namespace Swarmops.Logic.Financial this.Totals = new AnnualReportNode(); this.Totals.PreviousYear = PopulateOneTotal (this._singleLookups[0]); - this.Totals.ThisYear = PopulateOneTotal (this._singleLookups[5]); + this.Totals.ThisYear = PopulateOneTotal(this._singleLookups[5]); + this.Totals.ThisYearBudget = PopulateOneTotal(this._singleLookups[6]); for (int quarter = 0; quarter < 4; quarter++) { @@ -186,8 +188,8 @@ namespace Swarmops.Logic.Financial newLine.AccountId = account.Identity; newLine.AccountName = account.Name; newLine.AccountType = account.AccountType; - newLine.AccountValues = CreateYearlyReportNode (account.Identity, this._singleLookups); - newLine.AccountTreeValues = CreateYearlyReportNode (account.Identity, this._treeLookups); + newLine.AccountValues = CreateAnnualReportNode (account.Identity, this._singleLookups); + newLine.AccountTreeValues = CreateAnnualReportNode (account.Identity, this._treeLookups); if (this._treeMap.ContainsKey (account.Identity)) { @@ -199,7 +201,7 @@ namespace Swarmops.Logic.Financial } - private AnnualReportNode CreateYearlyReportNode (int accountId, Dictionary[] lookup) + private AnnualReportNode CreateAnnualReportNode (int accountId, Dictionary[] lookup) { AnnualReportNode node = new AnnualReportNode(); node.PreviousYear = lookup[0][accountId]; @@ -210,6 +212,7 @@ namespace Swarmops.Logic.Financial } node.ThisYear = lookup[5][accountId]; + node.ThisYearBudget = lookup[6][accountId]; return node; } @@ -230,10 +233,12 @@ namespace Swarmops.Logic.Financial private void PopulateLookups (FinancialAccounts accounts) { - this._singleLookups = new Dictionary[6]; - this._treeLookups = new Dictionary[6]; + // Seven elements in each array: lastyear, q1, q2, q3, q4, thisyear, thisyearbudget - for (int index = 0; index < 6; index++) + this._singleLookups = new Dictionary[7]; + this._treeLookups = new Dictionary[7]; + + for (int index = 0; index < 7; index++) { this._treeLookups[index] = new Dictionary(); this._singleLookups[index] = new Dictionary(); @@ -252,6 +257,17 @@ namespace Swarmops.Logic.Financial foreach (FinancialAccount account in accounts) { + // If result account, find budget + + if (this._accountType == FinancialAccountType.Result) + { + this._singleLookups[6][account.Identity] = account.GetBudgetCents (this.Year); + } + else + { + this._singleLookups[6][account.Identity] = 0; // if balance account, this is zero + } + // Find this year's inbound if (this._accountType == FinancialAccountType.Result) @@ -300,7 +316,7 @@ namespace Swarmops.Logic.Financial // copy to treeLookups - for (int index = 0; index < 6; index++) + for (int index = 0; index < 7; index++) { this._treeLookups[index][account.Identity] = this._singleLookups[index][account.Identity]; } @@ -308,7 +324,7 @@ namespace Swarmops.Logic.Financial // 3) Add all children's values to parents - for (int index = 0; index < 6; index++) + for (int index = 0; index < 7; index++) { AddChildrenValuesToParents (this._treeLookups[index], accounts); } @@ -360,6 +376,7 @@ namespace Swarmops.Logic.Financial public Int64 PreviousYear; public Int64[] Quarters; public Int64 ThisYear; + public Int64 ThisYearBudget; public AnnualReportNode() { diff --git a/Site5/App_GlobalResources/Global.resx b/Site5/App_GlobalResources/Global.resx index 5d7dc7e5..f15dbf89 100644 --- a/Site5/App_GlobalResources/Global.resx +++ b/Site5/App_GlobalResources/Global.resx @@ -717,4 +717,12 @@ Previous + + YTD + Try to keep short if there isn't an established shortform for "Year To Date", like "So far" or similar + + + Flags + As in a table column header + \ No newline at end of file diff --git a/Site5/App_GlobalResources/Pages.Ledgers.resx b/Site5/App_GlobalResources/Pages.Ledgers.resx index 6ea91c46..4214c098 100644 --- a/Site5/App_GlobalResources/Pages.Ledgers.resx +++ b/Site5/App_GlobalResources/Pages.Ledgers.resx @@ -732,4 +732,14 @@ Payout #{0:N0}, {5} (expected {1:yyyy-MMM-dd}) for {2}: {3} {4:N2} 0 is the payout Id, 1 is the date (do edit format if called for in culture), 2 is the recipient name, and 3 4 is the currency and amount, 5 is the specification (like "Expense Claim #4711") + + Budget vs Actual + + + This page displays the budgeted breakdown compared to a breakdown of the actual outcome so far. + + + Budget vs Actual + Financial budget vs. Actual financial outcome + \ No newline at end of file diff --git a/Site5/MainMenu-v5-OpenLedgers.xml b/Site5/MainMenu-v5-OpenLedgers.xml index 39f62c35..dc2bec5f 100644 --- a/Site5/MainMenu-v5-OpenLedgers.xml +++ b/Site5/MainMenu-v5-OpenLedgers.xml @@ -28,7 +28,7 @@ 0 - /Pages/v5/Ledgers/BudgetVsActual.aspx + /Pages/v5/Ledgers/BudgetActual.aspx Link diff --git a/Site5/MainMenu-v5.xml b/Site5/MainMenu-v5.xml index eeaf7199..d7e8ce8c 100644 --- a/Site5/MainMenu-v5.xml +++ b/Site5/MainMenu-v5.xml @@ -301,6 +301,17 @@ Submenu + + Ledgers_BudgetVsActual + 0 + + iconshock-abacus + /Pages/v5/Ledgers/BudgetActual.aspx + Link + + + + Ledgers_LiquidityForecast 3 diff --git a/Site5/Pages/v5/Ledgers/BudgetActual.aspx b/Site5/Pages/v5/Ledgers/BudgetActual.aspx new file mode 100644 index 00000000..679f0bdb --- /dev/null +++ b/Site5/Pages/v5/Ledgers/BudgetActual.aspx @@ -0,0 +1,113 @@ +<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="BudgetActual.aspx.cs" Inherits="Pages_v5_Ledgers_BudgetActual" %> + + + + + + + +

<%= CurrentOrganization.Currency.DisplayCode %>
 Loading
 

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

+ +
+
+ +
+
+ +
+ diff --git a/Site5/Pages/v5/Ledgers/BudgetActual.aspx.cs b/Site5/Pages/v5/Ledgers/BudgetActual.aspx.cs new file mode 100644 index 00000000..bb655ffa --- /dev/null +++ b/Site5/Pages/v5/Ledgers/BudgetActual.aspx.cs @@ -0,0 +1,64 @@ +using System; +using System.Globalization; +using Resources; +using Resources.Pages; +using Swarmops.Logic.Security; + +public partial class Pages_v5_Ledgers_BudgetActual : PageV5Base +{ + protected void Page_Load (object sender, EventArgs e) + { + if (!CurrentOrganization.IsEconomyEnabled) + { + Response.Redirect ("/Pages/v5/Financial/EconomyNotEnabled.aspx", true); + return; + } + + PageIcon = "iconshock-abacus"; + PageTitle = Ledgers.BudgetActual_PageTitle; + InfoBoxLiteral = Ledgers.BudgetActual_Info; + + // Security: If the org has open ledgers, then anyone may read. Otherwise, Financials.Read. + + if (!String.IsNullOrEmpty(CurrentOrganization.OpenLedgersDomain)) + { + PageAccessRequired = new Access(AccessAspect.Null, AccessType.Read); + } + else + { + PageAccessRequired = new Access(CurrentOrganization, AccessAspect.Financials, AccessType.Read); + } + + + 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(); + } + + RegisterControl (EasyUIControl.DataGrid | EasyUIControl.Tree); + } + + private void Localize() + { + int year = DateTime.UtcNow.Year; + + this.LabelContentHeader.Text = string.Format (Ledgers.BudgetActual_ContentHeader, + CurrentOrganization.Name); + this.LiteralHeaderLastYearActual.Text = Global.Financial_Actuals + @" " + (year - 1).ToString(CultureInfo.InvariantCulture); + this.LiteralHeaderBudget.Text = Global.Financial_Budget + @" " + year.ToString(CultureInfo.InvariantCulture); ; + this.LiteralHeaderActual.Text = Global.Financial_Actuals + @" " + Global.Financial_YTD; + this.LiteralActual.Text = Global.Financial_Actuals; + this.LiteralBudget.Text = Global.Financial_Budget; + this.LiteralHeaderAccountName.Text = Ledgers.ProfitLossStatement_AccountName; + this.LiteralHeaderFlags.Text = Global.Global_Flags; + } +} \ No newline at end of file diff --git a/Site5/Pages/v5/Ledgers/Json-BudgetActualData.aspx b/Site5/Pages/v5/Ledgers/Json-BudgetActualData.aspx new file mode 100644 index 00000000..9d91194f --- /dev/null +++ b/Site5/Pages/v5/Ledgers/Json-BudgetActualData.aspx @@ -0,0 +1 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-BudgetActualData.aspx.cs" Inherits="Pages_v5_Ledgers_Json_BudgetActualData" %> diff --git a/Site5/Pages/v5/Ledgers/Json-BudgetActualData.aspx.cs b/Site5/Pages/v5/Ledgers/Json-BudgetActualData.aspx.cs new file mode 100644 index 00000000..9a92763f --- /dev/null +++ b/Site5/Pages/v5/Ledgers/Json-BudgetActualData.aspx.cs @@ -0,0 +1,131 @@ +using System; +using System.Collections.Generic; +using System.Globalization; +using Resources.Pages; +using Swarmops.Common.Enums; +using Swarmops.Logic.Financial; + +public partial class Pages_v5_Ledgers_Json_BudgetActualData : DataV5Base +{ + private AuthenticationData _authenticationData; + private int _year = 2012; + + protected void Page_Load (object sender, EventArgs e) + { + // Get auth data + + this._authenticationData = GetAuthenticationDataAndCulture(); + + // Get current year + + this._year = DateTime.Today.Year; + + string yearParameter = Request.QueryString["Year"]; + + if (!string.IsNullOrEmpty (yearParameter)) + { + this._year = Int32.Parse (yearParameter); // will throw if non-numeric - don't matter for app + } + + AnnualReport report = AnnualReport.Create (CurrentOrganization, this._year, FinancialAccountType.Result); + LocalizeRoot (report.ReportLines); + + Response.ContentType = "application/json"; + + Response.Output.WriteLine ("{\"rows\": " + RecurseReport (report.ReportLines) + ", \"footer\": [" + + WriteFooter (report.Totals) + "]}"); + + Response.End(); + } + + + private void LocalizeRoot (List lines) + { + Dictionary localizeMap = new Dictionary(); + + localizeMap["%ASSET_ACCOUNTGROUP%"] = Resources.Global.Financial_Asset; + localizeMap["%DEBT_ACCOUNTGROUP%"] = Resources.Global.Financial_Debt; + localizeMap["%INCOME_ACCOUNTGROUP%"] = Resources.Global.Financial_Income; + localizeMap["%COST_ACCOUNTGROUP%"] = Resources.Global.Financial_Cost; + + foreach (AnnualReportLine line in lines) + { + if (localizeMap.ContainsKey (line.AccountName)) + { + line.AccountName = localizeMap[line.AccountName]; + } + } + } + + + private string WriteFooter (AnnualReportNode totals) + { + string result = string.Format ("\"name\":\"{0}\"", Ledgers.ProfitLossStatement_Results); + + result += string.Format(CultureInfo.CurrentCulture, ",\"lastYearActual\":\"{0:N0}\"", + (double)totals.PreviousYear / -100.0); + + result += string.Format(CultureInfo.CurrentCulture, ",\"yearBudget\":\"{0:N0}\"", (double)totals.ThisYearBudget / 100.0); + + result += string.Format(CultureInfo.CurrentCulture, ",\"yearActual\":\"{0:N0}\"", (double)totals.ThisYear / -100.0); + + return "{" + result + "}"; + } + + + private string RecurseReport (List reportLines) + { + List elements = new List(); + + foreach (AnnualReportLine line in reportLines) + { + string element = string.Format ("\"id\":\"{0}\",\"name\":\"{1}\"", line.AccountId, + JsonSanitize (line.AccountName)); + + if (line.Children.Count > 0) + { + element += ",\"lastYearActual\":" + + JsonDualString (line.AccountId, line.AccountTreeValues.PreviousYear, + line.AccountValues.PreviousYear); + + element += ",\"yearBudget\":" + + JsonDualString(line.AccountId, -line.AccountTreeValues.ThisYearBudget, -line.AccountValues.ThisYearBudget); + + element += ",\"yearActual\":" + + JsonDualString (line.AccountId, line.AccountTreeValues.ThisYear, line.AccountValues.ThisYear); + + + element += ",\"state\":\"closed\",\"children\":" + RecurseReport (line.Children); + } + else + { + element += string.Format (CultureInfo.CurrentCulture, ",\"lastYearActual\":\"{0:N0}\"", + (double) line.AccountValues.PreviousYear/-100.0); + + element += string.Format(CultureInfo.CurrentCulture, ",\"yearBudget\":\"{0:N0}\"", + (double)line.AccountValues.ThisYearBudget / 100.0); + + element += string.Format (CultureInfo.CurrentCulture, ",\"yearActual\":\"{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 (CultureInfo.CurrentCulture, + "\"Σ {1:N0} \"", + accountId, treeValue/-100.00); + } + return string.Format (CultureInfo.CurrentCulture, + "\"Σ {1:N0}{2:N0}\"", + accountId, treeValue/-100.0, singleValue/-100.0); + } +} \ No newline at end of file