More work on account plan

This commit is contained in:
Rick Falkvinge
2014-02-24 11:34:39 +00:00
parent 2c07f9427c
commit 7283aa52a8
20 changed files with 300 additions and 67 deletions
@@ -7,7 +7,7 @@ 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 open, int openedYear, int closedYear, bool expensable, bool administrative)
{
this.FinancialAccountId = financialAccountId;
this.Name = name;
@@ -19,10 +19,11 @@ namespace Swarmops.Basic.Types.Financial
this.OpenedYear = openedYear;
this.ClosedYear = closedYear;
this.Expensable = expensable;
this.Administrative = administrative;
}
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)
this(original.Identity, original.Name, original.AccountType, original.OrganizationId, original.ParentFinancialAccountId, original.OwnerPersonId, original.Open, original.OpenedYear, original.ClosedYear, original.Expensable, original.Administrative)
{
// Empty copy constructor
}
@@ -38,6 +39,7 @@ namespace Swarmops.Basic.Types.Financial
public int OpenedYear { get; protected set; }
public int ClosedYear { get; protected set; }
public bool Expensable { get; protected set; }
public bool Administrative { get; protected set; }
#region IHasIdentity Members
+4 -2
View File
@@ -15,7 +15,8 @@ namespace Swarmops.Database
{
private const string financialAccountFieldSequence =
" FinancialAccountId,Name,OrganizationId,AccountType,ParentFinancialAccountId," + // 0-4
" OwnerPersonId,Open,OpenedYear,ClosedYear,Expensable " + // 5-9
" OwnerPersonId,Open,OpenedYear,ClosedYear,Expensable," + // 5-9
" Administrative " + // 10
" FROM FinancialAccounts ";
public int CreateFinancialAccount(int pOrganizationId, string pName, FinancialAccountType pAccountType, int pParentFinancialAccountId)
@@ -690,8 +691,9 @@ namespace Swarmops.Database
int openedYear = reader.GetInt32(7);
int closedYear = reader.GetInt32(8);
bool expensable = reader.GetBoolean(9);
bool administrative = reader.GetBoolean(10);
return new BasicFinancialAccount(accountId, name, accountType, organizationId, parentFinancialAccountId, ownerPersonId, open, openedYear, closedYear, expensable);
return new BasicFinancialAccount(accountId, name, accountType, organizationId, parentFinancialAccountId, ownerPersonId, open, openedYear, closedYear, expensable, administrative);
}
private BasicFinancialAccountRow ReadFinancialAccountRowFromDataReader (DbDataReader reader)
+12
View File
@@ -379,4 +379,16 @@
<value>Yes</value>
<comment>For yes/no options</comment>
</data>
<data name="Financial_Asset" xml:space="preserve">
<value>Assets</value>
</data>
<data name="Financial_Cost" xml:space="preserve">
<value>Expenses</value>
</data>
<data name="Financial_Debt" xml:space="preserve">
<value>Liabilities</value>
</data>
<data name="Financial_Income" xml:space="preserve">
<value>Revenue</value>
</data>
</root>
+2 -2
View File
@@ -140,7 +140,7 @@
<value>Current</value>
</data>
<data name="BalanceSheet_Debt" xml:space="preserve">
<value>Debt</value>
<value>Liabilities</value>
</data>
<data name="BalanceSheet_DownloadFileName" xml:space="preserve">
<value>BalanceSheet</value>
@@ -180,7 +180,7 @@
<comment>The {0} is the organization name. The year number follows this string.</comment>
</data>
<data name="ProfitLossStatement_Costs" xml:space="preserve">
<value>Costs</value>
<value>Expenses</value>
</data>
<data name="ProfitLossStatement_DownloadFileName" xml:space="preserve">
<value>ProfitLoss</value>
@@ -0,0 +1 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-FinancialAccountsTree.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Financial.Json_FinancialAccountsTree" %>
@@ -0,0 +1,92 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Swarmops.Basic.Enums;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Swarm;
using Swarmops.Logic.Security;
using Swarmops.Logic.Structure;
namespace Swarmops.Frontend.Pages.v5.Financial
{
public partial class Json_FinancialAccountsTree : DataV5Base
{
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "application/json";
FinancialAccountType accountType =
(FinancialAccountType) (Enum.Parse(typeof (FinancialAccountType), Request.QueryString["AccountType"]));
string accountsJson = string.Empty;
int excludeId = -1;
string excludeIdString = Request.QueryString["ExcludeId"];
if (!String.IsNullOrEmpty(excludeIdString))
{
excludeId = Int32.Parse(excludeIdString);
}
// Get accounts
FinancialAccounts accounts = FinancialAccounts.ForOrganization(this.CurrentOrganization, accountType);
// Build tree (there should be a template for this)
Dictionary<int, List<FinancialAccount>> treeMap = new Dictionary<int, List<FinancialAccount>>();
foreach (FinancialAccount account in accounts)
{
if (account.Identity == excludeId)
{
continue;
}
if (!treeMap.ContainsKey(account.ParentIdentity))
{
treeMap[account.ParentIdentity] = new List<FinancialAccount>();
}
treeMap[account.ParentIdentity].Add(account);
}
accountsJson = RecurseTreeMap(treeMap, 0);
accountsJson = "[{\"id\":\"0\",\"text\":\"" +
JsonSanitize(Resources.Global.ResourceManager.GetString("Financial_" + accountType.ToString())) +
"\",\"state\":\"open\",\"children\":" +
accountsJson +
"}]";
Response.Output.WriteLine(accountsJson);
Response.End();
}
private string RecurseTreeMap(Dictionary<int, List<FinancialAccount>> treeMap, int node)
{
List<string> elements = new List<string>();
foreach (FinancialAccount account in treeMap[node])
{
string element = string.Format("\"id\":{0},\"text\":\"{1}\"", account.Identity,
JsonSanitize(account.Name));
if (treeMap.ContainsKey(account.Identity))
{
element += ",\"state\":\"closed\",\"children\":" + RecurseTreeMap(treeMap, account.Identity);
}
elements.Add("{" + element + "}");
}
return "[" + String.Join(",", elements.ToArray()) + "]";
}
}
}
@@ -1,4 +1,4 @@
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ComboBudgets.ascx.cs" Inherits="Swarmops.Controls.Financial.BudgetCombo" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ComboBudgets.ascx.cs" Inherits="Swarmops.Controls.Financial.ComboBudgets" %>
<script type="text/javascript">
$(document).ready(function () {
@@ -7,7 +7,7 @@ using System.Web.UI.WebControls;
namespace Swarmops.Controls.Financial
{
public partial class BudgetCombo : ControlV5Base
public partial class ComboBudgets : ControlV5Base
{
protected void Page_Load(object sender, EventArgs e)
{
+42
View File
@@ -0,0 +1,42 @@
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ComboPeople.ascx.cs" Inherits="Swarmops.Controls.Financial.ComboPeople" %>
<script type="text/javascript">
$(document).ready(function () {
$('#<%=this.ClientID %>_DropPeople').combobox({
animate: true,
height: 30
});
<% if (this.Selected != null)
{ %>
$('span#<%= this.ClientID %>_SpanPeople span input.combo-text').css('background', "url('<%= this.Selected.GetSecureAvatarLink(24) %>')");
$('span#<%= this.ClientID %>_SpanPeople span input.combo-text').text('<%= this.Selected.Canonical %>');
<% }
else if (this.NobodySelected)
{ %>
$('span#<%= this.ClientID %>_SpanPeople span input.combo-text').css('background', "url('/Images/Icons/iconshock-warning-24px.png')");
$('span#<%= this.ClientID %>_SpanPeople span input.combo-text').text('<%= Resources.Global.Global_NoOwner %>');
<% } else { %>
$('span#<%= this.ClientID %>_SpanPeople span input.combo-text').css('background', '');
<% } %>
$('#<%=this.ClientID %>_SpanPeople span.combo input.combo-text').keydown(function (e) {
switch (e.which) {
case 40: // down
$('#<%=this.ClientID %>_SpanPeople span.combo span span.combo-arrow').click();
break;
default: return; // exit this handler for other keys
}
e.preventDefault(); // prevent the default action (scroll / move caret)
});
});
</script>
<span id="<%=this.ClientID %>_SpanPeople"><select class="easyui-combobox comboperson" url="/Automation/Json-ExpensableBudgetsTree.aspx" name="DropPeople" id="<%=this.ClientID %>_DropPeople" animate="true" style="width:300px"></select></span>
@@ -0,0 +1,22 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Swarmops.Logic.Swarm;
namespace Swarmops.Controls.Financial
{
public partial class ComboPeople : ControlV5Base
{
protected void Page_Load(object sender, EventArgs e)
{
}
public Person Selected { set; protected get; }
public bool NobodySelected { set; protected get; }
}
}
@@ -1,4 +1,4 @@
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ComboPerson.ascx.cs" Inherits="Swarmops.Controls.Swarm.ComboPerson" %>
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="ComboPersonObsolete.ascx.cs" Inherits="Swarmops.Controls.Swarm.ComboPersonObsolete" %>
<telerik:RadComboBox runat="server" ID="ComboControl" Width="200px" Skin="WebBlue"
EnableLoadOnDemand="True" ShowMoreResultsBox="true"
@@ -18,7 +18,7 @@ using Telerik.Web.UI;
namespace Swarmops.Controls.Swarm
{
public partial class ComboPerson : ControlV5Base
public partial class ComboPersonObsolete : ControlV5Base
{
protected void Page_Load(object sender, EventArgs e)
{
@@ -1,5 +1,5 @@
<%@ Control Language="C#" AutoEventWireup="true" CodeFile="PersonDetailPopup.ascx.cs" Inherits="Swarmops.Controls.Swarm.PersonDetailPopup" %>
<%@ Register Src="~/Controls/v5/Swarm/ComboPerson.ascx" TagName="ComboPerson" TagPrefix="act5" %>
<%@ Register Src="~/Controls/v5/Swarm/ComboPersonObsolete.ascx" TagName="ComboPerson" TagPrefix="act5" %>
<asp:UpdatePanel ID="UpdateSetter" runat="server" UpdateMode="Conditional">
<ContentTemplate>
Binary file not shown.

After

Width:  |  Height:  |  Size: 970 B

+1 -1
View File
@@ -1,6 +1,6 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="AddMotion.aspx.cs" Inherits="Swarmops.Pages.Governance.AddMotion" %>
<%@ Register src="~/Controls/v5/Swarm/ComboPerson.ascx" tagname="ComboPerson" tagprefix="act5" %>
<%@ Register src="~/Controls/v5/Swarm/ComboPersonObsolete.ascx" tagname="ComboPerson" tagprefix="act5" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
<script type="text/javascript">
@@ -1,5 +1,5 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="AddMotionAmendment.aspx.cs" Inherits="Swarmops.Pages.Governance.AddMotionAmendment" %>
<%@ Register src="~/Controls/v5/Swarm/ComboPerson.ascx" tagname="ComboPerson" tagprefix="act5" %>
<%@ Register src="~/Controls/v5/Swarm/ComboPersonObsolete.ascx" tagname="ComboPerson" tagprefix="act5" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
+30 -5
View File
@@ -1,6 +1,7 @@
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="AccountPlan.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Ledgers.AccountPlan" %>
<%@ Register TagPrefix="Swarmops5" TagName="ExternalScripts" Src="~/Controls/v5/UI/ExternalScripts.ascx" %>
<%@ Register TagPrefix="Swarmops5" TagName="ComboBudgets" Src="~/Controls/v5/Financial/ComboBudgets.ascx" %>
<%@ Register TagPrefix="Swarmops5" TagName="ComboPeople" Src="~/Controls/v5/Swarm/ComboPeople.ascx" %>
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
<Swarmops5:ExternalScripts ID="ExternalScripts1" Package="easyui" Control="tree" runat="server" />
@@ -39,22 +40,32 @@
var accountId = $(this).attr("accountId");
var accountType = accountId.substring(0,1); // A, D, I, C
accountId = accountId.substring(1);
var accountTree = $('#<%=DropParents.ClientID %>_DropBudgets');
if (accountType == 'A') {
$('#DivEditAssetLabels').show();
$('#DivEditAssetControls').show();
$('#DivEditProfitLossLabels').hide();
$('#DivEditProfitLossControls').hide();
} else if (accountType == 'D') {
accountTree.combotree('reload', '/Automation/Json-FinancialAccountsTree.aspx?AccountType=Asset&ExcludeId=' + accountId);
} else if (accountType == 'D') { // Debt, aka Liability
$('#DivEditAssetLabels').hide();
$('#DivEditAssetControls').hide();
$('#DivEditProfitLossLabels').hide();
$('#DivEditProfitLossControls').hide();
accountTree.combotree('reload', '/Automation/Json-FinancialAccountsTree.aspx?AccountType=Debt&ExcludeId=' + accountId);
} else { // P&L account
$('#DivEditAssetLabels').hide();
$('#DivEditAssetControls').hide();
$('#DivEditProfitLossLabels').show();
$('#DivEditProfitLossControls').show();
if (accountType == 'I') {
accountTree.combotree('reload', '/Automation/Json-FinancialAccountsTree.aspx?AccountType=Income&ExcludeId=' + accountId);
} else { // C for Costs aka Expenses
accountTree.combotree('reload', '/Automation/Json-FinancialAccountsTree.aspx?AccountType=Cost&ExcludeId=' + accountId);
}
}
window.scrollTo(0, 0);
@@ -74,8 +85,16 @@
$('#CheckAccountAdministrative').switchButton( {checked: msg.d.Administrative });
$('#TextAccountName').val(msg.d.AccountName);
$('#TextAccountBudget').val(msg.d.Budget);
$('#SpanEditBalance').text(msg.d.Balance);
//var parentAccountNode = accountTree.tree('find', msg.d.ParentAccountId);
//console.log(parentAccountNode);
//accountTree.combotree('select', parentAccountNode.target);
accountTree.combotree('setText', msg.d.ParentAccountName);
// TODO: Owner, parent account, automation
$('span#<%= DropOwner.ClientID %>_SpanPeople span input.combo-text').css('background-image', "url('" + msg.d.AccountOwnerAvatarUrl + "')");
$('span#<%= DropOwner.ClientID %>_SpanPeople span input.combo-text').attr('placeholder', msg.d.AccountOwnerName);
$('span#<%= DropOwner.ClientID %>_SpanPeople span input.combo-text').val('');
}
});
@@ -84,6 +103,12 @@
}
});
$('#<%=this.DropOwner.ClientID %>_SpanPeople span.combo input.combo-text').keydown(function (e) {
// Clear the owner avatar on any keypress
$('span#<%= DropOwner.ClientID %>_SpanPeople span input.combo-text').css('background-image', "none");
});
$('div.datagrid').css('opacity', 0.4);
$("#IconCloseEdit").click(function() {
@@ -152,9 +177,9 @@
<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>Editing account (Under Construction/Test)</h2>
<div class="entryFields"><input type="text" id="TextAccountName" />&nbsp;<br />
<Swarmops5:ComboBudgets ID="DropBudgets" runat="server" />&nbsp;<br/>
<Swarmops5:ComboBudgets ID="DropParents" runat="server" />&nbsp;<br/>
&nbsp;<br/>
<div id="DivEditProfitLossControls"><Swarmops5:ComboBudgets ID="DropOwner" runat="server" />&nbsp;<br/>
<div id="DivEditProfitLossControls"><Swarmops5:ComboPeople ID="DropOwner" runat="server" />&nbsp;<br/>
<input type="text" id="TextAccountBudget" style="text-align: right"/>&nbsp;<br/>
&nbsp;<br/>
<div class="checkboxSpacer"></div><input type="checkbox" class="EditCheck" id="CheckAccountActive"/>
@@ -168,7 +193,7 @@
Parent account or group<br/>
<div id="DivEditProfitLossLabels"><h2>Daily operations</h2>
Owner<br/>
Budget (balance is SEK foo)<br/>
Budget (balance is SEK <span id="SpanEditBalance">foo</span>)<br/>
<h2>Switches</h2>
Active<br/>
Expensable<br/>
+23 -4
View File
@@ -5,6 +5,7 @@ using System.Web;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.WebControls;
using Swarmops.Basic.Enums;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Security;
@@ -39,18 +40,34 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
throw new UnauthorizedAccessException("A million nopes");
}
FinancialAccounts accountTree = account.GetTree();
int year = DateTime.Today.Year;
JsonAccountData result = new JsonAccountData();
result.AccountName = account.Name;
result.ParentAccountId = account.ParentIdentity;
result.ParentAccountName = account.ParentFinancialAccountId == 0
? Resources.Global.ResourceManager.GetString("Financial_" +
account.AccountType.ToString())
: account.Parent.Name;
result.Expensable = account.Expensable;
result.Administrative = false;
result.Open = account.Open;
result.Open = account.Administrative;
result.AccountOwnerName = account.OwnerPersonId != 0 ? account.Owner.Name : Resources.Global.Global_NoOwner;
result.AccountOwnerAvatarUrl = account.OwnerPersonId != 0
? account.Owner.GetSecureAvatarLink(16)
: "/Images/Icons/iconshock-warning-16x12px.png";
result.Budget = (account.GetTree().GetBudgetSumCents(DateTime.Today.Year)/100L).ToString("N0");
? account.Owner.GetSecureAvatarLink(24)
: "/Images/Icons/iconshock-warning-24px.png";
result.Budget = (accountTree.GetBudgetSumCents(year)/100L).ToString("N0");
if (account.AccountType == FinancialAccountType.Asset || account.AccountType == FinancialAccountType.Debt)
{
result.Balance = (accountTree.GetDeltaCents(new DateTime(1900, 1, 1), new DateTime(year + 1, 1, 1))/100L).ToString("N0");
}
else
{
result.Balance = (accountTree.GetDeltaCents(new DateTime(year, 1, 1), new DateTime(year + 1, 1, 1)) / 100L).ToString("N0");
}
return result;
}
@@ -59,6 +76,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
{
public string AccountName;
public int ParentAccountId;
public string ParentAccountName;
public string ClosedYear;
public bool Administrative;
public bool Expensable;
@@ -66,6 +84,7 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers
public string AccountOwnerName;
public string Budget;
public string AccountOwnerAvatarUrl;
public string Balance;
}
}
+45 -45
View File
@@ -1,49 +1,49 @@
.switch-button-label {
float: left;
.switch-button-label {
float: left;
font-size: 18px;
font-weight: 700;
cursor: pointer;
}
.switch-button-label.off {
color: #9fbcff;
}
.switch-button-label.on {
color: #0088CC;
}
.switch-button-background {
float: left;
position: relative;
background: #c6d7ff;
background: linear-gradient(to right, #4F4, #4F4, #FAA, #FAA);
font-weight: 700;
cursor: pointer;
}
.switch-button-label.off {
color: #9fbcff;
}
.switch-button-label.on {
color: #0088CC;
}
.switch-button-background {
float: left;
position: relative;
background: #c6d7ff;
background: linear-gradient(to right, #4F4, #4F4, #FAA, #FAA);
border: 1px solid #a3bfff;
box-shadow: #2d50a1 0px 1px 4px 0px inset;
box-shadow: #2d50a1 0px 1px 4px 0px inset;
margin: 1px 10px;
margin-top: 12px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
margin-top: 12px;
-webkit-border-radius: 4px;
-moz-border-radius: 4px;
border-radius: 4px;
cursor: pointer;
}
.switch-button-button {
position: absolute;
left: -1px;
top : -1px;
background: #FAFAFA;
border: 1px solid #a3bfff;
-webkit-border-radius: 45x;
-moz-border-radius: 5px;
border-radius: 5px;
box-shadow: #c6d7ff 0px 0px 4px 0px inset;
}
cursor: pointer;
}
.switch-button-button {
position: absolute;
left: -1px;
top : -1px;
background: #FAFAFA;
border: 1px solid #a3bfff;
-webkit-border-radius: 45x;
-moz-border-radius: 5px;
border-radius: 5px;
box-shadow: #c6d7ff 0px 0px 4px 0px inset;
}
+16
View File
@@ -712,6 +712,22 @@ input.entryError, span.entryError, div.entryError {
}
select.comboperson+span>input {
width: 252px !important;
padding-left: 34px;
/* background: url('http://s.gravatar.com/avatar/15638826ee119289c902c4f85e77a2f0?s=24&r=g'); */
background-repeat: no-repeat;
background-color: white;
background-position: 6px 2px;
}
select.comboperson+span>input:focus
{
background-image: none !important;
}
.button
{
cursor: pointer;