diff --git a/Basic/Types/Financial/BasicFinancialAccount.cs b/Basic/Types/Financial/BasicFinancialAccount.cs index bac28dae..709fa548 100644 --- a/Basic/Types/Financial/BasicFinancialAccount.cs +++ b/Basic/Types/Financial/BasicFinancialAccount.cs @@ -7,7 +7,8 @@ namespace Swarmops.Basic.Types.Financial { public BasicFinancialAccount (int financialAccountId, string name, FinancialAccountType accountType, int organizationId, int parentFinancialAccountId, int ownerPersonId, - bool open, int openedYear, int closedYear, bool expensable, bool administrative) + bool open, int openedYear, int closedYear, bool active, bool expensable, + bool administrative, int linkBackward, int linkForward) { this.FinancialAccountId = financialAccountId; this.Name = name; @@ -18,12 +19,15 @@ namespace Swarmops.Basic.Types.Financial this.Open = open; this.OpenedYear = openedYear; this.ClosedYear = closedYear; + this.Active = active; this.Expensable = expensable; this.Administrative = administrative; + this.LinkBackward = linkBackward; + this.LinkForward = linkForward; } public BasicFinancialAccount (BasicFinancialAccount original) : - this(original.Identity, original.Name, original.AccountType, original.OrganizationId, original.ParentFinancialAccountId, original.OwnerPersonId, original.Open, original.OpenedYear, original.ClosedYear, original.Expensable, original.Administrative) + this(original.Identity, original.Name, original.AccountType, original.OrganizationId, original.ParentFinancialAccountId, original.OwnerPersonId, original.Open, original.OpenedYear, original.ClosedYear, original.Active, original.Expensable, original.Administrative, original.LinkBackward, original.LinkForward) { // Empty copy constructor } @@ -38,8 +42,11 @@ namespace Swarmops.Basic.Types.Financial public bool Open { get; protected set; } public int OpenedYear { get; protected set; } public int ClosedYear { get; protected set; } + public bool Active { get; protected set; } public bool Expensable { get; protected set; } public bool Administrative { get; protected set; } + public int LinkBackward { protected get; set; } + public int LinkForward { protected get; set; } #region IHasIdentity Members diff --git a/Database/Database-Financials.cs b/Database/Database-Financials.cs index 718c90ee..1a41b06b 100644 --- a/Database/Database-Financials.cs +++ b/Database/Database-Financials.cs @@ -19,7 +19,7 @@ namespace Swarmops.Database private const string financialAccountFieldSequence = " FinancialAccountId,Name,OrganizationId,AccountType,ParentFinancialAccountId," + // 0-4 " OwnerPersonId,Open,OpenedYear,ClosedYear,Expensable," + // 5-9 - " Administrative " + // 10 + " Administrative,Active,LinkBackward,LinkForward " + // 10-13 " FROM FinancialAccounts "; public int CreateFinancialAccount(int pOrganizationId, string pName, FinancialAccountType pAccountType, int pParentFinancialAccountId) @@ -765,7 +765,7 @@ namespace Swarmops.Database { connection.Open(); - DbCommand command = GetDbCommand("SetFinancialAccountOpen", connection); + DbCommand command = GetDbCommand("SetFinancialAccountAdministrative", connection); command.CommandType = CommandType.StoredProcedure; AddParameterWithName(command, "financialAccountId", financialAccountId); @@ -864,8 +864,11 @@ namespace Swarmops.Database int closedYear = reader.GetInt32(8); bool expensable = reader.GetBoolean(9); bool administrative = reader.GetBoolean(10); + bool active = reader.GetBoolean(11); + int linkBackward = reader.GetInt32(12); + int linkForward = reader.GetInt32(13); - return new BasicFinancialAccount(accountId, name, accountType, organizationId, parentFinancialAccountId, ownerPersonId, open, openedYear, closedYear, expensable, administrative); + return new BasicFinancialAccount(accountId, name, accountType, organizationId, parentFinancialAccountId, ownerPersonId, open, openedYear, closedYear, active, expensable, administrative, linkBackward, linkForward); } private BasicFinancialAccountRow ReadFinancialAccountRowFromDataReader (DbDataReader reader) diff --git a/Logic/Financial/FinancialAccount.cs b/Logic/Financial/FinancialAccount.cs index a93ffc6a..6627331b 100644 --- a/Logic/Financial/FinancialAccount.cs +++ b/Logic/Financial/FinancialAccount.cs @@ -170,8 +170,10 @@ namespace Swarmops.Logic.Financial // This is ok. OpenedYear can throw an ArgumentException if there aren't any transactions yet. } - base.ParentFinancialAccountId = value.Identity; - SwarmDb.GetDatabaseForWriting().SetFinancialAccountParent(this.Identity, value.Identity); + int newParentId = value != null ? value.Identity : 0; + + base.ParentFinancialAccountId = newParentId; + SwarmDb.GetDatabaseForWriting().SetFinancialAccountParent(this.Identity, newParentId); } } @@ -213,7 +215,7 @@ namespace Swarmops.Logic.Financial } - public string Name + public new string Name { get { return base.Name; } set @@ -273,6 +275,53 @@ namespace Swarmops.Logic.Financial } } + public new bool Active + { + get { return base.Active; } + set + { + if (base.Active == value) + { + return; + } + + base.Active = value; + SwarmDb.GetDatabaseForWriting().SetFinancialAccountActive(this.Identity, value); + } + } + + + public new bool Expensable + { + get { return base.Expensable; } + set + { + if (base.Expensable == value) + { + return; + } + + base.Expensable = value; + SwarmDb.GetDatabaseForWriting().SetFinancialAccountExpensable(this.Identity, value); + } + } + + + public new bool Administrative + { + get { return base.Administrative; } + set + { + if (base.Administrative == value) + { + return; + } + + base.Administrative = value; + SwarmDb.GetDatabaseForWriting().SetFinancialAccountAdministrative(this.Identity, value); + } + } + #region ITreeNode Members diff --git a/Logic/Support/DatabaseMaintenance.cs b/Logic/Support/DatabaseMaintenance.cs index abf63b2f..196be7e2 100644 --- a/Logic/Support/DatabaseMaintenance.cs +++ b/Logic/Support/DatabaseMaintenance.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Linq; using System.Net; using System.Text; +using MySql.Data.MySqlClient; using Swarmops.Logic.Swarm; using Swarmops.Database; using System.Globalization; @@ -76,7 +77,17 @@ namespace Swarmops.Logic.Support foreach (string sqlCommand in sqlCommands) { - SwarmDb.GetDatabaseForAdmin().ExecuteAdminCommand(sqlCommand.Trim()); + try + { + SwarmDb.GetDatabaseForAdmin().ExecuteAdminCommand(sqlCommand.Trim()); + } + catch (MySqlException exception) + { + SwarmDb.GetDatabaseForWriting() + .CreateExceptionLogEntry(DateTime.UtcNow, "DatabaseUpgrade", exception); + + throw; + } } upgraded = true; diff --git a/Site5/Pages/v5/Ledgers/AccountPlan.aspx b/Site5/Pages/v5/Ledgers/AccountPlan.aspx index 1a429f8b..96b9b097 100644 --- a/Site5/Pages/v5/Ledgers/AccountPlan.aspx +++ b/Site5/Pages/v5/Ledgers/AccountPlan.aspx @@ -102,12 +102,12 @@ .change(function() { if (!suppressSwitchChangeAction) { $(this).parent().css('box-shadow', '0 0 1px 0 #FFFFC0'); - console.log($(this).checked); + var callParameters = "{'accountId': '" + escape(accountId) + "', 'switchName':'" + $(this).attr("rel") + "','switchValue':'" + $(this).prop('checked') + "'}"; $.ajax({ type: "POST", url: "AccountPlan.aspx/SetAccountSwitch", - data: "{'accountId': '" + escape(accountId) + "', 'switchName':'" + $(this).attr("rel") + "','switchValue':'" + $(this).checked + "'}", + data: callParameters, contentType: "application/json; charset=utf-8", dataType: "json", success: $.proxy(function(msg) { @@ -146,6 +146,15 @@ checkboxesInitialized = true; } + if (!parentDropInitialized) { + parentDropInitialized = true; + // Another weird construct for same reason. Show and hide the box once, and it'll init properly next. + setTimeout(function() { + $('#<%=this.DropParents.ClientID %>_SpanBudgets span.combo span span.combo-arrow').click(); + $('#<%=this.DropParents.ClientID %>_SpanBudgets span.combo span span.combo-arrow').click(); + }, 100); + } + $.ajax({ type: "POST", url: "AccountPlan.aspx/GetAccountData", @@ -155,7 +164,7 @@ success: function (msg) { suppressSwitchChangeAction = true; - $("#CheckAccountActive").prop("checked", msg.d.Open).change(); + $("#CheckAccountActive").prop("checked", msg.d.Active).change(); $("#CheckAccountExpensable").prop("checked", msg.d.Expensable).change(); $("#CheckAccountAdministrative").prop("checked", msg.d.Administrative).change(); suppressSwitchChangeAction = false; @@ -260,7 +269,7 @@ data: "{'accountId': '" + escape(accountId) + "', 'budget':'" + escape(newAccountBudget) + "'}", contentType: "application/json; charset=utf-8", dataType: "json", - success: function(msg) { // TODO: This needs four return values - changed, broken and changed, invalid, or not changed. Also, formatted number + success: function(msg) { if (msg.d.Result == 3 || msg.d.Result == 4) { // Invalid or NoPermission $('#TextAccountBudget').css('background-color', '#FFA0A0'); alertify.error("There was an error attempting to set your proposed budget."); // TODO: Localize @@ -322,7 +331,7 @@ if (currentText.length < 3) { accountTree.combotree('setText', parentAccountName); $('span#<%= DropParents.ClientID %>_SpanBudgets span input.combo-text').css('background-color', '#FFF'); - } else { + } else if (!accountTreeLoaded) { setTimeout(function() { setAccountTreeText(text); }, 250); @@ -330,17 +339,45 @@ } - function onAccountTreeSelect() { - alert('bar'); - } + function onAccountTreeSelect(parentAccountId) { + if (!accountTreeLoaded) { + return; + } + + $('span#<%= DropParents.ClientID %>_SpanBudgets span input.combo-text').css('background-color', '#FFFFE0'); + $.ajax({ + type: "POST", + url: "AccountPlan.aspx/SetAccountParent", + data: "{'accountId':'" + escape(accountId) + "','parentAccountId':'" + escape(parentAccountId) + "'}", + contentType: "application/json; charset=utf-8", + dataType: "json", + success: function(msg) { + if (msg.d) { // all went ok + $('span#<%= DropParents.ClientID %>_SpanBudgets span input.combo-text').css('background-color', '#E0FFE0'); + accountDirty = true; + } else { + $('span#<%= DropParents.ClientID %>_SpanBudgets span input.combo-text').css('background-color', '#FFA0A0'); + $('#<%=DropParents.ClientID %>_DropBudgets').combotree('setText', parentAccountName); + alertify.error("Cannot reparent accounts with transactions in closed ledgers - yet."); // TODO: Localize + } + $('span#<%= DropParents.ClientID %>_SpanBudgets span input.combo-text').animate({ backgroundColor: "#FFFFFF" }, 250); + }, + error: function() { + alertify.error("There was an error making the call to set budget parent. Is the server available?"); + $('span#<%= DropParents.ClientID %>_SpanBudgets span input.combo-text').css('background-color', '#FFA0A0'); + $('#<%=DropParents.ClientID %>_DropBudgets').combotree('setText', parentAccountName); + $('span#<%= DropParents.ClientID %>_SpanBudgets span input.combo-text').animate({ backgroundColor: "#FFFFFF" }, 250); + } + }); + } function onAccountTreeLoaded() { - // this didn't work much - not called on "reload" - alert('foo2'); + var accountTree = $('#<%=DropParents.ClientID %>_DropBudgets'); + // accountTree.combotree('select', 0); // clear any previous selection accountTreeLoaded = true; if (parentAccountName.length > 0) { - $('#<%=DropParents.ClientID %>_DropBudgets').combotree('setText', parentAccountName); + accountTree.combotree('setText', parentAccountName); $('span#<%= DropParents.ClientID %>_SpanBudgets span input.combo-text').css('background-color', '#FFF'); } } @@ -355,6 +392,7 @@ var accountDirty = false; var checkboxesInitialized = false; + var parentDropInitialized = false; var suppressSwitchChangeAction = false; var accountTreeLoaded = false; var parentAccountName = ''; @@ -402,7 +440,7 @@