From d82b34dafa4a3fb63bbd179c473a9df069a3f44c Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Tue, 29 Oct 2013 19:28:17 +0000 Subject: [PATCH] Added financial transaction tags; changed 2-D bookkeeping to tags --- .../BasicFinancialTransactionTagSet.cs | 6 +- .../Database-FinancialTransactionTagSets.cs | 10 +- .../Database-FinancialTransactionTagTypes.cs | 4 +- ...ialTransactionTagSetTypesStock.Designer.cs | 91 ++++++++++++ ....FinancialTransactionTagSetTypesStock.resx | 129 ++++++++++++++++++ Logic/Financial/FinancialTransactionTagSet.cs | 50 +++++++ .../FinancialTransactionTagSetType.cs | 26 ++++ .../FinancialTransactionTagSetTypesStock.cs | 15 ++ .../Financial/FinancialTransactionTagSets.cs | 20 +++ .../Financial/FinancialTransactionTagType.cs | 26 ++++ .../Financial/FinancialTransactionTagTypes.cs | 18 +++ .../OrganizationFinancialAccounts.cs | 12 -- Logic/Logic.csproj | 15 ++ Logic/Support/SingularFactory.cs | 5 + .../Json-ExpensableCostTypesTree.aspx | 1 - .../Json-ExpensableCostTypesTree.aspx.cs | 95 ------------- .../Automation/Json-TransactionTagsTree.aspx | 1 + .../Json-TransactionTagsTree.aspx.cs | 106 ++++++++++++++ .../Pages/v5/Financial/FileExpenseClaim.aspx | 15 +- .../v5/Financial/FileExpenseClaim.aspx.cs | 52 ++++++- 20 files changed, 574 insertions(+), 123 deletions(-) create mode 100644 Logic/App_GlobalResources/Logic.Financial.FinancialTransactionTagSetTypesStock.Designer.cs create mode 100644 Logic/App_GlobalResources/Logic.Financial.FinancialTransactionTagSetTypesStock.resx create mode 100644 Logic/Financial/FinancialTransactionTagSet.cs create mode 100644 Logic/Financial/FinancialTransactionTagSetType.cs create mode 100644 Logic/Financial/FinancialTransactionTagSetTypesStock.cs create mode 100644 Logic/Financial/FinancialTransactionTagSets.cs create mode 100644 Logic/Financial/FinancialTransactionTagType.cs create mode 100644 Logic/Financial/FinancialTransactionTagTypes.cs delete mode 100644 Site5/Automation/Json-ExpensableCostTypesTree.aspx delete mode 100644 Site5/Automation/Json-ExpensableCostTypesTree.aspx.cs create mode 100644 Site5/Automation/Json-TransactionTagsTree.aspx create mode 100644 Site5/Automation/Json-TransactionTagsTree.aspx.cs diff --git a/Basic/Types/Financial/BasicFinancialTransactionTagSet.cs b/Basic/Types/Financial/BasicFinancialTransactionTagSet.cs index 36754714..31332eac 100644 --- a/Basic/Types/Financial/BasicFinancialTransactionTagSet.cs +++ b/Basic/Types/Financial/BasicFinancialTransactionTagSet.cs @@ -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 diff --git a/Database/Database-FinancialTransactionTagSets.cs b/Database/Database-FinancialTransactionTagSets.cs index 5e66cafd..1eb33787 100644 --- a/Database/Database-FinancialTransactionTagSets.cs +++ b/Database/Database-FinancialTransactionTagSets.cs @@ -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()) { diff --git a/Database/Database-FinancialTransactionTagTypes.cs b/Database/Database-FinancialTransactionTagTypes.cs index 4d4db951..b29f4a95 100644 --- a/Database/Database-FinancialTransactionTagTypes.cs +++ b/Database/Database-FinancialTransactionTagTypes.cs @@ -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()) { diff --git a/Logic/App_GlobalResources/Logic.Financial.FinancialTransactionTagSetTypesStock.Designer.cs b/Logic/App_GlobalResources/Logic.Financial.FinancialTransactionTagSetTypesStock.Designer.cs new file mode 100644 index 00000000..53a184f5 --- /dev/null +++ b/Logic/App_GlobalResources/Logic.Financial.FinancialTransactionTagSetTypesStock.Designer.cs @@ -0,0 +1,91 @@ +//------------------------------------------------------------------------------ +// +// 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. +// +//------------------------------------------------------------------------------ + +namespace Swarmops.Logic.App_GlobalResources { + using System; + + + /// + /// A strongly-typed resource class, for looking up localized strings, etc. + /// + // 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() { + } + + /// + /// Returns the cached ResourceManager instance used by this class. + /// + [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; + } + } + + /// + /// Overrides the current thread's CurrentUICulture property for all + /// resource lookups using this strongly typed resource class. + /// + [global::System.ComponentModel.EditorBrowsableAttribute(global::System.ComponentModel.EditorBrowsableState.Advanced)] + internal static global::System.Globalization.CultureInfo Culture { + get { + return resourceCulture; + } + set { + resourceCulture = value; + } + } + + /// + /// Looks up a localized string similar to Cost Type. + /// + internal static string CostType { + get { + return ResourceManager.GetString("CostType", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Income Type. + /// + internal static string IncomeType { + get { + return ResourceManager.GetString("IncomeType", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Project. + /// + internal static string Project { + get { + return ResourceManager.GetString("Project", resourceCulture); + } + } + } +} diff --git a/Logic/App_GlobalResources/Logic.Financial.FinancialTransactionTagSetTypesStock.resx b/Logic/App_GlobalResources/Logic.Financial.FinancialTransactionTagSetTypesStock.resx new file mode 100644 index 00000000..34218e63 --- /dev/null +++ b/Logic/App_GlobalResources/Logic.Financial.FinancialTransactionTagSetTypesStock.resx @@ -0,0 +1,129 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + text/microsoft-resx + + + 2.0 + + + System.Resources.ResXResourceReader, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089 + + + Cost Type + + + Income Type + + + Project + + \ No newline at end of file diff --git a/Logic/Financial/FinancialTransactionTagSet.cs b/Logic/Financial/FinancialTransactionTagSet.cs new file mode 100644 index 00000000..066f9cad --- /dev/null +++ b/Logic/Financial/FinancialTransactionTagSet.cs @@ -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, + /// + /// This tag set should only be applied to income. + /// + ProfitOnly = 1, + /// + /// This tag set should only be applied to costs. + /// + LossOnly = 2, + /// + /// This tag set should be applied to both income and costs. + /// + Both = 3 + } + +} diff --git a/Logic/Financial/FinancialTransactionTagSetType.cs b/Logic/Financial/FinancialTransactionTagSetType.cs new file mode 100644 index 00000000..4a020c3c --- /dev/null +++ b/Logic/Financial/FinancialTransactionTagSetType.cs @@ -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"); + } + + } +} diff --git a/Logic/Financial/FinancialTransactionTagSetTypesStock.cs b/Logic/Financial/FinancialTransactionTagSetTypesStock.cs new file mode 100644 index 00000000..93520ed2 --- /dev/null +++ b/Logic/Financial/FinancialTransactionTagSetTypesStock.cs @@ -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 + } +} diff --git a/Logic/Financial/FinancialTransactionTagSets.cs b/Logic/Financial/FinancialTransactionTagSets.cs new file mode 100644 index 00000000..9fc52296 --- /dev/null +++ b/Logic/Financial/FinancialTransactionTagSets.cs @@ -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 + { + public static FinancialTransactionTagSets ForOrganization(Organization organization) + { + return FromArray(SwarmDb.GetDatabaseForReading().GetFinancialTransactionTagSets(organization)); + } + } +} diff --git a/Logic/Financial/FinancialTransactionTagType.cs b/Logic/Financial/FinancialTransactionTagType.cs new file mode 100644 index 00000000..f26b16f7 --- /dev/null +++ b/Logic/Financial/FinancialTransactionTagType.cs @@ -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; } + } + } +} diff --git a/Logic/Financial/FinancialTransactionTagTypes.cs b/Logic/Financial/FinancialTransactionTagTypes.cs new file mode 100644 index 00000000..e96d3105 --- /dev/null +++ b/Logic/Financial/FinancialTransactionTagTypes.cs @@ -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 + { + public static FinancialTransactionTagTypes ForSet (FinancialTransactionTagSet set) + { + return FromArray(SwarmDb.GetDatabaseForReading().GetFinancialTransactionTagTypes(set)); + } + } +} diff --git a/Logic/Financial/OrganizationFinancialAccounts.cs b/Logic/Financial/OrganizationFinancialAccounts.cs index 858fe199..93abb79e 100644 --- a/Logic/Financial/OrganizationFinancialAccounts.cs +++ b/Logic/Financial/OrganizationFinancialAccounts.cs @@ -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(); - } - } - } } diff --git a/Logic/Logic.csproj b/Logic/Logic.csproj index cfea1404..212c76da 100644 --- a/Logic/Logic.csproj +++ b/Logic/Logic.csproj @@ -64,6 +64,11 @@ + + True + True + Logic.Financial.FinancialTransactionTagSetTypesStock.resx + True True @@ -92,6 +97,12 @@ + + + + + + @@ -304,6 +315,10 @@ + + ResXFileCodeGenerator + Logic.Financial.FinancialTransactionTagSetTypesStock.Designer.cs + ResXFileCodeGenerator Logic.Swarm.DashboardTodos.Designer.cs diff --git a/Logic/Support/SingularFactory.cs b/Logic/Support/SingularFactory.cs index a1bc35c4..4af3893f 100644 --- a/Logic/Support/SingularFactory.cs +++ b/Logic/Support/SingularFactory.cs @@ -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 ------------ diff --git a/Site5/Automation/Json-ExpensableCostTypesTree.aspx b/Site5/Automation/Json-ExpensableCostTypesTree.aspx deleted file mode 100644 index dd21fd93..00000000 --- a/Site5/Automation/Json-ExpensableCostTypesTree.aspx +++ /dev/null @@ -1 +0,0 @@ -<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-ExpensableCostTypesTree.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Financial.Json_ExpensableCostTypesTree" %> diff --git a/Site5/Automation/Json-ExpensableCostTypesTree.aspx.cs b/Site5/Automation/Json-ExpensableCostTypesTree.aspx.cs deleted file mode 100644 index 10538a83..00000000 --- a/Site5/Automation/Json-ExpensableCostTypesTree.aspx.cs +++ /dev/null @@ -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> treeMap = new Dictionary>(); - - foreach (FinancialAccount account in accounts) - { - if (!treeMap.ContainsKey(account.ParentIdentity)) - { - treeMap[account.ParentIdentity] = new List(); - } - - 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> treeMap, int node) - { - List elements = new List(); - - 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()) + "]"; - - } - } -} \ No newline at end of file diff --git a/Site5/Automation/Json-TransactionTagsTree.aspx b/Site5/Automation/Json-TransactionTagsTree.aspx new file mode 100644 index 00000000..815572c5 --- /dev/null +++ b/Site5/Automation/Json-TransactionTagsTree.aspx @@ -0,0 +1 @@ +<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-TransactionTagsTree.aspx.cs" Inherits="Swarmops.Frontend.Pages.v5.Financial.Json_TransactionTagsTree" %> diff --git a/Site5/Automation/Json-TransactionTagsTree.aspx.cs b/Site5/Automation/Json-TransactionTagsTree.aspx.cs new file mode 100644 index 00000000..a368973b --- /dev/null +++ b/Site5/Automation/Json-TransactionTagsTree.aspx.cs @@ -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> treeMap = new Dictionary>(); + + foreach (FinancialTransactionTagType tagType in tagTypes) + { + if (!treeMap.ContainsKey(tagType.ParentIdentity)) + { + treeMap[tagType.ParentIdentity] = new List(); + } + + 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> treeMap, int node) + { + List elements = new List(); + + 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()) + "]"; + + } + + } +} \ No newline at end of file diff --git a/Site5/Pages/v5/Financial/FileExpenseClaim.aspx b/Site5/Pages/v5/Financial/FileExpenseClaim.aspx index 85f51a84..a55cda1e 100644 --- a/Site5/Pages/v5/Financial/FileExpenseClaim.aspx +++ b/Site5/Pages/v5/Financial/FileExpenseClaim.aspx @@ -15,16 +15,17 @@ $(document).ready(function () { - $('#DropCostTypes').combotree({ + + $('#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(); }); - + }); @@ -83,11 +84,13 @@ +
 
 
 
-  
+ "> 
+  
@@ -106,7 +109,7 @@


-
+ <%# Eval("TagSetLocalizedName") %>


diff --git a/Site5/Pages/v5/Financial/FileExpenseClaim.aspx.cs b/Site5/Pages/v5/Financial/FileExpenseClaim.aspx.cs index f882d322..9afee3e6 100644 --- a/Site5/Pages/v5/Financial/FileExpenseClaim.aspx.cs +++ b/Site5/Pages/v5/Financial/FileExpenseClaim.aspx.cs @@ -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 dataSource = new List(); + + 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; } + } } } \ No newline at end of file