From b6319750ab27db8a401572f6afdb2edf10465c07 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Fri, 23 Jan 2015 19:00:38 +0100 Subject: [PATCH] Account Plan enhancements 2 --- Site5/App_GlobalResources/Pages.Ledgers.resx | 4 ++ Site5/Pages/v5/Ledgers/AccountPlan.aspx | 38 +++++++++++++++++-- Site5/Pages/v5/Ledgers/AccountPlan.aspx.cs | 26 +++++++++++++ .../v5/Ledgers/Json-AccountPlanData.aspx.cs | 2 +- 4 files changed, 65 insertions(+), 5 deletions(-) diff --git a/Site5/App_GlobalResources/Pages.Ledgers.resx b/Site5/App_GlobalResources/Pages.Ledgers.resx index b84176fc..894e093d 100644 --- a/Site5/App_GlobalResources/Pages.Ledgers.resx +++ b/Site5/App_GlobalResources/Pages.Ledgers.resx @@ -562,4 +562,8 @@ Initial Balance (inbound into {0}), {1} {0} is the first ledger year in Swarmops. {1} is the currency code. + + Show Inactive Accounts (<span id="SpanInactiveCount">{0:N0}</span>) + The {0} is the number of inactive accounts. + \ No newline at end of file diff --git a/Site5/Pages/v5/Ledgers/AccountPlan.aspx b/Site5/Pages/v5/Ledgers/AccountPlan.aspx index 93fb17eb..b8e96639 100644 --- a/Site5/Pages/v5/Ledgers/AccountPlan.aspx +++ b/Site5/Pages/v5/Ledgers/AccountPlan.aspx @@ -51,9 +51,10 @@ }, rowStyler: function (rowData) { - if (rowData.inactive == true) + console.log(rowData); + if (rowData.inactive == "true") { - return { class: 'RowInactive', style: { color: '#c0c0c0' } }; + return { class: 'RowInactive' }; } } }); @@ -200,6 +201,16 @@ }); }); + $('#CheckOptionsShowInactive').change(function() { + if ($(this).prop("checked")) + { + $('.RowInactive').slideDown(); + } + else + { + $('.RowInactive').slideUp(); + } + }); }); @@ -332,6 +343,8 @@ boxShadow: '0 0 10px 2px rgba(0,255,0,0)' }, 250); accountDirty = true; + // update the "inactive count" display for all success calls, even though we only need it for "active" + updateInactiveCount(); } else { suppressSwitchChangeAction = true; $(this).click(); @@ -407,6 +420,20 @@ } + function updateInactiveCount() + { + $.ajax({ + type: "POST", + url: "/Pages/v5/Ledgers/AccountPlan.aspx/GetInactiveAccountCount", + data: "{}", + contentType: "application/json; charset=utf-8", + dataType: "json", + success: function(msg) { + $("#SpanInactiveCount").text(msg.d); + } + }); + } + function modalShow() { $('#divModalCover').fadeIn(); } @@ -533,6 +560,7 @@ .RowInactive { color: #C0C0C0; + display: none; } @@ -606,8 +634,10 @@

-
- +
+
diff --git a/Site5/Pages/v5/Ledgers/AccountPlan.aspx.cs b/Site5/Pages/v5/Ledgers/AccountPlan.aspx.cs index ca1bb100..2b8dcc97 100644 --- a/Site5/Pages/v5/Ledgers/AccountPlan.aspx.cs +++ b/Site5/Pages/v5/Ledgers/AccountPlan.aspx.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Collections.Generic; using System.Globalization; using System.Web; @@ -87,6 +88,11 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers this.LiteralLabelInitialAmount.Text = String.Format (Resources.Pages.Ledgers.AccountPlan_Edit_InitialBalance, CurrentOrganization.FirstFiscalYear, CurrentOrganization.Currency.DisplayCode); + + FinancialAccounts organizationAccounts = FinancialAccounts.ForOrganization(this.CurrentOrganization); + int inactiveCount = organizationAccounts.Count(account => !account.Active); + + this.LabelOptionsShowInactive.Text = String.Format(Resources.Pages.Ledgers.AccountPlan_Options_ShowInactive, inactiveCount); } PageAccessRequired = new Access (CurrentOrganization, AccessAspect.Bookkeeping, AccessType.Write); DbVersionRequired = 2; // Account reparenting @@ -383,12 +389,22 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers Int64 newSingleBudget = newTreeBudget - suballocatedBudget; account.SetBudgetCents (DateTime.Today.Year, newSingleBudget); + + // Once we've set the budget, also update the "yearly result" budget + + 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); + return new ChangeAccountDataResult { Result = ChangeAccountDataOperationsResult.Changed, NewData = (newTreeBudget/100).ToString ("N0", CultureInfo.CurrentCulture) }; } + return new ChangeAccountDataResult { Result = ChangeAccountDataOperationsResult.Invalid @@ -436,6 +452,16 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers } + [WebMethod] + public static string GetInactiveAccountCount() + { + AuthenticationData authData = GetAuthenticationDataAndCulture(); + + int inactiveAccountCount = FinancialAccounts.ForOrganization(authData.CurrentOrganization).Count(account => !account.Active); + return inactiveAccountCount.ToString("N0"); + } + + public class ChangeAccountDataResult { public ChangeAccountDataOperationsResult Result { set; get; } diff --git a/Site5/Pages/v5/Ledgers/Json-AccountPlanData.aspx.cs b/Site5/Pages/v5/Ledgers/Json-AccountPlanData.aspx.cs index f12b5caa..bba34f20 100644 --- a/Site5/Pages/v5/Ledgers/Json-AccountPlanData.aspx.cs +++ b/Site5/Pages/v5/Ledgers/Json-AccountPlanData.aspx.cs @@ -145,7 +145,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers CultureInfo.CurrentCulture) : string.Empty, editString, - account.Active? "true":"false" + account.Active? "false":"true" // reverses condition on purpose ) + grandChildren + '}'); }