Db0074 - prep for new import
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 => 73;
|
||||
public static int DbVersionExpected => 74;
|
||||
|
||||
|
||||
// This class is in horrible need of serious refactoring. For its simplicity in task, it's a horrible bowl of spaghetti.
|
||||
|
||||
@@ -70,4 +70,5 @@
|
||||
0070 - Added first Applications tables, procs [RF]
|
||||
0071 - Renamed Application to Applicant, to avoid a marsh and misery of name collisions [RF]
|
||||
0072 - Critical bugfix for 0069 [RF]
|
||||
0073 - FinancialTransactions.Comment and People.Name to UTF8 explicit charset [RF]
|
||||
0073 - FinancialTransactions.Comment and People.Name to UTF8 explicit charset [RF]
|
||||
0074 - Added FinancialTransaction.ImportSha256 for making bank import better [RF]
|
||||
@@ -0,0 +1,75 @@
|
||||
ALTER TABLE `FinancialTransactions`
|
||||
ADD COLUMN `ImportSha256` VARCHAR(80) NOT NULL DEFAULT '' AFTER `ImportHash`
|
||||
|
||||
#
|
||||
|
||||
DROP PROCEDURE IF EXISTS `CreateFinancialTransactionStub`
|
||||
|
||||
#
|
||||
|
||||
DROP PROCEDURE IF EXISTS `SetFinancialTransactionImportSha256`
|
||||
|
||||
#
|
||||
|
||||
CREATE PROCEDURE `CreateFinancialTransactionStub`(
|
||||
IN organizationId INTEGER,
|
||||
IN financialAccountId INTEGER,
|
||||
IN amountCents BIGINT,
|
||||
IN dateTime DATETIME,
|
||||
IN comment TEXT,
|
||||
IN importHash VARCHAR(32),
|
||||
IN importSha256 VARCHAR(80),
|
||||
IN personId INTEGER
|
||||
)
|
||||
BEGIN
|
||||
|
||||
DECLARE financialTransactionId INTEGER;
|
||||
DECLARE existingSha256 VARCHAR(80);
|
||||
|
||||
SELECT 0 INTO financialTransactionId;
|
||||
|
||||
IF ((SELECT COUNT(*) FROM FinancialTransactions WHERE FinancialTransactions.ImportHash=importHash) = 0)
|
||||
THEN
|
||||
INSERT INTO FinancialTransactions (OrganizationId, DateTime, Comment, ImportHash, ImportSha256)
|
||||
VALUES (organizationId, dateTime, comment, importHash, importSha256);
|
||||
|
||||
SELECT LAST_INSERT_ID() INTO financialTransactionId;
|
||||
|
||||
INSERT INTO FinancialTransactionRows (FinancialAccountId, FinancialTransactionId, AmountCents, CreatedDateTime, CreatedByPersonId)
|
||||
VALUES (financialAccountId, financialTransactionId, amountCents, DateTime, personId);
|
||||
|
||||
ELSE
|
||||
|
||||
SELECT FinancialTransactions.FinancialTransactionId INTO financialTransactionId FROM FinancialTransactions WHERE FinancialTransactions.ImportHash=importHash;
|
||||
SELECT FinancialTransactions.ImportSha256 INTO existingSha256 FROM FinancialTransactions WHERE FinancialTransactions.ImportHash=importHash;
|
||||
|
||||
IF (existingSha256 != importSha256)
|
||||
THEN
|
||||
|
||||
UPDATE FinancialTransactions
|
||||
SET FinancialTransactions.ImportSha256=importSha256
|
||||
WHERE FinancialTransactions.FinancialTransactionId=financialTransactionId;
|
||||
|
||||
SELECT -financialTransactionId INTO financialTransactionId;
|
||||
|
||||
END IF;
|
||||
|
||||
END IF;
|
||||
|
||||
SELECT financialTransactionId AS Identity;
|
||||
|
||||
END
|
||||
|
||||
#
|
||||
|
||||
|
||||
CREATE PROCEDURE `SetFinancialTransactionImportSha256`(
|
||||
IN financialTransactionId INTEGER,
|
||||
IN importSha256 VARCHAR(80)
|
||||
)
|
||||
BEGIN
|
||||
|
||||
UPDATE FinancialTransactions SET FinancialTransactions.ImportSha256 = importSha256
|
||||
WHERE FinancialTransactions.FinancialTransactionId = financialTransactionId;
|
||||
|
||||
END
|
||||
@@ -58,7 +58,7 @@ namespace Swarmops.Logic.Financial
|
||||
financialAccountId, amountCents,
|
||||
description, importHash, personId);
|
||||
|
||||
if (transactionId == 0)
|
||||
if (transactionId <= 0)
|
||||
{
|
||||
return null; // This was a dupe -- already imported, as determined by ImportHash
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user