Bugfix for VAT report generation

This commit is contained in:
Rick Falkvinge
2017-10-21 13:57:48 +02:00
parent df5b086809
commit 536cc40045
3 changed files with 51 additions and 3 deletions
+34
View File
@@ -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>();
+16 -2
View File
@@ -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
+1 -1
View File
@@ -39,7 +39,7 @@ namespace Swarmops.Frontend
// BEGIN TEST CODE
// VatReports.CreateNewReports();
VatReports.CreateNewReports();
// END TEST CODE