From 19f071bed2725cdb1d08da15d52eeca5e73fce17 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Sat, 8 Dec 2012 14:07:55 +0000 Subject: [PATCH] P&L is basically working - year selection and loc remains --- .../v5/Ledgers/Json-ProfitLossData.aspx.cs | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/Site5/Pages/v5/Ledgers/Json-ProfitLossData.aspx.cs b/Site5/Pages/v5/Ledgers/Json-ProfitLossData.aspx.cs index 81848120..2e43e63e 100644 --- a/Site5/Pages/v5/Ledgers/Json-ProfitLossData.aspx.cs +++ b/Site5/Pages/v5/Ledgers/Json-ProfitLossData.aspx.cs @@ -82,13 +82,31 @@ public partial class Pages_v5_Ledgers_Json_ProfitLossData : System.Web.UI.Page if (treeMap.ContainsKey(account.Identity)) { - element += string.Format(",\"lastYear\":\"Σ {1:N2}{2:N2}\"", account.Identity, treeLookups[0][account.Identity] / -100.0, singleLookups[0][account.Identity] / -100.0); + element += ",\"lastYear\":" + + JsonDualString(account.Identity, treeLookups[0][account.Identity], singleLookups[0][account.Identity]); + + for (int quarter = 1; quarter <= 4; quarter++) + { + element += string.Format(",\"q{0}\":", quarter) + + JsonDualString(account.Identity, treeLookups[quarter][account.Identity], singleLookups[quarter][account.Identity]); + } + + element += ",\"ytd\":" + + JsonDualString(account.Identity, treeLookups[5][account.Identity], singleLookups[5][account.Identity]); + element += ",\"state\":\"closed\",\"children\":" + RecurseTreeMap(treeMap, account.Identity); } else { - element += string.Format(",\"lastYear\":\"{0:N2}\"", (double) singleLookups[0][account.Identity] / -100.0); + element += string.Format(",\"lastYear\":\"{0:N0}\"", (double)singleLookups[0][account.Identity] / -100.0); + + for (int quarter = 1; quarter <= 4; quarter++) + { + element += string.Format(",\"q{0}\":\"{1:N0}\"", quarter, singleLookups[quarter][account.Identity]); + } + + element += string.Format(",\"ytd\":\"{0:N0}\"", (double)singleLookups[5][account.Identity] / -100.0); } elements.Add("{" + element + "}"); @@ -98,6 +116,16 @@ public partial class Pages_v5_Ledgers_Json_ProfitLossData : System.Web.UI.Page } + private string JsonDualString (int accountId, Int64 treeValue, Int64 singleValue) + { + if (treeValue != 0 && singleValue == 0) + { + return string.Format("\"Σ {1:N0} \"", accountId, treeValue / -100.00); + } + return string.Format("\"Σ {1:N0}{2:N0}\"", accountId, treeValue / -100.0, singleValue / -100.0); + } + + private void PopulateOrderedList (Dictionary> treeMap, FinancialAccounts orderedList, int renderNodeId) { foreach (FinancialAccount account in treeMap[renderNodeId])