diff --git a/Basic/Types/Financial/BasicVatReport.cs b/Basic/Types/Financial/BasicVatReport.cs
index 82c94d6a..4fb555e5 100644
--- a/Basic/Types/Financial/BasicVatReport.cs
+++ b/Basic/Types/Financial/BasicVatReport.cs
@@ -13,7 +13,7 @@ namespace Swarmops.Basic.Types.Financial
public BasicVatReport(int vatReportId, int organizationId, string guid, DateTime createdDateTime,
int yearMonthStart, int monthCount, bool open, Int64 turnoverCents, Int64 vatInboundCents,
- Int64 vatOutboundCents, bool underConstruction)
+ Int64 vatOutboundCents, int openTransactionId, int closeTransactionId, bool underConstruction)
{
this.VatReportId = vatReportId;
this.OrganizationId = organizationId;
@@ -25,6 +25,8 @@ namespace Swarmops.Basic.Types.Financial
this.TurnoverCents = turnoverCents;
this.VatInboundCents = vatInboundCents;
this.VatOutboundCents = vatOutboundCents;
+ this.OpenTransactionId = openTransactionId;
+ this.CloseTransactionId = closeTransactionId;
this.UnderConstruction = underConstruction;
}
@@ -33,7 +35,8 @@ namespace Swarmops.Basic.Types.Financial
public BasicVatReport(BasicVatReport original)
: this(original.Identity, original.OrganizationId, original.Guid, original.CreatedDateTime,
original.YearMonthStart, original.MonthCount, original.Open, original.TurnoverCents,
- original.VatInboundCents, original.VatOutboundCents, original.UnderConstruction)
+ original.VatInboundCents, original.VatOutboundCents, original.OpenTransactionId,
+ original.CloseTransactionId, original.UnderConstruction)
{
// empty copy ctor
}
@@ -50,6 +53,8 @@ namespace Swarmops.Basic.Types.Financial
public Int64 VatInboundCents { get; protected set; }
public Int64 VatOutboundCents { get; protected set; }
public bool Open { get; protected set; }
+ public int OpenTransactionId { get; protected set; }
+ public int CloseTransactionId { get; protected set; }
public bool UnderConstruction { get; protected set; }
// Interfaces
diff --git a/Database/Configuration.cs b/Database/Configuration.cs
index 5dcac3c8..5761b9b9 100644
--- a/Database/Configuration.cs
+++ b/Database/Configuration.cs
@@ -14,7 +14,7 @@ namespace Swarmops.Database
///
public static int DbVersionExpected
{
- get { return 49; }
+ get { return 50; }
}
diff --git a/Database/Database-VatReports.cs b/Database/Database-VatReports.cs
index 67a97498..ee25c72f 100644
--- a/Database/Database-VatReports.cs
+++ b/Database/Database-VatReports.cs
@@ -7,6 +7,7 @@ using System.Globalization;
using Swarmops.Basic.Types;
using Swarmops.Basic.Types.Financial;
using Swarmops.Common.Enums;
+using Swarmops.Common.Exceptions;
namespace Swarmops.Database
{
@@ -17,7 +18,7 @@ namespace Swarmops.Database
private const string vatReportFieldSequence =
" VatReportId,OrganizationId,Guid,CreatedDateTime,YearMonthStart," + // 0-4
"MonthCount,VatReports.Open,TurnoverCents,VatInboundCents,VatOutboundCents," + // 5-9
- "UnderConstruction " + // 10
+ "OpenTransactionId,CloseTransactionId,UnderConstruction " + // 10-12
"FROM VatReports ";
private const string vatReportItemFieldSequence =
@@ -38,10 +39,12 @@ namespace Swarmops.Database
Int64 turnoverCents = reader.GetInt64(7);
Int64 vatInboundCents = reader.GetInt64(8);
Int64 vatOutboundCents = reader.GetInt64(9);
- bool underConstruction = reader.GetBoolean (10);
+ int openTransactionId = reader.GetInt32(10);
+ int closeTransactionid = reader.GetInt32(11);
+ bool underConstruction = reader.GetBoolean (12);
return new BasicVatReport(vatReportId, organizationId, guid, createdDateTime, yearMonthStart, monthCount,
- open, turnoverCents, vatInboundCents, vatOutboundCents, underConstruction);
+ open, turnoverCents, vatInboundCents, vatOutboundCents, openTransactionId, closeTransactionid, underConstruction);
}
@@ -289,6 +292,49 @@ namespace Swarmops.Database
}
+ public void SetVatReportOpenTransaction(int vatReportId, int financialTransactionId)
+ {
+ using (DbConnection connection = GetMySqlDbConnection())
+ {
+ connection.Open();
+
+ DbCommand command = GetDbCommand("SetVatReportOpenTransaction", connection);
+ command.CommandType = CommandType.StoredProcedure;
+
+ AddParameterWithName(command, "vatReportId", vatReportId);
+ AddParameterWithName(command, "openTransactionId", financialTransactionId);
+
+ if (Convert.ToInt32(command.ExecuteScalar()) != 1) // returns count of rows updated
+ {
+ throw new DatabaseConcurrencyException();
+ }
+ }
+ }
+
+
+
+ public void SetVatReportCloseTransaction(int vatReportId, int financialTransactionId)
+ {
+ using (DbConnection connection = GetMySqlDbConnection())
+ {
+ connection.Open();
+
+ DbCommand command = GetDbCommand("SetVatReportCloseTransaction", connection);
+ command.CommandType = CommandType.StoredProcedure;
+
+ AddParameterWithName(command, "vatReportId", vatReportId);
+ AddParameterWithName(command, "closeTransactionId", financialTransactionId);
+
+ if (Convert.ToInt32(command.ExecuteScalar()) != 1) // returns count of rows updated
+ {
+
+ throw new DatabaseConcurrencyException();
+ }
+ }
+ }
+
+
+
#endregion
}
}
diff --git a/Database/Schemata/revisions.txt b/Database/Schemata/revisions.txt
index 18186653..34f8ba25 100644
--- a/Database/Schemata/revisions.txt
+++ b/Database/Schemata/revisions.txt
@@ -47,3 +47,4 @@
0047 - Fix for null case in SetVatReportReleased [RF]
0048 - Fix for CreateVatReportItem, ForeignObjectId=>ForeignId [RF]
0049 - Another fix for CreateVatReportItem
+0050 - Added VatReports.OpenTransaction, .CloseTransaction
\ No newline at end of file
diff --git a/Database/Schemata/upgrade-0050.sql b/Database/Schemata/upgrade-0050.sql
new file mode 100644
index 00000000..c8b38391
--- /dev/null
+++ b/Database/Schemata/upgrade-0050.sql
@@ -0,0 +1,46 @@
+ALTER TABLE `VatReports`
+ADD COLUMN `OpenTransactionId` INT NOT NULL DEFAULT 0 AFTER `Open`,
+ADD COLUMN `CloseTransactionId` INT NOT NULL DEFAULT 0 AFTER `OpenTransactionId`,
+ADD INDEX `Ix_OpenTx` (`OpenTransactionId` ASC),
+ADD INDEX `Ix_CloseTx` (`CloseTransactionId` ASC);
+
+
+#
+
+DROP PROCEDURE IF EXISTS `SetVatReportOpenTransaction`
+
+#
+
+DROP PROCEDURE IF EXISTS `SetVatReportCloseTransaction`
+
+#
+
+CREATE PROCEDURE `SetVatReportOpenTransaction`(
+ IN vatReportId INTEGER,
+ IN openTransactionId INTEGER
+)
+BEGIN
+
+ UPDATE VatReports SET OpenTransactionId=openTransactionId
+ WHERE VatReports.VatReportId=vatReportId;
+
+ SELECT ROW_COUNT() AS RecordsUpdated;
+
+END
+
+
+#
+
+CREATE PROCEDURE `SetVatReportCloseTransaction`(
+ IN vatReportId INTEGER,
+ IN closeTransactionId INTEGER
+)
+BEGIN
+
+ UPDATE VatReports SET CloseTransactionId=closeTransactionId
+ WHERE VatReports.VatReportId=vatReportId
+ AND VatReports.CloseTransactionId=0;
+
+ SELECT ROW_COUNT() AS RecordsUpdated;
+
+END
diff --git a/Logic/Financial/VatReport.cs b/Logic/Financial/VatReport.cs
index f1b186a9..0d441a8f 100644
--- a/Logic/Financial/VatReport.cs
+++ b/Logic/Financial/VatReport.cs
@@ -240,6 +240,38 @@ namespace Swarmops.Logic.Financial
}
}
}
+
+ public new int OpenTransactionId
+ {
+ get { return base.OpenTransactionId; }
+ set
+ {
+ SwarmDb.GetDatabaseForWriting().SetVatReportOpenTransaction(this.Identity, value);
+ base.OpenTransactionId = value;
+ }
+ }
+
+ public FinancialTransaction OpenTransaction
+ {
+ get { return FinancialTransaction.FromIdentity(OpenTransactionId); }
+ set { this.OpenTransactionId = value.Identity; }
+ }
+
+ public new int CloseTransactionId
+ {
+ get { return base.CloseTransactionId; }
+ set
+ {
+ SwarmDb.GetDatabaseForWriting().SetVatReportCloseTransaction(this.Identity, value);
+ base.CloseTransactionId = value;
+ }
+ }
+
+ public FinancialTransaction CloseTransaction
+ {
+ get { return FinancialTransaction.FromIdentity(CloseTransactionId); }
+ set { this.CloseTransactionId = value.Identity; }
+ }
}
}
diff --git a/Site/App_GlobalResources/Pages.Ledgers.designer.cs b/Site/App_GlobalResources/Pages.Ledgers.designer.cs
index 6eb7796d..ccef928f 100644
--- a/Site/App_GlobalResources/Pages.Ledgers.designer.cs
+++ b/Site/App_GlobalResources/Pages.Ledgers.designer.cs
@@ -618,6 +618,15 @@ namespace Resources.Pages {
}
}
+ ///