Added OrgSeqId to CAs, Expenses
This commit is contained in:
@@ -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
|
||||
Reference in New Issue
Block a user