From b1aa9711a203df8a7c4f4fd2fce07ee3be3f31fa Mon Sep 17 00:00:00 2001 From: James Griffiths Date: Tue, 24 Sep 2024 17:57:43 +0100 Subject: [PATCH 1/3] EHD-1043: ReportingYearsHelper.GetReportingYears - add ability to specify sector --- GenderPayGap.Core/Helpers/ReportingYearsHelper.cs | 10 +++++----- .../ScheduledJobs/SendReminderEmailsJob.cs | 9 +-------- .../Controllers/Admin/AdminDownloadsController.cs | 2 +- .../Admin/AdminOrganisationScopeController.cs | 2 +- .../Admin/AdminOrganisationStatusController.cs | 2 +- .../Admin/AdminViewOrganisationController.cs | 6 ++---- .../Controllers/Report/LateSubmissionController.cs | 6 +++--- .../Controllers/Report/ReportConfirmationController.cs | 2 +- .../Controllers/Report/ReportDiscardDraftController.cs | 4 ++-- .../Controllers/Report/ReportFiguresController.cs | 4 ++-- .../Report/ReportLinkToWebsiteController.cs | 4 ++-- .../Controllers/Report/ReportOverviewController.cs | 4 ++-- .../Report/ReportResponsiblePersonController.cs | 4 ++-- .../Report/ReportSizeOfOrganisationController.cs | 4 ++-- .../Controllers/Report/ReportStartingController.cs | 2 +- GenderPayGap.WebUI/Controllers/ScopeController.cs | 10 +++++----- GenderPayGap.WebUI/Helpers/ControllerHelper.cs | 6 ++++-- .../AllOrganisationReportsViewModel.cs | 2 +- .../ManageOrganisations/ManageOrganisationViewModel.cs | 4 ++-- GenderPayGap.WebUI/Views/ViewReports/Employer.cshtml | 2 +- 20 files changed, 41 insertions(+), 48 deletions(-) diff --git a/GenderPayGap.Core/Helpers/ReportingYearsHelper.cs b/GenderPayGap.Core/Helpers/ReportingYearsHelper.cs index 52649fd88..43f76e68b 100644 --- a/GenderPayGap.Core/Helpers/ReportingYearsHelper.cs +++ b/GenderPayGap.Core/Helpers/ReportingYearsHelper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using GenderPayGap.Core.Classes; @@ -8,10 +8,10 @@ namespace GenderPayGap.Core.Helpers { public static class ReportingYearsHelper { - public static List GetReportingYears() + public static List 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 @@ -24,9 +24,9 @@ public static List 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) diff --git a/GenderPayGap.WebUI/BackgroundJobs/ScheduledJobs/SendReminderEmailsJob.cs b/GenderPayGap.WebUI/BackgroundJobs/ScheduledJobs/SendReminderEmailsJob.cs index 3919b3779..22771dfec 100644 --- a/GenderPayGap.WebUI/BackgroundJobs/ScheduledJobs/SendReminderEmailsJob.cs +++ b/GenderPayGap.WebUI/BackgroundJobs/ScheduledJobs/SendReminderEmailsJob.cs @@ -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)) @@ -316,12 +316,5 @@ private static List GetReminderEmailDays() return reminderEmailDays; } - private static List GetActiveReportingYears(SectorTypes sectorType) - { - return ReportingYearsHelper.GetReportingYears() - .Where(year => GetDeadlineDateForReportingYear(sectorType, year) > VirtualDateTime.Now) - .ToList(); - } - } } diff --git a/GenderPayGap.WebUI/Controllers/Admin/AdminDownloadsController.cs b/GenderPayGap.WebUI/Controllers/Admin/AdminDownloadsController.cs index 6c149c65a..832b55a52 100644 --- a/GenderPayGap.WebUI/Controllers/Admin/AdminDownloadsController.cs +++ b/GenderPayGap.WebUI/Controllers/Admin/AdminDownloadsController.cs @@ -597,7 +597,7 @@ private static IEnumerable 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) record)["ReportDateTimeFor" + repYear] = org.GetReturn(repYear)?.StatusDate; } diff --git a/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationScopeController.cs b/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationScopeController.cs index c2956732c..6fa1b8edb 100644 --- a/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationScopeController.cs +++ b/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationScopeController.cs @@ -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)) { diff --git a/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationStatusController.cs b/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationStatusController.cs index 5f7320e4b..3f714115c 100644 --- a/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationStatusController.cs +++ b/GenderPayGap.WebUI/Controllers/Admin/AdminOrganisationStatusController.cs @@ -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)) { diff --git a/GenderPayGap.WebUI/Controllers/Admin/AdminViewOrganisationController.cs b/GenderPayGap.WebUI/Controllers/Admin/AdminViewOrganisationController.cs index 45727d089..e2592eb24 100644 --- a/GenderPayGap.WebUI/Controllers/Admin/AdminViewOrganisationController.cs +++ b/GenderPayGap.WebUI/Controllers/Admin/AdminViewOrganisationController.cs @@ -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; @@ -28,10 +29,7 @@ public IActionResult ViewOrganisation(long id) { Organisation organisation = dataRepository.Get(id); - int firstReportingYear = Global.FirstReportingYear; - int currentReportingYear = SectorTypes.Public.GetAccountingStartDate().Year; - int numberOfYears = currentReportingYear - firstReportingYear + 1; - List reportingYears = Enumerable.Range(firstReportingYear, numberOfYears).Reverse().ToList(); + List reportingYears = ReportingYearsHelper.GetReportingYears(organisation.SectorType).OrderByDescending(year => year).ToList(); var viewModel = new AdminViewOrganisationViewModel { diff --git a/GenderPayGap.WebUI/Controllers/Report/LateSubmissionController.cs b/GenderPayGap.WebUI/Controllers/Report/LateSubmissionController.cs index 13b1c6b58..86844d749 100644 --- a/GenderPayGap.WebUI/Controllers/Report/LateSubmissionController.cs +++ b/GenderPayGap.WebUI/Controllers/Report/LateSubmissionController.cs @@ -38,7 +38,7 @@ public IActionResult LateSubmissionWarningGet(string encryptedOrganisationId, in long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); var viewModel = new LateSubmissionWarningViewModel(); Organisation organisation = dataRepository.Get(organisationId); @@ -55,7 +55,7 @@ public IActionResult LateSubmissionReasonGet(string encryptedOrganisationId, int long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); if (!draftReturnService.DraftReturnExistsAndRequiredFieldsAreComplete(organisationId, reportingYear)) { @@ -83,7 +83,7 @@ public IActionResult LateSubmissionReasonPost(string encryptedOrganisationId, in long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); if (!draftReturnService.DraftReturnExistsAndRequiredFieldsAreComplete(organisationId, reportingYear)) { diff --git a/GenderPayGap.WebUI/Controllers/Report/ReportConfirmationController.cs b/GenderPayGap.WebUI/Controllers/Report/ReportConfirmationController.cs index 3e2c87bb5..9a74b1293 100644 --- a/GenderPayGap.WebUI/Controllers/Report/ReportConfirmationController.cs +++ b/GenderPayGap.WebUI/Controllers/Report/ReportConfirmationController.cs @@ -28,7 +28,7 @@ public IActionResult ReportConfirmation(string encryptedOrganisationId, int repo long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); Return foundReturn = LoadReturnFromOrganisationIdReportingYearAndConfirmationId(organisationId, reportingYear, confirmationId); diff --git a/GenderPayGap.WebUI/Controllers/Report/ReportDiscardDraftController.cs b/GenderPayGap.WebUI/Controllers/Report/ReportDiscardDraftController.cs index 7911a47b8..ab20d47cb 100644 --- a/GenderPayGap.WebUI/Controllers/Report/ReportDiscardDraftController.cs +++ b/GenderPayGap.WebUI/Controllers/Report/ReportDiscardDraftController.cs @@ -32,7 +32,7 @@ public IActionResult ReportDiscardDraftGet(string encryptedOrganisationId, int r long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); DraftReturn draftReturn = draftReturnService.GetDraftReturn(organisationId, reportingYear); bool draftReturnExists = draftReturn != null; @@ -68,7 +68,7 @@ public IActionResult ReportDiscardDraftPost(string encryptedOrganisationId, int long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); DraftReturn draftReturn = draftReturnService.GetDraftReturn(organisationId, reportingYear); bool draftReturnExists = draftReturn != null; diff --git a/GenderPayGap.WebUI/Controllers/Report/ReportFiguresController.cs b/GenderPayGap.WebUI/Controllers/Report/ReportFiguresController.cs index ef07fdc45..466f0b8aa 100644 --- a/GenderPayGap.WebUI/Controllers/Report/ReportFiguresController.cs +++ b/GenderPayGap.WebUI/Controllers/Report/ReportFiguresController.cs @@ -36,7 +36,7 @@ public IActionResult ReportFiguresGet(string encryptedOrganisationId, int report ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); var viewModel = new ReportFiguresViewModel(); @@ -73,7 +73,7 @@ public IActionResult ReportFiguresPost(string encryptedOrganisationId, int repor ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); ReportFiguresHelper.ValidateUserInput(ModelState, viewModel, reportingYear); diff --git a/GenderPayGap.WebUI/Controllers/Report/ReportLinkToWebsiteController.cs b/GenderPayGap.WebUI/Controllers/Report/ReportLinkToWebsiteController.cs index 9dc210d5d..e930bbbc1 100644 --- a/GenderPayGap.WebUI/Controllers/Report/ReportLinkToWebsiteController.cs +++ b/GenderPayGap.WebUI/Controllers/Report/ReportLinkToWebsiteController.cs @@ -32,7 +32,7 @@ public IActionResult ReportLinkToWebsiteGet(string encryptedOrganisationId, int long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); var viewModel = new ReportLinkToWebsiteViewModel(); PopulateViewModel(viewModel, organisationId, reportingYear); @@ -85,7 +85,7 @@ public IActionResult ReportLinkToWebsitePost(string encryptedOrganisationId, int long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); ValidateUserInput(viewModel); diff --git a/GenderPayGap.WebUI/Controllers/Report/ReportOverviewController.cs b/GenderPayGap.WebUI/Controllers/Report/ReportOverviewController.cs index c68ef9053..235b9a9cd 100644 --- a/GenderPayGap.WebUI/Controllers/Report/ReportOverviewController.cs +++ b/GenderPayGap.WebUI/Controllers/Report/ReportOverviewController.cs @@ -37,7 +37,7 @@ public IActionResult SubmitReturnPost(string encryptedOrganisationId, int report long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); DraftReturn draftReturn = draftReturnService.GetDraftReturn(organisationId, reportingYear); @@ -78,7 +78,7 @@ public IActionResult ReportOverview(string encryptedOrganisationId, int reportin long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); if (draftReturnService.ShouldShowLateWarning(organisationId, reportingYear) && canTriggerLateSubmissionWarning) { diff --git a/GenderPayGap.WebUI/Controllers/Report/ReportResponsiblePersonController.cs b/GenderPayGap.WebUI/Controllers/Report/ReportResponsiblePersonController.cs index 60cfde2a2..e073b8bb7 100644 --- a/GenderPayGap.WebUI/Controllers/Report/ReportResponsiblePersonController.cs +++ b/GenderPayGap.WebUI/Controllers/Report/ReportResponsiblePersonController.cs @@ -32,7 +32,7 @@ public IActionResult ReportResponsiblePersonGet(string encryptedOrganisationId, long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); Organisation organisation = dataRepository.Get(organisationId); if (organisation.SectorType == SectorTypes.Public) @@ -97,7 +97,7 @@ public IActionResult ReportResponsiblePersonPost(string encryptedOrganisationId, long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); Organisation organisation = dataRepository.Get(organisationId); if (organisation.SectorType == SectorTypes.Public) diff --git a/GenderPayGap.WebUI/Controllers/Report/ReportSizeOfOrganisationController.cs b/GenderPayGap.WebUI/Controllers/Report/ReportSizeOfOrganisationController.cs index 516c8943a..f815ff520 100644 --- a/GenderPayGap.WebUI/Controllers/Report/ReportSizeOfOrganisationController.cs +++ b/GenderPayGap.WebUI/Controllers/Report/ReportSizeOfOrganisationController.cs @@ -31,7 +31,7 @@ public IActionResult ReportSizeOfOrganisationGet(string encryptedOrganisationId, long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); var viewModel = new ReportSizeOfOrganisationViewModel(); PopulateViewModel(viewModel, organisationId, reportingYear, initialSubmission); @@ -85,7 +85,7 @@ public IActionResult ReportSizeOfOrganisationPost(string encryptedOrganisationId long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); if (!ModelState.IsValid) { diff --git a/GenderPayGap.WebUI/Controllers/Report/ReportStartingController.cs b/GenderPayGap.WebUI/Controllers/Report/ReportStartingController.cs index 985e3b3fc..48831bc05 100644 --- a/GenderPayGap.WebUI/Controllers/Report/ReportStartingController.cs +++ b/GenderPayGap.WebUI/Controllers/Report/ReportStartingController.cs @@ -28,7 +28,7 @@ public IActionResult ReportingStart(string encryptedOrganisationId, int reportin ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); var viewModel = new ReportStartingViewModel(); diff --git a/GenderPayGap.WebUI/Controllers/ScopeController.cs b/GenderPayGap.WebUI/Controllers/ScopeController.cs index b0271b855..22a36a269 100644 --- a/GenderPayGap.WebUI/Controllers/ScopeController.cs +++ b/GenderPayGap.WebUI/Controllers/ScopeController.cs @@ -39,7 +39,7 @@ public IActionResult ChangeOrganisationScope(string encryptedOrganisationId, int long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); // Get Organisation and OrganisationScope for reporting year Organisation organisation = dataRepository.Get(organisationId); @@ -57,7 +57,7 @@ public IActionResult SubmitOutOfScopeAnswers(string encryptedOrganisationId, int long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); // Get Organisation and OrganisationScope for reporting year Organisation organisation = dataRepository.Get(organisationId); @@ -81,7 +81,7 @@ public IActionResult ConfirmOutOfScopeAnswers(string encryptedOrganisationId, in long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); // Get Organisation Organisation organisation = dataRepository.Get(organisationId); @@ -116,7 +116,7 @@ public IActionResult ConfirmInScopeAnswers(string encryptedOrganisationId, int r long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); // Get Organisation and OrganisationScope for reporting year Organisation organisation = dataRepository.Get(organisationId); @@ -140,7 +140,7 @@ public IActionResult ScopeDeclared(string encryptedOrganisationId, int reporting long organisationId = ControllerHelper.DecryptOrganisationIdOrThrow404(encryptedOrganisationId); ControllerHelper.ThrowIfUserAccountRetiredOrEmailNotVerified(User, dataRepository); ControllerHelper.ThrowIfUserDoesNotHavePermissionsForGivenOrganisation(User, dataRepository, organisationId); - ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear); + ControllerHelper.ThrowIfReportingYearIsOutsideOfRange(reportingYear, organisationId, dataRepository); // Get Organisation and OrganisationScope for reporting year Organisation organisation = dataRepository.Get(organisationId); diff --git a/GenderPayGap.WebUI/Helpers/ControllerHelper.cs b/GenderPayGap.WebUI/Helpers/ControllerHelper.cs index 880ed9c9d..d7060692e 100644 --- a/GenderPayGap.WebUI/Helpers/ControllerHelper.cs +++ b/GenderPayGap.WebUI/Helpers/ControllerHelper.cs @@ -203,9 +203,11 @@ public static User LoadUserOrThrow404(long userId, IDataRepository dataRepositor return user; } - public static void ThrowIfReportingYearIsOutsideOfRange(int reportingYear) + public static void ThrowIfReportingYearIsOutsideOfRange(int reportingYear, long organisationId, IDataRepository dataRepository) { - if (!ReportingYearsHelper.GetReportingYears().Contains(reportingYear)) + Organisation organisation = dataRepository.Get(organisationId); + + if (!ReportingYearsHelper.GetReportingYears(organisation.SectorType).Contains(reportingYear)) { throw new PageNotFoundException(); } diff --git a/GenderPayGap.WebUI/Models/ManageOrganisations/AllOrganisationReportsViewModel.cs b/GenderPayGap.WebUI/Models/ManageOrganisations/AllOrganisationReportsViewModel.cs index c9618ee06..cf5d267b9 100644 --- a/GenderPayGap.WebUI/Models/ManageOrganisations/AllOrganisationReportsViewModel.cs +++ b/GenderPayGap.WebUI/Models/ManageOrganisations/AllOrganisationReportsViewModel.cs @@ -33,7 +33,7 @@ public AllOrganisationReportsViewModel(Database.Organisation organisation, User public List GetOrganisationDetailsForYears() { - List reportingYears = ReportingYearsHelper.GetReportingYears(); + List reportingYears = ReportingYearsHelper.GetReportingYears(Organisation.SectorType); var detailsForYears = new List(); foreach (int reportingYear in reportingYears) diff --git a/GenderPayGap.WebUI/Models/ManageOrganisations/ManageOrganisationViewModel.cs b/GenderPayGap.WebUI/Models/ManageOrganisations/ManageOrganisationViewModel.cs index c4bcc9668..932505e8d 100644 --- a/GenderPayGap.WebUI/Models/ManageOrganisations/ManageOrganisationViewModel.cs +++ b/GenderPayGap.WebUI/Models/ManageOrganisations/ManageOrganisationViewModel.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using GenderPayGap.Core; @@ -44,7 +44,7 @@ public List GetFullyRegisteredUsersForOrganisationWithCurrentUserFirst() public List GetOrganisationDetailsForYears() { - List reportingYears = ReportingYearsHelper.GetReportingYears(); + List reportingYears = ReportingYearsHelper.GetReportingYears(Organisation.SectorType); var detailsForYears = new List(); foreach (int reportingYear in reportingYears) diff --git a/GenderPayGap.WebUI/Views/ViewReports/Employer.cshtml b/GenderPayGap.WebUI/Views/ViewReports/Employer.cshtml index 4de25a98a..09760e216 100644 --- a/GenderPayGap.WebUI/Views/ViewReports/Employer.cshtml +++ b/GenderPayGap.WebUI/Views/ViewReports/Employer.cshtml @@ -167,7 +167,7 @@ - @foreach (int reportingYear in ReportingYearsHelper.GetReportingYears().OrderByDescending(y => y)) + @foreach (int reportingYear in ReportingYearsHelper.GetReportingYears(Model.SectorType).OrderByDescending(y => y)) { Return returnForYear = Model.GetReturn(reportingYear); ReportStatusTag reportStatusTag = ReportStatusTagHelper.GetReportStatusTag(Model, reportingYear); From 37b3f1485d9bfb7631b7079d61af766c27d2414d Mon Sep 17 00:00:00 2001 From: James Griffiths Date: Wed, 25 Sep 2024 10:17:48 +0100 Subject: [PATCH 2/3] EHD-1043: Manage Organisations page: Simplify page and fix badge bug --- .../Helpers/ReportingYearsHelper.cs | 8 +- .../Helpers/ReportStatusTagHelper.cs | 8 +- .../ManageOrganisationViewModel.cs | 44 ++- .../ManageOrganisation.cshtml | 282 ++++++++++++++++-- .../ReportStatusBadge.cshtml | 75 +++++ 5 files changed, 380 insertions(+), 37 deletions(-) create mode 100644 GenderPayGap.WebUI/Views/ManageOrganisations/ReportStatusBadge.cshtml diff --git a/GenderPayGap.Core/Helpers/ReportingYearsHelper.cs b/GenderPayGap.Core/Helpers/ReportingYearsHelper.cs index 43f76e68b..9ebf6ba4a 100644 --- a/GenderPayGap.Core/Helpers/ReportingYearsHelper.cs +++ b/GenderPayGap.Core/Helpers/ReportingYearsHelper.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.Linq; using GenderPayGap.Core.Classes; @@ -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; + } } } diff --git a/GenderPayGap.WebUI/Helpers/ReportStatusTagHelper.cs b/GenderPayGap.WebUI/Helpers/ReportStatusTagHelper.cs index 1a41832dc..9708ba9b2 100644 --- a/GenderPayGap.WebUI/Helpers/ReportStatusTagHelper.cs +++ b/GenderPayGap.WebUI/Helpers/ReportStatusTagHelper.cs @@ -30,14 +30,14 @@ public static ReportStatusTag GetReportStatusTag(Organisation organisation, int else { // Report has not been submitted - if (Global.ReportingStartYearsToExcludeFromLateFlagEnforcement.Contains(reportingYear)) + if (!organisation.GetScopeStatusForYear(reportingYear).IsInScopeVariant()) { - return ReportStatusTag.NotRequiredDueToCovid; + return ReportStatusTag.NotRequired; } - if (!organisation.GetScopeStatusForYear(reportingYear).IsInScopeVariant()) + if (Global.ReportingStartYearsToExcludeFromLateFlagEnforcement.Contains(reportingYear)) { - return ReportStatusTag.NotRequired; + return ReportStatusTag.NotRequiredDueToCovid; } if (ReportingYearsHelper.DeadlineHasPassedForYearAndSector(reportingYear, organisation.SectorType)) diff --git a/GenderPayGap.WebUI/Models/ManageOrganisations/ManageOrganisationViewModel.cs b/GenderPayGap.WebUI/Models/ManageOrganisations/ManageOrganisationViewModel.cs index 932505e8d..b176fb04e 100644 --- a/GenderPayGap.WebUI/Models/ManageOrganisations/ManageOrganisationViewModel.cs +++ b/GenderPayGap.WebUI/Models/ManageOrganisations/ManageOrganisationViewModel.cs @@ -6,20 +6,18 @@ using GenderPayGap.Core.Helpers; using GenderPayGap.Database; using GenderPayGap.Database.Models; -using GenderPayGap.Extensions; -using GenderPayGap.WebUI.Classes; namespace GenderPayGap.WebUI.Models.ManageOrganisations { public class ManageOrganisationViewModel { - public Database.Organisation Organisation { get; } + public Organisation Organisation { get; } public User User { get; } private readonly List allDraftReturns; - public ManageOrganisationViewModel(Database.Organisation organisation, User user, List allDraftReturns) + public ManageOrganisationViewModel(Organisation organisation, User user, List allDraftReturns) { Organisation = organisation; User = user; @@ -31,6 +29,7 @@ public List GetFullyRegisteredUsersForOrganisationWithCurrentUserFirst() List users = Organisation.UserOrganisations .Where(uo => uo.PINConfirmedDate.HasValue) .Select(uo => uo.User) + .OrderBy(user => user.Fullname) .ToList(); // The current user must be in this list (otherwise we wouldn't be able to visit this page) @@ -42,6 +41,43 @@ public List GetFullyRegisteredUsersForOrganisationWithCurrentUserFirst() return users; } + public bool DoesReturnOrDraftReturnExistForYear(int reportingYear) + { + bool hasReturnForYear = Organisation.HasSubmittedReturn(reportingYear); + bool hasDraftReturnForYear = allDraftReturns.Any(d => d.SnapshotYear == reportingYear); + + return hasReturnForYear || hasDraftReturnForYear; + } + + public string GetReportLinkText(int reportingYear) + { + bool hasReturnForYear = Organisation.HasSubmittedReturn(reportingYear); + bool hasDraftReturnForYear = allDraftReturns.Any(d => d.SnapshotYear == reportingYear); + + if (!hasReturnForYear && !hasDraftReturnForYear) + { + return "Draft report"; + } + + if (!hasReturnForYear && hasDraftReturnForYear) + { + return "Edit draft"; + } + + if (hasReturnForYear && !hasDraftReturnForYear) + { + return "Edit report"; + } + + return "Edit draft report"; + } + + public bool OrganisationIsRequiredToSubmit(int reportingYear) + { + return Organisation.GetScopeForYear(reportingYear).IsInScopeVariant() + && !Global.ReportingStartYearsToExcludeFromLateFlagEnforcement.Contains(reportingYear); + } + public List GetOrganisationDetailsForYears() { List reportingYears = ReportingYearsHelper.GetReportingYears(Organisation.SectorType); diff --git a/GenderPayGap.WebUI/Views/ManageOrganisations/ManageOrganisation.cshtml b/GenderPayGap.WebUI/Views/ManageOrganisations/ManageOrganisation.cshtml index 529b3eb70..041377020 100644 --- a/GenderPayGap.WebUI/Views/ManageOrganisations/ManageOrganisation.cshtml +++ b/GenderPayGap.WebUI/Views/ManageOrganisations/ManageOrganisation.cshtml @@ -1,5 +1,8 @@ @using GenderPayGap.Core +@using GenderPayGap.Core.Helpers @using GenderPayGap.Database +@using GenderPayGap.WebUI.Helpers +@using GenderPayGap.WebUI.Models.ViewReports @using GovUkDesignSystem @using GovUkDesignSystem.GovUkDesignSystemComponents @model GenderPayGap.WebUI.Models.ManageOrganisations.ManageOrganisationViewModel @@ -42,44 +45,267 @@ for @(Model.Organisation.OrganisationName) - -
+ + +

+ Your employer's reports +

+ + + + + + + + + + + + @foreach (int reportingYear in ReportingYearsHelper.GetReportingYears(Model.Organisation.SectorType).OrderByDescending(y => y)) + { + bool requiredToReportForYear = Model.OrganisationIsRequiredToSubmit(reportingYear); + ReportStatusTag reportStatusTag = ReportStatusTagHelper.GetReportStatusTag(Model.Organisation, reportingYear); + + + + + + + + + + + } + +
+ Deadline + + Reporting requirement + + Report status + + + Action + +
+ @(ReportingYearsHelper.GetDeadline(Model.Organisation.SectorType, reportingYear).ToString("d MMM yyyy")) + + You + @(requiredToReportForYear ? "are required" : "are not required") + to report. + @if (ReportingYearsHelper.CanChangeScope(Model.Organisation.SectorType, reportingYear)) + { +
+ + Think this is wrong? + + Change scope for year @(ReportingYearsHelper.FormatYearAsReportingPeriod(reportingYear)) + + + } +
+ @await Html.PartialAsync("ReportStatusBadge", + new ReportStatusBadgeViewModel + { + ReportStatusTag = reportStatusTag, + ReportSubmittedDate = Model.Organisation.GetReturn(reportingYear)?.Modified, + DeadlineDate = ReportingYearsHelper.GetDeadline(Model.Organisation.SectorType, reportingYear) + }) + + @if (requiredToReportForYear && + ReportingYearsHelper.IsReportingYearExcludedFromLateFlagEnforcement(reportingYear) && + (reportStatusTag == ReportStatusTag.NotRequiredDueToCovid || + reportStatusTag == ReportStatusTag.Overdue || + reportStatusTag == ReportStatusTag.SubmittedLate)) + { +
+
+ The deadline for 2019-20 was + @(ReportingYearsHelper.GetDeadline(Model.Organisation.SectorType, 2019).ToString("d MMMM yyyy")). + Due to Coronavirus (COVID-19), enforcement of reporting deadlines does not + apply to employers in the 2019-20 reporting year. +
+ } +
+ @if (Model.DoesReturnOrDraftReturnExistForYear(reportingYear)) + { + + @Model.GetReportLinkText(reportingYear) + + } + else + { + + @Model.GetReportLinkText(reportingYear) + + } +
+ +

+ Registered users +

+ + @{ + List usersRegisteredToReportForOrganisation = Model.GetFullyRegisteredUsersForOrganisationWithCurrentUserFirst(); + } + + @if (usersRegisteredToReportForOrganisation.Count == 1) // If s User can view this page, then there will always be at least 1 User - themselves! + { +

+ You are the only person registered to report for this employer. +

+

+ If you remove yourself: +

+
    +
  • You will not be able to report for this employer
  • +
  • Someone else must register to report on behalf of this employer - this can take up to a week
  • +
  • Your account will remain open
  • +
+ } + else + { +

+ The following people are registered to report gender pay gap information for this employer: +

+ } + + + + + + + + + + + @foreach (User userRegisteredToReport in usersRegisteredToReportForOrganisation) + { + string encryptedUserId = Encryption.EncryptQuerystring(userRegisteredToReport.UserId.ToString()); + + + + + + + } + +
+ Name + + Email address + + + Action + +
+ @(userRegisteredToReport.Fullname) + @if (userRegisteredToReport.UserId == Model.User.UserId) + { + (You) + } + + @(userRegisteredToReport.EmailAddress) + + + Remove user + + @(userRegisteredToReport.Fullname) + + +
+ + +

+ Employer details +

+ +
Need to make changes to your employer's details? -
- If you are a private or voluntary employer and need to change your employer name, sector information, - or address you should do this via Companies House. Changes you make will automatically be reflected on this service. - If this information is not available on Companies House, please contact - - @Global.GpgReportingEmail - -
+ + @if (Model.Organisation.SectorType == SectorTypes.Private && + !string.IsNullOrWhiteSpace(Model.Organisation.CompanyNumber) && + !Model.Organisation.OptedOutFromCompaniesHouseUpdate) + { +
+

+ If you need to change your employer name, sector information, or registered address you should do this via Companies House. + Changes you make will automatically be reflected on this service. +

+

+ If this information is not available on Companies House, please contact + + @Global.GpgReportingEmail + +

+
+ } + else + { +
+ Please contact + + @Global.GpgReportingEmail + +
+ }
- @{ - await Html.RenderPartialAsync("OrganisationReportsTable", Model); - -
-

- See all reports -

+
+
+
+ Employer name +
+
+ @(Model.Organisation.OrganisationName) +
- await Html.RenderPartialAsync("UsersRegisteredToReportForOrganisation", Model); - } - -

- Registered Address -

-

- @foreach (string addressLine in Model.Organisation.GetLatestAddress().GetAddressLines()) +

+
+ Registered address +
+
+ @foreach (string addressLine in Model.Organisation.GetLatestAddress().GetAddressLines()) + { + @(addressLine)
+ } +
+
+ @if (Model.Organisation.GetSicCodes().Any()) { - @(addressLine)
+
+
+ Nature of business +
+ (SIC codes) +
+
+
    + @foreach (OrganisationSicCode organisationSicCode in Model.Organisation.OrganisationSicCodes.Where(osc => !osc.IsRetired())) + { +
  • + @(organisationSicCode.SicCode.SicCodeId) + @(organisationSicCode.SicCode.Description) +
    + + part of: @(organisationSicCode.SicCode.SicSection.Description) + +
  • + } +
+
+
} -

- +
diff --git a/GenderPayGap.WebUI/Views/ManageOrganisations/ReportStatusBadge.cshtml b/GenderPayGap.WebUI/Views/ManageOrganisations/ReportStatusBadge.cshtml new file mode 100644 index 000000000..57526ac14 --- /dev/null +++ b/GenderPayGap.WebUI/Views/ManageOrganisations/ReportStatusBadge.cshtml @@ -0,0 +1,75 @@ +@model GenderPayGap.WebUI.Models.ViewReports.ReportStatusBadgeViewModel +@using GenderPayGap.Core +@using GovUkDesignSystem +@using GovUkDesignSystem.GovUkDesignSystemComponents + +@{ + Func reportTagHtml = null; + string reportTagColour = ""; + + + switch(Model.ReportStatusTag) + { + case ReportStatusTag.SubmittedVoluntarily: + reportTagHtml = @Reported voluntarily; + reportTagColour = "govuk-tag--green"; + break; + + case ReportStatusTag.SubmittedLate: + reportTagHtml = @ + Submitted late + @if (Model.ReportSubmittedDate.HasValue) + { + + on +
+ @Model.ReportSubmittedDate.Value.ToString("d MMMM yyyy") +
+ } +
; + reportTagColour = "govuk-tag--orange"; + break; + + case ReportStatusTag.Submitted: + reportTagHtml = @Reported; + reportTagColour = "govuk-tag--green"; + break; + + case ReportStatusTag.Due: + reportTagHtml = @ + Due on +
+ @Model.DeadlineDate.ToString("d MMMM yyyy") +
; + reportTagColour = "govuk-tag--blue"; + break; + case ReportStatusTag.Overdue: + int daysOverdue = VirtualDateTime.Now.Date.Subtract(Model.DeadlineDate).TotalDays.ToInt32(); + reportTagHtml = @ + @(daysOverdue) + @(daysOverdue == 1 ? "day" : "days") + overdue + ; + reportTagColour = "govuk-tag--red"; + break; + case ReportStatusTag.NotRequired: + reportTagHtml = @ + Not required + ; + reportTagColour = "govuk-tag--grey"; + break; + case ReportStatusTag.NotRequiredDueToCovid: + reportTagHtml = @ + Not required due to COVID + ; + reportTagColour = "govuk-tag--grey"; + break; + + } +} + +@await Html.GovUkTag(new TagViewModel +{ + Html = reportTagHtml, + Classes = reportTagColour +}) From d2338a81efe8062ce675843fd5d462b4d2d16aa1 Mon Sep 17 00:00:00 2001 From: James Griffiths Date: Wed, 25 Sep 2024 10:23:00 +0100 Subject: [PATCH 3/3] EHD-1043: Manage Organisations page: Remove unused code --- GenderPayGap.Core/Enums.cs | 20 -- .../Models/Extensions/Organisation.cs | 31 -- .../DatabaseTests/OrganisationTests.cs | 71 ---- .../ManageOrganisations/ManageOrganisation.cs | 84 ----- .../ManageOrganisationsController.cs | 40 --- .../AllOrganisationReportsViewModel.cs | 212 ------------ .../ManageOrganisationViewModel.cs | 219 +----------- .../Shared/ReportStatusBadgeViewModel.cs | 13 - .../AllOrganisationReports.cshtml | 313 ------------------ .../OrganisationReportsTable.cshtml | 255 -------------- ...rsRegisteredToReportForOrganisation.cshtml | 123 ------- .../Views/Shared/_ReportStatusBadge.cshtml | 70 ---- 12 files changed, 2 insertions(+), 1449 deletions(-) delete mode 100644 GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/DatabaseTests/OrganisationTests.cs delete mode 100644 GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/Views/ManageOrganisations/ManageOrganisation.cs delete mode 100644 GenderPayGap.WebUI/Models/ManageOrganisations/AllOrganisationReportsViewModel.cs delete mode 100644 GenderPayGap.WebUI/Models/Shared/ReportStatusBadgeViewModel.cs delete mode 100644 GenderPayGap.WebUI/Views/ManageOrganisations/AllOrganisationReports.cshtml delete mode 100644 GenderPayGap.WebUI/Views/ManageOrganisations/OrganisationReportsTable.cshtml delete mode 100644 GenderPayGap.WebUI/Views/ManageOrganisations/UsersRegisteredToReportForOrganisation.cshtml delete mode 100644 GenderPayGap.WebUI/Views/Shared/_ReportStatusBadge.cshtml diff --git a/GenderPayGap.Core/Enums.cs b/GenderPayGap.Core/Enums.cs index f56822ef0..dc9bb886e 100644 --- a/GenderPayGap.Core/Enums.cs +++ b/GenderPayGap.Core/Enums.cs @@ -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 { @@ -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, diff --git a/GenderPayGap.Database/Models/Extensions/Organisation.cs b/GenderPayGap.Database/Models/Extensions/Organisation.cs index ac05db422..3e7631b4b 100644 --- a/GenderPayGap.Database/Models/Extensions/Organisation.cs +++ b/GenderPayGap.Database/Models/Extensions/Organisation.cs @@ -345,21 +345,6 @@ public bool HadSubmittedReturnAsOfDate(int reportingYear, DateTime asOfDate) return GetReturnForYearAsOfDate(reportingYear, asOfDate) != null; } - public IEnumerable 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 /// @@ -401,22 +386,6 @@ public override int GetHashCode() return OrganisationId.GetHashCode(); } - [Obsolete("Use ReportingYearsHelper.GetReportingYears() instead")] - public IEnumerable 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; diff --git a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/DatabaseTests/OrganisationTests.cs b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/DatabaseTests/OrganisationTests.cs deleted file mode 100644 index 24ce2a6cd..000000000 --- a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/DatabaseTests/OrganisationTests.cs +++ /dev/null @@ -1,71 +0,0 @@ -using System.Collections.Generic; -using System.Linq; -using GenderPayGap.Tests.Common.TestHelpers; -using NUnit.Framework; - -namespace GenderPayGap.Database.Tests -{ - [TestFixture] - public class OrganisationTests - { - - [SetUp] - public void BeforeEach() - { - _testOrganisation = OrganisationHelper.GetPublicOrganisation(); - - Return mocked2017Return = ReturnHelper.CreateTestReturn(_testOrganisation); - OrganisationHelper.LinkOrganisationAndReturn(_testOrganisation, mocked2017Return); - - Return mocked2018Return = ReturnHelper.CreateTestReturn(_testOrganisation, 2018); - OrganisationHelper.LinkOrganisationAndReturn(_testOrganisation, mocked2018Return); - } - - private Organisation _testOrganisation; - - [TestCase(2, 2)] - [TestCase(1, 1)] - public void OrganisationDB_GetRecentReportingYears_Returns_The_Correct_Years(int countOfYears, int expected) - { - // Arrange - Act - IEnumerable returnedDates = _testOrganisation.GetRecentReportingYears(countOfYears); - int actualCountOfReturnedDates = returnedDates.Count(); - - // Assert - Assert.AreEqual(expected, actualCountOfReturnedDates); - } - - [TestCase(2, 2)] - [TestCase(1, 1)] - public void OrganisationDB_GetRecentReports_Returns_The_Correct_Years(int countOfYears, int expected) - { - // Arrange - Act - IEnumerable returnsAvailableInPreviousYears = _testOrganisation.GetRecentReports(countOfYears); - int actualCount = returnsAvailableInPreviousYears.Count(); - - // Assert - Assert.AreEqual(expected, actualCount); - } - - [Test] - public void OrganisationDB_GetRecentReports_Returns_New_Return_If_No_Data_Available() - { - // todo: the logic under test here should be changed, since it's not correct that a 'new return' - filled with zeroes!! - is created if the system doesn't find one a return on the database for a particular year. - - // Arrange - _testOrganisation.Returns = new List(); // remove returns - - // Act - IEnumerable returnsAvailableForTheLastTwoYears = _testOrganisation.GetRecentReports(2); - int actualCount = returnsAvailableForTheLastTwoYears.Count(); - Return returnForCurrentYear = returnsAvailableForTheLastTwoYears.ElementAt(0); - Return returnForPreviousYear = returnsAvailableForTheLastTwoYears.ElementAt(1); - - // Assert - Assert.AreEqual(2, actualCount); - Assert.AreEqual(0, returnForCurrentYear.ReturnId); - Assert.AreEqual(0, returnForPreviousYear.ReturnId); - } - - } -} diff --git a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/Views/ManageOrganisations/ManageOrganisation.cs b/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/Views/ManageOrganisations/ManageOrganisation.cs deleted file mode 100644 index 71670eb34..000000000 --- a/GenderPayGap.UnitTests/GenderPayGap.WebUI.Tests/Views/ManageOrganisations/ManageOrganisation.cs +++ /dev/null @@ -1,84 +0,0 @@ -using System; -using GenderPayGap.Core; -using GenderPayGap.Core.Helpers; -using GenderPayGap.Database; -using GenderPayGap.Database.Models; -using GenderPayGap.Extensions; -using GenderPayGap.Tests.Common.TestHelpers; -using GenderPayGap.WebUI.Models.ManageOrganisations; -using GenderPayGap.WebUI.Tests.TestHelpers; -using NUnit.Framework; - -namespace GenderPayGap.WebUI.Tests.Views.ManageOrganisations -{ - [TestFixture] - public class ManageOrganisation - { - private static readonly int ReportingYear = ReportingYearsHelper.GetCurrentReportingYearForSector(SectorTypes.Private); - private const int PastReportingYear = 2018; - private readonly User user = UserHelpers.CreateUsers().Find(u => u.UserId == 24572); - - private readonly Organisation organisationOutOfScope = OrganisationHelper.GetOrganisationInAGivenScope(ScopeStatuses.OutOfScope, ReportingYear); - private readonly Organisation organisationInScope = OrganisationHelper.GetOrganisationInAGivenScope(ScopeStatuses.InScope, ReportingYear); - private readonly Organisation organisationInScopeForPastYear = OrganisationHelper.GetOrganisationInAGivenScope(ScopeStatuses.InScope, PastReportingYear); - - - [Test] - public void WhenOnManageOrganisationPage_IfOrganisationIsNotRequiredToReport_ThenReportStatusIsNotRequired() - { - var viewModel = new ManageOrganisationDetailsForYearViewModel(organisationOutOfScope, ReportingYear, new DraftReturn()); - - string reportTagText = viewModel.GetReportTagText(); - - Assert.AreEqual("Report not required", reportTagText); - } - - [Test] - public void WhenOnManageOrganisationPage_IfHasNotSubmittedBeforeTheDeadline_ThenReportStatusIsDueByDate() - { - var viewModel = new ManageOrganisationDetailsForYearViewModel(organisationInScope, ReportingYear, null); - - string reportTagText = viewModel.GetReportTagText(); - - Assert.True(reportTagText.Contains("Report due by")); - } - - [Test] - public void WhenOnManageOrganisationPage_IfHasNotSubmittedAfterTheDeadline_ThenReportStatusIsOverdue() - { - var viewModel = new ManageOrganisationDetailsForYearViewModel(organisationInScopeForPastYear, PastReportingYear, null); - - string reportTagText = viewModel.GetReportTagText(); - - Assert.AreEqual("Report overdue", reportTagText); - } - - [Test] - public void WhenOnManageOrganisationPage_IfHasSubmittedBeforeTheDeadline_ThenReportStatusSubmitted() - { - UserOrganisation userOrg = UserOrganisationHelper.LinkUserWithOrganisation(user, organisationInScope); - Return ret = ReturnHelper.GetSubmittedReturnForOrganisationAndYear(userOrg, ReportingYear); - OrganisationHelper.LinkOrganisationAndReturn(organisationInScope, ret); - - var viewModel = new ManageOrganisationDetailsForYearViewModel(organisationInScope, ReportingYear, null); - - string reportTagText = viewModel.GetReportTagText(); - - Assert.AreEqual("Report submitted", reportTagText); - } - - [Test] - public void WhenOnManageOrganisationPage_IfHasSubmittedAfterTheDeadline_ThenReportStatusSubmittedLate() - { - Return ret = ReturnHelper.CreateLateReturn(PastReportingYear, organisationInScopeForPastYear, 3); - OrganisationHelper.LinkOrganisationAndReturn(organisationInScopeForPastYear, ret); - - var viewModel = new ManageOrganisationDetailsForYearViewModel(organisationInScopeForPastYear, PastReportingYear, null); - - string reportTagText = viewModel.GetReportTagText(); - - Assert.AreEqual("Report submitted late", reportTagText); - } - - } -} diff --git a/GenderPayGap.WebUI/Controllers/ManageOrganisations/ManageOrganisationsController.cs b/GenderPayGap.WebUI/Controllers/ManageOrganisations/ManageOrganisationsController.cs index 41ac28a35..08ad35157 100644 --- a/GenderPayGap.WebUI/Controllers/ManageOrganisations/ManageOrganisationsController.cs +++ b/GenderPayGap.WebUI/Controllers/ManageOrganisations/ManageOrganisationsController.cs @@ -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; @@ -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(organisationId); - if (OrganisationIsNewThisYearAndHasNotProvidedScopeForLastYear(organisation)) - { - return RedirectToAction("DeclareScopeGet", "Scope", new { encryptedOrganisationId = encryptedOrganisationId }); - } - - // build the view model - List allDraftReturns = - dataRepository.GetAll() - .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(); diff --git a/GenderPayGap.WebUI/Models/ManageOrganisations/AllOrganisationReportsViewModel.cs b/GenderPayGap.WebUI/Models/ManageOrganisations/AllOrganisationReportsViewModel.cs deleted file mode 100644 index cf5d267b9..000000000 --- a/GenderPayGap.WebUI/Models/ManageOrganisations/AllOrganisationReportsViewModel.cs +++ /dev/null @@ -1,212 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using GenderPayGap.Core; -using GenderPayGap.Core.Classes; -using GenderPayGap.Core.Helpers; -using GenderPayGap.Database; -using GenderPayGap.Database.Models; -using GenderPayGap.WebUI.Classes; - -namespace GenderPayGap.WebUI.Models.ManageOrganisations -{ - public class AllOrganisationReportsViewModel - { - - public Database.Organisation Organisation { get; } - public User User { get; } - - private readonly List allDraftReturns; - public int? CurrentPage { get; set; } - public int? TotalPages { get; set; } - public int? EntriesPerPage { get; set; } - - public AllOrganisationReportsViewModel(Database.Organisation organisation, User user, List allDraftReturns, int? currentPage, int? totalPages, int? entriesPerPage) - { - Organisation = organisation; - User = user; - this.allDraftReturns = allDraftReturns; - CurrentPage = currentPage; - TotalPages = totalPages; - EntriesPerPage = entriesPerPage; - } - - public List GetOrganisationDetailsForYears() - { - List reportingYears = ReportingYearsHelper.GetReportingYears(Organisation.SectorType); - var detailsForYears = new List(); - - foreach (int reportingYear in reportingYears) - { - // Get organisation's scope for given reporting year - var scopeForYear = Organisation.GetScopeForYear(reportingYear); - - if (scopeForYear != null) - { - detailsForYears.Add( - new AllOrganisationReportsForYearViewModel( - Organisation, - reportingYear, - allDraftReturns.Where(d => d.SnapshotYear == reportingYear) - .OrderByDescending(d => d.Modified) - .FirstOrDefault() - ) - ); - } - } - - return detailsForYears; - } - } - - public class AllOrganisationReportsForYearViewModel - { - - public int ReportingYear { get; } - - private readonly Database.Organisation organisation; - private readonly bool hasDraftReturnForYear; - - public AllOrganisationReportsForYearViewModel(Database.Organisation organisation, int reportingYear, DraftReturn draftReturnForYear) - { - this.organisation = organisation; - ReportingYear = reportingYear; - hasDraftReturnForYear = draftReturnForYear != null; - } - - public object GetFormattedYearText() - { - return ReportingYearsHelper.FormatYearAsReportingPeriod(ReportingYear); - } - - public bool CanChangeScope() - { - int currentReportingYear = organisation.SectorType.GetAccountingStartDate().Year; - int earliestAllowedReportingYear = currentReportingYear - (Global.EditableScopeCount - 1); - return ReportingYear >= earliestAllowedReportingYear; - } - - public string GetRequiredToReportOrNotText() - { - OrganisationScope scopeForYear = organisation.GetScopeForYear(ReportingYear); - - return scopeForYear.IsInScopeVariant() - ? "You are required to report." - : "You are not required to report."; - } - - private DateTime GetAccountingDate() - { - return organisation.SectorType.GetAccountingStartDate(ReportingYear); - } - - public DateTime GetReportingDeadline() - { - DateTime snapshotDate = GetAccountingDate(); - return ReportingYearsHelper.GetDeadlineForAccountingDate(snapshotDate); - } - - private bool DeadlineHasPassed() - { - return ReportingYearsHelper.DeadlineForAccountingDateHasPassed(GetAccountingDate()); - } - - private bool OrganisationIsRequiredToSubmit() - { - return organisation.GetScopeForYear(ReportingYear).IsInScopeVariant() - && !Global.ReportingStartYearsToExcludeFromLateFlagEnforcement.Contains(GetAccountingDate().Year); - } - - public ReportTag GetReportTag() - { - Return returnForYear = organisation.GetReturn(ReportingYear); - bool reportIsSubmitted = returnForYear != null; - - return reportIsSubmitted ? GetSubmittedReportTag(returnForYear) : GetNotSubmittedReportTag(); - } - - public ReportStatusBadgeType GetReportBadge() - { - var tag = GetReportTag(); - switch (tag) - { - case ReportTag.Submitted: - return ReportStatusBadgeType.Reported; - case ReportTag.SubmittedLate: - return ReportStatusBadgeType.SubmittedLate; - case ReportTag.Due: - return ReportStatusBadgeType.Due; - case ReportTag.Overdue: - return ReportStatusBadgeType.Overdue; - case ReportTag.NotRequired: - return ReportStatusBadgeType.NotRequired; - default: - return ReportStatusBadgeType.Due; - } - } - - private ReportTag GetSubmittedReportTag(Return returnForYear) - { - bool returnIsRequired = returnForYear.IsRequired(); - - if (returnIsRequired && returnForYear.IsLateSubmission) - { - return ReportTag.SubmittedLate; - } - - return ReportTag.Submitted; - } - - private ReportTag GetNotSubmittedReportTag() - { - if (!OrganisationIsRequiredToSubmit()) - { - return ReportTag.NotRequired; - } - - return DeadlineHasPassed() ? ReportTag.Overdue : ReportTag.Due; - } - - public string GetReportTagText() - { - switch (GetReportTag()) - { - case ReportTag.Due: - return "Report due by " + GetReportingDeadline().ToString("d MMMM yyyy"); - case ReportTag.Overdue: - return "Report overdue"; - case ReportTag.Submitted: - return "Report submitted"; - case ReportTag.SubmittedLate: - return "Report submitted late"; - default: - return "Report not required"; - } - } - - public string GetReportLinkText() - { - Return returnForYear = organisation.GetReturn(ReportingYear); - bool hasReturnForYear = returnForYear != null; - - if (!hasReturnForYear && !hasDraftReturnForYear) - { - return "Draft report"; - } - - if (!hasReturnForYear && hasDraftReturnForYear) - { - return "Edit draft"; - } - - if (hasReturnForYear && !hasDraftReturnForYear) - { - return "Edit report"; - } - - return "Edit draft report"; - } - - } - -} diff --git a/GenderPayGap.WebUI/Models/ManageOrganisations/ManageOrganisationViewModel.cs b/GenderPayGap.WebUI/Models/ManageOrganisations/ManageOrganisationViewModel.cs index b176fb04e..8aaaf7d01 100644 --- a/GenderPayGap.WebUI/Models/ManageOrganisations/ManageOrganisationViewModel.cs +++ b/GenderPayGap.WebUI/Models/ManageOrganisations/ManageOrganisationViewModel.cs @@ -1,9 +1,6 @@ -using System; -using System.Collections.Generic; +using System.Collections.Generic; using System.Linq; using GenderPayGap.Core; -using GenderPayGap.Core.Classes; -using GenderPayGap.Core.Helpers; using GenderPayGap.Database; using GenderPayGap.Database.Models; @@ -48,7 +45,7 @@ public bool DoesReturnOrDraftReturnExistForYear(int reportingYear) return hasReturnForYear || hasDraftReturnForYear; } - + public string GetReportLinkText(int reportingYear) { bool hasReturnForYear = Organisation.HasSubmittedReturn(reportingYear); @@ -77,218 +74,6 @@ public bool OrganisationIsRequiredToSubmit(int reportingYear) return Organisation.GetScopeForYear(reportingYear).IsInScopeVariant() && !Global.ReportingStartYearsToExcludeFromLateFlagEnforcement.Contains(reportingYear); } - - public List GetOrganisationDetailsForYears() - { - List reportingYears = ReportingYearsHelper.GetReportingYears(Organisation.SectorType); - var detailsForYears = new List(); - - foreach (int reportingYear in reportingYears) - { - // Get organisation's scope for given reporting year - var scopeForYear = Organisation.GetScopeForYear(reportingYear); - - if (scopeForYear != null) - { - detailsForYears.Add( - new ManageOrganisationDetailsForYearViewModel( - Organisation, - reportingYear, - allDraftReturns.Where(d => d.SnapshotYear == reportingYear) - .OrderByDescending(d => d.Modified) - .FirstOrDefault() - ) - ); - } - } - - return detailsForYears; - } - - } - - public class ManageOrganisationDetailsForYearViewModel - { - - public int ReportingYear { get; } - - private readonly Database.Organisation organisation; - private readonly DraftReturn draftReturnForYear; - private readonly bool hasDraftReturnForYear; - - public ManageOrganisationDetailsForYearViewModel(Database.Organisation organisation, int reportingYear, DraftReturn draftReturnForYear) - { - this.organisation = organisation; - ReportingYear = reportingYear; - this.draftReturnForYear = draftReturnForYear; - hasDraftReturnForYear = draftReturnForYear != null; - } - - - public object GetFormattedYearText() - { - return ReportingYearsHelper.FormatYearAsReportingPeriod(ReportingYear); - } - - public bool CanChangeScope() - { - int currentReportingYear = organisation.SectorType.GetAccountingStartDate().Year; - int earliestAllowedReportingYear = currentReportingYear - (Global.EditableScopeCount - 1); - return ReportingYear >= earliestAllowedReportingYear; - } - - public string GetRequiredToReportOrNotText() - { - OrganisationScope scopeForYear = organisation.GetScopeForYear(ReportingYear); - - return scopeForYear.IsInScopeVariant() - ? "You are required to report." - : "You are not required to report."; - } - - private DateTime GetAccountingDate() - { - return organisation.SectorType.GetAccountingStartDate(ReportingYear); - } - - private DateTime GetReportingDeadline() - { - DateTime snapshotDate = GetAccountingDate(); - return ReportingYearsHelper.GetDeadlineForAccountingDate(snapshotDate); - } - - private bool DeadlineHasPassed() - { - return ReportingYearsHelper.DeadlineForAccountingDateHasPassed(GetAccountingDate()); - } - - private bool OrganisationIsRequiredToSubmit() - { - return organisation.GetScopeForYear(ReportingYear).IsInScopeVariant() - && !Global.ReportingStartYearsToExcludeFromLateFlagEnforcement.Contains(GetAccountingDate().Year); - } - - public ReportTag GetReportTag() - { - Return returnForYear = organisation.GetReturn(ReportingYear); - bool reportIsSubmitted = returnForYear != null; - - return reportIsSubmitted ? GetSubmittedReportTag(returnForYear) : GetNotSubmittedReportTag(); - } - - private ReportTag GetSubmittedReportTag(Return returnForYear) - { - bool returnIsRequired = returnForYear.IsRequired(); - - if (returnIsRequired && returnForYear.IsLateSubmission) - { - return ReportTag.SubmittedLate; - } - - return ReportTag.Submitted; - } - - private ReportTag GetNotSubmittedReportTag() - { - if (!OrganisationIsRequiredToSubmit()) - { - return ReportTag.NotRequired; - } - - return DeadlineHasPassed() ? ReportTag.Overdue : ReportTag.Due; - } - - public string GetReportTagText() - { - switch (GetReportTag()) - { - case ReportTag.Due: - return "Report due by " + GetReportingDeadline().ToString("d MMMM yyyy"); - case ReportTag.Overdue: - return "Report overdue"; - case ReportTag.Submitted: - return "Report submitted"; - case ReportTag.SubmittedLate: - return "Report submitted late"; - default: - return "Report not required"; - } - } - - public string GetReportTagClassName() - { - switch (GetReportTag()) - { - case ReportTag.Due: - return "govuk-tag--blue"; - case ReportTag.Overdue: - return "govuk-tag--red"; - case ReportTag.Submitted: - case ReportTag.SubmittedLate: - return "govuk-tag--green"; - default: - return "govuk-tag--grey"; - } - } - - public string GetReportTagDescription() - { - ReportTag tag = GetReportTag(); - Return returnForYear = organisation.GetReturn(ReportingYear); - - switch (tag) - { - case ReportTag.Overdue: - return "This report was due on " + GetReportingDeadline().ToString("d MMMM yyyy"); - case ReportTag.Submitted: - case ReportTag.SubmittedLate: - return "Reported on " + returnForYear.Modified.ToString("d MMMM yyyy"); - default: - return null; - } - } - - public string GetModifiedDateText() - { - if (hasDraftReturnForYear && draftReturnForYear.Modified != DateTime.MinValue) - { - return "Last edited on " + draftReturnForYear.Modified.ToString("d MMMM yyyy"); - } - - return null; - - } - - public bool DoesReturnOrDraftReturnExistForYear() - { - Return returnForYear = organisation.GetReturn(ReportingYear); - bool hasReturnForYear = returnForYear != null; - - return hasReturnForYear || hasDraftReturnForYear; - } - - public string GetReportLinkText() - { - Return returnForYear = organisation.GetReturn(ReportingYear); - bool hasReturnForYear = returnForYear != null; - - if (!hasReturnForYear && !hasDraftReturnForYear) - { - return "Draft report"; - } - - if (!hasReturnForYear && hasDraftReturnForYear) - { - return "Edit draft"; - } - - if (hasReturnForYear && !hasDraftReturnForYear) - { - return "Edit report"; - } - - return "Edit draft report"; - } } } diff --git a/GenderPayGap.WebUI/Models/Shared/ReportStatusBadgeViewModel.cs b/GenderPayGap.WebUI/Models/Shared/ReportStatusBadgeViewModel.cs deleted file mode 100644 index 1715f3096..000000000 --- a/GenderPayGap.WebUI/Models/Shared/ReportStatusBadgeViewModel.cs +++ /dev/null @@ -1,13 +0,0 @@ -using GenderPayGap.Core; - -namespace GenderPayGap.WebUI.Models.Shared -{ - - public class ReportStatusBadgeViewModel - { - public ReportStatusBadgeType ReportStatus { get; set; } - public string DateText { get; set; } - public bool Desktop { get; set; } - public string Classes { get; set; } - } -} diff --git a/GenderPayGap.WebUI/Views/ManageOrganisations/AllOrganisationReports.cshtml b/GenderPayGap.WebUI/Views/ManageOrganisations/AllOrganisationReports.cshtml deleted file mode 100644 index ea90fccc0..000000000 --- a/GenderPayGap.WebUI/Views/ManageOrganisations/AllOrganisationReports.cshtml +++ /dev/null @@ -1,313 +0,0 @@ -@using Newtonsoft.Json -@using GenderPayGap.Core -@using GenderPayGap.Core.Classes -@using GenderPayGap.Core.Helpers -@using GenderPayGap.WebUI.Models.ManageOrganisations -@using GenderPayGap.WebUI.Models.Shared -@using GovUkDesignSystem -@using GovUkDesignSystem.GovUkDesignSystemComponents -@model GenderPayGap.WebUI.Models.ManageOrganisations.AllOrganisationReportsViewModel - -@{ - ViewBag.Title = "View all your employers reports - Gender pay gap service"; - Layout = "~/Views/GovUkFrontend/GovUkFrontendLayout.cshtml"; - var organisation = Model.Organisation; - string encryptedOrganisationId = Encryption.EncryptQuerystring(organisation.OrganisationId.ToString()); -} - -@section BeforeMain { - @{ - var crumbs = new List - { - new CrumbViewModel - { - Text = "Manage Employers", - Href = Url.Action("ManageOrganisationsGet", "ManageOrganisations") - }, - new CrumbViewModel - { - Text = Model.Organisation.OrganisationName, - Href = Url.Action("ManageOrganisationGet", "ManageOrganisations", new {encryptedOrganisationId}) - }, - new CrumbViewModel - { - Text = "All reports" - }, - }; - } - - @(await Html.GovUkBreadcrumbs(new BreadcrumbsViewModel - { - Crumbs = crumbs - })) -} - -
-
-

- All reports -
- - for @(Model.Organisation.OrganisationName) - -

-
- @{ - var desktopHeader = new List - { - new TableCellViewModel - { - Text = "Snapshot date" - }, - new TableCellViewModel - { - Text = "Reporting requirement", - }, - new TableCellViewModel - { - Text = "Report status", - }, - new TableCellViewModel - { - Text = " ", - } - }; - - var allReports = Model.GetOrganisationDetailsForYears(); - var yearsForSelectComponent = allReports.Select(report => organisation.SectorType.GetAccountingStartDate(report.ReportingYear).ToString("dd/MM/yyyy")).ToList(); - var allDesktopRows = allReports.Select(report => GenerateDesktopRow(report)).ToList(); - var allMobileRows = allReports.Select(report => GenerateMobileRow(report)).ToList(); - - TableRowViewModel GenerateDesktopRow(AllOrganisationReportsForYearViewModel report) - { - var newRow = new TableRowViewModel - { - Row = new List - { - new TableCellViewModel - { - Html = @ - @organisation.SectorType.GetAccountingStartDate(report.ReportingYear).ToString("dd/MM/yyyy") - , - Classes = "govuk-!-font-weight-bold" - }, - new TableCellViewModel - { - Html = @ -
- @report.GetRequiredToReportOrNotText() -
- @if (report.CanChangeScope()) - { - - } -
- }, - new TableCellViewModel - { - Html = @ - @{ await Html.RenderPartialAsync("_ReportStatusBadge", - new ReportStatusBadgeViewModel - { - Desktop = true, - DateText = report.GetReportingDeadline().ToString("d MMMM yyyy"), - ReportStatus = report.GetReportBadge() - }); - } - - }, - new TableCellViewModel - { - Html = @ - - @report.GetReportLinkText() - - - }, - } - }; - return newRow; - } - - TableRowViewModel GenerateMobileRow(AllOrganisationReportsForYearViewModel report) - { - var newRow = new TableRowViewModel - { - Row = new List - { - new TableCellViewModel - { - Html = @ - - Snapshot date: @organisation.SectorType.GetAccountingStartDate(report.ReportingYear).ToString("dd/MM/yyyy") - - -
- @report.GetRequiredToReportOrNotText() -
- @if (report.CanChangeScope()) - { - - } - @{ await Html.RenderPartialAsync("_ReportStatusBadge", - new ReportStatusBadgeViewModel - { - Desktop = false, - DateText = report.GetReportingDeadline().ToString("d MMMM yyyy"), - ReportStatus = report.GetReportBadge(), - Classes = "govuk-!-margin-top-5 govuk-!-margin-bottom-3" - }); - } -
- - @report.GetReportLinkText() - -
, - Classes = "govuk-!-padding-bottom-8" - } - } - }; - return newRow; - } - - var dateJoinedRow = new TableRowViewModel - { - Row = new List - { - new TableCellViewModel - { - Html = @ - @await Html.GovUkHint( - new HintViewModel - { - Text = "Employer joined Gender Pay Gap service on " + @Model.Organisation.Created.ToString("dd/MM/yyyy"), - Classes = "govuk-!-margin-top-4 govuk-!-text-align-centre" - }) - , - Colspan = 4 - } - } - }; - - var indexOfCompanyJoined = organisation.GetRecentReports(Global.ShowReportYearCount).ToList().FindIndex(report => Model.Organisation.Created > ReportingYearsHelper.GetDeadlineForAccountingDate(report.AccountingDate)); - if(indexOfCompanyJoined >= 0) - { - allMobileRows.Insert(indexOfCompanyJoined, dateJoinedRow); - allDesktopRows.Insert(indexOfCompanyJoined, dateJoinedRow); - } - else - { - allMobileRows.Add(dateJoinedRow); - allDesktopRows.Add(dateJoinedRow); - } - - var currentPage = Model.CurrentPage; - var entriesPerPage = Model.EntriesPerPage ?? 10; - var startIndex = (currentPage - 1) * entriesPerPage; - var endIndex = startIndex + entriesPerPage > allDesktopRows.Count ? allDesktopRows.Count : startIndex + entriesPerPage; - - var desktopDisplayRows = allDesktopRows.Where((row, i) => i >= startIndex && i < endIndex).ToList(); - var mobileDisplayRows = allMobileRows.Where((row, i) => i >= startIndex && i < endIndex).ToList(); - } -
- -
-
- - @await Html.GovUkTable(new TableGovUkViewModel - { - Head = desktopHeader, - Rows = desktopDisplayRows, - Classes = "gpg-govuk-hideOnMobile govuk-grid-column-full" - }) - - @await Html.GovUkTable(new TableGovUkViewModel - { - Head = new List(), - Rows = mobileDisplayRows, - Classes = "gpg-govuk-hideOnDesktop govuk-grid-column-full" - }) - - @{ - var nextLink = new PaginationLinkViewModel() - { - Text = "Next page", - LabelText = $"{Model.CurrentPage + 1} of {Model.TotalPages}", - Href = Url.Action("AllOrganisationReportsGet", new {encryptedOrganisationId, page = Model.CurrentPage + 1}) - }; - - var previousLink = new PaginationLinkViewModel() - { - Text = "Previous page", - LabelText = $"{Model.CurrentPage - 1} of {Model.TotalPages}", - Href = Url.Action("AllOrganisationReportsGet", new {encryptedOrganisationId, page = Model.CurrentPage - 1}) - }; - - if (Model.TotalPages < 2 || Model.CurrentPage == Model.TotalPages) - nextLink = null; - if (Model.CurrentPage < 2) - previousLink = null; - } - @await Html.GovUkPagination(new PaginationViewModel() - { - Next = nextLink, - Previous = previousLink, - }) -
-
- - - - - diff --git a/GenderPayGap.WebUI/Views/ManageOrganisations/OrganisationReportsTable.cshtml b/GenderPayGap.WebUI/Views/ManageOrganisations/OrganisationReportsTable.cshtml deleted file mode 100644 index fe171b826..000000000 --- a/GenderPayGap.WebUI/Views/ManageOrganisations/OrganisationReportsTable.cshtml +++ /dev/null @@ -1,255 +0,0 @@ -@using GenderPayGap.Core.Classes -@using GenderPayGap.Core.Helpers -@using GenderPayGap.WebUI.Models.ManageOrganisations -@using GovUkDesignSystem -@using GovUkDesignSystem.GovUkDesignSystemComponents -@using GenderPayGap.Core -@model GenderPayGap.WebUI.Models.ManageOrganisations.ManageOrganisationViewModel - -@{ - var organisation = Model.Organisation; - - var desktopHeadings = new List - { - new TableCellViewModel - { - Text = "Snapshot date", - Colspan = 1 - }, - new TableCellViewModel - { - Text = "Reporting requirements", - Colspan = 1 - }, - new TableCellViewModel - { - Text = "Report status", - Colspan = 1 - }, - new TableCellViewModel - { - Text = " ", - Colspan = 1 - } - }; - - var allReturns = Model.GetOrganisationDetailsForYears(); - var desktopCurrentReportingPeriodRows = new List(); - var desktopMissingReportingPeriodRows = new List(); - var mobileCurrentReportingPeriodRows = new List(); - var mobileMissingReportingPeriodRows = new List(); - string encryptedOrganisationId = Encryption.EncryptQuerystring(Model.Organisation.OrganisationId.ToString()); - foreach (var organisationReturn in allReturns) - { - var reportTag = organisationReturn.GetReportTag(); - var currentReportingYear = ReportingYearsHelper.GetCurrentReportingYear(); - - if (reportTag == ReportTag.Overdue) - { - desktopMissingReportingPeriodRows.Add(GenerateDesktopRow(organisationReturn)); - mobileMissingReportingPeriodRows.Add(GenerateMobileRow(organisationReturn)); - } - else if (organisationReturn.ReportingYear == currentReportingYear) - { - desktopCurrentReportingPeriodRows.Add(GenerateDesktopRow(organisationReturn)); - mobileCurrentReportingPeriodRows.Add(GenerateMobileRow(organisationReturn)); - } - } - - TableRowViewModel GenerateDesktopRow(ManageOrganisationDetailsForYearViewModel viewModel) - { - var newRow = new TableRowViewModel - { - Row = new List - { - new TableCellViewModel - { - Html = @ - @organisation.SectorType.GetAccountingStartDate(viewModel.ReportingYear).ToString("dd/MM/yyyy") - , - Classes = "govuk-!-font-weight-bold" - }, - new TableCellViewModel - { - Html = @ -
- @viewModel.GetRequiredToReportOrNotText() -
- @if (viewModel.CanChangeScope()) - { - - } -
- }, - new TableCellViewModel - { - Html = @ - - @viewModel.GetReportTagText().ToUpper() - - @{ - string description = viewModel.GetReportTagDescription(); - string modifiedDateText = viewModel.GetModifiedDateText(); - string modifiedDateTextClass = description != null ? "" : "govuk-!-margin-top-3"; - - if (description != null) - { -
@description
- } - - if (modifiedDateText != null) - { -
@modifiedDateText
- } - } -
- }, - new TableCellViewModel - { - Html = @ - @if (viewModel.DoesReturnOrDraftReturnExistForYear()) - { - - @viewModel.GetReportLinkText() - - } - else - { - - @viewModel.GetReportLinkText() - - } - - }, - } - }; - return newRow; - } - - TableRowViewModel GenerateMobileRow(ManageOrganisationDetailsForYearViewModel viewModel) - { - var newRow = new TableRowViewModel - { - Row = new List - { - new TableCellViewModel - { - Html = @ -
-

- Snapshot date: @organisation.SectorType.GetAccountingStartDate(viewModel.ReportingYear).ToString("dd/MM/yyyy") -

- @if (viewModel.CanChangeScope()) - { -

- @viewModel.GetRequiredToReportOrNotText() -

- - } - else - { -

- @viewModel.GetRequiredToReportOrNotText() -

- } -
- - - @viewModel.GetReportTagText().ToUpper() - - -
- @{ - string description = viewModel.GetReportTagDescription(); - string modifiedDateText = viewModel.GetModifiedDateText(); - string modifiedDateTextClass = description != null ? "" : "govuk-!-margin-top-4"; - - if (description != null) - { -
@description
- } - - if (modifiedDateText != null) - { -
@modifiedDateText
- } - } -
-
- -
- @if (viewModel.DoesReturnOrDraftReturnExistForYear()) - { - - @viewModel.GetReportLinkText() - - } - else - { - - @viewModel.GetReportLinkText() - - } -
-
- }, - } - }; - return newRow; - } -} - -

Manage reports

-

Manage reports

-@{ - var missingReports = desktopMissingReportingPeriodRows.Count > 0; - var mobileReportingPeriodsClasses = missingReports ? "gpg-govuk-hideOnDesktop govuk-!-margin-bottom-9" : "gpg-govuk-hideOnDesktop govuk-!-margin-bottom-1"; -} - -@await Html.GovUkTable(new TableGovUkViewModel - { - Head = desktopHeadings, - Rows = desktopCurrentReportingPeriodRows, - Classes = "gpg-govuk-hideOnMobile" - }) -@await Html.GovUkTable(new TableGovUkViewModel - { - Head = new List(), - Rows = mobileCurrentReportingPeriodRows, - Classes = mobileReportingPeriodsClasses - }) - -@if (missingReports) -{ -

Missing reports

-

Missing reports

- @await Html.GovUkTable(new TableGovUkViewModel - { - Head = desktopHeadings, - Rows = desktopMissingReportingPeriodRows, - Classes = "gpg-govuk-hideOnMobile govuk-!-margin-bottom-3" - }) - @await Html.GovUkTable(new TableGovUkViewModel - { - Head = new List(), - Rows = mobileMissingReportingPeriodRows, - Classes = "gpg-govuk-hideOnDesktop govuk-!-margin-bottom-1" - }) -} - - - - - diff --git a/GenderPayGap.WebUI/Views/ManageOrganisations/UsersRegisteredToReportForOrganisation.cshtml b/GenderPayGap.WebUI/Views/ManageOrganisations/UsersRegisteredToReportForOrganisation.cshtml deleted file mode 100644 index 65ed38805..000000000 --- a/GenderPayGap.WebUI/Views/ManageOrganisations/UsersRegisteredToReportForOrganisation.cshtml +++ /dev/null @@ -1,123 +0,0 @@ -@using GenderPayGap.Database -@using GovUkDesignSystem -@using GovUkDesignSystem.GovUkDesignSystemComponents -@model GenderPayGap.WebUI.Models.ManageOrganisations.ManageOrganisationViewModel - -@{ - var encryptedOrganisationId = Encryption.EncryptQuerystring(Model.Organisation.OrganisationId.ToString()); - - var desktopHeadings = new List - { - new TableCellViewModel - { - Text = "User", - Colspan = 1 - }, - new TableCellViewModel - { - Text = "Action", - Colspan = 1 - } - }; - - var mobileRows = new List(); - var desktopRows = new List(); - @foreach (User userRegisteredToReport in Model.GetFullyRegisteredUsersForOrganisationWithCurrentUserFirst()) - { - var encryptedUserId = Encryption.EncryptQuerystring(userRegisteredToReport.UserId.ToString()); - - var mobileRow = new TableRowViewModel - { - Row = new List - { - new TableCellViewModel - { - Html = @ -

- @userRegisteredToReport.Fullname - @if (userRegisteredToReport.UserId == Model.User.UserId) - { - (You) - } -

-

- - Remove user @userRegisteredToReport.Fullname - -

-
- } - } - }; - var desktopRow = new TableRowViewModel - { - Row = new List - { - new TableCellViewModel - { - Html = @ -

- @userRegisteredToReport.Fullname - @if (userRegisteredToReport.UserId == Model.User.UserId) - { - (You) - } -

-
- }, - new TableCellViewModel - { - Html = @ -

- - Remove user @userRegisteredToReport.Fullname - -

-
- } - } - }; - desktopRows.Add(desktopRow); - mobileRows.Add(mobileRow); - } -} - -

Registered users

- @{ - var usersRegisteredToReportForOrganisation = Model.Organisation.UserOrganisations.Where(uo => uo.PINConfirmedDate.HasValue).Select(uo => uo.User).Distinct().ToList(); - } - - @if (usersRegisteredToReportForOrganisation.Count == 0) - { -

- You are the only person registered to report for this employer. -

-

- If you remove yourself: -

-
    -
  • You will not be able to report for this employer
  • -
  • Someone else must register this employer to report - this can take up to a week
  • -
  • Your account will remain open
  • -
- } - else - { -

- The following people are registered to report gender pay gap information for this employer. -

- } - - @await Html.GovUkTable(new TableGovUkViewModel - { - Head = desktopHeadings, - Rows = desktopRows, - Classes = "gpg-govuk-hideOnMobile" - }) - @await Html.GovUkTable(new TableGovUkViewModel - { - Head = new List(), - Rows = mobileRows, - Classes = "gpg-govuk-hideOnDesktop" - }) - \ No newline at end of file diff --git a/GenderPayGap.WebUI/Views/Shared/_ReportStatusBadge.cshtml b/GenderPayGap.WebUI/Views/Shared/_ReportStatusBadge.cshtml deleted file mode 100644 index 9eac6fcfa..000000000 --- a/GenderPayGap.WebUI/Views/Shared/_ReportStatusBadge.cshtml +++ /dev/null @@ -1,70 +0,0 @@ -@model GenderPayGap.WebUI.Models.Shared.ReportStatusBadgeViewModel -@using GenderPayGap.Core -@using GovUkDesignSystem -@using GovUkDesignSystem.GovUkDesignSystemComponents - -@{ - Func html = null; - string htmlClass = ""; - - - switch(Model.ReportStatus) - { - case ReportStatusBadgeType.Due: - if (Model.Desktop) - { - html = @DUE @Model.DateText.ToUpper(); - } - else - { - html = @REPORT DUE
@Model.DateText.ToUpper()
; - } - htmlClass = "govuk-tag--blue"; - break; - case ReportStatusBadgeType.Overdue: - if (Model.Desktop) - { - html = @OVERDUE @Model.DateText.ToUpper(); - } - else - { - html = @REPORT OVERDUE
@Model.DateText.ToUpper()
; - } - htmlClass = "govuk-tag--red"; - break; - case ReportStatusBadgeType.SubmittedLate: - if (Model.Desktop) - { - html = @SUBMITTED LATE ON @Model.DateText.ToUpper(); - } - else - { - html = @SUBMITTED LATE ON
@Model.DateText.ToUpper()
; - } - htmlClass = "govuk-tag--green"; - break; - case ReportStatusBadgeType.Reported: - html = @REPORTED; - htmlClass = "govuk-tag--green"; - break; - case ReportStatusBadgeType.NotRequired: - html = @@(Model.Desktop ? "" : "REPORT") NOT REQUIRED; - htmlClass = "govuk-tag--grey"; - break; - case ReportStatusBadgeType.NotRequiredDueToCovid: - html = @@(Model.Desktop ? "" : "REPORT") NOT REQUIRED; - htmlClass = "govuk-tag--grey"; - break; - case ReportStatusBadgeType.VoluntarilyReported: - html = @REPORTED VOLUNTARILY; - htmlClass = "govuk-tag--green"; - break; - - } -} - -@await Html.GovUkTag(new TagViewModel -{ - Html = html, - Classes = htmlClass + " " + Model.Classes -})