Added Budget vs. Actual report
This commit is contained in:
@@ -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<int, Int64>[] lookup)
|
||||
private AnnualReportNode CreateAnnualReportNode (int accountId, Dictionary<int, Int64>[] 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<int, Int64>[6];
|
||||
this._treeLookups = new Dictionary<int, Int64>[6];
|
||||
// Seven elements in each array: lastyear, q1, q2, q3, q4, thisyear, thisyearbudget
|
||||
|
||||
for (int index = 0; index < 6; index++)
|
||||
this._singleLookups = new Dictionary<int, Int64>[7];
|
||||
this._treeLookups = new Dictionary<int, Int64>[7];
|
||||
|
||||
for (int index = 0; index < 7; index++)
|
||||
{
|
||||
this._treeLookups[index] = new Dictionary<int, Int64>();
|
||||
this._singleLookups[index] = new Dictionary<int, Int64>();
|
||||
@@ -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()
|
||||
{
|
||||
|
||||
@@ -717,4 +717,12 @@
|
||||
<data name="Global_WizardPrevious" xml:space="preserve">
|
||||
<value>Previous</value>
|
||||
</data>
|
||||
<data name="Financial_YTD" xml:space="preserve">
|
||||
<value>YTD</value>
|
||||
<comment>Try to keep short if there isn't an established shortform for "Year To Date", like "So far" or similar</comment>
|
||||
</data>
|
||||
<data name="Global_Flags" xml:space="preserve">
|
||||
<value>Flags</value>
|
||||
<comment>As in a table column header</comment>
|
||||
</data>
|
||||
</root>
|
||||
@@ -732,4 +732,14 @@
|
||||
<value>Payout #{0:N0}, {5} (expected {1:yyyy-MMM-dd}) for {2}: {3} {4:N2}</value>
|
||||
<comment>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")</comment>
|
||||
</data>
|
||||
<data name="BudgetActual_ContentHeader" xml:space="preserve">
|
||||
<value>Budget vs Actual</value>
|
||||
</data>
|
||||
<data name="BudgetActual_Info" xml:space="preserve">
|
||||
<value>This page displays the budgeted breakdown compared to a breakdown of the actual outcome so far.</value>
|
||||
</data>
|
||||
<data name="BudgetActual_PageTitle" xml:space="preserve">
|
||||
<value>Budget vs Actual</value>
|
||||
<comment>Financial budget vs. Actual financial outcome</comment>
|
||||
</data>
|
||||
</root>
|
||||
@@ -28,7 +28,7 @@
|
||||
<UserLevel>0</UserLevel>
|
||||
<Permissions />
|
||||
<ImageUrl />
|
||||
<NavigateUrl>/Pages/v5/Ledgers/BudgetVsActual.aspx</NavigateUrl>
|
||||
<NavigateUrl>/Pages/v5/Ledgers/BudgetActual.aspx</NavigateUrl>
|
||||
<Type>Link</Type>
|
||||
<Children />
|
||||
</MainMenuItem>
|
||||
|
||||
@@ -301,6 +301,17 @@
|
||||
<Type>Submenu</Type>
|
||||
<Children>
|
||||
|
||||
<MainMenuItem>
|
||||
<ResourceKey>Ledgers_BudgetVsActual</ResourceKey>
|
||||
<UserLevel>0</UserLevel>
|
||||
<Permissions />
|
||||
<ImageUrl>iconshock-abacus</ImageUrl>
|
||||
<NavigateUrl>/Pages/v5/Ledgers/BudgetActual.aspx</NavigateUrl>
|
||||
<Type>Link</Type>
|
||||
<Children />
|
||||
</MainMenuItem>
|
||||
|
||||
|
||||
<MainMenuItem>
|
||||
<ResourceKey>Ledgers_LiquidityForecast</ResourceKey>
|
||||
<UserLevel>3</UserLevel>
|
||||
|
||||
@@ -0,0 +1,113 @@
|
||||
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="BudgetActual.aspx.cs" Inherits="Pages_v5_Ledgers_BudgetActual" %>
|
||||
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
|
||||
|
||||
<script type="text/javascript">
|
||||
|
||||
$(document).ready(function () {
|
||||
|
||||
$('#tableBudgetActual').treegrid(
|
||||
{
|
||||
onBeforeExpand: function (foo) {
|
||||
$('span.budgetactualdata-collapsed-' + foo.id).fadeOut('fast', function () {
|
||||
$('span.budgetactualdata-expanded-' + foo.id).fadeIn('slow');
|
||||
});
|
||||
},
|
||||
|
||||
onBeforeCollapse: function (foo) {
|
||||
$('span.budgetactualdata-expanded-' + foo.id).fadeOut('fast', function () {
|
||||
$('span.budgetactualdata-collapsed-' + foo.id).fadeIn('slow');
|
||||
});
|
||||
},
|
||||
|
||||
onLoadSuccess: function () {
|
||||
$('div.datagrid').css('opacity', 1);
|
||||
$('#imageLoadIndicator').hide();
|
||||
$('span.loadingHeader').hide();
|
||||
$('span.allYearsHeader').show();
|
||||
|
||||
var selectedYear = $('#<%=DropYears.ClientID %>').val();
|
||||
|
||||
if (selectedYear == currentYear)
|
||||
{
|
||||
$('span.previousYearsHeader').hide();
|
||||
$('span.currentYearHeader').show();
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#previousLastActual').text(actualLoc + ' ' + (selectedYear - 1));
|
||||
$('#previousBudget').text(budgetLoc + ' ' + selectedYear);
|
||||
$('#previousYtd').text(actualLoc + ' ' + selectedYear);
|
||||
|
||||
$('span.currentYearHeader').hide();
|
||||
$('span.previousYearsHeader').show();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
$('#<%=DropYears.ClientID %>').change(function () {
|
||||
var selectedYear = $('#<%=DropYears.ClientID %>').val();
|
||||
|
||||
$('#tableBudgetActual').treegrid({ url: 'Json-BudgetActualData.aspx?Year=' + selectedYear });
|
||||
$('#imageLoadIndicator').show();
|
||||
$('div.datagrid').css('opacity', 0.4);
|
||||
|
||||
$('#tableBudgetActual').treegrid('reload');
|
||||
});
|
||||
|
||||
|
||||
$('div.datagrid').css('opacity', 0.4);
|
||||
});
|
||||
|
||||
var currentYear = <%=DateTime.Today.Year %>;
|
||||
|
||||
var budgetLoc = '<asp:Literal ID="LiteralBudget" runat="server" />';
|
||||
var actualLoc = '<asp:Literal ID="LiteralActual" runat="server" />';
|
||||
|
||||
</script>
|
||||
<style>
|
||||
.content h2 select {
|
||||
font-size: 16px;
|
||||
font-weight: bold;
|
||||
color: #1C397E;
|
||||
letter-spacing: 1px;
|
||||
}
|
||||
table.datagrid-ftable {
|
||||
font-weight: 500;
|
||||
}
|
||||
</style>
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
|
||||
<h2><div class="elementFloatFar"><%= CurrentOrganization.Currency.DisplayCode %></div><div class="elementFloatNear"><asp:Label ID="LabelContentHeader" runat="server" /> <asp:DropDownList runat="server" ID="DropYears"/> <img alt="Loading" src="/Images/Abstract/ajaxloader-blackcircle.gif" ID="imageLoadIndicator" /></div> </h2>
|
||||
<table id="tableBudgetActual" title="" class="easyui-treegrid" style="width:680px;height:600px"
|
||||
url="Json-BudgetActualData.aspx"
|
||||
rownumbers="false"
|
||||
animate="true" showFooter="true" fitColumns="true"
|
||||
idField="id" treeField="name">
|
||||
<thead>
|
||||
<tr>
|
||||
<th field="name" width="178"><asp:Literal ID="LiteralHeaderAccountName" runat="server"/></th>
|
||||
<th field="lastYearActual" width="80" align="right"><span class="previousYearsHeader" id="previousLastActual" style="display:none"></span><span class="currentYearHeader" style="display:none"><asp:Literal ID="LiteralHeaderLastYearActual" runat="server" /></span><span class="loadingHeader">—</span></th>
|
||||
<th field="yearBudget" width="80" align="right"><span class="previousYearsHeader" id="previousBudget" style="display:none"></span><span class="currentYearHeader" style="display:none" id="currentQ1"><asp:Literal ID="LiteralHeaderBudget" runat="server" /></span><span class="loadingHeader">—</span></th>
|
||||
<th field="yearActual" width="80" align="right"><span class="previousYearsHeader" id="previousYtd" style="display:none"></span><span class="currentYearHeader" style="display:none" id="currentQ2"><asp:Literal ID="LiteralHeaderActual" runat="server" /></span><span class="loadingHeader">—</span></th>
|
||||
<th field="flags" width="40" align="right"><span class="allYearsHeader" style="display:none" id="currentFlags"><asp:Literal ID="LiteralHeaderFlags" runat="server" /></span><span class="loadingHeader">—</span></th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
<div style="clear:both"></div>
|
||||
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderSide" Runat="Server">
|
||||
<h2 class="blue"><asp:Label ID="LabelSidebarDownload" Text="Download This" runat="server" /><span class="arrow"></span></h2>
|
||||
|
||||
<div class="box">
|
||||
<div class="content">
|
||||
<div class="link-row-encaps" id="linkDownloadReport" onclick="document.location='placeholder';" >
|
||||
<div class="link-row-icon" style="background-image:url('/Images/Icons/iconshock-downarrow-16px.png');background-position:-1px -1px"></div>
|
||||
<span id="spanDownloadText">ProfitLossxxxx-yyyymmdd.csv</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</asp:Content>
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-BudgetActualData.aspx.cs" Inherits="Pages_v5_Ledgers_Json_BudgetActualData" %>
|
||||
@@ -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<AnnualReportLine> lines)
|
||||
{
|
||||
Dictionary<string, string> localizeMap = new Dictionary<string, string>();
|
||||
|
||||
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<AnnualReportLine> reportLines)
|
||||
{
|
||||
List<string> elements = new List<string>();
|
||||
|
||||
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,
|
||||
"\"<span class=\\\"budgetactualdata-collapsed-{0}\\\"><strong>Σ</strong> {1:N0}</span><span class=\\\"budgetactualdata-expanded-{0}\\\" style=\\\"display:none\\\"> </span>\"",
|
||||
accountId, treeValue/-100.00);
|
||||
}
|
||||
return string.Format (CultureInfo.CurrentCulture,
|
||||
"\"<span class=\\\"budgetactualdata-collapsed-{0}\\\"><strong>Σ</strong> {1:N0}</span><span class=\\\"budgetactualdata-expanded-{0}\\\" style=\\\"display:none\\\">{2:N0}</span>\"",
|
||||
accountId, treeValue/-100.0, singleValue/-100.0);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user