VAT report work

This commit is contained in:
Rick Falkvinge
2017-10-08 21:32:16 +02:00
parent 8c73218594
commit 6f59b2a837
5 changed files with 39 additions and 7 deletions
+5 -5
View File
@@ -24,7 +24,7 @@ namespace Swarmops.Database
" VatReportItemId,VatReportId,FinancialTransactionId,ForeignId,FinancialDependencyTypes.Name AS FinancialDependencyType," + // 0-4
"TurnoverCents,VatInboundCents,VatOutboundCents " +
"FROM VatReportItems " +
"JOIN FinancialDependencyTypes ON (VatReportItemId.FinancialDependencyTypeId=FinancialDependencyTypes.FinancialDependencyTypeId) ";
"JOIN FinancialDependencyTypes ON (VatReportItems.FinancialDependencyTypeId=FinancialDependencyTypes.FinancialDependencyTypeId) ";
private static BasicVatReport ReadVatReportFromDataReader (IDataRecord reader)
{
@@ -178,12 +178,12 @@ namespace Swarmops.Database
DbCommand command =
GetDbCommand(
"SELECT " + accountId.ToString(CultureInfo.InvariantCulture) + ", FinancialTransactions.TransactionId, FinancialTransactions.DateTime, FinancialTransactions.Comment, AmountCents, CreatedDateTime, CreatedByPersonId " +
"SELECT " + accountId.ToString(CultureInfo.InvariantCulture) + ", FinancialTransactions.FinancialTransactionId, FinancialTransactions.DateTime, FinancialTransactions.Comment, AmountCents, CreatedDateTime, CreatedByPersonId " +
" FROM FinancialTransactionRows " +
" JOIN FinancialTransactions ON (FinancialTransactionRows.FinancialTransactionId = FinancialTransactions.FinancialTransactionId) " +
" WHERE NOT EXISTS (SELECT * FROM VatReportItems WHERE FinancialTransactionId = FinancialTransactions.FinancialTransactionRowId) " +
" AND AccountId = @accountId " +
" AND FinancialTransaction.DateTime < @endDateTime" , connection);
" WHERE NOT EXISTS (SELECT * FROM VatReportItems WHERE VatReportItems.FinancialTransactionId = FinancialTransactions.FinancialTransactionId) " +
" AND FinancialAccountId = @accountId " +
" AND FinancialTransactions.DateTime < @endDateTime" , connection);
AddParameterWithName(command, "accountId", accountId);
AddParameterWithName(command, "endDateTime", endDate);
+2 -1
View File
@@ -43,4 +43,5 @@
0043 - FinancialTransactionRows housekeeping [RF]
0044 - Mark bitcoin as cryptocurrency [RF]
0045 - VAT Report work [RF]
0046 - VatReports.Turnover=>TurnoverCents [RF]
0046 - VatReports.Turnover=>TurnoverCents [RF]
0047 - Fix for null case in SetVatReportReleased [RF]
+30
View File
@@ -0,0 +1,30 @@
DROP PROCEDURE IF EXISTS `SetVatReportReleased`
#
CREATE PROCEDURE `SetVatReportReleased`(
vatReportId INT
)
BEGIN
IF EXISTS (SELECT * FROM VatReportItems WHERE VatReportItems.VatReportId=vatReportId)
THEN
UPDATE VatReports
SET
VatReports.TurnoverCents = (SELECT SUM(TurnoverCents) FROM VatReportItems WHERE VatReportItems.VatReportId=vatReportId),
VatReports.VatInboundCents = (SELECT SUM(VatInboundCents) FROM VatReportItems WHERE VatReportItems.VatReportId=vatReportId),
VatReports.VatOutboundCents = (SELECT SUM(VatOutboundCents) FROM VatReportItems WHERE VatReportItems.VatReportId=vatReportId),
VatReports.UnderConstruction = 0
WHERE VatReports.VatReportId=vatReportId;
ELSE
UPDATE VatReports
SET VatReports.UnderConstruction = 0
WHERE VatReports.VatReportId=vatReportId;
END IF;
END
+1
View File
@@ -51,6 +51,7 @@ namespace Swarmops.Logic.Financial
internal static VatReport Create(Organization organization, int year, int startMonth, int monthCount)
{
VatReport newReport = CreateDbRecord(organization, year, startMonth, monthCount);
VatReportItems testItems = newReport.Items;
DateTime startDate = new DateTime(year, startMonth, 1).AddYears(-1); // start a year before report starts
DateTime endDate = new DateTime(year, startMonth, 1).AddMonths(monthCount);
+1 -1
View File
@@ -49,7 +49,7 @@ namespace Swarmops.Logic.Financial
DateTime nextReport = lastReport.AddMonths(reportMonthInterval);
DateTime nextReportGenerationTime = nextReport.AddMonths(reportMonthInterval).AddDays(4); // Make the report on the 4th after the period has ended
if (nextReportGenerationTime > nowUtc)
if (nowUtc > nextReportGenerationTime)
{
// Create a new report