diff --git a/Basic/Types/Financial/BasicFinancialAccountRow.cs b/Basic/Types/Financial/BasicFinancialAccountRow.cs index 25719c99..aa4dd02b 100644 --- a/Basic/Types/Financial/BasicFinancialAccountRow.cs +++ b/Basic/Types/Financial/BasicFinancialAccountRow.cs @@ -4,7 +4,7 @@ namespace Swarmops.Basic.Types.Financial { public class BasicFinancialAccountRow { - public BasicFinancialAccountRow (int financialAccountId, int financialTransactionId, DateTime dateTime, + public BasicFinancialAccountRow (int financialAccountId, int financialTransactionId, int financialTransactionRowId, DateTime dateTime, string comment, Int64 amountCents, DateTime rowDateTime, int rowCreatedByPersonId) { FinancialAccountId = financialAccountId; @@ -18,14 +18,15 @@ namespace Swarmops.Basic.Types.Financial public BasicFinancialAccountRow (BasicFinancialAccountRow original) : this ( - original.FinancialAccountId, original.FinancialTransactionId, original.TransactionDateTime, - original.Description, + original.FinancialAccountId, original.FinancialTransactionId, original.FinancialTransactionRowId, + original.TransactionDateTime, original.Description, original.AmountCents, original.RowDateTime, original.RowCreatedByPersonId) { } public int FinancialAccountId { get; private set; } public int FinancialTransactionId { get; private set; } + public int FinancialTransactionRowId { get; private set; } public DateTime TransactionDateTime { get; private set; } public string Description { get; private set; } public Int64 AmountCents { get; private set; } diff --git a/Database/Database-Financials.cs b/Database/Database-Financials.cs index 1cfdc0b1..08ab97ad 100644 --- a/Database/Database-Financials.cs +++ b/Database/Database-Financials.cs @@ -386,7 +386,7 @@ namespace Swarmops.Database DbCommand command = GetDbCommand ( - "select FinancialTransactionRows.FinancialAccountId,FinancialTransactionRows.FinancialTransactionId,FinancialTransactions.DateTime,FinancialTransactions.Comment,FinancialTransactionRows.AmountCents,FinancialTransactionRows.CreatedDateTime,FinancialTransactionRows.CreatedByPersonId FROM FinancialTransactions,FinancialTransactionRows WHERE FinancialTransactionRows.Deleted=0 AND FinancialTransactions.FinancialTransactionId=FinancialTransactionRows.FinancialTransactionId AND FinancialTransactionRows.FinancialAccountId IN (" + + "select FinancialTransactionRows.FinancialAccountId,FinancialTransactionRows.FinancialTransactionId,FinancialTransactionRows.FinancialTransactionRowId,FinancialTransactions.DateTime,FinancialTransactions.Comment,FinancialTransactionRows.AmountCents,FinancialTransactionRows.CreatedDateTime,FinancialTransactionRows.CreatedByPersonId FROM FinancialTransactions,FinancialTransactionRows WHERE FinancialTransactionRows.Deleted=0 AND FinancialTransactions.FinancialTransactionId=FinancialTransactionRows.FinancialTransactionId AND FinancialTransactionRows.FinancialAccountId IN (" + JoinIds (financialAccountIds) + ") AND DateTime " + selectorLower + " '" + startDateTime.ToString ("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture) + "' AND DateTime " + selectorUpper + " '" + endDateTime.ToString ("yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture) + @@ -421,7 +421,7 @@ namespace Swarmops.Database DbCommand command = GetDbCommand ( - "select FinancialTransactionRows.FinancialAccountId,FinancialTransactionRows.FinancialTransactionId,FinancialTransactions.DateTime,FinancialTransactions.Comment,FinancialTransactionRows.AmountCents,FinancialTransactionRows.CreatedDateTime,FinancialTransactionRows.CreatedByPersonId FROM FinancialTransactions,FinancialTransactionRows WHERE FinancialTransactionRows.Deleted=0 AND FinancialTransactions.FinancialTransactionId=FinancialTransactionRows.FinancialTransactionId AND FinancialTransactionRows.FinancialAccountId IN (" + + "select FinancialTransactionRows.FinancialAccountId,FinancialTransactionRows.FinancialTransactionId,FinancialTransactionRows.FinancialTransactionRowId,FinancialTransactions.DateTime,FinancialTransactions.Comment,FinancialTransactionRows.AmountCents,FinancialTransactionRows.CreatedDateTime,FinancialTransactionRows.CreatedByPersonId FROM FinancialTransactions,FinancialTransactionRows WHERE FinancialTransactionRows.Deleted=0 AND FinancialTransactions.FinancialTransactionId=FinancialTransactionRows.FinancialTransactionId AND FinancialTransactionRows.FinancialAccountId IN (" + JoinIds (financialAccountIds) + ") ORDER BY DateTime DESC,FinancialTransactions.FinancialTransactionId,FinancialTransactionRows.CreatedDateTime LIMIT " + rowCount + ";", @@ -919,13 +919,14 @@ namespace Swarmops.Database { int accountId = reader.GetInt32 (0); int transactionId = reader.GetInt32 (1); - DateTime transactionDateTime = reader.GetDateTime (2); - string comment = reader.GetString (3); - Int64 amountCents = reader.GetInt64 (4); - DateTime rowDateTime = reader.GetDateTime (5); - int rowCreatedByPersonId = reader.GetInt32 (6); + int transactionRowId = reader.GetInt32(2); + DateTime transactionDateTime = reader.GetDateTime (3); + string comment = reader.GetString (4); + Int64 amountCents = reader.GetInt64 (5); + DateTime rowDateTime = reader.GetDateTime (6); + int rowCreatedByPersonId = reader.GetInt32 (7); - return new BasicFinancialAccountRow (accountId, transactionId, transactionDateTime, comment, amountCents, + return new BasicFinancialAccountRow (accountId, transactionId, transactionRowId, transactionDateTime, comment, amountCents, rowDateTime, rowCreatedByPersonId); } diff --git a/Database/Database-VatReports.cs b/Database/Database-VatReports.cs index 3c3f2979..b5d12462 100644 --- a/Database/Database-VatReports.cs +++ b/Database/Database-VatReports.cs @@ -245,7 +245,7 @@ namespace Swarmops.Database DbCommand command = GetDbCommand( - "SELECT " + accountId.ToString(CultureInfo.InvariantCulture) + ", FinancialTransactions.FinancialTransactionId, FinancialTransactions.DateTime, FinancialTransactions.Comment, AmountCents, CreatedDateTime, CreatedByPersonId " + + "SELECT " + accountId.ToString(CultureInfo.InvariantCulture) + ", FinancialTransactions.FinancialTransactionId, FinancialTransactionRows.FinancialTransactionRowId, FinancialTransactions.DateTime, FinancialTransactions.Comment, AmountCents, CreatedDateTime, CreatedByPersonId " + " FROM FinancialTransactionRows " + " JOIN FinancialTransactions ON (FinancialTransactionRows.FinancialTransactionId = FinancialTransactions.FinancialTransactionId) " + " WHERE NOT EXISTS (SELECT * FROM VatReportItems WHERE VatReportItems.FinancialTransactionId = FinancialTransactions.FinancialTransactionId) " + diff --git a/Logic/Financial/FinancialAccount.cs b/Logic/Financial/FinancialAccount.cs index fd44197e..af3803df 100644 --- a/Logic/Financial/FinancialAccount.cs +++ b/Logic/Financial/FinancialAccount.cs @@ -210,20 +210,23 @@ namespace Swarmops.Logic.Financial { const string initialBalanceTransactionTitle = "Initial Balances"; - Int64 currentInitialBalanceCents = this.GetDeltaCents(new DateTime(1900, 1, 1), + Int64 currentInitialBalanceCents = this.GetDeltaCents(Constants.DateTimeLow, new DateTime(this.Organization.FirstFiscalYear, 1, 1)); // Test: Assert that the currency set equals the currency for the account if (this.ForeignCurrency != null) { - + if (value.Currency.Identity != this.ForeignCurrency.Identity) + { + throw new ArgumentException("Foreign currency mismatch"); + } } else { if (value.Currency.Identity != this.Organization.Currency.Identity) { - throw new ArgumentException("Currency mismatch"); + throw new ArgumentException("Presentation currency mismatch"); } } @@ -279,7 +282,8 @@ namespace Swarmops.Logic.Financial // First, get the current initial balance in account nonpresentation currency: - Money currentInitialBalanceCents = ForeignBalanceTotalCents + Int64 initialBalanceForeignCents = GetForeignBalanceDeltaCents(Constants.DateTimeLow, + new DateTime(this.Organization.FirstFiscalYear, 1, 1)).Cents; // Find the newly added transaction row // (WARNING / RACE: This may return an incorrect row, if there's a lag betweeen @@ -288,7 +292,7 @@ namespace Swarmops.Logic.Financial testRows = FinancialAccountRows.ForOrganization(this.Organization, Constants.DateTimeLow, new DateTime(this.Organization.FirstFiscalYear, 1, 1)); - FinancialAccountRow lastFoundRow = null; + FinancialTransactionRow lastFoundRow = null; foreach (FinancialAccountRow row in testRows) { @@ -301,6 +305,9 @@ namespace Swarmops.Logic.Financial // Amend the last found row, which is assumed to be a result of the RecalculateTx // call above, to reflect the new initial balance in foreign currency. + Int64 currentBalanceForeignCents = this.ForeignBalanceTotalCents.Cents; + Int64 lastRowForeignCents = lastFoundRow. + } } catch (Exception weirdException) diff --git a/Logic/Financial/FinancialAccountRow.cs b/Logic/Financial/FinancialAccountRow.cs index 0afb094b..d92ecc38 100644 --- a/Logic/Financial/FinancialAccountRow.cs +++ b/Logic/Financial/FinancialAccountRow.cs @@ -27,5 +27,10 @@ namespace Swarmops.Logic.Financial { get { return FinancialTransaction.FromIdentity (FinancialTransactionId); } } + + public FinancialTransactionRow TransactionRow + { + get { return FinancialTransactionRow.FromIdentity(this.FinancialTransactionRowId); } + } } } \ No newline at end of file