Account Plan works; still needs loc & testing

This commit is contained in:
Rick Falkvinge
2014-09-27 13:09:22 +02:00
parent 7f9469bbfa
commit ef160918ca
7 changed files with 187 additions and 29 deletions
@@ -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
+6 -3
View File
@@ -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)
+52 -3
View File
@@ -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
+12 -1
View File
@@ -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;
+51 -13
View File
@@ -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 @@
<div id="divModalCover" class="modalcover">
<div id="divModalBox" class="box modal">
<div class="content">
<div style="float:right;margin-top: 2px;margin-right: -5px"><img id="IconCloseEdit" src="/Images/Icons/iconshock-cross-16px.png" /></div><h2 id="HeaderModal">Editing account (Under Construction/Test until next sprint)</h2>
<div style="float:right;margin-top: 2px;margin-right: -5px"><img id="IconCloseEdit" src="/Images/Icons/iconshock-cross-16px.png" /></div><h2 id="HeaderModal">Editing account</h2>
<div id="DivModalFields" class="entryFields"><input type="text" id="TextAccountName" />&nbsp;<br />
<Swarmops5:ComboBudgets ID="DropParents" runat="server" OnClientLoaded="onAccountTreeLoaded" OnClientSelect="onAccountTreeSelect" />&nbsp;<br/>
&nbsp;<br/>
@@ -413,7 +451,7 @@
<label for="CheckAccountExpensable">Expensable</label><div class="CheckboxContainer"><input type="checkbox" rel="Expensable" class="EditCheck" id="CheckAccountExpensable"/></div><br/>
<label for="CheckAccountAdministrative">Admin</label><div class="CheckboxContainer"><input type="checkbox" rel="Administrative" class="EditCheck" id="CheckAccountAdministrative"/></div>
&nbsp;<br/></div>
<div id="DivEditAssetControls"><asp:DropDownList runat="server" ID="DropAccountUploadFormats"/>&nbsp;<br/>
<div id="DivEditAssetControls"><asp:DropDownList runat="server" ID="DropAccountUploadFormats"/>
<input type="text" id="TextAutomationPaymentTag" readonly="readonly"/>&nbsp;<br/></div>
</div>
<div class="entryLabels">Account name<br/>
+56 -6
View File
@@ -9,6 +9,7 @@ using System.Web.UI.WebControls;
using Swarmops.Basic.Enums;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
using Swarmops.Logic.Support;
using Swarmops.Logic.Swarm;
namespace Swarmops.Frontend.Pages.v5.Ledgers
@@ -56,6 +57,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
: account.Parent.Name;
result.Expensable = account.Expensable;
result.Administrative = account.Administrative;
result.Active = account.Active;
result.Open = account.Open;
result.AccountOwnerName = account.OwnerPersonId != 0 ? account.Owner.Name : Resources.Global.Global_NoOwner;
result.AccountOwnerAvatarUrl = account.OwnerPersonId != 0
@@ -109,12 +111,20 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
AuthenticationData authData = GetAuthenticationDataAndCulture();
FinancialAccount account = FinancialAccount.FromIdentity(accountId);
string newName = HttpContext.Current.Server.UrlDecode(name);
if (account.Name == newName)
{
// no change
return true;
}
if (!PrepareAccountChange(account, authData, true))
{
return false;
}
account.Name = HttpContext.Current.Server.UrlDecode(name);
account.Name = newName;
return true;
}
@@ -124,15 +134,25 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
AuthenticationData authData = GetAuthenticationDataAndCulture();
FinancialAccount account = FinancialAccount.FromIdentity(accountId);
if (account.ParentFinancialAccountId == parentAccountId)
{
// no change
return true;
}
if (!PrepareAccountChange(account, authData, true))
{
return false;
}
FinancialAccount newParent = FinancialAccount.FromIdentity(parentAccountId);
if (newParent.OrganizationId != authData.CurrentOrganization.Identity)
FinancialAccount newParent = null; // to cover the root account case (reparenting to root)
if (parentAccountId != 0)
{
throw new ArgumentException("Parent account mismatches with organization identity");
newParent = FinancialAccount.FromIdentity(parentAccountId);
if (newParent.OrganizationId != authData.CurrentOrganization.Identity)
{
throw new ArgumentException("Parent account mismatches with organization identity");
}
}
account.Parent = newParent;
@@ -202,6 +222,35 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
}
}
[WebMethod]
public static bool SetAccountSwitch(int accountId, string switchName, bool switchValue)
{
AuthenticationData authData = GetAuthenticationDataAndCulture();
FinancialAccount account = FinancialAccount.FromIdentity(accountId);
if (!PrepareAccountChange(account, authData, false))
{
return false;
}
switch (switchName)
{
case "Active":
account.Active = switchValue;
break;
case "Administrative":
account.Administrative = switchValue;
break;
case "Expensable":
account.Expensable = switchValue;
break;
default:
throw new NotImplementedException("Unknown switchName parameter");
}
return true;
}
public class ChangeAccountDataResult
{
@@ -218,11 +267,11 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
/// </summary>
Changed = 1,
/// <summary>
/// The account has transactions in closed ledgers, so the account was broken in two -
/// The account has transactions in closed ledgers, so the account was split in two -
/// the closed ledgers were kept, and all open ledgers were moved into a new account
/// with the new data.
/// </summary>
ChangedBroken = 2,
ChangedWithDiscontinuity = 2,
/// <summary>
/// The user doesn't have write permissions.
/// </summary>
@@ -242,6 +291,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
public bool Administrative;
public bool Expensable;
public bool Open;
public bool Active;
public string AccountOwnerName;
public string Budget;
public string AccountOwnerAvatarUrl;
+1 -1
View File
@@ -28,7 +28,7 @@ namespace Swarmops.Utility
if (!logOnly)
{
new MailTransmitter(Strings.MailSenderName, Strings.MailSenderAddress,
"PirateWeb EXCEPTION!",
"Swarmops EXCEPTION!",
e.ToString(), People.FromIdentities(new int[] { 1 }), false).Send();
}
}