Testing P&L statement on live system
This commit is contained in:
@@ -57,6 +57,7 @@
|
||||
<Compile Include="Enums\ExternalActivityType.cs" />
|
||||
<Compile Include="Enums\OrganizationFinancialAccountType.cs" />
|
||||
<Compile Include="Types\BasicBallot.cs" />
|
||||
<Compile Include="Types\Financial\BasicCashAdvance.cs" />
|
||||
<Compile Include="Types\BasicCommunicationTurnaround.cs" />
|
||||
<Compile Include="Types\BasicElection.cs" />
|
||||
<Compile Include="Types\BasicExceptionLog.cs" />
|
||||
|
||||
@@ -188,7 +188,15 @@ namespace Activizr.Basic.Enums
|
||||
/// <summary>
|
||||
/// If "1", this financial account may be charged with invoices
|
||||
/// </summary>
|
||||
FinancialAccountEnabledForInvoicing
|
||||
FinancialAccountEnabledForInvoicing,
|
||||
/// <summary>
|
||||
/// Organization's operations currency, stored as currency code
|
||||
/// </summary>
|
||||
OrgCurrency,
|
||||
/// <summary>
|
||||
/// First bookkeeping year of org in Activizr (can set inbound balances for this year only)
|
||||
/// </summary>
|
||||
OrgFirstBookkeepingYear
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,60 @@
|
||||
using System;
|
||||
using Activizr.Basic.Interfaces;
|
||||
|
||||
namespace Activizr.Basic.Types.Financial
|
||||
{
|
||||
[Serializable]
|
||||
public class BasicCashAdvance: IHasIdentity
|
||||
{
|
||||
public BasicCashAdvance(int cashAdvanceId, int organizationId, int personId, DateTime createdDateTime, int createdByPersonId,
|
||||
int financialAccountId, Int64 amountCents, string description, bool open, bool attested,
|
||||
bool paidOut, int attestedByPersonId, DateTime attestedDateTime)
|
||||
{
|
||||
this.CashAdvanceId = cashAdvanceId;
|
||||
this.OrganizationId = organizationId;
|
||||
this.PersonId = personId;
|
||||
this.CreatedDateTime = createdDateTime;
|
||||
this.CreatedByPersonId = createdByPersonId;
|
||||
this.FinancialAccountId = financialAccountId;
|
||||
this.AmountCents = amountCents;
|
||||
this.Description = description;
|
||||
this.Open = open;
|
||||
this.Attested = attested;
|
||||
this.PaidOut = paidOut;
|
||||
this.AttestedByPersonId = attestedByPersonId;
|
||||
this.AttestedDateTime = attestedDateTime;
|
||||
}
|
||||
|
||||
public BasicCashAdvance (BasicCashAdvance original):
|
||||
this(original.CashAdvanceId, original.OrganizationId, original.PersonId, original.CreatedDateTime, original.CreatedByPersonId,
|
||||
original.FinancialAccountId, original.AmountCents,original.Description, original.Open, original.Attested,
|
||||
original.PaidOut, original.AttestedByPersonId, original.AttestedDateTime)
|
||||
{
|
||||
// copy ctor - no action other than copying original object
|
||||
}
|
||||
|
||||
public BasicCashAdvance()
|
||||
{
|
||||
// Never call this ctor directly. Produces an intentional compile-time error. Exists for serialization only.
|
||||
}
|
||||
|
||||
|
||||
public int CashAdvanceId { get; private set; }
|
||||
public int OrganizationId { get; private set; }
|
||||
public int PersonId { get; protected set; }
|
||||
public DateTime CreatedDateTime { get; protected set; }
|
||||
public int CreatedByPersonId { get; protected set; }
|
||||
public int FinancialAccountId { get; protected set; }
|
||||
public Int64 AmountCents { get; protected set; }
|
||||
public string Description { get; protected set; }
|
||||
public bool Open { get; protected set; }
|
||||
public bool Attested { get; protected set; }
|
||||
public bool PaidOut { get; protected set; }
|
||||
public int AttestedByPersonId { get; protected set; }
|
||||
public DateTime AttestedDateTime { get; protected set; }
|
||||
|
||||
// IHasIdentity interface
|
||||
|
||||
public int Identity { get { return this.CashAdvanceId; } }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,523 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Data;
|
||||
using System.Data.Common;
|
||||
using System.Text;
|
||||
using Activizr.Basic.Enums;
|
||||
using Activizr.Basic.Types;
|
||||
using Activizr.Basic.Types.Financial;
|
||||
|
||||
namespace Activizr.Database
|
||||
{
|
||||
public partial class PirateDb
|
||||
{
|
||||
|
||||
#region Database field reading
|
||||
|
||||
private const string cashAdvanceFieldSequence =
|
||||
" CashAdvanceId,OrganizationId,PersonId,CreatedDateTime,CreatedByPersonId," + // 0-4
|
||||
"FinancialAccountId,AmountCents,Description,Open,Attested," + // 5-9
|
||||
"PaidOut,AttestedByPersonId,AttestedDateTime " + // 10-12
|
||||
"FROM CashAdvances ";
|
||||
|
||||
private static BasicCashAdvance ReadCashAdvanceFromDataReader(IDataRecord reader)
|
||||
{
|
||||
int cashAdvanceId = reader.GetInt32(0);
|
||||
int organizationId = reader.GetInt32(1);
|
||||
int personId = reader.GetInt32(2);
|
||||
DateTime createdDateTime = reader.GetDateTime(3);
|
||||
int createdByPersonId = reader.GetInt32(4);
|
||||
|
||||
int financialAccountId = reader.GetInt32(5);
|
||||
Int64 amountCents = reader.GetInt64(6);
|
||||
string description = reader.GetString(7);
|
||||
bool open = reader.GetBoolean(8);
|
||||
bool attested = reader.GetBoolean(9);
|
||||
|
||||
bool paidOut = reader.GetBoolean(10);
|
||||
int attestedByPersonId = reader.GetInt32(11);
|
||||
DateTime attestedDateTime = reader.GetDateTime(12);
|
||||
|
||||
return new BasicCashAdvance(cashAdvanceId, organizationId, personId, createdDateTime, createdByPersonId,
|
||||
financialAccountId, amountCents, description, open, attested,
|
||||
paidOut, attestedByPersonId, attestedDateTime);
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Database record reading -- SELECT clauses
|
||||
|
||||
|
||||
public BasicCashAdvance GetCashAdvance (int cashAdvanceId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand("SELECT " + cashAdvanceFieldSequence +
|
||||
" WHERE CashAdvanceId=" + cashAdvanceId.ToString(),
|
||||
connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return ReadCashAdvanceFromDataReader(reader);
|
||||
}
|
||||
|
||||
throw new ArgumentException("No such CashAdvanceId:" + cashAdvanceId.ToString());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
public BasicCashAdvance[] GetCashAdvances(params object[] conditions)
|
||||
{
|
||||
List<BasicCashAdvance> result = new List<BasicCashAdvance>();
|
||||
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand(
|
||||
"SELECT " + cashAdvanceFieldSequence + ConstructWhereClause("CashAdvances", conditions), connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
result.Add(ReadCashAdvanceFromDataReader(reader));
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Creation and manipulation -- stored procedures
|
||||
|
||||
|
||||
public int CreateCashAdvance(int personId, int createdByPersonId, int organizationId, int financialAccountId,
|
||||
Int64 amountCents, string description)
|
||||
{
|
||||
if (description.Length > 128)
|
||||
{
|
||||
description = description.Substring(0, 128); // varchar(128) field
|
||||
}
|
||||
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("CreateCashAdvance", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "personId", personId);
|
||||
AddParameterWithName(command, "createdByPersonId", createdByPersonId);
|
||||
AddParameterWithName(command, "createdDateTime", DateTime.Now);
|
||||
AddParameterWithName(command, "organizationId", organizationId);
|
||||
AddParameterWithName(command, "amountCents", amountCents);
|
||||
AddParameterWithName(command, "financialAccountId", financialAccountId);
|
||||
AddParameterWithName(command, "description", description);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// TODO: SetCashAdvanceAttested
|
||||
|
||||
|
||||
public void SetCashAdvanceOpen(int cashAdvanceId, bool open)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetCashAdvanceOpen", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "cashAdvanceId", cashAdvanceId);
|
||||
AddParameterWithName(command, "open", open);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SetCashAdvancePaidOut(int cashAdvanceId, bool paidOut)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetCashAdvancePaidOut", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "cashAdvanceId", cashAdvanceId);
|
||||
AddParameterWithName(command, "paidOut", paidOut);
|
||||
|
||||
command.ExecuteNonQuery();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
#region Dead template code
|
||||
|
||||
/*
|
||||
public BasicExpenseClaim GetExpenseClaim(int expenseClaimId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand(
|
||||
"SELECT ExpenseClaimId,ClaimingPersonId,CreatedDateTime,Open,Attested," +
|
||||
"Validated,Claimed,OrganizationId,GeographyId,BudgetId,BudgetYear," +
|
||||
"ExpenseDate,Description,PreApprovedAmount,Amount,Repaid " +
|
||||
"FROM ExpenseClaims WHERE ExpenseClaimId=" + expenseClaimId.ToString(),
|
||||
connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return ReadExpenseFromDataReader(reader);
|
||||
}
|
||||
|
||||
throw new ArgumentException("Unknown ExpenseClaim Id");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BasicExpenseClaim[] GetExpenseClaimsByClaimer(int claimingPersonId)
|
||||
{
|
||||
List<BasicExpenseClaim> result = new List<BasicExpenseClaim>();
|
||||
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand("SELECT ExpenseClaimId,ClaimingPersonId,CreatedDateTime,Open,Attested," +
|
||||
"Validated,Claimed,OrganizationId,GeographyId,BudgetId,BudgetYear," +
|
||||
"ExpenseDate,Description,PreApprovedAmount,Amount,Repaid " +
|
||||
"FROM ExpenseClaims WHERE ClaimingPersonId=" + claimingPersonId.ToString(),
|
||||
connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
result.Add(ReadExpenseFromDataReader(reader));
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BasicExpenseClaim[] GetExpenseClaimsByBudgetAndYear(int budgetId, int budgetYear)
|
||||
{
|
||||
List<BasicExpenseClaim> result = new List<BasicExpenseClaim>();
|
||||
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand("SELECT ExpenseClaimId,ClaimingPersonId,CreatedDateTime,Open,Attested," +
|
||||
"Validated,Claimed,OrganizationId,GeographyId,BudgetId,BudgetYear," +
|
||||
"ExpenseDate,Description,PreApprovedAmount,Amount,Repaid " +
|
||||
"FROM ExpenseClaims WHERE BudgetId=" + budgetId.ToString() + " AND BudgetYear=" + budgetYear.ToString(),
|
||||
connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
result.Add(ReadExpenseFromDataReader(reader));
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public BasicExpenseClaim[] GetExpenseClaimsByOrganization(int organizationId)
|
||||
{
|
||||
List<BasicExpenseClaim> result = new List<BasicExpenseClaim>();
|
||||
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand("SELECT ExpenseClaimId,ClaimingPersonId,CreatedDateTime,Open,Attested," +
|
||||
"Validated,Claimed,OrganizationId,GeographyId,BudgetId,BudgetYear," +
|
||||
"ExpenseDate,Description,PreApprovedAmount,Amount,Repaid " +
|
||||
"FROM ExpenseClaims WHERE OrganizationId=" + organizationId.ToString(),
|
||||
connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
while (reader.Read())
|
||||
{
|
||||
result.Add(ReadExpenseFromDataReader(reader));
|
||||
}
|
||||
|
||||
return result.ToArray();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private BasicExpenseClaim ReadExpenseFromDataReader(DbDataReader reader)
|
||||
{
|
||||
int expenseClaimId = reader.GetInt32(0);
|
||||
int claimingPersonId = reader.GetInt32(1);
|
||||
DateTime createdDateTime = reader.GetDateTime(2);
|
||||
bool open = reader.GetBoolean(3);
|
||||
bool attested = reader.GetBoolean(4);
|
||||
bool documented = reader.GetBoolean(5);
|
||||
bool claimed = reader.GetBoolean(6);
|
||||
int organizationId = reader.GetInt32(7);
|
||||
int geographyId = reader.GetInt32(8); // obsolete field
|
||||
int budgetId = reader.GetInt32(9);
|
||||
int budgetYear = reader.GetInt32(10);
|
||||
DateTime expenseDate = reader.GetDateTime(11);
|
||||
string description = reader.GetString(12);
|
||||
double preApprovedAmount = reader.GetDouble(13);
|
||||
double amount = reader.GetDouble(14);
|
||||
bool repaid = reader.GetBoolean(15);
|
||||
|
||||
return new BasicExpenseClaim(expenseClaimId, claimingPersonId, createdDateTime,
|
||||
open, attested, documented, claimed, organizationId, geographyId,
|
||||
budgetId, budgetYear, expenseDate, description, preApprovedAmount,
|
||||
amount, repaid);
|
||||
}
|
||||
|
||||
|
||||
public int CreateExpenseClaim(int claimingPersonId, int organizationId, int budgetId, int budgetYear,
|
||||
DateTime expenseDate, string description, double amount)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("CreateExpenseClaim", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "claimingPersonId", claimingPersonId);
|
||||
AddParameterWithName(command, "createdDateTime", DateTime.Now);
|
||||
AddParameterWithName(command, "organizationId", organizationId);
|
||||
AddParameterWithName(command, "budgetId", budgetId);
|
||||
AddParameterWithName(command, "budgetYear", budgetYear);
|
||||
AddParameterWithName(command, "expenseDate", expenseDate);
|
||||
AddParameterWithName(command, "description", description);
|
||||
AddParameterWithName(command, "amount", amount);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
public int SetExpenseClaimDescription(int expenseClaimId, string description)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetExpenseClaimDescription", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
|
||||
AddParameterWithName(command, "description", description);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int SetExpenseClaimBudget(int expenseClaimId, int budgetId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetExpenseClaimBudget", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
|
||||
AddParameterWithName(command, "budgetId", budgetId);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int SetExpenseClaimBudgetYear(int expenseClaimId, int budgetYear)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetExpenseClaimBudgetYear", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
|
||||
AddParameterWithName(command, "budgetYear", budgetYear);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int SetExpenseClaimDate(int expenseClaimId, DateTime expenseDate)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetExpenseClaimDate", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
|
||||
AddParameterWithName(command, "expenseDate", expenseDate);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int SetExpenseClaimAmount(int expenseClaimId, double amount)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetExpenseClaimAmount", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
|
||||
AddParameterWithName(command, "amount", amount);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int SetExpenseClaimAttested(int expenseClaimId, bool attested)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetExpenseClaimAttested", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
|
||||
AddParameterWithName(command, "attested", attested);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int SetExpenseClaimValidated(int expenseClaimId, bool validated)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetExpenseClaimValidated", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
|
||||
AddParameterWithName(command, "validated", validated);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int SetExpenseClaimOpen(int expenseClaimId, bool open)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetExpenseClaimOpen", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
|
||||
AddParameterWithName(command, "open", open);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public int SetExpenseClaimRepaid(int expenseClaimId, bool repaid)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetExpenseClaimRepaid", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
|
||||
AddParameterWithName(command, "repaid", repaid);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public int CreateExpenseEvent(int expenseId, ExpenseEventType eventType, int personId)
|
||||
{
|
||||
// WARNING: NOT CONVERTED TO V4 YET
|
||||
|
||||
using (DbConnection connection = GetSqlServerDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("CreateExpenseEvent", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "expenseId", expenseId);
|
||||
AddParameterWithName(command, "dateTime", DateTime.Now);
|
||||
AddParameterWithName(command, "eventPersonId", personId);
|
||||
AddParameterWithName(command, "eventType", eventType.ToString());
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
*/
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -56,6 +56,7 @@
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Configuration.cs" />
|
||||
<Compile Include="Database-CashAdvances.cs" />
|
||||
<Compile Include="Database-Currencies.cs" />
|
||||
<Compile Include="Database-Initialization.cs" />
|
||||
<Compile Include="Database-Meetings.cs" />
|
||||
|
||||
@@ -0,0 +1,65 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Text;
|
||||
using Activizr.Basic.Types.Financial;
|
||||
using Activizr.Database;
|
||||
using Activizr.Logic.Pirates;
|
||||
using Activizr.Logic.Structure;
|
||||
|
||||
namespace Activizr.Logic.Financial
|
||||
{
|
||||
[Serializable]
|
||||
public class CashAdvance: BasicCashAdvance, IAttestable
|
||||
{
|
||||
#region Construction and creation
|
||||
|
||||
private CashAdvance(BasicCashAdvance basic): base(basic)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
public static CashAdvance FromBasic (BasicCashAdvance basic)
|
||||
{
|
||||
return new CashAdvance(basic);
|
||||
}
|
||||
|
||||
public static CashAdvance FromIdentity (int cashAdvanceId)
|
||||
{
|
||||
return FromBasic(PirateDb.GetDatabaseForReading().GetCashAdvance(cashAdvanceId));
|
||||
}
|
||||
|
||||
public static CashAdvance FromIdentityAggressive (int cashAdvanceId)
|
||||
{
|
||||
return FromBasic(PirateDb.GetDatabaseForWriting().GetCashAdvance(cashAdvanceId));
|
||||
}
|
||||
|
||||
public static CashAdvance Create(Organization organization, Person forPerson, Person createdByPerson, Int64 amountCents, FinancialAccount budget, string description)
|
||||
{
|
||||
return
|
||||
FromIdentityAggressive(PirateDb.GetDatabaseForWriting().CreateCashAdvance(forPerson.Identity,
|
||||
createdByPerson.Identity,
|
||||
organization.Identity,
|
||||
budget.Identity, amountCents,
|
||||
description));
|
||||
}
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
#region Implementation of IAttestable
|
||||
|
||||
public void Attest(Person attester)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
public void Deattest(Person deattester)
|
||||
{
|
||||
throw new NotImplementedException();
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -64,6 +64,7 @@
|
||||
<Reference Include="System.Xml" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<Compile Include="Financial\CashAdvance.cs" />
|
||||
<Compile Include="Financial\ImportedBankData.cs" />
|
||||
<Compile Include="Pirates\Interfaces.cs" />
|
||||
<Compile Include="Security\Accesses.cs" />
|
||||
|
||||
@@ -151,7 +151,37 @@ namespace Activizr.Logic.Structure
|
||||
get { return OptionalData.GetOptionalDataBool(ObjectOptionalDataType.OrgEconomyEnabled); }
|
||||
}
|
||||
|
||||
public void EnableEconomy()
|
||||
public Currency Currency
|
||||
{
|
||||
get
|
||||
{
|
||||
if (!IsEconomyEnabled)
|
||||
{
|
||||
throw new InvalidOperationException("Cannot request currency; organization is not economy-enabled");
|
||||
}
|
||||
|
||||
string currencyCode = OptionalData.GetOptionalDataString(ObjectOptionalDataType.OrgCurrency);
|
||||
|
||||
if (string.IsNullOrEmpty(currencyCode))
|
||||
{
|
||||
if (this.Identity == 1 && (this.Name.StartsWith("Piratpartiet") || this.Name.StartsWith("Sandbox")))
|
||||
{
|
||||
// This is a one-off to fix the v4 installation. Currency is SEK.
|
||||
OptionalData.SetOptionalDataString(ObjectOptionalDataType.OrgCurrency, "SEK");
|
||||
currencyCode = "SEK";
|
||||
}
|
||||
if (this.Identity == 2 && (this.Name.StartsWith("European")))
|
||||
{
|
||||
OptionalData.SetOptionalDataString(ObjectOptionalDataType.OrgCurrency, "SEK");
|
||||
currencyCode = "SEK";
|
||||
}
|
||||
}
|
||||
|
||||
return Currency.FromCode(currencyCode);
|
||||
}
|
||||
}
|
||||
|
||||
public void EnableEconomy(Currency currency)
|
||||
{
|
||||
if (IsEconomyEnabled)
|
||||
{
|
||||
@@ -224,6 +254,10 @@ namespace Activizr.Logic.Structure
|
||||
FinancialAccountType.Cost, 0);
|
||||
conferenceBase.IsConferenceParent = true;
|
||||
|
||||
// Set the currency
|
||||
|
||||
OptionalData.SetOptionalDataString(ObjectOptionalDataType.OrgCurrency, currency.Code);
|
||||
|
||||
// Finally, flag the org as enabled
|
||||
|
||||
this.OptionalData.SetOptionalDataBool(ObjectOptionalDataType.OrgEconomyEnabled, true);
|
||||
|
||||
@@ -261,8 +261,8 @@
|
||||
<data name="Menu5_Ledgers_Payroll" xml:space="preserve">
|
||||
<value>Payroll</value>
|
||||
</data>
|
||||
<data name="Menu5_Ledgers_ResultSheet" xml:space="preserve">
|
||||
<value>Result Sheet</value>
|
||||
<data name="Menu5_Ledgers_ProfitLossStatement" xml:space="preserve">
|
||||
<value>Profit & Loss Statement</value>
|
||||
</data>
|
||||
<data name="Menu5_Ledgers_SetBudgets" xml:space="preserve">
|
||||
<value>Set Budget Amounts</value>
|
||||
|
||||
@@ -255,7 +255,7 @@
|
||||
<data name="Menu5_Ledgers_Payroll" xml:space="preserve">
|
||||
<value>Lönelista</value>
|
||||
</data>
|
||||
<data name="Menu5_Ledgers_ResultSheet" xml:space="preserve">
|
||||
<data name="Menu5_Ledgers_ProfitLossStatement" xml:space="preserve">
|
||||
<value>Resulträkning</value>
|
||||
</data>
|
||||
<data name="Menu5_Ledgers_SetBudgets" xml:space="preserve">
|
||||
|
||||
@@ -117,10 +117,62 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="RequestCashAdvance_Amount" xml:space="preserve">
|
||||
<value>Advance amount (in {0})</value>
|
||||
<comment>{0} is the currency.</comment>
|
||||
</data>
|
||||
<data name="RequestCashAdvance_BankAccount" xml:space="preserve">
|
||||
<value>Account Number</value>
|
||||
</data>
|
||||
<data name="RequestCashAdvance_BankClearing" xml:space="preserve">
|
||||
<value>Clearing Number</value>
|
||||
</data>
|
||||
<data name="RequestCashAdvance_BankName" xml:space="preserve">
|
||||
<value>Bank Name</value>
|
||||
</data>
|
||||
<data name="RequestCashAdvance_Budget" xml:space="preserve">
|
||||
<value>Budget</value>
|
||||
</data>
|
||||
<data name="RequestCashAdvance_HeaderBankDetails" xml:space="preserve">
|
||||
<value>Your Bank Details</value>
|
||||
</data>
|
||||
<data name="RequestCashAdvance_Info" xml:space="preserve">
|
||||
<value>If you are about to make a purchase on behalf of the organization, but need the money in advance rather than claiming them back afterwards, you can request a cash advance for a specific purpose.</value>
|
||||
</data>
|
||||
<data name="RequestCashAdvance_PageTitle" xml:space="preserve">
|
||||
<value>Request Cash Advance</value>
|
||||
</data>
|
||||
<data name="RequestCashAdvance_Purpose" xml:space="preserve">
|
||||
<value>Purpose</value>
|
||||
</data>
|
||||
<data name="RequestCashAdvance_SuccessMessagePartOne" xml:space="preserve">
|
||||
<value>A cash advance has been requested for <strong>{0}</strong> for the purpose of {1}. The requested amount is {2} {3:N2}. Note that this is a <strong>loan</strong> 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">
|
||||
<value>This needs to be attested by the budget owner and will then proceed to payout.</value>
|
||||
</data>
|
||||
<data name="RequestCashAdvance_SuccessMessagePartTwoOwnBudget" xml:space="preserve">
|
||||
<value>As this is your own budget, this has been automatically attested and has proceeded to payout.</value>
|
||||
<comment>This is displayed if either the person creating the cash advance OR the person receiving it is the budget owner.</comment>
|
||||
</data>
|
||||
<data name="RequestCashAdvance_ValidationError_Amount" xml:space="preserve">
|
||||
<value>Please enter the amount of money (in {0}) that you'd like to advance.</value>
|
||||
<comment>{0} is the currency.</comment>
|
||||
</data>
|
||||
<data name="RequestCashAdvance_ValidationError_BankAccount" xml:space="preserve">
|
||||
<value>Please enter your bank account number.</value>
|
||||
</data>
|
||||
<data name="RequestCashAdvance_ValidationError_BankClearing" xml:space="preserve">
|
||||
<value>Please enter your bank's clearing number.</value>
|
||||
</data>
|
||||
<data name="RequestCashAdvance_ValidationError_BankName" xml:space="preserve">
|
||||
<value>Please enter your bank's name.</value>
|
||||
</data>
|
||||
<data name="RequestCashAdvance_ValidationError_Budget" xml:space="preserve">
|
||||
<value>Please select a budget to charge.</value>
|
||||
</data>
|
||||
<data name="RequestCashAdvance_ValidationError_Purpose" xml:space="preserve">
|
||||
<value>Please state the purpose of the cash advance.</value>
|
||||
</data>
|
||||
</root>
|
||||
@@ -117,6 +117,12 @@
|
||||
<resheader name="writer">
|
||||
<value>System.Resources.ResXResourceWriter, System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089</value>
|
||||
</resheader>
|
||||
<data name="ProfitLossStatement_Info" xml:space="preserve">
|
||||
<value>The P&L is an overview of income and expenditures, and are grouped by budgets or cost/income type. The sum of all income and expenditure is the yearly result. You may also want to look at the <a href="BalanceSheet.aspx">balance sheet</a> which is the overview of assets and debts.</value>
|
||||
</data>
|
||||
<data name="ProfitLossStatement_PageTitle" xml:space="preserve">
|
||||
<value>Profit & Loss Statement</value>
|
||||
</data>
|
||||
<data name="SetRootBudgets_BudgetOwnerHeader" xml:space="preserve">
|
||||
<value>Budget, Owner</value>
|
||||
<comment>Displayed above editables</comment>
|
||||
|
||||
@@ -66,6 +66,8 @@
|
||||
|
||||
$("a[rel*=leanModal]").leanModal();
|
||||
|
||||
<asp:Literal runat="server" ID="LiteralDocumentReadyHook" />
|
||||
|
||||
});
|
||||
|
||||
</script>
|
||||
@@ -178,7 +180,7 @@
|
||||
<telerik:RadMenuItem runat="server" Text="XYZ Ledgers" Permission="All" UserLevel="3" GlobalResourceKey="Menu5_Ledgers">
|
||||
<Items>
|
||||
<telerik:RadMenuItem runat="server" Text="XYZ Balance Sheet" Permission="All" UserLevel="3" ImageUrl="~/Images/PageIcons/iconshock-treasure-16px.png" GlobalResourceKey="Menu5_Ledgers_BalanceSheet" />
|
||||
<telerik:RadMenuItem runat="server" Text="XYZ Result Sheet" Permission="All" UserLevel="3" ImageUrl="~/Images/PageIcons/iconshock-abacus-16px.png" GlobalResourceKey="Menu5_Ledgers_ResultSheet" />
|
||||
<telerik:RadMenuItem runat="server" Text="XYZ P&L Statement" Permission="All" UserLevel="3" NavigateUrl="~/Pages/v5/Ledgers/ProfitLossStatement.aspx" ImageUrl="~/Images/PageIcons/iconshock-abacus-16px.png" GlobalResourceKey="Menu5_Ledgers_ProfitLossStatement" />
|
||||
<telerik:RadMenuItem runat="server" IsSeparator="true" UserLevel="3" />
|
||||
<telerik:RadMenuItem runat="server" Text="XYZ Audit Ledgers" ImageUrl="~/Images/PageIcons/iconshock-ledger-inspect-16px.png" Permission="EconomyDetail:Read" UserLevel="3" GlobalResourceKey="Menu5_Ledgers_AuditLedgers" />
|
||||
<telerik:RadMenuItem runat="server" Text="XYZ Account Plan" Permission="Economy:Read" UserLevel="3" GlobalResourceKey="Menu5_Ledgers_AccountPlan" />
|
||||
|
||||
@@ -96,6 +96,21 @@ namespace Activizr
|
||||
SetupDropboxes();
|
||||
|
||||
this.ButtonSwitchOrganizations.Attributes.Add("onclick", "$('#" + this.TextSwitchToOrganizationId.ClientID + "').val($('#" + this.DropSwitchOrganizations.ClientID + "').val()); $('#" + this.ButtonActuatorSwitchOrganizations.ClientID + "').click();");
|
||||
|
||||
// Check for message to display
|
||||
|
||||
HttpCookie dashMessage = Request.Cookies["DashboardMessage"];
|
||||
|
||||
if (dashMessage != null && dashMessage.Value.Length > 0)
|
||||
{
|
||||
this.LiteralDocumentReadyHook.Text = string.Format("alertify.alert(unescape('{0}'.replace(/\\+/g, '%20')));", dashMessage.Value);
|
||||
Response.SetCookie(new HttpCookie("DashboardMessage", string.Empty));
|
||||
Response.Cookies ["DashboardMessage"].Expires = DateTime.Now.AddYears(-10);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.LiteralDocumentReadyHook.Text = string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
private void SetupDropboxes()
|
||||
|
||||
@@ -2,7 +2,10 @@
|
||||
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
|
||||
<script src="https://hostedscripts.falkvinge.net/easyui/jquery.easyui.min.js" type="text/javascript"></script>
|
||||
<link rel="stylesheet" type="text/css" href="https://hostedscripts.falkvinge.net/easyui/themes/icon.css">
<link rel="stylesheet" type="text/css" href="https://hostedscripts.falkvinge.net/easyui/themes/default/tree.css"/>
<link rel="stylesheet" type="text/css" href="/Style/v5-easyui-elements.css">
<script type="text/javascript">
|
||||
<link rel="stylesheet" type="text/css" href="https://hostedscripts.falkvinge.net/easyui/themes/icon.css">
|
||||
<link rel="stylesheet" type="text/css" href="https://hostedscripts.falkvinge.net/easyui/themes/default/tree.css"/>
|
||||
<link rel="stylesheet" type="text/css" href="/Style/v5-easyui-elements.css">
|
||||
<script type="text/javascript">
|
||||
$(document).ready(function () {
|
||||
$('#DropBudgets').combotree({
|
||||
animate: true
|
||||
@@ -11,22 +14,27 @@
|
||||
$('input.combo-text').click(function () {
|
||||
$('span.combo-arrow').click();
|
||||
});
|
||||
|
||||
$('input.combo-text').focus(function () {
|
||||
$('span.combo-arrow').click();
|
||||
});
|
||||
|
||||
});
|
||||
|
||||
|
||||
function validateFields() {
|
||||
var isValid = true;
|
||||
|
||||
isValid = validateTextField('#<%=this.TextAccount.ClientID %>', "Please state your bank account number.") && isValid;
|
||||
isValid = validateTextField('#<%=this.TextClearing.ClientID %>', "Please enter your bank's clearing number.") && isValid;
|
||||
isValid = validateTextField('#<%=this.TextBank.ClientID %>', "Please enter your bank's name.") && isValid;
|
||||
isValid = validateTextField('#<%=this.TextAccount.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorBankAccount" />") && isValid;
|
||||
isValid = validateTextField('#<%=this.TextClearing.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorBankClearing" />") && isValid;
|
||||
isValid = validateTextField('#<%=this.TextBank.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorBankName" />") && isValid;
|
||||
|
||||
if ($('#DropBudgets').combotree('tree').tree('getSelected') == null) {
|
||||
isValid = false;
|
||||
alertify.error("Please select a budget.");
|
||||
alertify.error("<asp:Literal runat="server" ID="LiteralErrorBudget" />");
|
||||
}
|
||||
|
||||
isValid = validateTextField('#<%=this.TextPurpose.ClientID %>', "Please state the purpose of the cash advance.") && isValid;
|
||||
isValid = validateTextField('#<%=this.TextPurpose.ClientID %>', "<asp:Literal runat="server" ID="LiteralErrorPurpose" />") && isValid;
|
||||
|
||||
$.ajax({
|
||||
type: "POST",
|
||||
@@ -38,7 +46,7 @@
|
||||
success: function (msg) {
|
||||
if (msg.d != true) {
|
||||
isValid = false;
|
||||
alertify.error("Please enter the amount of money (in SEK) that you'd like to advance.");
|
||||
alertify.error("<asp:Literal runat="server" ID="LiteralErrorAmount" />");
|
||||
$('#<%=this.TextAmount.ClientID %>').focus();
|
||||
}
|
||||
}
|
||||
@@ -57,7 +65,8 @@
|
||||
return true;
|
||||
}
|
||||
|
||||
</script>
</asp:Content>
|
||||
</script>
|
||||
</asp:Content>
|
||||
|
||||
|
||||
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
|
||||
@@ -69,16 +78,16 @@
|
||||
<asp:TextBox runat="server" ID="TextBank" /> <br/>
|
||||
<asp:TextBox runat="server" ID="TextClearing" /> <br/>
|
||||
<asp:TextBox runat="server" ID="TextAccount" /> <br/>
|
||||
<asp:Button ID="ButtonRequest" runat="server" CssClass="buttonAccentColor" OnClientClick="return validateFields();" Text="Request"/>
|
||||
<asp:Button ID="ButtonRequest" runat="server" CssClass="buttonAccentColor" OnClientClick="return validateFields();" OnClick="ButtonRequest_Click" Text="Request"/>
|
||||
</div>
|
||||
<div class="entryLabels">
|
||||
Amount (SEK)<br/>
|
||||
Purpose<br/>
|
||||
Budget<br/>
|
||||
<h2>Your bank details</h2>
|
||||
Bank<br/>
|
||||
Clearing#<br/>
|
||||
Account#
|
||||
<asp:Label runat="server" ID="LabelAmount" /><br/>
|
||||
<asp:Label runat="server" ID="LabelPurpose" /><br/>
|
||||
<asp:Label runat="server" ID="LabelBudget" /><br/>
|
||||
<h2><asp:Label runat="server" ID="LabelHeaderBankDetails" /></h2>
|
||||
<asp:Label runat="server" ID="LabelBankName" /><br/>
|
||||
<asp:Label runat="server" ID="LabelBankClearing" /><br/>
|
||||
<asp:Label runat="server" ID="LabelBankAccount" />
|
||||
</div>
|
||||
<div style="clear:both"></div>
|
||||
</asp:Content>
|
||||
|
||||
@@ -24,6 +24,83 @@ public partial class Pages_v5_Finance_RequestCashAdvance : PageV5Base
|
||||
this.TextAccount.Text = this.CurrentUser.BankAccount;
|
||||
this.TextAmount.Text = 0.ToString("N2");
|
||||
this.TextAmount.Focus();
|
||||
|
||||
Localize();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private void Localize()
|
||||
{
|
||||
this.LabelAmount.Text = string.Format(Resources.Pages.Finance.RequestCashAdvance_Amount,
|
||||
CurrentOrganization.Currency.Code);
|
||||
this.LabelPurpose.Text = Resources.Pages.Finance.RequestCashAdvance_Purpose;
|
||||
this.LabelBudget.Text = Resources.Pages.Finance.RequestCashAdvance_Budget;
|
||||
this.LabelHeaderBankDetails.Text = Resources.Pages.Finance.RequestCashAdvance_HeaderBankDetails;
|
||||
this.LabelBankName.Text = Resources.Pages.Finance.RequestCashAdvance_BankName;
|
||||
this.LabelBankClearing.Text = Resources.Pages.Finance.RequestCashAdvance_BankClearing;
|
||||
this.LabelBankAccount.Text = Resources.Pages.Finance.RequestCashAdvance_BankAccount;
|
||||
|
||||
this.LiteralErrorAmount.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_Amount;
|
||||
this.LiteralErrorPurpose.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_Purpose;
|
||||
this.LiteralErrorBudget.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_Budget;
|
||||
this.LiteralErrorBankName.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_BankName;
|
||||
this.LiteralErrorBankClearing.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_BankClearing;
|
||||
this.LiteralErrorBankAccount.Text = Resources.Pages.Finance.RequestCashAdvance_ValidationError_BankAccount;
|
||||
}
|
||||
|
||||
|
||||
protected void ButtonRequest_Click(object sender, EventArgs e)
|
||||
{
|
||||
// The data has been validated client-side already. We'll throw unfriendly exceptions if invalid data is passed here.
|
||||
|
||||
double amount = Double.Parse(this.TextAmount.Text, NumberStyles.Number); // parses in current culture - intentional
|
||||
Int64 amountCents = (Int64) amount*100;
|
||||
|
||||
string description = this.TextPurpose.Text;
|
||||
|
||||
FinancialAccount budget = FinancialAccount.FromIdentity(Int32.Parse(this.Request.Form["DropBudgets"]));
|
||||
|
||||
// sanity check
|
||||
|
||||
if (budget.Organization.Identity != CurrentOrganization.Identity)
|
||||
{
|
||||
throw new InvalidOperationException("Budget-organization mismatch; won't file cash advance");
|
||||
}
|
||||
|
||||
// Store bank details for current user
|
||||
|
||||
CurrentUser.BankName = this.TextBank.Text;
|
||||
CurrentUser.BankClearing = this.TextClearing.Text;
|
||||
CurrentUser.BankAccount = this.TextAccount.Text;
|
||||
|
||||
// Create cash advance
|
||||
|
||||
CashAdvance cashAdvance = CashAdvance.Create(CurrentOrganization, CurrentUser, CurrentUser, amountCents, budget,
|
||||
description);
|
||||
|
||||
// Create success message
|
||||
|
||||
string successMessage = string.Format(Resources.Pages.Finance.RequestCashAdvance_SuccessMessagePartOne,
|
||||
HttpUtility.HtmlEncode(CurrentUser.Name),
|
||||
HttpUtility.HtmlEncode(description), CurrentOrganization.Currency.Code,
|
||||
(double) (amountCents/100.0));
|
||||
|
||||
if (budget.OwnerPersonId != CurrentUser.Identity)
|
||||
{
|
||||
successMessage += "<br/><br/>" + Resources.Pages.Finance.RequestCashAdvance_SuccessMessagePartTwo + "<br/>";
|
||||
}
|
||||
else
|
||||
{
|
||||
successMessage += "<br/><br/>" + Resources.Pages.Finance.RequestCashAdvance_SuccessMessagePartTwoOwnBudget +
|
||||
"<br/>";
|
||||
// TODO: Auto-attest
|
||||
}
|
||||
|
||||
Response.AppendCookie(new HttpCookie("DashboardMessage", HttpUtility.UrlEncode(successMessage)));
|
||||
|
||||
// Redirect to dashboard
|
||||
|
||||
Response.Redirect("/", true);
|
||||
}
|
||||
}
|
||||
@@ -527,7 +527,7 @@ public partial class Pages_v5_Init_Default : System.Web.UI.Page
|
||||
|
||||
Activizr.Logic.Structure.Organization.Create(0, "Sandbox", "Sandbox", "Sandbox", "activizr.com", "Act",
|
||||
rootGeographyId, true,
|
||||
true, 0).EnableEconomy();
|
||||
true, 0).EnableEconomy(Activizr.Logic.Financial.Currency.FromCode("EUR"));
|
||||
|
||||
_initProgress = 100;
|
||||
_initMessage = "Complete.";
|
||||
|
||||
@@ -0,0 +1 @@
|
||||
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Json-ProfitLossData.aspx.cs" Inherits="Pages_v5_Ledgers_Json_ProfitLossData" %>
|
||||
@@ -0,0 +1,285 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
using Activizr.Basic.Enums;
|
||||
using Activizr.Logic.Financial;
|
||||
using Activizr.Logic.Pirates;
|
||||
using Activizr.Logic.Security;
|
||||
using Activizr.Logic.Structure;
|
||||
|
||||
public partial class Pages_v5_Ledgers_Json_ProfitLossData : System.Web.UI.Page
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
// Current authentication
|
||||
|
||||
string identity = HttpContext.Current.User.Identity.Name;
|
||||
string[] identityTokens = identity.Split(',');
|
||||
|
||||
string userIdentityString = identityTokens[0];
|
||||
string organizationIdentityString = identityTokens[1];
|
||||
|
||||
int currentUserId = Convert.ToInt32(userIdentityString);
|
||||
int currentOrganizationId = Convert.ToInt32(organizationIdentityString);
|
||||
|
||||
Person currentUser = Person.FromIdentity(currentUserId);
|
||||
Authority authority = currentUser.GetAuthority();
|
||||
Organization currentOrganization = Organization.FromIdentity(currentOrganizationId);
|
||||
|
||||
// Get accounts
|
||||
|
||||
FinancialAccounts accounts = FinancialAccounts.ForOrganization(currentOrganization, FinancialAccountType.Result);
|
||||
|
||||
// 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);
|
||||
}
|
||||
|
||||
|
||||
FinancialAccounts orderedList = new FinancialAccounts(); // This list is guaranteed to have parents before children
|
||||
|
||||
PopulateOrderedList(treeMap, orderedList, 0); // recursively add nodes parents-first
|
||||
PopulateLookups(orderedList); // populate the lookup tables for results per account
|
||||
|
||||
Response.ContentType = "application/json";
|
||||
|
||||
int renderRootNodeId = 0;
|
||||
|
||||
if (treeMap[0].Count == 1)
|
||||
{
|
||||
// assume there's a master root like "Costs"; bypass it
|
||||
|
||||
renderRootNodeId = treeMap[0][0].Identity;
|
||||
}
|
||||
|
||||
Response.Output.WriteLine(RecurseTreeMap(treeMap, renderRootNodeId));
|
||||
|
||||
Response.End();
|
||||
}
|
||||
|
||||
|
||||
private string RecurseTreeMap (Dictionary<int, List<FinancialAccount>> treeMap, int renderNodeId)
|
||||
{
|
||||
List<string> elements = new List<string>();
|
||||
|
||||
foreach (FinancialAccount account in treeMap[renderNodeId])
|
||||
{
|
||||
string element = string.Format("\"id\":{0},\"name\":\"{1}\"", account.Identity,
|
||||
account.Name.Replace("\"", "'"));
|
||||
|
||||
element += string.Format(",\"lastYear\":\"{0:N2} ({1:N2})\"", singleLookups[0][account.Identity],
|
||||
treeLookups[0][account.Identity]);
|
||||
|
||||
element += string.Format(",\"ytd\":\"{0:N2} ({1:N2})\"", singleLookups[5][account.Identity],
|
||||
treeLookups[5][account.Identity]);
|
||||
|
||||
if (treeMap.ContainsKey(account.Identity))
|
||||
{
|
||||
element += ",\"state\":\"closed\",\"children\":" + RecurseTreeMap(treeMap, account.Identity);
|
||||
}
|
||||
|
||||
elements.Add("{" + element + "}");
|
||||
}
|
||||
|
||||
return "[" + String.Join(",", elements.ToArray()) + "]";
|
||||
}
|
||||
|
||||
|
||||
private void PopulateOrderedList (Dictionary<int, List<FinancialAccount>> treeMap, FinancialAccounts orderedList, int renderNodeId)
|
||||
{
|
||||
foreach (FinancialAccount account in treeMap[renderNodeId])
|
||||
{
|
||||
orderedList.Add(account);
|
||||
|
||||
if (treeMap.ContainsKey(account.Identity))
|
||||
{
|
||||
PopulateOrderedList(treeMap, orderedList, account.Identity); // recursive call
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
private int _year = 2012;
|
||||
private Dictionary<int, Int64>[] singleLookups;
|
||||
private Dictionary<int, Int64>[] treeLookups;
|
||||
|
||||
|
||||
private void PopulateLookups(FinancialAccounts accounts)
|
||||
{
|
||||
singleLookups = new Dictionary<int, Int64>[6];
|
||||
treeLookups = new Dictionary<int, Int64>[6];
|
||||
|
||||
for (int index = 0; index < 6; index++)
|
||||
{
|
||||
treeLookups[index] = new Dictionary<int, Int64>();
|
||||
singleLookups[index] = new Dictionary<int, Int64>();
|
||||
}
|
||||
|
||||
DateTime[] quarterBoundaries =
|
||||
{
|
||||
new DateTime(_year, 1, 1), new DateTime(_year, 3, 1), new DateTime(_year, 6, 1),
|
||||
new DateTime(_year, 9, 1), new DateTime(_year + 1, 1, 1)
|
||||
};
|
||||
|
||||
// 1) Actually, the accounts are already sorted. Or are supposed to be, anyway,
|
||||
// since FinancialAccounts.ForOrganization gets the _tree_ rather than the flat list.
|
||||
|
||||
// 2) Add all values to the accounts.
|
||||
|
||||
foreach (FinancialAccount account in accounts)
|
||||
{
|
||||
// Find this year's inbound
|
||||
|
||||
singleLookups[0][account.Identity] = account.GetDeltaCents(new DateTime(_year - 1, 1, 1), new DateTime(_year, 1, 1));
|
||||
|
||||
// Find quarter diffs
|
||||
|
||||
for (int quarter = 0; quarter < 4; quarter++)
|
||||
{
|
||||
singleLookups[quarter + 1][account.Identity] = account.GetDeltaCents(quarterBoundaries[quarter],
|
||||
quarterBoundaries[quarter + 1]);
|
||||
}
|
||||
|
||||
// Find outbound
|
||||
|
||||
singleLookups[5][account.Identity] = account.GetDeltaCents(new DateTime(_year, 1, 1), new DateTime(_year + 1, 1, 1));
|
||||
|
||||
// copy to treeLookups
|
||||
|
||||
for (int index = 0; index < 6; index++)
|
||||
{
|
||||
treeLookups[index][account.Identity] = singleLookups[index][account.Identity];
|
||||
}
|
||||
}
|
||||
|
||||
// 3) Add all children's values to parents
|
||||
|
||||
for (int index = 0; index < 6; index++)
|
||||
{
|
||||
AddChildrenValuesToParents(treeLookups[index], accounts);
|
||||
}
|
||||
|
||||
// Done.
|
||||
}
|
||||
|
||||
|
||||
private void AddChildrenValuesToParents(Dictionary<int, Int64> lookup, FinancialAccounts accounts)
|
||||
{
|
||||
// Iterate backwards and add any value to its parent's value, as they are sorted in tree order.
|
||||
|
||||
for (int index = accounts.Count - 1; index >= 0; index--)
|
||||
{
|
||||
int parentFinancialAccountId = accounts[index].ParentFinancialAccountId;
|
||||
int accountId = accounts[index].Identity;
|
||||
|
||||
if (parentFinancialAccountId != 0)
|
||||
{
|
||||
lookup[parentFinancialAccountId] += lookup[accountId];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
/*
|
||||
protected void GridBudgetAccounts_ItemCreated(object sender, GridItemEventArgs e)
|
||||
{
|
||||
// CreateExpandCollapseButton(e.Item, "Name");
|
||||
|
||||
if (e.Item is GridHeaderItem && e.Item.OwnerTableView != this.GridBudgetAccounts.MasterTableView)
|
||||
{
|
||||
e.Item.Style["display"] = "none";
|
||||
}
|
||||
|
||||
if (e.Item is GridNestedViewItem)
|
||||
{
|
||||
e.Item.Cells[0].Visible = false;
|
||||
}
|
||||
|
||||
if (e.Item is GridDataItem)
|
||||
{
|
||||
int year = DateTime.Today.Year;
|
||||
|
||||
FinancialAccount account = (FinancialAccount) e.Item.DataItem;
|
||||
|
||||
if (account == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
HyperLink editLink = (HyperLink) e.Item.FindControl("ManageLink");
|
||||
editLink.Attributes["href"] = "#";
|
||||
editLink.Attributes["onclick"] = String.Format("return ShowAccountForm('{0}','{1}');",
|
||||
account.FinancialAccountId, e.Item.ItemIndex);
|
||||
|
||||
PopulateLine(e.Item);
|
||||
}
|
||||
}
|
||||
|
||||
protected void PopulateLine(GridItem item)
|
||||
{
|
||||
FinancialAccount account = (FinancialAccount) item.DataItem;
|
||||
|
||||
if (account == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
Label labelAccountName = (Label) item.FindControl("LabelAccountName");
|
||||
Literal literalLastYear = (Literal) item.FindControl("LiteralLastYear");
|
||||
Literal literalQ1 = (Literal) item.FindControl("LiteralQuarter1");
|
||||
Literal literalQ2 = (Literal) item.FindControl("LiteralQuarter2");
|
||||
Literal literalQ3 = (Literal) item.FindControl("LiteralQuarter3");
|
||||
Literal literalQ4 = (Literal) item.FindControl("LiteralQuarter4");
|
||||
Literal literalYtd = (Literal) item.FindControl("LiteralThisYear");
|
||||
|
||||
PopulateDualFigure(literalLastYear, "LastYear", 0, account.Identity);
|
||||
PopulateDualFigure(literalQ1, "Q1", 1, account.Identity);
|
||||
PopulateDualFigure(literalQ2, "Q2", 2, account.Identity);
|
||||
PopulateDualFigure(literalQ3, "Q3", 3, account.Identity);
|
||||
PopulateDualFigure(literalQ4, "Q4", 4, account.Identity);
|
||||
PopulateDualFigure(literalYtd, "Ytd", 5, account.Identity);
|
||||
labelAccountName.Text = account.Name;
|
||||
}
|
||||
*/
|
||||
private void PopulateDualFigure(Literal literal, string spanPrefix, int category, int accountId)
|
||||
{
|
||||
Int64 treeValue = treeLookups[category][accountId];
|
||||
Int64 singleValue = singleLookups[category][accountId];
|
||||
|
||||
string span =
|
||||
string.Format(
|
||||
"<span ID=\"GridSpanExpanded{1}{0}\" style=\"display:none\">{2:N0}</span><span ID=\"GridSpanCollapsed{1}{0}\">{4}{3:N0}</span>",
|
||||
accountId, spanPrefix, singleValue, treeValue,
|
||||
singleValue != treeValue ? "<b>Σ</b> " : string.Empty);
|
||||
literal.Text = span;
|
||||
}
|
||||
|
||||
private void PopulateFigureCollapsed(Label label, int category, int accountId)
|
||||
{
|
||||
string prefix = string.Empty;
|
||||
|
||||
Int64 treeValue = treeLookups[category][accountId];
|
||||
Int64 singleValue = singleLookups[category][accountId];
|
||||
|
||||
if (treeValue != singleValue)
|
||||
{
|
||||
prefix = "Σ ";
|
||||
}
|
||||
|
||||
label.Text = prefix + treeValue.ToString("N0");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
<%@ Page Title="" Language="C#" MasterPageFile="~/Master-v5.master" AutoEventWireup="true" CodeFile="ProfitLossStatement.aspx.cs" Inherits="Pages_v5_Ledgers_ProfitLossStatement" %>
|
||||
|
||||
<asp:Content ID="Content1" ContentPlaceHolderID="PlaceHolderHead" Runat="Server">
|
||||
<script src="https://hostedscripts.falkvinge.net/easyui/jquery.easyui.min.js" type="text/javascript"></script>
|
||||
<link rel="stylesheet" type="text/css" href="https://hostedscripts.falkvinge.net/easyui/themes/icon.css">
|
||||
<link rel="stylesheet" type="text/css" href="https://hostedscripts.falkvinge.net/easyui/themes/default/tree.css"/>
|
||||
<link rel="stylesheet" type="text/css" href="https://hostedscripts.falkvinge.net/easyui/themes/default/datagrid.css"/>
|
||||
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content2" ContentPlaceHolderID="PlaceHolderMain" Runat="Server">
|
||||
<div style="float:right"><asp:DropDownList runat="server" ID="DropYears"/></div>
|
||||
<h2>P&L for Piratpartiet For Year</h2>
|
||||
<table id="test" title="" class="easyui-treegrid" style="width:680px;height:600px"
|
||||
url="Json-ProfitLossData.aspx"
|
||||
rownumbers="false"
|
||||
animate="true"
|
||||
idField="id" treeField="name">
|
||||
<thead>
|
||||
<tr>
|
||||
<th field="name" width="195">Account</th>
|
||||
<th field="lastYear" width="80" align="right">Last Year</th>
|
||||
<th field="q1" width="80" align="right">Q1</th>
|
||||
<th field="q2" width="80" align="right">Q2</th>
|
||||
<th field="q3" width="80" align="right">Q3</th>
|
||||
<th field="q4" width="80" align="right">Q4</th>
|
||||
<th field="ytd" width="80" align="right">YTD</th>
|
||||
</tr>
|
||||
</thead>
|
||||
</table>
|
||||
<div style="clear:both"></div>
|
||||
|
||||
</asp:Content>
|
||||
<asp:Content ID="Content3" ContentPlaceHolderID="PlaceHolderSide" Runat="Server">
|
||||
</asp:Content>
|
||||
|
||||
@@ -0,0 +1,16 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
using System.Web;
|
||||
using System.Web.UI;
|
||||
using System.Web.UI.WebControls;
|
||||
|
||||
public partial class Pages_v5_Ledgers_ProfitLossStatement : PageV5Base
|
||||
{
|
||||
protected void Page_Load(object sender, EventArgs e)
|
||||
{
|
||||
this.PageIcon = "iconshock-abacus";
|
||||
this.PageTitle = Resources.Pages.Ledgers.ProfitLossStatement_PageTitle;
|
||||
this.InfoBoxLiteral = Resources.Pages.Ledgers.ProfitLossStatement_Info;
|
||||
}
|
||||
}
|
||||
@@ -511,7 +511,7 @@ span.loginalphabetasign
|
||||
margin-top: 5px;
|
||||
margin-bottom: 5px;
|
||||
font-size: 24px;
|
||||
width: 335px;
|
||||
width: 330px;
|
||||
|
||||
-webkit-box-shadow: 0 1px 3px 1px #1C397E;
|
||||
-moz-box-shadow: 0 1px 3px 1px #1C397E;
|
||||
@@ -521,8 +521,8 @@ span.loginalphabetasign
|
||||
|
||||
.entryFields input, .entryFields textarea, .entryFields select
|
||||
{
|
||||
border-radius: 15px;
|
||||
padding: 0px 10px 0px 15px;
|
||||
border-radius: 10px;
|
||||
padding: 0px 10px 0px 10px;
|
||||
font-size: 24px;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user