From edfd8af9cf565505987425edaa38b556cca5daed Mon Sep 17 00:00:00 2001 From: Falkvinge Date: Mon, 30 Oct 2017 09:39:28 +0100 Subject: [PATCH] Refactor: Organization.HasCurrentLedgers --- Logic/Financial/VatReport.cs | 12 +++++ Logic/Structure/Organization.cs | 5 ++ Site/Pages/v5/Ledgers/BalanceSheet.aspx.cs | 2 +- .../v5/Ledgers/BalanceSheetSimplified.aspx.cs | 2 +- .../v5/Ledgers/Json-VatReportData.aspx.cs | 2 + .../v5/Ledgers/ProfitLossStatement.aspx.cs | 2 +- Site/Pages/v5/Ledgers/ViewVatReports.aspx.cs | 46 +++++++++++++------ 7 files changed, 55 insertions(+), 16 deletions(-) diff --git a/Logic/Financial/VatReport.cs b/Logic/Financial/VatReport.cs index 83f308b6..6b3a0f2f 100644 --- a/Logic/Financial/VatReport.cs +++ b/Logic/Financial/VatReport.cs @@ -40,6 +40,18 @@ namespace Swarmops.Logic.Financial return FromBasic(SwarmDb.GetDatabaseForWriting().GetVatReport(vatReportId)); } + public static VatReport FromGuid(string guid) + { + int vatReportId = SwarmDb.GetDatabaseForReading().GetVatReportIdFromGuid(guid); + + if (vatReportId == 0) + { + throw new ArgumentException("No such report"); + } + + return FromIdentity(vatReportId); + } + private static VatReport CreateDbRecord (Organization organization, int year, int startMonth, int monthCount) { System.Guid guid = System.Guid.NewGuid(); diff --git a/Logic/Structure/Organization.cs b/Logic/Structure/Organization.cs index fe111dcf..4a994340 100644 --- a/Logic/Structure/Organization.cs +++ b/Logic/Structure/Organization.cs @@ -683,6 +683,11 @@ namespace Swarmops.Logic.Structure } } + public bool HasOpenLedgers + { + get { return !String.IsNullOrEmpty(OpenLedgersDomain); } + } + #endregion #region UptakeGeographies diff --git a/Site/Pages/v5/Ledgers/BalanceSheet.aspx.cs b/Site/Pages/v5/Ledgers/BalanceSheet.aspx.cs index 1e4109f4..d5809230 100644 --- a/Site/Pages/v5/Ledgers/BalanceSheet.aspx.cs +++ b/Site/Pages/v5/Ledgers/BalanceSheet.aspx.cs @@ -20,7 +20,7 @@ namespace Swarmops.Frontend.Pages.Ledgers // Security: If the org has open ledgers, then anyone may read. Otherwise, Financials.Read. - if (!String.IsNullOrEmpty (CurrentOrganization.OpenLedgersDomain)) + if (CurrentOrganization.HasOpenLedgers) { PageAccessRequired = new Access (AccessAspect.Null, AccessType.Read); } diff --git a/Site/Pages/v5/Ledgers/BalanceSheetSimplified.aspx.cs b/Site/Pages/v5/Ledgers/BalanceSheetSimplified.aspx.cs index 2216a43d..8c7c41f6 100644 --- a/Site/Pages/v5/Ledgers/BalanceSheetSimplified.aspx.cs +++ b/Site/Pages/v5/Ledgers/BalanceSheetSimplified.aspx.cs @@ -23,7 +23,7 @@ namespace Swarmops.Frontend.Pages.Ledgers // Security: If the org has open ledgers, then anyone may read. Otherwise, Financials.Read. - if (!String.IsNullOrEmpty (CurrentOrganization.OpenLedgersDomain)) + if (CurrentOrganization.HasOpenLedgers) { PageAccessRequired = new Access (AccessAspect.Null, AccessType.Read); } diff --git a/Site/Pages/v5/Ledgers/Json-VatReportData.aspx.cs b/Site/Pages/v5/Ledgers/Json-VatReportData.aspx.cs index d1b0bb0a..9d53dd98 100644 --- a/Site/Pages/v5/Ledgers/Json-VatReportData.aspx.cs +++ b/Site/Pages/v5/Ledgers/Json-VatReportData.aspx.cs @@ -39,6 +39,8 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers VatReport report = VatReport.FromIdentity(_reportId); + // TODO: AUTH CHECK + Response.ContentType = "application/json"; Int64 turnoverCentsTotal = 0; diff --git a/Site/Pages/v5/Ledgers/ProfitLossStatement.aspx.cs b/Site/Pages/v5/Ledgers/ProfitLossStatement.aspx.cs index c907c344..271bf156 100644 --- a/Site/Pages/v5/Ledgers/ProfitLossStatement.aspx.cs +++ b/Site/Pages/v5/Ledgers/ProfitLossStatement.aspx.cs @@ -23,7 +23,7 @@ namespace Swarmops.Frontend.Pages.Ledgers // Security: If the org has open ledgers, then anyone may read. Otherwise, Financials.Read. - if (!String.IsNullOrEmpty (CurrentOrganization.OpenLedgersDomain)) + if (CurrentOrganization.HasOpenLedgers) { PageAccessRequired = new Access (AccessAspect.Null, AccessType.Read); } diff --git a/Site/Pages/v5/Ledgers/ViewVatReports.aspx.cs b/Site/Pages/v5/Ledgers/ViewVatReports.aspx.cs index 1a94cfa9..8f320a40 100644 --- a/Site/Pages/v5/Ledgers/ViewVatReports.aspx.cs +++ b/Site/Pages/v5/Ledgers/ViewVatReports.aspx.cs @@ -23,9 +23,18 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers PageTitle = Resources.Pages.Ledgers.ViewVatReports_PageTitle; InfoBoxLiteral = Resources.Pages.Ledgers.ViewVatReports_Info; - // Security: If the org has open ledgers, then anyone may read. Otherwise, Financials.Read. + // Security: If the org has open ledgers, or key was given, then anyone may read. Otherwise, Financials.Read. - if (!String.IsNullOrEmpty(CurrentOrganization.OpenLedgersDomain)) + int specificReportId = 0; + VatReport specificReport = null; + string reportKey = Request.QueryString["ReportKey"]; + if (!string.IsNullOrEmpty(reportKey)) + { + specificReport = VatReport.FromGuid(reportKey); + specificReportId = specificReport.Identity; + } + + if (CurrentOrganization.HasOpenLedgers || specificReportId > 0) { PageAccessRequired = new Access(AccessAspect.Null, AccessType.Read); } @@ -37,23 +46,34 @@ namespace Swarmops.Frontend.Pages.v5.Ledgers if (!Page.IsPostBack) { + Localize(); + // Populate VAT report dropdown - // TODO: Disable if viewing specific report and not open ledgers - - VatReports reports = VatReports.ForOrganization(CurrentOrganization, true); - reports.Sort(VatReports.VatReportSorterByDate); - - foreach (VatReport report in reports) + if (specificReportId > 0 && !CurrentOrganization.HasOpenLedgers) { - this.DropReports.Items.Add(new ListItem(report.Description, - report.Identity.ToString(CultureInfo.InvariantCulture))); + // Show one single report + + this.LabelContentHeader.Text = specificReport.Description; + this.DropReports.Visible = false; + this.InitialReportId = specificReport.Identity; } + else + { + // Populate dropdown - this.InitialReportId = reports.Last().Identity; - this.DropReports.SelectedValue = this.InitialReportId.ToString(CultureInfo.InvariantCulture); + VatReports reports = VatReports.ForOrganization(CurrentOrganization, true); + reports.Sort(VatReports.VatReportSorterByDate); - Localize(); + foreach (VatReport report in reports) + { + this.DropReports.Items.Add(new ListItem(report.Description, + report.Identity.ToString(CultureInfo.InvariantCulture))); + } + + this.InitialReportId = reports.Last().Identity; + this.DropReports.SelectedValue = this.InitialReportId.ToString(CultureInfo.InvariantCulture); + } } RegisterControl(EasyUIControl.DataGrid | EasyUIControl.Tree);