Refactor: Moved financial basic types into Swarmops.Basic.Types.Financial

This commit is contained in:
Rick Falkvinge
2013-10-06 10:10:07 +00:00
parent 6b584d87d5
commit da7752e394
32 changed files with 106 additions and 148 deletions
+5 -5
View File
@@ -66,7 +66,7 @@
<Compile Include="Types\BasicElection.cs" />
<Compile Include="Types\BasicExceptionLog.cs" />
<Compile Include="Types\BasicExternalActivity.cs" />
<Compile Include="Types\BasicFinancialValidation.cs" />
<Compile Include="Types\Financial\BasicFinancialValidation.cs" />
<Compile Include="Types\BasicPostalCode.cs" />
<Compile Include="Types\Financial\BasicFinancialAccount.cs" />
<Compile Include="Types\Governance\BasicMeeting.cs" />
@@ -98,10 +98,10 @@
<Compile Include="Types\BasicExpenseClaim.cs" />
<Compile Include="Types\BasicExternalCredential.cs" />
<Compile Include="Types\BasicExternalIdentity.cs" />
<Compile Include="Types\BasicFinancialAccountRow.cs" />
<Compile Include="Types\BasicFinancialDependency.cs" />
<Compile Include="Types\BasicFinancialTransaction.cs" />
<Compile Include="Types\BasicFinancialTransactionRow.cs" />
<Compile Include="Types\Financial\BasicFinancialAccountRow.cs" />
<Compile Include="Types\Financial\BasicFinancialDependency.cs" />
<Compile Include="Types\Financial\BasicFinancialTransaction.cs" />
<Compile Include="Types\Financial\BasicFinancialTransactionRow.cs" />
<Compile Include="Types\BasicInboundInvoice.cs" />
<Compile Include="Types\BasicInternalPoll.cs" />
<Compile Include="Types\BasicInternalPollCandidate.cs" />
@@ -95,13 +95,5 @@ namespace Swarmops.Basic.Enums
/// When closing books, this is the yearly result (balanced against DebtsEquity)
/// </summary>
CostsYearlyResult, // multi-account type
/// <summary>
/// Dimension 2 - default income account
/// </summary>
IncomeTypeUnspecified,
/// <summary>
/// Dimensione 2 - default cost account
/// </summary>
CostTypeUnspecified
};
}
@@ -7,7 +7,7 @@ namespace Swarmops.Basic.Types.Financial
{
public BasicFinancialAccount (int financialAccountId, string name, FinancialAccountType accountType,
int organizationId, int parentFinancialAccountId, int ownerPersonId,
int dimension, bool open, int openedYear, int closedYear, bool expensable)
bool open, int openedYear, int closedYear, bool expensable)
{
this.FinancialAccountId = financialAccountId;
this.Name = name;
@@ -15,7 +15,6 @@ namespace Swarmops.Basic.Types.Financial
this.OrganizationId = organizationId;
this.OwnerPersonId = ownerPersonId;
this.ParentFinancialAccountId = parentFinancialAccountId;
this.Dimension = dimension;
this.Open = open;
this.OpenedYear = openedYear;
this.ClosedYear = closedYear;
@@ -23,7 +22,7 @@ namespace Swarmops.Basic.Types.Financial
}
public BasicFinancialAccount (BasicFinancialAccount original) :
this(original.Identity, original.Name, original.AccountType, original.OrganizationId, original.ParentFinancialAccountId, original.OwnerPersonId, original.Dimension, 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)
{
// Empty copy constructor
}
@@ -35,7 +34,6 @@ namespace Swarmops.Basic.Types.Financial
public FinancialAccountType AccountType { get; private set; }
public int OwnerPersonId { get; protected set; }
public int ParentFinancialAccountId { get; private set; }
public int Dimension { get; protected set; }
public bool Open { get; protected set; }
public int OpenedYear { get; protected set; }
public int ClosedYear { get; protected set; }
@@ -1,8 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
namespace Swarmops.Basic.Types
namespace Swarmops.Basic.Types.Financial
{
public class BasicFinancialAccountRow
{
@@ -1,9 +1,6 @@
using System;
using System.Collections.Generic;
using System.Text;
using Swarmops.Basic.Enums;
namespace Swarmops.Basic.Types
namespace Swarmops.Basic.Types.Financial
{
/// <summary>
/// This class encapsulates what a financial transaction was constructed from.
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using Swarmops.Basic.Interfaces;
namespace Swarmops.Basic.Types
namespace Swarmops.Basic.Types.Financial
{
public class BasicFinancialTransaction : IHasIdentity
{
@@ -1,9 +1,7 @@
using System;
using System.Collections.Generic;
using System.Text;
using Swarmops.Basic.Interfaces;
namespace Swarmops.Basic.Types
namespace Swarmops.Basic.Types.Financial
{
public class BasicFinancialTransactionRow : IHasIdentity
{
@@ -1,10 +1,8 @@
using System;
using System.Collections.Generic;
using System.Text;
using Swarmops.Basic.Enums;
using Swarmops.Basic.Interfaces;
namespace Swarmops.Basic.Types
namespace Swarmops.Basic.Types.Financial
{
public class BasicFinancialValidation: IHasIdentity
{
+6 -5
View File
@@ -72,11 +72,12 @@ namespace Swarmops.Database
{
connection.Open();
DbCommand command =
GetDbCommand(
"SELECT Documents.DocumentId,Documents.ServerFileName,Documents.ClientFileName,Documents.Description,DocumentTypes.Name AS DocumentType,Documents.ForeignId,Documents.FileSize,Documents.UploadedByPersonId,Documents.UploadedDateTime From Documents,DocumentTypes " +
"WHERE Documents.Description = '" + description.Replace ("'", "''") + "' AND " +
"Documents.UploadedDateTime > '" + DateTime.UtcNow.AddDays(-1).ToString("yyyy-MM-dd HH:mm") + "'", connection);
string sqlQuery =
"SELECT Documents.DocumentId,Documents.ServerFileName,Documents.ClientFileName,Documents.Description,DocumentTypes.Name AS DocumentType,Documents.ForeignId,Documents.FileSize,Documents.UploadedByPersonId,Documents.UploadedDateTime From Documents,DocumentTypes " +
"WHERE Documents.Description = '" + description.Replace ("'", "''") + "' AND " +
"Documents.UploadedDateTime > '" + DateTime.UtcNow.AddDays (-1).ToString ("yyyy-MM-dd HH:mm") + "'";
DbCommand command = GetDbCommand(sqlQuery, connection);
using (DbDataReader reader = command.ExecuteReader())
{
@@ -5,6 +5,7 @@ using System.Data.Common;
using Swarmops.Basic.Enums;
using Swarmops.Basic.Interfaces;
using Swarmops.Basic.Types;
using Swarmops.Basic.Types.Financial;
namespace Swarmops.Database
+6 -28
View File
@@ -15,8 +15,7 @@ namespace Swarmops.Database
{
private const string financialAccountFieldSequence =
" FinancialAccountId,Name,OrganizationId,AccountType,ParentFinancialAccountId," + // 0-4
" OwnerPersonId,Dimension,Open,OpenedYear,ClosedYear, " + // 5-9
" Expensable " + // 10
" OwnerPersonId,Open,OpenedYear,ClosedYear,Expensable " + // 5-9
" FROM FinancialAccounts ";
public int CreateFinancialAccount(int pOrganizationId, string pName, FinancialAccountType pAccountType, int pParentFinancialAccountId)
@@ -38,25 +37,6 @@ namespace Swarmops.Database
}
public void SetFinancialAccountDimension(int financialAccountId, int dimension)
{
// This is only intended to be used when creating the account, and never used once in use.
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("SetFinancialAccountDimension", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "financialAccountId", financialAccountId);
AddParameterWithName(command, "dimension", dimension);
command.ExecuteNonQuery();
}
}
public BasicFinancialAccount GetFinancialAccount(int financialAccountId)
{
using (DbConnection connection = GetMySqlDbConnection())
@@ -686,7 +666,6 @@ namespace Swarmops.Database
}
}
private BasicFinancialTransactionRow ReadFinancialTransactionRowFromDataReader(DbDataReader reader)
{
int rowId = reader.GetInt32(0);
@@ -707,13 +686,12 @@ namespace Swarmops.Database
var accountType = (FinancialAccountType) reader.GetInt32(3);
int parentFinancialAccountId = reader.GetInt32(4);
int ownerPersonId = reader.GetInt32(5);
int dimension = reader.GetInt32(6);
bool open = reader.GetBoolean(7);
int openedYear = reader.GetInt32(8);
int closedYear = reader.GetInt32(9);
bool expensable = reader.GetBoolean(10);
bool open = reader.GetBoolean(6);
int openedYear = reader.GetInt32(7);
int closedYear = reader.GetInt32(8);
bool expensable = reader.GetBoolean(9);
return new BasicFinancialAccount(accountId, name, accountType, organizationId, parentFinancialAccountId, ownerPersonId, dimension, open, openedYear, closedYear, expensable);
return new BasicFinancialAccount(accountId, name, accountType, organizationId, parentFinancialAccountId, ownerPersonId, open, openedYear, closedYear, expensable);
}
private BasicFinancialAccountRow ReadFinancialAccountRowFromDataReader (DbDataReader reader)
+1
View File
@@ -7,6 +7,7 @@ using System.Text;
using Swarmops.Basic.Enums;
using Swarmops.Basic.Interfaces;
using Swarmops.Basic.Types;
using Swarmops.Basic.Types.Financial;
namespace Swarmops.Database
{
@@ -73,7 +73,7 @@ namespace Swarmops.Logic.App_GlobalResources {
}
/// <summary>
/// Looks up a localized string similar to [OrganizationName] Cash Advance Requested.
/// Looks up a localized string similar to [OrganizationName] Cash Advance Requested: [CurrencyCode] [BudgetAmountFloat].
/// </summary>
internal static string CashAdvance_Requested_Subject {
get {
@@ -81,6 +81,26 @@ namespace Swarmops.Logic.App_GlobalResources {
}
}
/// <summary>
/// Looks up a localized string similar to [ConcernedPersonName] has created an expense claim against the budget of [BudgetName] for the amount of [CurrencyCode] [BudgetAmountFloat]. The claim concerns [RequestPurpose]. You will need to attest this expense claim.
///
///Please log on to Swarmops at [SystemUrl] to attest or deny..
/// </summary>
internal static string ExpenseClaim_Created_Body {
get {
return ResourceManager.GetString("ExpenseClaim_Created_Body", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to [OrganizationName] Expense Claim Created: [CurrencyCode] [BudgetAmountFloat].
/// </summary>
internal static string ExpenseClaim_Created_Subject {
get {
return ResourceManager.GetString("ExpenseClaim_Created_Subject", resourceCulture);
}
}
/// <summary>
/// Looks up a localized string similar to An unhandled exception was thrown in Swarmops:
///
@@ -123,7 +123,15 @@
Please log on to Swarmops at [SystemUrl] to attest or deny.</value>
</data>
<data name="CashAdvance_Requested_Subject" xml:space="preserve">
<value>[OrganizationName] Cash Advance Requested</value>
<value>[OrganizationName] Cash Advance Requested: [CurrencyCode] [BudgetAmountFloat]</value>
</data>
<data name="ExpenseClaim_Created_Body" xml:space="preserve">
<value>[ConcernedPersonName] has created an expense claim against the budget of [BudgetName] for the amount of [CurrencyCode] [BudgetAmountFloat]. The claim concerns [RequestPurpose]. You will need to attest this expense claim.
Please log on to Swarmops at [SystemUrl] to attest or deny.</value>
</data>
<data name="ExpenseClaim_Created_Subject" xml:space="preserve">
<value>[OrganizationName] Expense Claim Created: [CurrencyCode] [BudgetAmountFloat]</value>
</data>
<data name="System_Exception_Body" xml:space="preserve">
<value>An unhandled exception was thrown in Swarmops:
@@ -90,7 +90,11 @@ namespace Swarmops.Logic.Communications.Transmission
System_Startup,
System_Exception,
CashAdvance_Requested,
CashAdvance_Attested
CashAdvance_Attested,
ExpenseClaim_Created,
ExpenseClaim_Attested,
ExpenseClaim_Validated,
Payout_Settled
}
// ReSharper restore InconsistentNaming
+9 -2
View File
@@ -3,6 +3,8 @@ using System.Collections.Generic;
using Swarmops.Basic.Enums;
using Swarmops.Basic.Types;
using Swarmops.Database;
using Swarmops.Logic.Communications;
using Swarmops.Logic.Communications.Transmission;
using Swarmops.Logic.Swarm;
using Swarmops.Logic.Structure;
using Swarmops.Logic.Support;
@@ -56,12 +58,15 @@ namespace Swarmops.Logic.Financial
transaction.AddRow(organization.FinancialAccounts.DebtsExpenseClaims, -amountCents, claimer);
transaction.AddRow(budget, amountCents, claimer);
transaction.AddRow(costType, amountCents, claimer); // dimension 2
// Make the transaction dependent on the expense claim
transaction.Dependency = newClaim;
// Create notification
OutboundComm.CreateNotificationForAttest(budget, claimer, (double)amountCents / 100.0, description, NotificationResource.ExpenseClaim_Created); // Slightly misplaced logic, but failsafer here
return newClaim;
}
@@ -363,6 +368,8 @@ namespace Swarmops.Logic.Financial
nominalTransaction[debtAccountId] = -AmountCents;
nominalTransaction[BudgetId] = AmountCents;
// TODO: Balance cost account, too
}
this.FinancialTransaction.RecalculateTransaction(nominalTransaction, updatingPerson);
-13
View File
@@ -112,19 +112,6 @@ namespace Swarmops.Logic.Financial
}
}
new public int Dimension
{
get { return base.Dimension; }
set
{
if (base.Dimension != value)
{
SwarmDb.GetDatabaseForWriting().SetFinancialAccountDimension(this.Identity, value);
base.Dimension = value;
}
}
}
public Person Owner
{
get
+1
View File
@@ -1,4 +1,5 @@
using Swarmops.Basic.Types;
using Swarmops.Basic.Types.Financial;
namespace Swarmops.Logic.Financial
{
+1
View File
@@ -1,5 +1,6 @@
using System.Collections.Generic;
using Swarmops.Basic.Types;
using Swarmops.Basic.Types.Financial;
namespace Swarmops.Logic.Financial
{
+8
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using Swarmops.Basic.Enums;
using Swarmops.Basic.Interfaces;
using Swarmops.Basic.Types;
using Swarmops.Basic.Types.Financial;
using Swarmops.Database;
using Swarmops.Logic.Swarm;
using Swarmops.Logic.Structure;
@@ -273,6 +274,9 @@ namespace Swarmops.Logic.Financial
public bool RecalculateTransaction (Dictionary<int, Int64> nominalTransaction, Person loggingPerson)
{
// TODO: Update dimension 2 with dimension 1 P&L accounts as template
bool changedTransaction = false;
// We need to create a delta. This is... somewhat complicated.
@@ -335,6 +339,10 @@ namespace Swarmops.Logic.Financial
}
}
// TODO: Dimension 2
return changedTransaction;
}
@@ -1,5 +1,6 @@
using System;
using Swarmops.Basic.Types;
using Swarmops.Basic.Types.Financial;
using Swarmops.Database;
namespace Swarmops.Logic.Financial
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using Swarmops.Basic.Enums;
using Swarmops.Basic.Types;
using Swarmops.Basic.Types.Financial;
namespace Swarmops.Logic.Financial
{
+1
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using Swarmops.Basic.Enums;
using Swarmops.Basic.Interfaces;
using Swarmops.Basic.Types;
using Swarmops.Basic.Types.Financial;
using Swarmops.Database;
using Swarmops.Logic.Structure;
using Swarmops.Logic.Support;
+1
View File
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.Text;
using Swarmops.Basic.Types;
using Swarmops.Basic.Types.Financial;
using Swarmops.Logic.Swarm;
namespace Swarmops.Logic.Financial
+1
View File
@@ -4,6 +4,7 @@ using System.Text;
using Swarmops.Basic.Enums;
using Swarmops.Basic.Interfaces;
using Swarmops.Basic.Types;
using Swarmops.Basic.Types.Financial;
using Swarmops.Database;
using Swarmops.Logic.Swarm;
using Swarmops.Logic.Support;
@@ -182,18 +182,6 @@ namespace Swarmops.Logic.Financial
get { return this[OrganizationFinancialAccountType.IncomeSales]; }
}
public FinancialAccount IncomeTypeUnspecified
{
// dimension 2
get { return this[OrganizationFinancialAccountType.IncomeTypeUnspecified]; }
}
public FinancialAccount CostTypeUnspecified
{
// dimension 2
get { return this[OrganizationFinancialAccountType.CostTypeUnspecified]; }
}
public FinancialAccounts CostsConferences
{
get
@@ -234,7 +222,7 @@ namespace Swarmops.Logic.Financial
foreach (FinancialAccount account in costAccounts)
{
if (account.Identity != yearlyResultId && account.Dimension == 1 && account.Expensable)
if (account.Identity != yearlyResultId && account.Expensable) // really should be redundant, but still...
{
result.Add(account);
}
@@ -251,43 +239,8 @@ namespace Swarmops.Logic.Financial
get
{
FinancialAccounts result = new FinancialAccounts();
int yearlyResultId = this.CostsYearlyResult.Identity;
FinancialAccounts costAccounts =
FinancialAccounts.ForOrganization(Organization.FromIdentity(_organizationId),
FinancialAccountType.Cost);
foreach (FinancialAccount account in costAccounts)
{
if (account.Identity != yearlyResultId && account.Dimension == 2 && account.Expensable)
{
result.Add(account);
}
}
if (result.Count == 0)
{
// Cost types have not been primed; add default account to organization and return it.
FinancialAccount defaultCostTypeAccount = FinancialAccount.Create(this._organizationId,
"Unspecified Costs",
FinancialAccountType.Cost, 0);
defaultCostTypeAccount.Dimension = 2;
this[OrganizationFinancialAccountType.CostTypeUnspecified] = defaultCostTypeAccount;
FinancialAccount defaultIncomeTypeAccount = FinancialAccount.Create(this._organizationId,
"Unspecified Income",
FinancialAccountType.Income, 0);
defaultIncomeTypeAccount.Dimension = 2;
this[OrganizationFinancialAccountType.IncomeTypeUnspecified] = defaultIncomeTypeAccount;
result.Add(defaultCostTypeAccount);
}
return result;
throw new NotImplementedException();
}
}
+1
View File
@@ -4,6 +4,7 @@ using System.Globalization;
using System.Text;
using Swarmops.Basic.Enums;
using Swarmops.Basic.Types;
using Swarmops.Basic.Types.Financial;
using Swarmops.Database;
using Swarmops.Logic.Swarm;
using Swarmops.Logic.Structure;
-10
View File
@@ -265,16 +265,6 @@ namespace Swarmops.Logic.Structure
FinancialAccounts[OrganizationFinancialAccountType.IncomeSales] =
FinancialAccount.Create(this.Identity, "Sales", FinancialAccountType.Income, 0);
// 2-dimension base accounts
FinancialAccount incomeUnspecified = FinancialAccount.Create(this.Identity, "Unspecified Income", FinancialAccountType.Income, 0);
incomeUnspecified.Dimension = 2;
FinancialAccounts[OrganizationFinancialAccountType.IncomeTypeUnspecified] = incomeUnspecified;
FinancialAccount costUnspecified = FinancialAccount.Create(this.Identity, "Unspecified Cost", FinancialAccountType.Cost, 0);
costUnspecified.Dimension = 2;
FinancialAccounts[OrganizationFinancialAccountType.CostTypeUnspecified] = costUnspecified;
// Then, create various cost accounts that are probably needed, or that could be used as a starting point
+1
View File
@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.Text;
using Swarmops.Basic.Enums;
using Swarmops.Basic.Types;
using Swarmops.Basic.Types.Financial;
using Swarmops.Database;
using Swarmops.Logic.Financial;
using Swarmops.Logic.Structure;
+14 -2
View File
@@ -253,8 +253,8 @@
<value>Upload File</value>
<comment>Displayed on "Submit" button next to file upload controls.</comment>
</data>
<data name="Global_UploadFileToActivizr" xml:space="preserve">
<value>Upload File To Activizr</value>
<data name="Global_UploadFileToSwarmops" xml:space="preserve">
<value>Upload File To Swarmops</value>
<comment>Used as header above upload sections.</comment>
</data>
<data name="Global_Upload_ErrorSelectFile" xml:space="preserve">
@@ -324,4 +324,16 @@
<data name="Global_Today" xml:space="preserve">
<value>Today</value>
</data>
<data name="Financial_TransactionTagSetTypeName_CostType" xml:space="preserve">
<value>Cost Type</value>
<comment>Second-dimension bookkeeping</comment>
</data>
<data name="Financial_TransactionTagSetTypeName_ProjectName" xml:space="preserve">
<value>Project</value>
<comment>Tagging costs/income to projects</comment>
</data>
<data name="Sidebar_Related" xml:space="preserve">
<value>Related</value>
<comment>List of shortcuts to related actions to current one</comment>
</data>
</root>
@@ -312,7 +312,7 @@
<value>Purpose</value>
</data>
<data name="RequestCashAdvance_SuccessMessagePartOne" xml:space="preserve">
<value>A cash advance has been requested for &lt;strong&gt;{0}&lt;/strong&gt; for the purpose of {1}. The requested amount is {2} {3:N2}. Note that this is a &lt;strong&gt;loan&lt;/strong&gt; from the organization until receipts have been presented.</value>
<value>A cash advance has been requested for &lt;strong&gt;{0}&lt;/strong&gt;. The requested amount is {2} {3:N2}. Note that this is a &lt;strong&gt;loan&lt;/strong&gt; from the organization until receipts have been presented.</value>
<comment>{0} is the person receiving the advance, {1} is the entered description. {2} is the currency (in caps) and {3:N2} is the amount, with two decimals, displayed in culture.</comment>
</data>
<data name="RequestCashAdvance_SuccessMessagePartTwo" xml:space="preserve">
@@ -43,7 +43,7 @@ namespace Swarmops.Site.Pages.Ledgers
this.LabelSelectFileType.Text = Resources.Pages.Ledgers.UploadBankFiles_SelectBankFileType;
this.LabelSelectAccount.Text = Resources.Pages.Ledgers.UploadBankFiles_SelectAccount;
this.LabelUploadH2Header.Text = Resources.Pages.Ledgers.UploadBankFiles_UploadBankFile;
this.LabelUploadH3Header.Text = Resources.Global.Global_UploadFileToActivizr;
this.LabelUploadH3Header.Text = Resources.Global.Global_UploadFileToSwarmops;
this.Upload.Text = Resources.Global.Global_UploadFile;
this.LabelProcessing.Text = Resources.Global.Global_ProcessingFile;
this.LinkUploadAnother.Text = Resources.Pages.Ledgers.UploadBankFiles_UploadAnother;