Added OrgSeqId to CAs, Expenses
This commit is contained in:
@@ -6,8 +6,9 @@ namespace Swarmops.Basic.Types.Financial
|
||||
[Serializable]
|
||||
public class BasicCashAdvance : IHasIdentity
|
||||
{
|
||||
public BasicCashAdvance (int cashAdvanceId, int organizationId, int personId, DateTime createdDateTime,
|
||||
int createdByPersonId,
|
||||
public
|
||||
BasicCashAdvance (int cashAdvanceId, int organizationId, int organizationSequenceId,
|
||||
int personId, DateTime createdDateTime, int createdByPersonId,
|
||||
int financialAccountId, Int64 amountCents, string description, bool open, bool attested,
|
||||
bool paidOut, int attestedByPersonId, DateTime attestedDateTime)
|
||||
{
|
||||
@@ -28,8 +29,8 @@ namespace Swarmops.Basic.Types.Financial
|
||||
|
||||
public BasicCashAdvance (BasicCashAdvance original) :
|
||||
this (
|
||||
original.CashAdvanceId, original.OrganizationId, original.PersonId, original.CreatedDateTime,
|
||||
original.CreatedByPersonId,
|
||||
original.CashAdvanceId, original.OrganizationId, original.OrganizationSequenceId,
|
||||
original.PersonId, original.CreatedDateTime, original.CreatedByPersonId,
|
||||
original.BudgetId, original.AmountCents, original.Description, original.Open, original.Attested,
|
||||
original.PaidOut, original.AttestedByPersonId, original.AttestedDateTime)
|
||||
{
|
||||
@@ -44,6 +45,7 @@ namespace Swarmops.Basic.Types.Financial
|
||||
|
||||
public int CashAdvanceId { get; private set; }
|
||||
public int OrganizationId { get; private set; }
|
||||
public int OrganizationSequenceId { get; protected set; }
|
||||
public int PersonId { get; protected set; }
|
||||
public DateTime CreatedDateTime { get; protected set; }
|
||||
public int CreatedByPersonId { get; protected set; }
|
||||
|
||||
@@ -5,15 +5,12 @@ namespace Swarmops.Basic.Types.Financial
|
||||
{
|
||||
public class BasicExpenseClaim : IHasIdentity
|
||||
{
|
||||
public readonly int GeographyId;
|
||||
public readonly int OrganizationId;
|
||||
|
||||
/// <summary>
|
||||
/// Normal constructor
|
||||
/// </summary>
|
||||
public BasicExpenseClaim (int expenseClaimId, int claimingPersonId, DateTime createdDateTime,
|
||||
bool open, bool attested, bool documented, bool claimed, int organizationId,
|
||||
int geographyId, int budgetId, DateTime expenseDate,
|
||||
int organizationSequenceId, int geographyId, int budgetId, DateTime expenseDate,
|
||||
string description, double preApprovedAmount, Int64 amountCents, Int64 vatCents, bool repaid, bool keepSeparate)
|
||||
{
|
||||
this.ExpenseClaimId = expenseClaimId;
|
||||
@@ -41,13 +38,17 @@ namespace Swarmops.Basic.Types.Financial
|
||||
public BasicExpenseClaim (BasicExpenseClaim original)
|
||||
: this (original.Identity, original.ClaimingPersonId, original.CreatedDateTime,
|
||||
original.Open, original.Attested, original.Validated, original.Claimed,
|
||||
original.OrganizationId, original.GeographyId, original.BudgetId,
|
||||
original.ExpenseDate, original.Description,
|
||||
original.OrganizationId, original.OrganizationId,
|
||||
original.GeographyId, original.BudgetId, original.ExpenseDate, original.Description,
|
||||
original.PreApprovedAmount, original.AmountCents, original.VatCents, original.Repaid, original.KeepSeparate)
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
public int GeographyId { get; private set; }
|
||||
|
||||
public int OrganizationId { get; private set; }
|
||||
public int OrganizationSequenceId { get; protected set; }
|
||||
public int ExpenseClaimId { get; private set; }
|
||||
public DateTime ExpenseDate { get; protected set; }
|
||||
public string Description { get; protected set; }
|
||||
|
||||
@@ -12,7 +12,7 @@ namespace Swarmops.Database
|
||||
/// <summary>
|
||||
/// This is the IN-CODE revision of the database. The version we expect to be running against.
|
||||
/// </summary>
|
||||
public static int DbVersionExpected => 65;
|
||||
public static int DbVersionExpected => 66;
|
||||
|
||||
|
||||
// This class is in horrible need of serious refactoring. For its simplicity in task, it's a horrible bowl of spaghetti.
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Swarmops.Database
|
||||
private const string cashAdvanceFieldSequence =
|
||||
" CashAdvanceId,OrganizationId,PersonId,CreatedDateTime,CreatedByPersonId," + // 0-4
|
||||
"FinancialAccountId,AmountCents,Description,Open,Attested," + // 5-9
|
||||
"PaidOut,AttestedByPersonId,AttestedDateTime " + // 10-12
|
||||
"PaidOut,AttestedByPersonId,AttestedDateTime,OrganizationSequenceId " + // 10-13
|
||||
"FROM CashAdvances ";
|
||||
|
||||
private static BasicCashAdvance ReadCashAdvanceFromDataReader (IDataRecord reader)
|
||||
@@ -34,8 +34,9 @@ namespace Swarmops.Database
|
||||
bool paidOut = reader.GetBoolean (10);
|
||||
int attestedByPersonId = reader.GetInt32 (11);
|
||||
DateTime attestedDateTime = reader.GetDateTime (12);
|
||||
int organizationSequenceId = reader.GetInt32(13);
|
||||
|
||||
return new BasicCashAdvance (cashAdvanceId, organizationId, personId, createdDateTime, createdByPersonId,
|
||||
return new BasicCashAdvance (cashAdvanceId, organizationId, organizationSequenceId, personId, createdDateTime, createdByPersonId,
|
||||
financialAccountId, amountCents, description, open, attested,
|
||||
paidOut, attestedByPersonId, attestedDateTime);
|
||||
}
|
||||
@@ -142,6 +143,22 @@ namespace Swarmops.Database
|
||||
}
|
||||
|
||||
|
||||
public int SetCashAdvanceSequence(int cashAdvanceId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetCashAdvanceOrganizationSequenceId", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "cashAdvanceId", cashAdvanceId);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void SetCashAdvanceAmountCents(int cashAdvanceId, Int64 amountCents)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
|
||||
@@ -14,7 +14,7 @@ namespace Swarmops.Database
|
||||
" ExpenseClaimId,ClaimingPersonId,CreatedDateTime,Open,Attested," +
|
||||
" Validated,Claimed,OrganizationId,GeographyId,BudgetId," +
|
||||
" ExpenseDate,Description,PreApprovedAmount,AmountCents,Repaid,KeepSeparate, " +
|
||||
" VatCents " +
|
||||
" VatCents, OrganizaionSequenceId " +
|
||||
" FROM ExpenseClaims";
|
||||
|
||||
public BasicExpenseClaim GetExpenseClaim (int expenseClaimId)
|
||||
@@ -180,35 +180,15 @@ namespace Swarmops.Database
|
||||
bool repaid = reader.GetBoolean (14);
|
||||
bool keepSeparate = reader.GetBoolean (15);
|
||||
Int64 vatCents = reader.GetInt64(16);
|
||||
int organizationSequenceId = reader.GetInt32(17);
|
||||
|
||||
return new BasicExpenseClaim (expenseClaimId, claimingPersonId, createdDateTime,
|
||||
open, attested, documented, claimed, organizationId, geographyId,
|
||||
open, attested, documented, claimed, organizationId, organizationSequenceId, geographyId,
|
||||
budgetId, expenseDate, description, preApprovedAmount,
|
||||
amountCents, vatCents, repaid, keepSeparate);
|
||||
}
|
||||
|
||||
|
||||
public int CreateExpenseClaim (int claimingPersonId, int organizationId, int budgetId,
|
||||
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, "expenseDate", expenseDate);
|
||||
AddParameterWithName (command, "description", description);
|
||||
AddParameterWithName (command, "amount", amount);
|
||||
|
||||
return Convert.ToInt32 (command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
public int CreateExpenseClaim (int claimingPersonId, int organizationId, int budgetId,
|
||||
DateTime expenseDate, string description, Int64 amountCents)
|
||||
{
|
||||
@@ -216,7 +196,7 @@ namespace Swarmops.Database
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand ("CreateExpenseClaimPrecise", connection);
|
||||
DbCommand command = GetDbCommand ("CreateExpenseClaim", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName (command, "claimingPersonId", claimingPersonId);
|
||||
@@ -265,6 +245,23 @@ namespace Swarmops.Database
|
||||
}
|
||||
|
||||
|
||||
|
||||
public int SetExpenseClaimSequence(int expenseClaimId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command = GetDbCommand("SetExpenseClaimOrganizationSequenceId", connection);
|
||||
command.CommandType = CommandType.StoredProcedure;
|
||||
|
||||
AddParameterWithName(command, "expenseClaimId", expenseClaimId);
|
||||
|
||||
return Convert.ToInt32(command.ExecuteScalar());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public int SetExpenseClaimBudget (int expenseClaimId, int budgetId)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
|
||||
@@ -63,3 +63,4 @@
|
||||
0063 - Added DeriveUnique to HotBitcoinAddresses for ability to create unique HBAs [RF]
|
||||
0064 - Quick fix for OutboundInvoices (how did this error happen?) [RF]
|
||||
0065 - Dumb fix for 0062 (or rather, the error was dumb) [RF]
|
||||
0066 - Added OrganizationSequenceId to CashAdvances, ExpenseClaims
|
||||
|
||||
@@ -0,0 +1,186 @@
|
||||
ALTER TABLE `ExpenseClaims`
|
||||
CHANGE COLUMN `ExpenseClaimId` `ExpenseClaimId` INT(11) UNSIGNED NOT NULL ,
|
||||
CHANGE COLUMN `ClaimingPersonId` `ClaimingPersonId` INT(11) UNSIGNED NOT NULL ,
|
||||
CHANGE COLUMN `LastExpenseEventTypeId` `LastExpenseEventTypeId` INT(11) UNSIGNED NOT NULL DEFAULT '0' COMMENT 'Legacy, ignore' ,
|
||||
ADD COLUMN `OrganizationSequenceId` INT NOT NULL DEFAULT 0 AFTER `OrganizationId`,
|
||||
DROP COLUMN `Amount`,
|
||||
ADD INDEX `Index_OrgSequenceId` (`OrganizationSequenceId` ASC)
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
ALTER TABLE `CashAdvances`
|
||||
ADD COLUMN `OrganizationSequenceId` INT NOT NULL DEFAULT 0 AFTER `OrganizationId`,
|
||||
ADD INDEX `IdxOrgSequenceId` (`OrganizationSequenceId` ASC)
|
||||
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
DROP PROCEDURE IF EXISTS `CreateExpenseClaim`
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
DROP PROCEDURE IF EXISTS `CreateExpenseClaimPrecise`
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
DROP PROCEDURE IF EXISTS `CreateCashAdvance`
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
DROP PROCEDURE IF EXISTS `SetExpenseClaimOrganizationSequenceId`
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
DROP PROCEDURE IF EXISTS `SetCashAdvanceOrganizationSequenceId`
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
|
||||
CREATE PROCEDURE `CreateExpenseClaim`(
|
||||
IN claimingPersonId INTEGER,
|
||||
IN createdDateTime DATETIME,
|
||||
IN organizationId INTEGER,
|
||||
IN budgetId INTEGER,
|
||||
IN expenseDate DATETIME,
|
||||
IN description VARCHAR(256),
|
||||
IN amountCents BIGINT
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE newIdentity INTEGER;
|
||||
DECLARE sequenceNumber INTEGER;
|
||||
|
||||
INSERT INTO ExpenseClaims (ClaimingPersonId,CreatedDateTime,Open,Attested,Validated,
|
||||
Claimed,OrganizationId,GeographyId,BudgetId,ExpenseDate,Description,
|
||||
PreApprovedAmount,AmountCents)
|
||||
|
||||
VALUES (claimingPersonId, createdDateTime,1,0,0,1,organizationId,0,budgetId,
|
||||
expenseDate,description,0.0,amountCents);
|
||||
|
||||
SELECT LAST_INSERT_ID() INTO newIdentity;
|
||||
|
||||
SELECT COUNT(*) FROM ExpenseClaims WHERE
|
||||
ExpenseClaims.OrganizationId = organizationId AND
|
||||
ExpenseClaims.expenseClaimId <= newIdentity INTO sequenceNumber;
|
||||
|
||||
UPDATE ExpenseClaims
|
||||
SET ExpenseClaims.OrganizationSequenceId = sequenceNumber
|
||||
WHERE ExpenseClaims.expenseClaimId = newIdentity;
|
||||
|
||||
SELECT newIdentity AS Identity;
|
||||
|
||||
END
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
CREATE PROCEDURE `CreateCashAdvance`(
|
||||
personId INT,
|
||||
createdDateTime DATETIME,
|
||||
createdByPersonId INT,
|
||||
organizationId INT,
|
||||
amountCents BIGINT,
|
||||
financialAccountId INT,
|
||||
description VARCHAR(128)
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE newIdentity INTEGER;
|
||||
DECLARE sequenceNumber INTEGER;
|
||||
|
||||
INSERT INTO CashAdvances(
|
||||
PersonId,CreatedByPersonId,CreatedDateTime,OrganizationId,FinancialAccountId,
|
||||
AmountCents,Description,Open,Attested,AttestedByPersonId,
|
||||
AttestedDateTime,PaidOut)
|
||||
VALUES (
|
||||
personId,createdByPersonId,createdDateTime,organizationid,financialAccountId,
|
||||
amountCents,description,1,0,0,'1970-01-01',0);
|
||||
|
||||
SELECT LAST_INSERT_ID() INTO newIdentity;
|
||||
|
||||
SELECT COUNT(*) FROM CashAdvances WHERE
|
||||
CashAdvances.OrganizationId = organizationId AND
|
||||
CashAdvances.cashAdvanceId <= newIdentity INTO sequenceNumber;
|
||||
|
||||
UPDATE CashAdvances
|
||||
SET CashAdvances.OrganizationSequenceId = sequenceNumber
|
||||
WHERE CashAdvances.cashAdvanceId = newIdentity;
|
||||
|
||||
SELECT newIdentity AS Identity;
|
||||
|
||||
END
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
CREATE PROCEDURE `SetExpenseClaimOrganizationSequenceId`(
|
||||
IN expenseClaimId INTEGER
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE organizationId INTEGER;
|
||||
DECLARE sequenceNumber INTEGER;
|
||||
|
||||
SELECT ExpenseClaims.OrganizationId
|
||||
FROM ExpenseClaims
|
||||
WHERE ExpenseClaims.ExpenseClaimId = expenseClaimId
|
||||
INTO organizationId;
|
||||
|
||||
SELECT COUNT(*)
|
||||
FROM OutboundInvoices
|
||||
WHERE OutboundInvoices.OrganizationId=organizationId
|
||||
AND OutboundInvoices.OutboundInvoiceId <= outboundInvoiceId
|
||||
INTO sequenceNumber;
|
||||
|
||||
UPDATE OutboundInvoices SET OrganizationSequenceId = sequenceNumber
|
||||
WHERE OutboundInvoices.OutboundInvoiceId = outboundInvoiceId;
|
||||
|
||||
SELECT sequenceNumber AS OrganizationSequenceId;
|
||||
|
||||
END
|
||||
|
||||
|
||||
#
|
||||
|
||||
|
||||
CREATE PROCEDURE `SetCashAdvanceOrganizationSequenceId`(
|
||||
IN cashAdvanceId INTEGER
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE organizationId INTEGER;
|
||||
DECLARE sequenceNumber INTEGER;
|
||||
|
||||
SELECT CashAdvances.OrganizationId
|
||||
FROM CashAdvances
|
||||
WHERE CashAdvances.CashAdvanceId = cashAdvanceId
|
||||
INTO organizationId;
|
||||
|
||||
SELECT COUNT(*)
|
||||
FROM CashAdvances
|
||||
WHERE CashAdvances.OrganizationId=organizationId
|
||||
AND CashAdvances.CashAdvanceId <= cashAdvanceId
|
||||
INTO sequenceNumber;
|
||||
|
||||
UPDATE CashAdvances SET OrganizationSequenceId = sequenceNumber
|
||||
WHERE CashAdvances.CashAdvanceId = cashAdvanceId;
|
||||
|
||||
SELECT sequenceNumber AS OrganizationSequenceId;
|
||||
|
||||
END
|
||||
@@ -96,6 +96,26 @@ namespace Swarmops.Logic.Financial
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
public new int OrganizationSequenceId
|
||||
{
|
||||
get
|
||||
{
|
||||
if (base.OrganizationSequenceId == 0)
|
||||
{
|
||||
// This case is for legacy installations before DbVersion 66, when
|
||||
// OrganizationSequenceId was added for each new cash advance
|
||||
|
||||
SwarmDb db = SwarmDb.GetDatabaseForWriting();
|
||||
base.OrganizationSequenceId = db.SetCashAdvanceSequence(this.Identity);
|
||||
return base.OrganizationSequenceId;
|
||||
}
|
||||
|
||||
return base.OrganizationSequenceId;
|
||||
}
|
||||
}
|
||||
|
||||
public Person Person
|
||||
{
|
||||
get { return Person.FromIdentity (PersonId); }
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Swarmops.Logic.Financial
|
||||
|
||||
// Create the financial transaction with rows
|
||||
|
||||
string transactionDescription = "Expense #" + newClaim.Identity + ": " + description; // TODO: Localize
|
||||
string transactionDescription = "Expense #" + newClaim.OrganizationSequenceId + ": " + description; // TODO: Localize
|
||||
|
||||
if (transactionDescription.Length > 64)
|
||||
{
|
||||
@@ -100,6 +100,26 @@ namespace Swarmops.Logic.Financial
|
||||
|
||||
#endregion
|
||||
|
||||
|
||||
|
||||
public new int OrganizationSequenceId
|
||||
{
|
||||
get
|
||||
{
|
||||
if (base.OrganizationSequenceId == 0)
|
||||
{
|
||||
// This case is for legacy installations before DbVersion 66, when
|
||||
// OrganizationSequenceId was added for each new expense claim
|
||||
|
||||
SwarmDb db = SwarmDb.GetDatabaseForWriting();
|
||||
base.OrganizationSequenceId = db.SetExpenseClaimSequence(this.Identity);
|
||||
return base.OrganizationSequenceId;
|
||||
}
|
||||
|
||||
return base.OrganizationSequenceId;
|
||||
}
|
||||
}
|
||||
|
||||
public Person Claimer
|
||||
{
|
||||
get { return Person.FromIdentity (base.ClaimingPersonId); }
|
||||
|
||||
@@ -77,8 +77,7 @@ namespace Swarmops.Frontend.Pages.v5.Financial
|
||||
// Create cash advance
|
||||
|
||||
CashAdvance cashAdvance = CashAdvance.Create (CurrentOrganization, CurrentUser, CurrentUser, amountCents,
|
||||
budget,
|
||||
description);
|
||||
budget, description);
|
||||
|
||||
// Create success message
|
||||
|
||||
|
||||
+1
-1
@@ -83,7 +83,7 @@
|
||||
<bindingRedirect oldVersion="0.0.0.0-4.5.9.0" newVersion="4.5.9.0" />
|
||||
</dependentAssembly>
|
||||
<dependentAssembly>
|
||||
<assemblyIdentity name="Newtonsoft.Json" culture="netural" publicKeyToken="30ad4fe6b2a6aeed" />
|
||||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" />
|
||||
<bindingRedirect oldVersion="6.0.0.0-9.0.0.0" newVersion="9.0.0.0" />
|
||||
<codeBase version="6.0.0.0" href="bin\Newtonsoft.Json.6.0.0.dll" />
|
||||
<codeBase version="9.0.0.0" href="bin\Newtonsoft.Json.dll" />
|
||||
|
||||
Reference in New Issue
Block a user