Skip to content

Commit

Permalink
Merge pull request #591 from cabinetoffice/EHD-1043-manage-organisati…
Browse files Browse the repository at this point in the history
…ons-page

EHD-1043: Manage Organisations page
  • Loading branch information
jamesgriff authored Sep 25, 2024
2 parents 099b20f + d2338a8 commit d4b9138
Show file tree
Hide file tree
Showing 33 changed files with 393 additions and 1,504 deletions.
20 changes: 0 additions & 20 deletions GenderPayGap.Core/Enums.cs
Original file line number Diff line number Diff line change
Expand Up @@ -317,15 +317,6 @@ public enum ReminderEmailStatus : byte
Completed = 1
}

public enum ReportTag
{
Submitted = 0,
SubmittedLate = 1,
Due = 2,
Overdue = 3,
NotRequired = 4
}

public static class EnumHelper
{

Expand All @@ -347,17 +338,6 @@ public static class CookieNames
public const string LastCompareQuery = "compare";
}

public enum ReportStatusBadgeType
{
Due,
Overdue,
Reported,
NotRequired,
NotRequiredDueToCovid,
VoluntarilyReported,
SubmittedLate,
}

public enum ReportStatusTag
{
SubmittedVoluntarily,
Expand Down
14 changes: 10 additions & 4 deletions GenderPayGap.Core/Helpers/ReportingYearsHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace GenderPayGap.Core.Helpers
{
public static class ReportingYearsHelper
{
public static List<int> GetReportingYears()
public static List<int> GetReportingYears(SectorTypes sector = SectorTypes.Public)
{
int firstReportingYear = Global.FirstReportingYear;
int currentReportingYear = GetCurrentReportingYear();
int currentReportingYear = GetCurrentReportingYear(sector);
int numberOfYears = (currentReportingYear - firstReportingYear) + 1;

// Use a manual List capacity allocation and a for-loop to reduce memory usage
Expand All @@ -24,9 +24,9 @@ public static List<int> GetReportingYears()
return reportingYears;
}

public static int GetCurrentReportingYear()
public static int GetCurrentReportingYear(SectorTypes sector = SectorTypes.Public)
{
return SectorTypes.Public.GetAccountingStartDate().Year;
return sector.GetAccountingStartDate().Year;
}

public static int GetCurrentReportingYearForSector(SectorTypes sector)
Expand Down Expand Up @@ -107,5 +107,11 @@ public static bool IsReportingYearExcludedFromLateFlagEnforcement(int reportingY
return Global.ReportingStartYearsToExcludeFromLateFlagEnforcement.Contains(reportingYear);
}

public static bool CanChangeScope(SectorTypes sectorType, int reportingYear)
{
int currentReportingYear = sectorType.GetAccountingStartDate().Year;
int earliestAllowedReportingYear = currentReportingYear - (Global.EditableScopeCount - 1);
return reportingYear >= earliestAllowedReportingYear;
}
}
}
31 changes: 0 additions & 31 deletions GenderPayGap.Database/Models/Extensions/Organisation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -345,21 +345,6 @@ public bool HadSubmittedReturnAsOfDate(int reportingYear, DateTime asOfDate)
return GetReturnForYearAsOfDate(reportingYear, asOfDate) != null;
}

public IEnumerable<Return> GetRecentReports(int recentCount)
{
foreach (int year in GetRecentReportingYears(recentCount))
{
var defaultReturn = new Return {
Organisation = this,
AccountingDate = SectorType.GetAccountingStartDate(year),
Modified = VirtualDateTime.Now
};
defaultReturn.IsLateSubmission = defaultReturn.CalculateIsLateSubmission();

yield return GetReturn(year) ?? defaultReturn;
}
}

#endregion

/// <summary>
Expand Down Expand Up @@ -401,22 +386,6 @@ public override int GetHashCode()
return OrganisationId.GetHashCode();
}

[Obsolete("Use ReportingYearsHelper.GetReportingYears() instead")]
public IEnumerable<int> GetRecentReportingYears(int recentCount)
{
int endYear = SectorType.GetAccountingStartDate().Year;
int startYear = endYear - (recentCount - 1);
if (startYear < Global.FirstReportingYear)
{
startYear = Global.FirstReportingYear;
}

for (int year = endYear; year >= startYear; year--)
{
yield return year;
}
}

public bool IsSearchable()
{
return Status == Core.OrganisationStatuses.Active || Status == Core.OrganisationStatuses.Retired;
Expand Down

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ private void SendReminderEmailsAction(string runId)

private void SendReminderEmailsForSectorType(SectorTypes sector, string runId, DateTime startTime)
{
var activeReportingYears = GetActiveReportingYears(sector);
var activeReportingYears = ReportingYearsHelper.GetReportingYears(sector);
foreach (int year in activeReportingYears)
{
if (IsAfterEarliestReminderForReportingYear(sector, year))
Expand Down Expand Up @@ -316,12 +316,5 @@ private static List<int> GetReminderEmailDays()
return reminderEmailDays;
}

private static List<int> GetActiveReportingYears(SectorTypes sectorType)
{
return ReportingYearsHelper.GetReportingYears()
.Where(year => GetDeadlineDateForReportingYear(sectorType, year) > VirtualDateTime.Now)
.ToList();
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -597,7 +597,7 @@ private static IEnumerable<dynamic> BuildOrganisationsWithNoSubmittedReturnsReco
record.PhoneNumber = latestUserOrg?.User.ContactPhoneNumber;
record.EmailAddress = latestUserOrg?.User.EmailAddress;

foreach (int repYear in ReportingYearsHelper.GetReportingYears())
foreach (int repYear in ReportingYearsHelper.GetReportingYears(org.SectorType))
{
((IDictionary<string, object>) record)["ReportDateTimeFor" + repYear] = org.GetReturn(repYear)?.StatusDate;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ private void UpdateAdminChangeMultipleScopesViewModelFromOrganisation(AdminChang
{
viewModel.Organisation = organisation;

foreach (int reportingYear in ReportingYearsHelper.GetReportingYears())
foreach (int reportingYear in ReportingYearsHelper.GetReportingYears(organisation.SectorType))
{
if (!viewModel.Years.Any(y => y.ReportingYear == reportingYear))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ private void UpdateAdminChangeStatusViewModelFromOrganisation(AdminChangeOrganis
organisation.Status == OrganisationStatuses.Pending ||
organisation.Status == OrganisationStatuses.Active)
{
foreach (int reportingYear in ReportingYearsHelper.GetReportingYears())
foreach (int reportingYear in ReportingYearsHelper.GetReportingYears(organisation.SectorType))
{
if (!viewModel.Years.Any(y => y.ReportingYear == reportingYear))
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using System.Linq;
using GenderPayGap.Core;
using GenderPayGap.Core.Classes;
using GenderPayGap.Core.Helpers;
using GenderPayGap.Core.Interfaces;
using GenderPayGap.Database;
using GenderPayGap.WebUI.Helpers;
Expand All @@ -28,10 +29,7 @@ public IActionResult ViewOrganisation(long id)
{
Organisation organisation = dataRepository.Get<Organisation>(id);

int firstReportingYear = Global.FirstReportingYear;
int currentReportingYear = SectorTypes.Public.GetAccountingStartDate().Year;
int numberOfYears = currentReportingYear - firstReportingYear + 1;
List<int> reportingYears = Enumerable.Range(firstReportingYear, numberOfYears).Reverse().ToList();
List<int> reportingYears = ReportingYearsHelper.GetReportingYears(organisation.SectorType).OrderByDescending(year => year).ToList();

var viewModel = new AdminViewOrganisationViewModel
{
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.Linq;
using GenderPayGap.Core;
using GenderPayGap.Core.Classes;
using GenderPayGap.Core.Interfaces;
using GenderPayGap.Database;
Expand Down Expand Up @@ -71,45 +70,6 @@ public IActionResult ManageOrganisationGet(string encryptedOrganisationId)
return View("ManageOrganisation", viewModel);
}

[HttpGet("{encryptedOrganisationId}/all-reports")]
[Authorize(Roles = LoginRoles.GpgEmployer)]
public IActionResult AllOrganisationReportsGet(string encryptedOrganisationId, int? page = 1)
{
long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId);
User user = ControllerHelper.GetGpgUserFromAspNetUser(User, dataRepository);
ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(user);
ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId);

var organisation = dataRepository.Get<Organisation>(organisationId);
if (OrganisationIsNewThisYearAndHasNotProvidedScopeForLastYear(organisation))
{
return RedirectToAction("DeclareScopeGet", "Scope", new { encryptedOrganisationId = encryptedOrganisationId });
}

// build the view model
List<DraftReturn> allDraftReturns =
dataRepository.GetAll<DraftReturn>()
.Where(d => d.OrganisationId == organisationId)
.ToList();

var totalEntries = organisation.GetRecentReports(Global.ShowReportYearCount).Count() + 1; // Years we report for + the year they joined
var maxEntriesPerPage = 10;
var totalPages = (int)Math.Ceiling((double)totalEntries / maxEntriesPerPage);

if (page < 1)
{
page = 1;
}

if (page > totalPages)
{
page = totalPages;
}

var viewModel = new AllOrganisationReportsViewModel(organisation, user, allDraftReturns, page, totalPages, maxEntriesPerPage);
return View("AllOrganisationReports", viewModel);
}

private static bool OrganisationIsNewThisYearAndHasNotProvidedScopeForLastYear(Organisation organisation)
{
DateTime currentYearSnapshotDate = organisation.SectorType.GetAccountingStartDate();
Expand Down
Loading

0 comments on commit d4b9138

Please sign in to comment.