From 2d553c85bf7213a38e6168591a8164ec5918c7c9 Mon Sep 17 00:00:00 2001 From: Rick Falkvinge Date: Tue, 11 Dec 2012 22:13:24 +0000 Subject: [PATCH] Fix for embarrassing bug in balance sheet (it was calculated like a result sheet) --- Logic/Financial/YearlyReport.cs | 34 +++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/Logic/Financial/YearlyReport.cs b/Logic/Financial/YearlyReport.cs index 71701d27..ee48481c 100644 --- a/Logic/Financial/YearlyReport.cs +++ b/Logic/Financial/YearlyReport.cs @@ -15,6 +15,7 @@ namespace Activizr.Logic.Financial YearlyReport report = new YearlyReport(); report.Organization = organization; report.Year = year; + report._accountType = accountType; // Get accounts @@ -63,6 +64,9 @@ namespace Activizr.Logic.Financial } + private FinancialAccountType _accountType; + + private void PopulateTotals() { this.Totals = new YearlyReportNode(); @@ -163,7 +167,20 @@ namespace Activizr.Logic.Financial { // Find this year's inbound - _singleLookups[0][account.Identity] = account.GetDeltaCents(new DateTime(this.Year - 1, 1, 1), new DateTime(this.Year, 1, 1)); + if (_accountType == FinancialAccountType.Result) + { + _singleLookups[0][account.Identity] = account.GetDeltaCents(new DateTime(this.Year - 1, 1, 1), + new DateTime(this.Year, 1, 1)); + } + else if (_accountType == FinancialAccountType.Balance) + { + _singleLookups[0][account.Identity] = account.GetDeltaCents(new DateTime(1900, 1, 1), + new DateTime(this.Year, 1, 1)); + } + else + { + throw new InvalidOperationException("Can only calculate yearly reports for balance or P&L statements"); + } // Find quarter diffs @@ -175,7 +192,20 @@ namespace Activizr.Logic.Financial // Find outbound - _singleLookups[5][account.Identity] = account.GetDeltaCents(new DateTime(this.Year, 1, 1), new DateTime(this.Year + 1, 1, 1)); + if (_accountType == FinancialAccountType.Result) + { + _singleLookups[5][account.Identity] = account.GetDeltaCents(new DateTime(this.Year, 1, 1), + new DateTime(this.Year + 1, 1, 1)); + } + else if (_accountType == FinancialAccountType.Balance) + { + _singleLookups[6][account.Identity] = account.GetDeltaCents(new DateTime(1900, 1, 1), + new DateTime(this.Year + 1, 1, 1)); + } + else + { + throw new InvalidOperationException("Can only calculate yearly reports for balance or P&L statements"); + } // copy to treeLookups