Bugfix for VAT report generation
This commit is contained in:
@@ -92,6 +92,40 @@ namespace Swarmops.Database
|
||||
}
|
||||
|
||||
|
||||
public int GetVatReportIdFromCloseTransaction(int closeTransactionId)
|
||||
{
|
||||
return GetVatReportIdFromIntegerField("CloseTransactionId", closeTransactionId);
|
||||
}
|
||||
|
||||
public int GetVatReportIdFromOpenTransaction(int openTransactionId)
|
||||
{
|
||||
return GetVatReportIdFromIntegerField("OpenTransactionId", openTransactionId);
|
||||
}
|
||||
|
||||
private int GetVatReportIdFromIntegerField(string integerFieldName, int integerValue)
|
||||
{
|
||||
using (DbConnection connection = GetMySqlDbConnection())
|
||||
{
|
||||
connection.Open();
|
||||
|
||||
DbCommand command =
|
||||
GetDbCommand(
|
||||
"SELECT VatReportId FROM VatReports WHERE " + integerFieldName + "=" + integerValue + ";", connection);
|
||||
|
||||
using (DbDataReader reader = command.ExecuteReader())
|
||||
{
|
||||
if (reader.Read())
|
||||
{
|
||||
return reader.GetInt32(0);
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
public BasicVatReport[] GetVatReports(params object[] conditions)
|
||||
{
|
||||
List<BasicVatReport> result = new List<BasicVatReport>();
|
||||
|
||||
@@ -217,12 +217,26 @@ namespace Swarmops.Logic.Financial
|
||||
private static FinancialAccountRows RowsNotInVatReport(FinancialAccount account, DateTime endDateTime)
|
||||
{
|
||||
Organization organization = account.Organization;
|
||||
SwarmDb dbRead = SwarmDb.GetDatabaseForReading();
|
||||
|
||||
FinancialAccountRows rows =
|
||||
FinancialAccountRows rowsIntermediate =
|
||||
FinancialAccountRows.FromArray(
|
||||
SwarmDb.GetDatabaseForReading().GetAccountRowsNotInVatReport(account.Identity, endDateTime));
|
||||
|
||||
return rows;
|
||||
FinancialAccountRows rowsFinal = new FinancialAccountRows();
|
||||
foreach (FinancialAccountRow row in rowsIntermediate)
|
||||
{
|
||||
// Check if this row _closes_ an _existing_ VAT report, in which case it should _not_ be included
|
||||
|
||||
int vatReportId = dbRead.GetVatReportIdFromCloseTransaction(row.FinancialTransactionId);
|
||||
if (vatReportId == 0)
|
||||
{
|
||||
// This particular transaction doesn't close an existing VAT report
|
||||
rowsFinal.Add(row);
|
||||
}
|
||||
}
|
||||
|
||||
return rowsFinal;
|
||||
}
|
||||
|
||||
public string Description
|
||||
|
||||
@@ -39,7 +39,7 @@ namespace Swarmops.Frontend
|
||||
|
||||
// BEGIN TEST CODE
|
||||
|
||||
// VatReports.CreateNewReports();
|
||||
VatReports.CreateNewReports();
|
||||
|
||||
// END TEST CODE
|
||||
|
||||
|
||||
Reference in New Issue
Block a user