Added native currency to txrows

This commit is contained in:
Rick Falkvinge
2015-12-03 15:47:38 +01:00
parent 01b5ce0ec3
commit 787e0a48e6
7 changed files with 157 additions and 6 deletions
+1 -1
View File
@@ -14,7 +14,7 @@ namespace Swarmops.Database
/// </summary>
public static int DbVersionExpected
{
get { return 31; }
get { return 32; }
}
+46 -2
View File
@@ -614,10 +614,10 @@ namespace Swarmops.Database
{
connection.Open();
DbCommand command =
using (DbCommand command =
GetDbCommand (
"select AmountCents from FinancialAccountBudgetsMonthly where Year=" + year +
" AND FinancialAccountId=" + financialAccountId + " ORDER BY Month;", connection);
" AND FinancialAccountId=" + financialAccountId + " ORDER BY Month;", connection))
using (DbDataReader reader = command.ExecuteReader())
{
@@ -1042,6 +1042,50 @@ namespace Swarmops.Database
}
public void SetFinancialTransactionForeignId(int financialTransactionId, FinancialForeignIdType foreignIdType, string foreignId)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command = GetDbCommand("SetFinancialTransactionForeignId", connection);
command.CommandType = CommandType.StoredProcedure;
AddParameterWithName(command, "financialTransactionId", financialTransactionId);
AddParameterWithName(command, "financialTransactionForeignIdType", (int) foreignIdType);
AddParameterWithName(command, "foreignId", foreignId);
command.ExecuteNonQuery();
}
}
public Int64 GetFinancialTransactionFromForeignId(FinancialForeignIdType foreignIdType, string foreignId)
{
using (DbConnection connection = GetMySqlDbConnection())
{
connection.Open();
DbCommand command =
GetDbCommand(
"Select FinancialTransactionId from FinancialTransactionForeignIds WHERE FinancialTransactionForeignIdType=" + (int) foreignIdType +
" AND ForeignId='" + SqlSanitize (foreignId) + "';", connection);
using (DbDataReader reader = command.ExecuteReader())
{
if (reader.Read())
{
return reader.GetInt32 (0);
}
return 0; // none found. Todo: throw exception instead? This behavior is inconsistent
}
}
}
public DateTime GetFinancialAccountFirstTransactionDate (int financialAccountId)
{
using (DbConnection connection = GetMySqlDbConnection())
+2 -1
View File
@@ -28,4 +28,5 @@
0028 - Bugfix for 0027 [RF]
0029 - Added unspent satoshis to hotaddress on create unspent [RF]
0030 - Added flexibility for Resolver classes for OutboundComms [RF]
0031 - Added foreign ID tables, procs for transactions, to track blockchain [RF]
0031 - Added foreign ID tables, procs for transactions, to track blockchain [RF]
0032 - Added native currency to transaction rows, for multi-currency accounting [RF]
+42
View File
@@ -0,0 +1,42 @@
CREATE TABLE `FinancialTransactionRowsNativeCurrency` (
`FinancialTransactionRowId` INT NOT NULL,
`CurrencyId` INT NOT NULL,
`NativeAmountCents` BIGINT NOT NULL,
PRIMARY KEY (`FinancialTransactionRowId`))
#
DROP procedure IF EXISTS `SetFinancialTransactionRowNativeCurrency`
#
CREATE PROCEDURE `SetFinancialTransactionRowNativeCurrency`(
IN financialTransactionRowId INT,
IN currencyId INT,
IN nativeAmountCents BIGINT
)
BEGIN
IF ((SELECT COUNT(*) FROM FinancialTransactionRows
WHERE FinancialTransactionRows.FinancialTransactionRowId=financialTransactionRowId) = 0)
THEN
INSERT INTO FinancialTransactionRowsNativeCurrency (FinancialTransactionRowId,CurrencyId,NativeAmountCents)
VALUES (financialTransactionRowId,currencyId,nativeAmountCents);
ELSE
UPDATE FinancialTransactionRowsNativeCurrency
SET FinancialTransactionRowsNativeCurrency.CurrencyId=currencyId,
FinancialTransactionRowsNativeCurrency.NativeAmountCents=nativeAmountCents
WHERE FinancialTransactionRowsNativeCurrency.FinancialTransactionRowId=
financialTransactionRowId;
END IF;
END