Added financial transaction tags; changed 2-D bookkeeping to tags

This commit is contained in:
Rick Falkvinge
2013-10-29 19:28:17 +00:00
parent 8472167b79
commit d82b34dafa
20 changed files with 574 additions and 123 deletions
@@ -8,17 +8,18 @@ namespace Swarmops.Basic.Types.Financial
{
public class BasicFinancialTransactionTagSet: IHasIdentity
{
public BasicFinancialTransactionTagSet (int financialTransactionTagSetId, int financialTransactionTagSetTypeId, int organizationId, int order, bool allowUntagged)
public BasicFinancialTransactionTagSet (int financialTransactionTagSetId, int financialTransactionTagSetTypeId, int organizationId, int order, bool allowUntagged, int profitLossType)
{
this.FinancialTransactionTagSetId = financialTransactionTagSetId;
this.FinancialTransactionTagSetTypeId = financialTransactionTagSetTypeId;
this.OrganizationId = organizationId;
this.Order = order;
this.AllowUntagged = allowUntagged;
this.ProfitLossType = profitLossType;
}
public BasicFinancialTransactionTagSet (BasicFinancialTransactionTagSet original):
this (original.FinancialTransactionTagSetId, original.FinancialTransactionTagSetTypeId, original.OrganizationId, original.Order, original.AllowUntagged)
this (original.FinancialTransactionTagSetId, original.FinancialTransactionTagSetTypeId, original.OrganizationId, original.Order, original.AllowUntagged, original.ProfitLossType)
{
// copy ctor
}
@@ -28,6 +29,7 @@ namespace Swarmops.Basic.Types.Financial
public int OrganizationId { get; private set; }
public int Order { get; protected set; }
public bool AllowUntagged { get; protected set; }
public int ProfitLossType { get; protected set; }
#region Implementation of IHasIdentity
@@ -16,7 +16,8 @@ namespace Swarmops.Database
private const string financialTransactionTagSetFieldSequence =
" FinancialTransactionTagSetId,FinancialTransactionTagSetTypeId,OrganizationId,Order,AllowUntagged " + // 0-4
" FinancialTransactionTagSetId,FinancialTransactionTagSetTypeId,OrganizationId,DisplayOrder,AllowUntagged," + // 0-4
"ProfitLossType " + // 5
"FROM FinancialTransactionTagSets ";
private static BasicFinancialTransactionTagSet ReadFinancialTransactionTagSetFromDataReader(IDataRecord reader)
@@ -26,8 +27,9 @@ namespace Swarmops.Database
int organizationId = reader.GetInt32 (2);
int order = reader.GetInt32 (3);
bool allowUntagged = reader.GetBoolean (4);
int profitLossType = reader.GetInt32(5);
return new BasicFinancialTransactionTagSet(financialTransactionTagSetId, financialTransactionTagSetTypeId, organizationId, order, allowUntagged);
return new BasicFinancialTransactionTagSet(financialTransactionTagSetId, financialTransactionTagSetTypeId, organizationId, order, allowUntagged, profitLossType);
}
#endregion
@@ -43,7 +45,7 @@ namespace Swarmops.Database
connection.Open();
DbCommand command =
GetDbCommand("SELECT" + financialTransactionTagSetTypeFieldSequence + " WHERE FinancialTransactionTagSetId=" + financialTransactionTagSetId.ToString(CultureInfo.InvariantCulture), connection);
GetDbCommand("SELECT" + financialTransactionTagSetFieldSequence + " WHERE FinancialTransactionTagSetId=" + financialTransactionTagSetId.ToString(CultureInfo.InvariantCulture), connection);
using (DbDataReader reader = command.ExecuteReader())
{
@@ -67,7 +69,7 @@ namespace Swarmops.Database
{
connection.Open();
DbCommand command = GetDbCommand("SELECT" + financialTransactionTagSetFieldSequence + ConstructWhereClause ("FinancialTransactionTagSets", conditions) + " ORDER BY Order", connection);
DbCommand command = GetDbCommand("SELECT" + financialTransactionTagSetFieldSequence + ConstructWhereClause ("FinancialTransactionTagSets", conditions) + " ORDER BY DisplayOrder", connection);
using (DbDataReader reader = command.ExecuteReader())
{
@@ -16,7 +16,7 @@ namespace Swarmops.Database
private const string financialTransactionTagTypeFieldSequence =
" FinancialTransactionTagTypeId,ParentFinancialTransacationTagTypeId,FinancialTransactionTagSetId,Name,Active," + // 0-4
" FinancialTransactionTagTypeId,ParentFinancialTransactionTagTypeId,FinancialTransactionTagSetId,Name,Active," + // 0-4
"OpenedYear,ClosedYear " + // 5-6
"FROM FinancialTransactionTagTypes ";
@@ -72,7 +72,7 @@ namespace Swarmops.Database
{
connection.Open();
DbCommand command = GetDbCommand("SELECT" + financialTransactionTagSetFieldSequence + ConstructWhereClause("FinancialTransactionTagTypes", conditions), connection);
DbCommand command = GetDbCommand("SELECT" + financialTransactionTagTypeFieldSequence + ConstructWhereClause("FinancialTransactionTagTypes", conditions), connection);
using (DbDataReader reader = command.ExecuteReader())
{
@@ -0,0 +1,91 @@
//------------------------------------------------------------------------------
// <auto-generated>
// This code was generated by a tool.
// Runtime Version:4.0.30319.1008
//
// Changes to this file may cause incorrect behavior and will be lost if
// the code is regenerated.
// </auto-generated>
//------------------------------------------------------------------------------
namespace Swarmops.Logic.App_GlobalResources {
using System;
/// <summary>
/// A strongly-typed resource class, for looking up localized strings, etc.
/// </summary>
// This class was auto-generated by the StronglyTypedResourceBuilder
// class via a tool like ResGen or Visual Studio.
// To add or remove a member, edit your .ResX file then rerun ResGen
// with the /str option, or rebuild your VS project.
[global::System.CodeDom.Compiler.GeneratedCodeAttribute("System.Resources.Tools.StronglyTypedResourceBuilder", "4.0.0.0")]
[global::System.Diagnostics.DebuggerNonUserCodeAttribute()]
[global::System.Runtime.CompilerServices.CompilerGeneratedAttribute()]
internal class Logic_Financial_FinancialTransactionTagSetTypesStock {
private static global::System.Resources.ResourceManager resourceMan;
private static global::System.Globalization.CultureInfo resourceCulture;
[global::System.Diagnostics.CodeAnalysis.SuppressMessageAttribute("Microsoft.Performance", "CA1811:AvoidUncalledPrivateCode")]
internal Logic_Financial_FinancialTransactionTagSetTypesStock() {
}
/// <summary>
/// Returns the cached ResourceManager instance used by this class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Resources.ResourceManager ResourceManager {
get {
if (object.ReferenceEquals(resourceMan, null)) {
global::System.Resources.ResourceManager temp = new global::System.Resources.ResourceManager("Swarmops.Logic.App_GlobalResources.Logic.Financial.FinancialTransactionTagSetType" +
"sStock", typeof(Logic_Financial_FinancialTransactionTagSetTypesStock).Assembly);
resourceMan = temp;
}
return resourceMan;
}
}
/// <summary>
/// Overrides the current thread's CurrentUICulture property for all
/// resource lookups using this strongly typed resource class.
/// </summary>
[global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)]
internal static global::System.Globalization.CultureInfo Culture {
get {
return resourceCulture;
}
set {
resourceCulture = value;
}
}
/// <summary>
/// Looks up a localized string similar to Cost Type.
/// </summary>
internal static string CostType {
get {
return ResourceManager.GetString("CostType", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Income Type.
/// </summary>
internal static string IncomeType {
get {
return ResourceManager.GetString("IncomeType", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to Project.
/// </summary>
internal static string Project {
get {
return ResourceManager.GetString("Project", resourceCulture);
}
}
}
}
@@ -0,0 +1,129 @@
<?xml version="1.0" encoding="utf-8"?>
<root>
<!--
Microsoft ResX Schema
Version 2.0
The primary goals of this format is to allow a simple XML format
that is mostly human readable. The generation and parsing of the
various data types are done through the TypeConverter classes
associated with the data types.
Example:
... ado.net/XML headers & schema ...
<resheader name="resmimetype">text/microsoft-resx</resheader>
<resheader name="version">2.0</resheader>
<resheader name="reader">System.Resources.ResXResourceReader, System.Windows.Forms, ...</resheader>
<resheader name="writer">System.Resources.ResXResourceWriter, System.Windows.Forms, ...</resheader>
<data name="Name1"><value>this is my long string</value><comment>this is a comment</comment></data>
<data name="Color1" type="System.Drawing.Color, System.Drawing">Blue</data>
<data name="Bitmap1" mimetype="application/x-microsoft.net.object.binary.base64">
<value>[base64 mime encoded serialized .NET Framework object]</value>
</data>
<data name="Icon1" type="System.Drawing.Icon, System.Drawing" mimetype="application/x-microsoft.net.object.bytearray.base64">
<value>[base64 mime encoded string representing a byte array form of the .NET Framework object]</value>
<comment>This is a comment</comment>
</data>
There are any number of "resheader" rows that contain simple
name/value pairs.
Each data row contains a name, and value. The row also contains a
type or mimetype. Type corresponds to a .NET class that support
text/value conversion through the TypeConverter architecture.
Classes that don't support this are serialized and stored with the
mimetype set.
The mimetype is used for serialized objects, and tells the
ResXResourceReader how to depersist the object. This is currently not
extensible. For a given mimetype the value must be set accordingly:
Note - application/x-microsoft.net.object.binary.base64 is the format
that the ResXResourceWriter will generate, however the reader can
read any of the formats listed below.
mimetype: application/x-microsoft.net.object.binary.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Binary.BinaryFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.soap.base64
value : The object must be serialized with
: System.Runtime.Serialization.Formatters.Soap.SoapFormatter
: and then encoded with base64 encoding.
mimetype: application/x-microsoft.net.object.bytearray.base64
value : The object must be serialized into a byte array
: using a System.ComponentModel.TypeConverter
: and then encoded with base64 encoding.
-->
<xsd:schema id="root" xmlns="" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:msdata="urn:schemas-microsoft-com:xml-msdata">
<xsd:import namespace="http://www.w3.org/XML/1998/namespace" />
<xsd:element name="root" msdata:IsDataSet="true">
<xsd:complexType>
<xsd:choice maxOccurs="unbounded">
<xsd:element name="metadata">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" />
</xsd:sequence>
<xsd:attribute name="name" use="required" type="xsd:string" />
<xsd:attribute name="type" type="xsd:string" />
<xsd:attribute name="mimetype" type="xsd:string" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="assembly">
<xsd:complexType>
<xsd:attribute name="alias" type="xsd:string" />
<xsd:attribute name="name" type="xsd:string" />
</xsd:complexType>
</xsd:element>
<xsd:element name="data">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
<xsd:element name="comment" type="xsd:string" minOccurs="0" msdata:Ordinal="2" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" msdata:Ordinal="1" />
<xsd:attribute name="type" type="xsd:string" msdata:Ordinal="3" />
<xsd:attribute name="mimetype" type="xsd:string" msdata:Ordinal="4" />
<xsd:attribute ref="xml:space" />
</xsd:complexType>
</xsd:element>
<xsd:element name="resheader">
<xsd:complexType>
<xsd:sequence>
<xsd:element name="value" type="xsd:string" minOccurs="0" msdata:Ordinal="1" />
</xsd:sequence>
<xsd:attribute name="name" type="xsd:string" use="required" />
</xsd:complexType>
</xsd:element>
</xsd:choice>
</xsd:complexType>
</xsd:element>
</xsd:schema>
<resheader name="resmimetype">
<value>text/microsoft-resx</value>
</resheader>
<resheader name="version">
<value>2.0</value>
</resheader>
<resheader name="reader">
<value>System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<resheader name="writer">
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
</resheader>
<data name="CostType" xml:space="preserve">
<value>Cost Type</value>
</data>
<data name="IncomeType" xml:space="preserve">
<value>Income Type</value>
</data>
<data name="Project" xml:space="preserve">
<value>Project</value>
</data>
</root>
@@ -0,0 +1,50 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swarmops.Basic.Types.Financial;
using Swarmops.Database;
namespace Swarmops.Logic.Financial
{
public class FinancialTransactionTagSet: BasicFinancialTransactionTagSet
{
private FinancialTransactionTagSet (BasicFinancialTransactionTagSet basic): base (basic)
{
// ctor
}
public static FinancialTransactionTagSet FromBasic (BasicFinancialTransactionTagSet basic)
{
return new FinancialTransactionTagSet(basic);
}
public static FinancialTransactionTagSet FromIdentity (int identity)
{
return FromBasic(SwarmDb.GetDatabaseForReading().GetFinancialTransactionTagSet(identity));
}
public new TagSetProfitLossType ProfitLossType
{
get { return (TagSetProfitLossType) base.ProfitLossType; }
}
}
public enum TagSetProfitLossType
{
Unknown = 0,
/// <summary>
/// This tag set should only be applied to income.
/// </summary>
ProfitOnly = 1,
/// <summary>
/// This tag set should only be applied to costs.
/// </summary>
LossOnly = 2,
/// <summary>
/// This tag set should be applied to both income and costs.
/// </summary>
Both = 3
}
}
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swarmops.Logic.Interfaces;
namespace Swarmops.Logic.Financial
{
public class FinancialTransactionTagSetType
{
public static string GetLocalizedName (int identity)
{
if (identity < 0)
{
string resource = ((FinancialTransactionTagSetTypesStock) identity).ToString();
return
App_GlobalResources.Logic_Financial_FinancialTransactionTagSetTypesStock.ResourceManager.GetString(
resource);
}
throw new NotImplementedException("Custom set names are not implemented yet");
}
}
}
@@ -0,0 +1,15 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Swarmops.Logic.Financial
{
public enum FinancialTransactionTagSetTypesStock
{
Unknown = 0,
CostType = -1,
IncomeType = -2,
ProjectName = -3
}
}
@@ -0,0 +1,20 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swarmops.Basic.Types.Financial;
using Swarmops.Database;
using Swarmops.Logic.Structure;
using Swarmops.Logic.Support;
namespace Swarmops.Logic.Financial
{
public class FinancialTransactionTagSets :
PluralBase<FinancialTransactionTagSets, FinancialTransactionTagSet, BasicFinancialTransactionTagSet>
{
public static FinancialTransactionTagSets ForOrganization(Organization organization)
{
return FromArray(SwarmDb.GetDatabaseForReading().GetFinancialTransactionTagSets(organization));
}
}
}
@@ -0,0 +1,26 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swarmops.Basic.Types.Financial;
namespace Swarmops.Logic.Financial
{
public class FinancialTransactionTagType: BasicFinancialTransactionTagType
{
private FinancialTransactionTagType (BasicFinancialTransactionTagType basicTagType): base (basicTagType)
{
// private ctor
}
public static FinancialTransactionTagType FromBasic (BasicFinancialTransactionTagType basic)
{
return new FinancialTransactionTagType(basic);
}
public int ParentIdentity
{
get { return base.ParentFinancialTransactionTagTypeId; }
}
}
}
@@ -0,0 +1,18 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Swarmops.Basic.Types.Financial;
using Swarmops.Database;
using Swarmops.Logic.Support;
namespace Swarmops.Logic.Financial
{
public class FinancialTransactionTagTypes: PluralBase<FinancialTransactionTagTypes,FinancialTransactionTagType,BasicFinancialTransactionTagType>
{
public static FinancialTransactionTagTypes ForSet (FinancialTransactionTagSet set)
{
return FromArray(SwarmDb.GetDatabaseForReading().GetFinancialTransactionTagTypes(set));
}
}
}
@@ -232,17 +232,5 @@ namespace Swarmops.Logic.Financial
}
}
public FinancialAccounts ExpensableCostTypes
{
// TODO: This needs to return a tree, not a flat list.
get
{
throw new NotImplementedException();
}
}
}
}
+15
View File
@@ -64,6 +64,11 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="App_GlobalResources\Logic.Financial.FinancialTransactionTagSetTypesStock.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
<DependentUpon>Logic.Financial.FinancialTransactionTagSetTypesStock.resx</DependentUpon>
</Compile>
<Compile Include="App_GlobalResources\Logic.Swarm.DashboardTodos.Designer.cs">
<AutoGen>True</AutoGen>
<DesignTime>True</DesignTime>
@@ -92,6 +97,12 @@
<Compile Include="Communications\Transmission\PayloadBase.cs" />
<Compile Include="Financial\CashAdvance.cs" />
<Compile Include="Financial\CashAdvances.cs" />
<Compile Include="Financial\FinancialTransactionTagSet.cs" />
<Compile Include="Financial\FinancialTransactionTagSets.cs" />
<Compile Include="Financial\FinancialTransactionTagSetType.cs" />
<Compile Include="Financial\FinancialTransactionTagSetTypesStock.cs" />
<Compile Include="Financial\FinancialTransactionTagType.cs" />
<Compile Include="Financial\FinancialTransactionTagTypes.cs" />
<Compile Include="Financial\ImportedBankData.cs" />
<Compile Include="Financial\YearlyReport.cs" />
<Compile Include="Security\Accesses.cs" />
@@ -304,6 +315,10 @@
</ProjectReference>
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="App_GlobalResources\Logic.Financial.FinancialTransactionTagSetTypesStock.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Logic.Financial.FinancialTransactionTagSetTypesStock.Designer.cs</LastGenOutput>
</EmbeddedResource>
<EmbeddedResource Include="App_GlobalResources\Logic.Swarm.DashboardTodos.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>Logic.Swarm.DashboardTodos.Designer.cs</LastGenOutput>
+5
View File
@@ -86,6 +86,11 @@ namespace Swarmops.Logic.Support
case "Swarmops.Basic.Types.BasicSalary":
return Salary.FromBasic((BasicSalary) basic);
case "Swarmops.Basic.Types.Financial.BasicFinancialTransactionTagSet":
return FinancialTransactionTagSet.FromBasic ((BasicFinancialTransactionTagSet) basic);
case "Swarmops.Basic.Types.Financial.BasicFinancialTransactionTagType":
return FinancialTransactionTagType.FromBasic((BasicFinancialTransactionTagType) basic);
// ------------ GOVERNANCE CLASSES ------------
@@ -1 +0,0 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-ExpensableCostTypesTree.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Financial.Json_ExpensableCostTypesTree" %>
@@ -1,95 +0,0 @@
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.Logic.Financial;
using Swarmops.Logic.Swarm;
using Swarmops.Logic.Security;
using Swarmops.Logic.Structure;
namespace Swarmops.Frontend.Pages.v5.Financial
{
public partial class Json_ExpensableCostTypesTree : DataV5Base
{
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "application/json";
// Is this stuff in cache already?
string cacheKey = "CostTypes-Json-" +
this.CurrentOrganization.Identity.ToString((CultureInfo.InvariantCulture));
string accountsJson =
(string) Cache[cacheKey];
if (accountsJson != null)
{
Response.Output.WriteLine(accountsJson);
Response.End();
return;
}
// Not in cache. Construct.
// Get accounts
FinancialAccounts accounts = this.CurrentOrganization.FinancialAccounts.ExpensableCostTypes;
// 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 (!treeMap.ContainsKey(account.ParentIdentity))
{
treeMap[account.ParentIdentity] = new List<FinancialAccount>();
}
treeMap[account.ParentIdentity].Add(account);
}
int renderRootNodeId = 0;
if (treeMap[0].Count == 1 && treeMap.ContainsKey(treeMap[0][0].Identity))
{
// assume there's a master root like "Costs"; bypass it
renderRootNodeId = treeMap[0][0].Identity;
}
accountsJson = RecurseTreeMap(treeMap, renderRootNodeId);
Cache.Insert(cacheKey, accountsJson, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero);
// cache lasts for five minutes, no sliding expiration
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,
account.Name.Replace("\"", "'"));
if (treeMap.ContainsKey(account.Identity))
{
element += ",\"state\":\"closed\",\"children\":" + RecurseTreeMap(treeMap, account.Identity);
}
elements.Add("{" + element + "}");
}
return "[" + String.Join(",", elements.ToArray()) + "]";
}
}
}
@@ -0,0 +1 @@
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-TransactionTagsTree.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Financial.Json_TransactionTagsTree" %>
@@ -0,0 +1,106 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
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_TransactionTagsTree : DataV5Base
{
protected void Page_Load(object sender, EventArgs e)
{
Response.ContentType = "application/json";
int tagSetId = Int32.Parse(Request.QueryString["TagSetId"]);
FinancialTransactionTagSet tagSet = FinancialTransactionTagSet.FromIdentity(tagSetId);
if (tagSet.OrganizationId != this.CurrentOrganization.Identity)
{
throw new UnauthorizedAccessException();
}
// Is this stuff in cache already?
string cacheKey = "FinancialTransactionTagTypes-Json-" +
tagSetId.ToString((CultureInfo.InvariantCulture));
string tagsJson =
(string) Cache[cacheKey];
if (tagsJson != null)
{
Response.Output.WriteLine(tagsJson);
Response.End();
return;
}
// Not in cache. Construct.
// Get accounts
FinancialTransactionTagTypes tagTypes = FinancialTransactionTagTypes.ForSet(tagSet);
// Build tree (there should be a template for this)
Dictionary<int, List<FinancialTransactionTagType>> treeMap = new Dictionary<int, List<FinancialTransactionTagType>>();
foreach (FinancialTransactionTagType tagType in tagTypes)
{
if (!treeMap.ContainsKey(tagType.ParentIdentity))
{
treeMap[tagType.ParentIdentity] = new List<FinancialTransactionTagType>();
}
treeMap[tagType.ParentIdentity].Add(tagType);
}
int renderRootNodeId = 0;
if (treeMap[0].Count == 1 && treeMap.ContainsKey(treeMap[0][0].Identity))
{
// assume there's a master root like "Costs"; bypass it
renderRootNodeId = treeMap[0][0].Identity;
}
tagsJson = RecurseTreeMap(treeMap, renderRootNodeId);
Cache.Insert(cacheKey, tagsJson, null, DateTime.Now.AddMinutes(5), TimeSpan.Zero);
// cache lasts for five minutes, no sliding expiration
Response.Output.WriteLine(tagsJson);
Response.End();
}
private string RecurseTreeMap(Dictionary<int, List<FinancialTransactionTagType>> treeMap, int node)
{
List<string> elements = new List<string>();
foreach (FinancialTransactionTagType tagType in treeMap[node])
{
string element = string.Format("\"id\":{0},\"text\":\"{1}\"", tagType.Identity,
tagType.Name.Replace("\"", "\\\""));
if (treeMap.ContainsKey(tagType.Identity))
{
element += ",\"state\":\"closed\",\"children\":" + RecurseTreeMap(treeMap, tagType.Identity);
}
elements.Add("{" + element + "}");
}
return "[" + String.Join(",", elements.ToArray()) + "]";
}
}
}
@@ -15,16 +15,17 @@
$(document).ready(function () {
$('#DropCostTypes').combotree({
<asp:Repeater ID="RepeaterTagDropScript" runat="server"><ItemTemplate>
$('#DropTags<%# Eval("TagSetId") %>').combotree({
animate: true,
height: 30
});
$('#SpanCostTypes span.combo input.combo-text').click(function () {
$('#SpanCostTypes span.combo span span.combo-arrow').click();
$('#SpanDropTags<%# Eval("TagSetId") %> span.combo input.combo-text').click(function () {
$('#SpanDropTags<%# Eval("TagSetId") %> span.combo span span.combo-arrow').click();
});
</ItemTemplate></asp:Repeater>
});
@@ -83,11 +84,13 @@
<asp:Content ID="Content5" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
<asp:HiddenField ID="TagSetIdentifiers" runat="server"/>
<div class="entryFields">
<asp:TextBox runat="server" ID="TextAmount" CssClass="alignRight" />&nbsp;<br/>
<asp:TextBox runat="server" ID="TextPurpose" />&nbsp;<br/>
<Swarmops5:ComboBudgets ID="ComboBudgets" runat="server" />&nbsp;<br/>
<span id="SpanCostTypes"><select class="easyui-combotree" url="/Automation/Json-ExpensableCostTypesTree.aspx" name="DropCostTypes" id="DropCostTypes" animate="true" style="width:300px"></select></span>&nbsp;<br/>
<asp:Repeater ID="RepeaterTagDrop" runat="server"><ItemTemplate><span id="SpanDropTags<%# Eval("TagSetId") %>"><select class="easyui-combotree" url="/Automation/Json-TransactionTagsTree.aspx?TagSetId=<%# Eval("TagSetId") %>" name="DropTags<%# Eval("TagSetId") %>" id="DropTags<%# Eval("TagSetId") %>" animate="true" style="width:300px"></select></span>&nbsp;<br/></ItemTemplate></asp:Repeater>
&nbsp;<br/><!-- placeholder for label-side H2 -->
<!-- file upload begins here -->
@@ -106,7 +109,7 @@
<asp:Label runat="server" ID="LabelAmount" /><br/>
<asp:Label runat="server" ID="LabelPurpose" /><br/>
<asp:Label runat="server" ID="LabelBudget" /><br/>
<asp:Label runat="server" ID="LabelCostType" /><br/>
<asp:Repeater ID="RepeaterTagLabels" runat="server"><ItemTemplate><%# Eval("TagSetLocalizedName") %><br/></ItemTemplate></asp:Repeater>
<h2><asp:Label runat="server" ID="LabelHeaderImageFiles" /></h2>
<asp:Label runat="server" ID="LabelImageFiles" /><br/>
<h2><asp:Label runat="server" ID="LabelHeaderBankDetails" /></h2>
@@ -12,6 +12,50 @@ namespace Swarmops.Frontend.Pages.v5.Financial
{
public partial class FileExpenseClaim : PageV5Base
{
protected void Page_Init(object sender, EventArgs e)
{
string tagSetIdsString = Request.Form["HiddenTagSetIdentifiers"];
int[] tagSetIds;
if (String.IsNullOrEmpty(tagSetIdsString))
{
tagSetIds = FinancialTransactionTagSets.ForOrganization(this.CurrentOrganization).Identities;
}
else
{
string[] tagSetIdStrings = tagSetIdsString.Split(',');
tagSetIds = new int[tagSetIdStrings.Length];
for (int index = 0; index < tagSetIdStrings.Length; index++)
{
tagSetIds[index] = Int32.Parse(tagSetIdStrings[index]);
}
}
List<TagSetDataSourceItem> dataSource = new List<TagSetDataSourceItem>();
foreach (int tagSetId in tagSetIds)
{
TagSetDataSourceItem item = new TagSetDataSourceItem()
{
TagSetId = tagSetId,
TagSetLocalizedName =
FinancialTransactionTagSetType.GetLocalizedName(
FinancialTransactionTagSet.FromIdentity(tagSetId).
FinancialTransactionTagSetTypeId)
};
dataSource.Add(item);
}
this.RepeaterTagLabels.DataSource = dataSource;
this.RepeaterTagDrop.DataSource = dataSource;
this.RepeaterTagDropScript.DataSource = dataSource;
this.RepeaterTagLabels.DataBind();
this.RepeaterTagDrop.DataBind();
this.RepeaterTagDropScript.DataBind();
}
protected void Page_Load(object sender, EventArgs e)
{
if (!this.CurrentOrganization.IsEconomyEnabled)
@@ -45,7 +89,6 @@ namespace Swarmops.Frontend.Pages.v5.Financial
CurrentOrganization.Currency.Code);
this.LabelPurpose.Text = Resources.Pages.Financial.FileExpenseClaim_Description;
this.LabelBudget.Text = Resources.Pages.Financial.FileExpenseClaim_Budget;
this.LabelCostType.Text = Resources.Pages.Financial.FileExpenseClaim_CostType;
this.LabelHeaderBankDetails.Text = Resources.Pages.Financial.FileExpenseClaim_HeaderBankDetails;
this.LabelBankName.Text = Resources.Pages.Financial.FileExpenseClaim_BankName;
this.LabelBankClearing.Text = Resources.Pages.Financial.FileExpenseClaim_BankClearing;
@@ -134,5 +177,12 @@ namespace Swarmops.Frontend.Pages.v5.Financial
Response.Redirect("/", true);
}
protected class TagSetDataSourceItem
{
public int TagSetId { get; set; }
public string TagSetLocalizedName { get; set; }
}
}
}