From 861e76addcddcd7879021206f49862a760682c50 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Wed, 1 Jan 2020 19:37:44 +0100 Subject: [PATCH] Bugfix for when interval changes --- Logic/Financial/VatReport.cs | 20 +++++++++++--------- 1 file changed, 11 insertions(+), 9 deletions(-) diff --git a/Logic/Financial/VatReport.cs b/Logic/Financial/VatReport.cs index bf634f46..4c060d10 100644 --- a/Logic/Financial/VatReport.cs +++ b/Logic/Financial/VatReport.cs @@ -77,23 +77,24 @@ namespace Swarmops.Logic.Financial throw new InvalidOperationException("VAT report is not yet due or has already been generated"); } - DateTime thisReport = new DateTime(organization.FirstFiscalYear, 1, 1); // default to first report + DateTime thisReportDate = new DateTime(organization.FirstFiscalYear, 1, 1); // default to first report VatReports reports = VatReports.ForOrganization(organization, true); if (reports.Count > 0) { reports.Sort(VatReports.VatReportSorterByDate); - DateTime lastReport = new DateTime(reports.Last().YearMonthStart / 100, reports.Last().YearMonthStart % 100, + VatReport lastReport = reports.Last(); + DateTime lastReportDate = new DateTime(lastReport.YearMonthStart / 100, reports.Last().YearMonthStart % 100, 1); - thisReport = lastReport.AddMonths(reportMonthInterval); + thisReportDate = lastReportDate.AddMonths(lastReport.MonthCount); } - while (thisReport.AddMonths(reportMonthInterval) < nowUtc) + while (thisReportDate.AddMonths(reportMonthInterval) < nowUtc) { - VatReport.Create(organization, thisReport.Year, thisReport.Month, reportMonthInterval); - thisReport = thisReport.AddMonths(reportMonthInterval); + VatReport.Create(organization, thisReportDate.Year, thisReportDate.Month, reportMonthInterval); + thisReportDate = thisReportDate.AddMonths(reportMonthInterval); } @@ -173,11 +174,12 @@ namespace Swarmops.Logic.Financial { reports.Sort(VatReports.VatReportSorterByDate); - DateTime lastReport = new DateTime(reports.Last().YearMonthStart/100, reports.Last().YearMonthStart%100, + VatReport lastReport = reports.Last(); + DateTime lastReportDate = new DateTime(lastReport.YearMonthStart/100, reports.Last().YearMonthStart%100, 1); - DateTime nextReport = lastReport.AddMonths(reportMonthInterval); - DateTime nextReportGenerationTime = nextReport.AddMonths(reportMonthInterval); + DateTime nextReportDate = lastReportDate.AddMonths(lastReport.MonthCount); + DateTime nextReportGenerationTime = nextReportDate.AddMonths(reportMonthInterval); return nextReportGenerationTime; }