diff --git a/Basic/Types/Financial/BasicFinancialAccount.cs b/Basic/Types/Financial/BasicFinancialAccount.cs index 296d99d5..bac28dae 100644 --- a/Basic/Types/Financial/BasicFinancialAccount.cs +++ b/Basic/Types/Financial/BasicFinancialAccount.cs @@ -34,7 +34,7 @@ namespace Swarmops.Basic.Types.Financial public int OrganizationId { get; private set; } public FinancialAccountType AccountType { get; private set; } public int OwnerPersonId { get; protected set; } - public int ParentFinancialAccountId { get; private set; } + public int ParentFinancialAccountId { get; protected set; } public bool Open { get; protected set; } public int OpenedYear { get; protected set; } public int ClosedYear { get; protected set; } diff --git a/Database/Database-Constructors.cs b/Database/Database-Constructors.cs index a449c619..076dec2a 100644 --- a/Database/Database-Constructors.cs +++ b/Database/Database-Constructors.cs @@ -49,6 +49,9 @@ namespace Swarmops.Database } + /// + /// The actual revision of the database (as told by the database). + /// public static int DbVersion { get @@ -67,6 +70,14 @@ namespace Swarmops.Database } } + /// + /// This is the IN-CODE revision of the database. The version we expect to be running against. + /// + public static int DbVersionExpected + { + get { return 2; } + } + [Obsolete ("Do not use. Use SwarmDb.GetDatabaseForReading(), ...ForWriting() or ...ForAdmin().", true)] public static SwarmDb GetDatabase() diff --git a/Database/Database-Financials.cs b/Database/Database-Financials.cs index 918c6f1c..718c90ee 100644 --- a/Database/Database-Financials.cs +++ b/Database/Database-Financials.cs @@ -679,6 +679,134 @@ namespace Swarmops.Database } } + public void SetFinancialAccountClosedYear(int financialAccountId, int closedYear) + { + using (DbConnection connection = GetMySqlDbConnection()) + { + connection.Open(); + + DbCommand command = GetDbCommand("SetFinancialAccountClosedYear", connection); + command.CommandType = CommandType.StoredProcedure; + + AddParameterWithName(command, "financialAccountId", financialAccountId); + AddParameterWithName(command, "closedYear", closedYear); + + command.ExecuteNonQuery(); + } + } + + public void SetFinancialAccountParent(int financialAccountId, int parentFinancialAccountId) + { + using (DbConnection connection = GetMySqlDbConnection()) + { + connection.Open(); + + DbCommand command = GetDbCommand("SetFinancialAccountParent", connection); + command.CommandType = CommandType.StoredProcedure; + + AddParameterWithName(command, "financialAccountId", financialAccountId); + AddParameterWithName(command, "parentFinancialAccountId", parentFinancialAccountId); + + command.ExecuteNonQuery(); + } + } + + public void SetFinancialAccountActive(int financialAccountId, bool active) + { + using (DbConnection connection = GetMySqlDbConnection()) + { + connection.Open(); + + DbCommand command = GetDbCommand("SetFinancialAccountActive", connection); + command.CommandType = CommandType.StoredProcedure; + + AddParameterWithName(command, "financialAccountId", financialAccountId); + AddParameterWithName(command, "active", active); + + command.ExecuteNonQuery(); + } + } + + public void SetFinancialAccountExpensable(int financialAccountId, bool expensable) + { + using (DbConnection connection = GetMySqlDbConnection()) + { + connection.Open(); + + DbCommand command = GetDbCommand("SetFinancialAccountExpensable", connection); + command.CommandType = CommandType.StoredProcedure; + + AddParameterWithName(command, "financialAccountId", financialAccountId); + AddParameterWithName(command, "expensable", expensable); + + command.ExecuteNonQuery(); + } + } + + public void SetFinancialAccountOpen(int financialAccountId, bool open) + { + using (DbConnection connection = GetMySqlDbConnection()) + { + connection.Open(); + + DbCommand command = GetDbCommand("SetFinancialAccountOpen", connection); + command.CommandType = CommandType.StoredProcedure; + + AddParameterWithName(command, "financialAccountId", financialAccountId); + AddParameterWithName(command, "open", open); + + command.ExecuteNonQuery(); + } + } + + public void SetFinancialAccountAdministrative(int financialAccountId, bool administrative) + { + using (DbConnection connection = GetMySqlDbConnection()) + { + connection.Open(); + + DbCommand command = GetDbCommand("SetFinancialAccountOpen", connection); + command.CommandType = CommandType.StoredProcedure; + + AddParameterWithName(command, "financialAccountId", financialAccountId); + AddParameterWithName(command, "administrative", administrative); + + command.ExecuteNonQuery(); + } + } + + public void SetFinancialAccountLinkBackward(int financialAccountId, int linkBackward) + { + using (DbConnection connection = GetMySqlDbConnection()) + { + connection.Open(); + + DbCommand command = GetDbCommand("SetFinancialAccountOwner", connection); + command.CommandType = CommandType.StoredProcedure; + + AddParameterWithName(command, "financialAccountId", financialAccountId); + AddParameterWithName(command, "linkBackward", linkBackward); + + command.ExecuteNonQuery(); + } + } + + public void SetFinancialAccountLinkForward(int financialAccountId, int linkForward) + { + using (DbConnection connection = GetMySqlDbConnection()) + { + connection.Open(); + + DbCommand command = GetDbCommand("SetFinancialAccountOwner", connection); + command.CommandType = CommandType.StoredProcedure; + + AddParameterWithName(command, "financialAccountId", financialAccountId); + AddParameterWithName(command, "linkForward", linkForward); + + command.ExecuteNonQuery(); + } + } + public void SetFinancialAccountOwner(int financialAccountId, int ownerPersonId) { using (DbConnection connection = GetMySqlDbConnection()) diff --git a/Database/Schemata/revisions.txt b/Database/Schemata/revisions.txt new file mode 100644 index 00000000..bc6fe22a --- /dev/null +++ b/Database/Schemata/revisions.txt @@ -0,0 +1,2 @@ +0001 - Initial baseline, Rick Falkvinge +0002 - Added functions for account plan maintenance and back/forward links to FinancialAccounts, Rick Falkvinge diff --git a/Logic/Financial/FinancialAccount.cs b/Logic/Financial/FinancialAccount.cs index 1cdb9426..a93ffc6a 100644 --- a/Logic/Financial/FinancialAccount.cs +++ b/Logic/Financial/FinancialAccount.cs @@ -148,7 +148,31 @@ namespace Swarmops.Logic.Financial public FinancialAccount Parent { - get { return FromIdentity(this.ParentFinancialAccountId); } + get + { + return FromIdentity(this.ParentFinancialAccountId); + } + set + { + // We do not change the parent lightly. It cannot be changed if this account has transactions + // in closedledger space. + + try + { + int yearClosed = this.Organization.Parameters.FiscalBooksClosedUntilYear; + if (this.OpenedYear >= yearClosed) + { + throw new InvalidOperationException("Can't reparent an account with transactions in closedledger space"); + } + } + catch (ArgumentException) + { + // 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); + } } @@ -171,7 +195,7 @@ namespace Swarmops.Logic.Financial { // HACK HACK HACK HACK HACK for our pilots; this will be softcoded later TODO - if (this.OrganizationId != 1 || this.Organization.Name != "Piratpartiet SE") + if (this.OrganizationId != 1 || !PilotInstallationIds.IsPilot(PilotInstallationIds.PiratePartySE)) { return null; } @@ -194,7 +218,19 @@ namespace Swarmops.Logic.Financial get { return base.Name; } set { - // TODO: OPENEDYEAR TEST + try + { + int yearClosed = this.Organization.Parameters.FiscalBooksClosedUntilYear; + if (this.OpenedYear >= yearClosed) + { + throw new InvalidOperationException("Can't rename an account with transactions in closedledger space"); + } + } + catch (ArgumentException) + { + // This is ok and can be thrown if OpenedYear throws because there are no transactions yet. + } + SwarmDb.GetDatabaseForWriting().SetFinancialAccountName(this.Identity, value); base.Name = value; } diff --git a/Logic/Support/DatabaseMaintenance.cs b/Logic/Support/DatabaseMaintenance.cs index 5d7608a6..abf63b2f 100644 --- a/Logic/Support/DatabaseMaintenance.cs +++ b/Logic/Support/DatabaseMaintenance.cs @@ -56,8 +56,8 @@ namespace Swarmops.Logic.Support static public void UpgradeSchemata() { - int currentDbVersion = Int32.Parse(SwarmDb.GetDatabaseForReading().GetKeyValue("DbVersion")); - int expectedDbVersion = SwarmDb.DbVersion; + int currentDbVersion = SwarmDb.DbVersion; + int expectedDbVersion = SwarmDb.DbVersionExpected; string sql; bool upgraded = false; diff --git a/Site5/App_Code/PageV5Base.cs b/Site5/App_Code/PageV5Base.cs index aeba4809..ae43c1f7 100644 --- a/Site5/App_Code/PageV5Base.cs +++ b/Site5/App_Code/PageV5Base.cs @@ -126,6 +126,13 @@ public class PageV5Base : System.Web.UI.Page Response.Redirect("/Pages/v5/Security/AccessDenied.aspx"); } + // Check necessary database revision + + if (this.DbVersionRequired > SwarmDb.DbVersion) + { + Response.Redirect("/Pages/v5/Security/DatabaseUpgradeRequired.aspx"); + } + base.OnPreRender(e); } diff --git a/Site5/App_GlobalResources/Pages.Security.resx b/Site5/App_GlobalResources/Pages.Security.resx index 44bf5782..560bb3e8 100644 --- a/Site5/App_GlobalResources/Pages.Security.resx +++ b/Site5/App_GlobalResources/Pages.Security.resx @@ -112,10 +112,10 @@ 2.0 - System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceReader, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 - System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 Access to this page was denied @@ -127,7 +127,7 @@ Access Denied - <p>The Activizr security framework has denied you access to the page you were trying to go to. This usually means that its functions were above the access levels granted to you for the currently selected organization (<em>{0}</em>). This has not been logged nor reported anywhere.</p><p>There are several reasons why this may have happened:</p> + <p>The Swarmops security framework has denied you access to the page you were trying to go to. This usually means that its functions were above the access levels granted to you for the currently selected organization (<em>{0}</em>). This has not been logged nor reported anywhere.</p><p>There are several reasons why this may have happened:</p> Current organization @@ -144,4 +144,17 @@ Switch + + Database Upgrade Pending + + + This page requires an upgraded Swarmops database. + + + Awaiting Database Upgrade + + + <p>There is a database upgrade pending that prevents your access to this page. <strong>This is a temporary condition</strong> and the Swarmops servers should already be working on performing the necessary upgrade.</p> +<p>Retry loading the page in a few minutes. If the condition persists for more than fifteen minutes, contact your system administrator.</p> + \ No newline at end of file diff --git a/Site5/Controls/v5/Financial/ComboBudgets.ascx b/Site5/Controls/v5/Financial/ComboBudgets.ascx index b5e7077c..3ce76d3d 100644 --- a/Site5/Controls/v5/Financial/ComboBudgets.ascx +++ b/Site5/Controls/v5/Financial/ComboBudgets.ascx @@ -7,8 +7,14 @@ height: 30 <% if (!String.IsNullOrEmpty(this.OnClientLoaded)) { - Response.Write(", onLoadSuccess: " + this.OnClientLoaded + "()"); - }%> + Response.Write(", onLoadSuccess: function() { " + this.OnClientLoaded + "(); }"); + } + if (!String.IsNullOrEmpty(this.OnClientSelect)) + { + Response.Write(", onSelect: function(account) { " + this.OnClientSelect + "(account.id); }"); + } + + %> }); $('#<%=this.ClientID %>_SpanBudgets span.combo input.combo-text').click(function () { diff --git a/Site5/Controls/v5/Financial/ComboBudgets.ascx.cs b/Site5/Controls/v5/Financial/ComboBudgets.ascx.cs index 88aa0ed2..06ce8480 100644 --- a/Site5/Controls/v5/Financial/ComboBudgets.ascx.cs +++ b/Site5/Controls/v5/Financial/ComboBudgets.ascx.cs @@ -15,5 +15,6 @@ namespace Swarmops.Controls.Financial } public string OnClientLoaded { get; set; } + public string OnClientSelect { get; set; } } } \ No newline at end of file diff --git a/Site5/Pages/v5/Ledgers/AccountPlan.aspx b/Site5/Pages/v5/Ledgers/AccountPlan.aspx index 912344af..1a429f8b 100644 --- a/Site5/Pages/v5/Ledgers/AccountPlan.aspx +++ b/Site5/Pages/v5/Ledgers/AccountPlan.aspx @@ -330,8 +330,14 @@ } + function onAccountTreeSelect() { + alert('bar'); + } + + function onAccountTreeLoaded() { - // this didn't work much - not called on "reload" + // this didn't work much - not called on "reload" + alert('foo2'); accountTreeLoaded = true; if (parentAccountName.length > 0) { $('#<%=DropParents.ClientID %>_DropBudgets').combotree('setText', parentAccountName); @@ -398,7 +404,7 @@

Editing account (Under Construction/Test until next sprint)

 
-  
+  
 
 
 
diff --git a/Site5/Pages/v5/Ledgers/AccountPlan.aspx.cs b/Site5/Pages/v5/Ledgers/AccountPlan.aspx.cs index 67ec3d85..7a9240f7 100644 --- a/Site5/Pages/v5/Ledgers/AccountPlan.aspx.cs +++ b/Site5/Pages/v5/Ledgers/AccountPlan.aspx.cs @@ -27,6 +27,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers this.PageTitle = Resources.Pages.Ledgers.AccountPlan_PageTitle; this.InfoBoxLiteral = Resources.Pages.Ledgers.AccountPlan_Info; this.PageAccessRequired = new Access(this.CurrentOrganization, AccessAspect.Bookkeeping, AccessType.Write); + this.DbVersionRequired = 2; // Account reparenting } @@ -117,6 +118,27 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers return true; } + [WebMethod] + public static bool SetAccountParent (int accountId, int parentAccountId) + { + AuthenticationData authData = GetAuthenticationDataAndCulture(); + FinancialAccount account = FinancialAccount.FromIdentity(accountId); + + if (!PrepareAccountChange(account, authData, true)) + { + return false; + } + + FinancialAccount newParent = FinancialAccount.FromIdentity(parentAccountId); + if (newParent.OrganizationId != authData.CurrentOrganization.Identity) + { + throw new ArgumentException("Parent account mismatches with organization identity"); + } + + account.Parent = newParent; + return true; + } + [WebMethod] public static bool SetAccountOwner(int accountId, int newOwnerId) { @@ -128,7 +150,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers return false; } - // TODO: Verify that authdata.AuthenticatedPerson can see personId, or this can be exploited to enumerate all people + // TODO SECURITY: Verify that authdata.AuthenticatedPerson can see personId, or this can be exploited to enumerate all people account.Owner = Person.FromIdentity(newOwnerId); return true; diff --git a/Site5/Pages/v5/Security/AccessDenied.aspx b/Site5/Pages/v5/Security/AccessDenied.aspx index 0c638ffa..a696e4ca 100644 --- a/Site5/Pages/v5/Security/AccessDenied.aspx +++ b/Site5/Pages/v5/Security/AccessDenied.aspx @@ -13,12 +13,5 @@ -

- -
-
- -
-
diff --git a/Site5/Pages/v5/Security/AccessDenied.aspx.cs b/Site5/Pages/v5/Security/AccessDenied.aspx.cs index 536b7d65..6ca6f026 100644 --- a/Site5/Pages/v5/Security/AccessDenied.aspx.cs +++ b/Site5/Pages/v5/Security/AccessDenied.aspx.cs @@ -12,8 +12,7 @@ public partial class Security_AccessDenied : PageV5Base this.PageIcon = "iconshock-disconnect"; this.LabelAccessDeniedHeader.Text = Resources.Pages.Security.AccessDenied_Header; - this.LabelSidebarInfo.Text = Resources.Global.Sidebar_Information; - this.LabelAccessDeniedInfo.Text = Resources.Pages.Security.AccessDenied_Info; + this.InfoBoxLiteral = Resources.Pages.Security.AccessDenied_Info; this.LiteralAccessDeniedRant.Text = String.Format(Resources.Pages.Security.AccessDenied_Rant, this.CurrentOrganization.Name); } } \ No newline at end of file diff --git a/Site5/Pages/v5/Security/DatabaseUpgradeRequired.aspx b/Site5/Pages/v5/Security/DatabaseUpgradeRequired.aspx new file mode 100644 index 00000000..03d4cc24 --- /dev/null +++ b/Site5/Pages/v5/Security/DatabaseUpgradeRequired.aspx @@ -0,0 +1,13 @@ +<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="DatabaseUpgradeRequired.aspx.cs" Inherits="Security_DatabaseUpgradeRequired" %> + + + + + +

+ +
+ + + + diff --git a/Site5/Pages/v5/Security/DatabaseUpgradeRequired.aspx.cs b/Site5/Pages/v5/Security/DatabaseUpgradeRequired.aspx.cs new file mode 100644 index 00000000..164e8ac2 --- /dev/null +++ b/Site5/Pages/v5/Security/DatabaseUpgradeRequired.aspx.cs @@ -0,0 +1,18 @@ +using System; +using System.Collections.Generic; +using System.Web; +using System.Web.UI; +using System.Web.UI.WebControls; + +public partial class Security_DatabaseUpgradeRequired : PageV5Base +{ + protected void Page_Load(object sender, EventArgs e) + { + this.PageTitle = Resources.Pages.Security.DatabaseUpgradeRequired_PageTitle; + this.PageIcon = "iconshock-disconnect"; + + this.LabelDbUpgradeRequiredHeader.Text = Resources.Pages.Security.DatabaseUpgradeRequired_Header; + this.InfoBoxLiteral = Resources.Pages.Security.DatabaseUpgradeRequired_Info; + this.LiteralDbUpgradeRequiredRant.Text = Resources.Pages.Security.DatabaseUpgradeRequired_Rant; + } +} \ No newline at end of file