Account Plan enhancements 4

This commit is contained in:
Rick Falkvinge
2015-01-24 09:42:54 +01:00
parent 71aa07e60f
commit 9339511baa
4 changed files with 49 additions and 6 deletions
+9 -1
View File
@@ -134,7 +134,7 @@
</data>
<data name="BalanceSheet_ContentHeader" xml:space="preserve">
<value>Balance Sheet for {0},</value>
<comment>{0} is the organization name. The year follows immediately.</comment>
<comment>{0} is the organization name. The year follows immediately, so keep ending comma.</comment>
</data>
<data name="BalanceSheet_Current" xml:space="preserve">
<value>Current</value>
@@ -566,4 +566,12 @@
<value>Show Inactive Accounts (&lt;span id="SpanInactiveCount"&gt;{0:N0}&lt;/span&gt;)</value>
<comment>The {0} is the number of inactive accounts.</comment>
</data>
<data name="AccountPlan_ProjectedLoss" xml:space="preserve">
<value>Projected Loss {0}</value>
<comment>"Projected" as in "Budgeted". {0} is year.</comment>
</data>
<data name="AccountPlan_ProjectedProfit" xml:space="preserve">
<value>Projected Profit {0}</value>
<comment>"Projected" as in "Budgeted". {0} is year.</comment>
</data>
</root>
+14 -1
View File
@@ -48,10 +48,18 @@
beginEditAccount();
});
if ($('#CheckOptionShowInactive').prop("checked"))
{
$('.RowInactive').show();
}
},
rowStyler: function (rowData) {
console.log(rowData);
if (rowData.rowCssClass != null)
{
return { class: rowData.rowCssClass };
}
if (rowData.inactive == "true")
{
return { class: 'RowInactive' };
@@ -562,6 +570,11 @@
color: #C0C0C0;
display: none;
}
.RowProjectedLoss, .RowProjectedProfit
{
font-weight:500;
}
</style>
</asp:Content>
+3 -3
View File
@@ -391,14 +391,14 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
account.SetBudgetCents (DateTime.Today.Year, newSingleBudget);
// Once we've set the budget, also update the "yearly result" budget.
// This will be the WRONG SIGN for a P&L budget, but much better for display purposes (positive result is a profit, negative a loss).
// Will need to compensate for this in a future budget vs. actuals display.
// The "yearly result" budget isn't shown in the account plan, but is
// abstracted to "projected loss" or "projected gain" pseudobudgets.
int thisYear = DateTime.UtcNow.Year;
FinancialAccounts allProfitLossAccounts = FinancialAccounts.ForOrganization(authData.CurrentOrganization);
Int64 newProfitLossProjection = allProfitLossAccounts.Where(queryAccount => queryAccount.Identity != authData.CurrentOrganization.FinancialAccounts.CostsYearlyResult.Identity).Sum(queryAccount => queryAccount.GetBudgetCents(thisYear));
authData.CurrentOrganization.FinancialAccounts.CostsYearlyResult.SetBudgetCents(thisYear, newProfitLossProjection);
authData.CurrentOrganization.FinancialAccounts.CostsYearlyResult.SetBudgetCents(thisYear, -newProfitLossProjection);
return new ChangeAccountDataResult
{
@@ -19,6 +19,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
private Dictionary<int, Int64> _treeBalanceLookup;
private Dictionary<int, Int64> _treeBudgetLookup;
private int _year = 2012;
private int _resultAccountId;
protected void Page_Load (object sender, EventArgs e)
{
@@ -40,6 +41,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
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) + ",";
@@ -55,6 +57,16 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
{
string childrenString = GetAccountsRecurse (type, 0);
Int64 projectedResults = _treeBudgetLookup.ContainsKey (_resultAccountId) ? _treeBudgetLookup[_resultAccountId] : 0;
if (type == FinancialAccountType.Income && projectedResults <= 0) // expected profit or zero
{
childrenString += "," + GetProfitLossNode("ProjectedProfit", -projectedResults);
}
else if (type == FinancialAccountType.Cost && projectedResults >= 0) // expected loss or zero
{
childrenString += "," + GetProfitLossNode("ProjectedLoss", projectedResults);
}
string addString =
String.Format (
"<img class=\\\"IconAdd\\\" accountType=\\\"{0}\\\" src=\\\"/Images/Icons/iconshock-add-16px.png\\\" />",
@@ -66,6 +78,16 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
"</a>)\",\"state\":\"open\",\"children\":[" + childrenString + "],\"action\":\"" + addString + "\"}";
}
private string GetProfitLossNode(string resource, Int64 amount)
{
string node = '{' + string.Format(
"\"id\":\"{0}\",\"accountName\":\"{1}\",\"rowCssClass\":\"{2}\",\"budget\":\"{3:N0}\"",
"Row" + resource, string.Format (Resources.Pages.Ledgers.ResourceManager.GetString("AccountPlan_" + resource), _year), "Row" + resource, amount / 100.0) + '}';
return node;
}
private string GetAccountsRecurse (FinancialAccountType accountType, int rootNodeId)
{
List<string> childStrings = new List<string>();
@@ -84,7 +106,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
foreach (FinancialAccount account in this._hashedAccounts[rootNodeId])
{
if (account.Identity == rootNodeId || account.AccountType != accountType)
if (account.Identity == rootNodeId || account.AccountType != accountType || account.Identity == _resultAccountId)
{
continue;
}