public IActionResult CompareEmployers(string command, int year = 0) { if (year == 0) { year = ReportingYearsHelper.GetTheMostRecentCompletedReportingYear(); } string args = command.AfterFirst(":"); command = command.BeforeFirst(":"); //Clear the default back url of the employer hub pages EmployerBackUrl = null; ReportBackUrl = null; switch (command.ToLower()) { case "employer": EmployerBackUrl = RequestUrl.PathAndQuery; return(RedirectToAction(nameof(ViewingController.Employer), "Viewing", new { employerIdentifier = args })); case "report": ReportBackUrl = RequestUrl.PathAndQuery; return(RedirectToAction(nameof(ViewingController.Report), "Viewing", new { employerIdentifier = args, year })); } return(new HttpBadRequestResult($"Invalid command '{command}'")); }
public void Is_True_When_ModifiedDate_Is_Late_And_InScope(SectorTypes sector, ScopeStatuses scopeStatus) { var totalYearOffsets = 4; for (var yearOffset = 0; yearOffset < totalYearOffsets; yearOffset++) { // Arrange int testYear = VirtualDateTime.Now.Year - yearOffset; DateTime snapshotDate = sector.GetAccountingStartDate(testYear); DateTime modifiedDate = ReportingYearsHelper.GetDeadlineForAccountingDate(snapshotDate).AddDays(2); Organisation testOrganisation = sector == SectorTypes.Private ? OrganisationHelper.GetPrivateOrganisation() : OrganisationHelper.GetPublicOrganisation(); OrganisationScope testScope = ScopeHelper.CreateScope(scopeStatus, snapshotDate); Return testReturn = ReturnHelper.CreateLateReturn(testOrganisation, snapshotDate, modifiedDate, testScope); // Act bool actual = testReturn.IsLateSubmission; // Assert Assert.AreEqual(true, actual); } }
public IActionResult DownloadCompareData(int year = 0) { if (year == 0) { year = ReportingYearsHelper.GetTheMostRecentCompletedReportingYear(); } var result = CompareEmployers(year) as ViewResult; var viewModel = result.Model as CompareViewModel; IEnumerable <CompareReportModel> data = viewModel?.CompareReports; //Ensure we some data if (data == null || !data.Any()) { return(new HttpNotFoundResult($"There is no employer data for year {year}")); } DataTable model = OrganisationBusinessLogic.GetCompareDatatable(data); //Setup the HTTP response var contentDisposition = new ContentDisposition { FileName = $"Compared GPG Data {ReportingYearsHelper.FormatYearAsReportingPeriod(year)}.csv", Inline = false }; HttpContext.SetResponseHeader("Content-Disposition", contentDisposition.ToString()); /* No Longer required as AspNetCore has response buffering on by default * Response.BufferOutput = true; */ //Track the download WebTracker.TrackPageView(this, contentDisposition.FileName); //Return the data return(Content(model.ToCSV(), "text/csv")); }
public List <ManageOrganisationDetailsForYearViewModel> GetOrganisationDetailsForYears() { List <int> reportingYears = ReportingYearsHelper.GetReportingYears(); var detailsForYears = new List <ManageOrganisationDetailsForYearViewModel>(); 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 bool IsValidReturn() { bool optOutOfReporting = ReportingYearsHelper.IsReportingYearWithFurloughScheme(AccountingDate) && OptedOutOfReportingPayQuarters; bool hasPayQuartersData = MaleLowerPayBand.HasValue && FemaleLowerPayBand.HasValue && MaleMiddlePayBand.HasValue && FemaleMiddlePayBand.HasValue && MaleUpperPayBand.HasValue && FemaleUpperPayBand.HasValue && MaleUpperQuartilePayBand.HasValue && FemaleUpperQuartilePayBand.HasValue; bool hasEnterCalculationsData = DiffMeanHourlyPayPercent.HasValue && DiffMedianHourlyPercent.HasValue && MaleMedianBonusPayPercent.HasValue && FemaleMedianBonusPayPercent.HasValue && FemaleMoneyFromMeanHourlyRate >= 0 && FemaleMoneyFromMedianHourlyRate >= 0; bool hasValidBonusFigures = MaleMedianBonusPayPercent == 0 || DiffMeanBonusPercent.HasValue && DiffMedianBonusPercent.HasValue; bool hasValidGpgFigures = (optOutOfReporting || hasPayQuartersData) && hasEnterCalculationsData && hasValidBonusFigures; if (SectorType == SectorTypes.Public) { return(hasValidGpgFigures); } bool hasPersonResponsibleData = !string.IsNullOrWhiteSpace(JobTitle) && !string.IsNullOrWhiteSpace(FirstName) && !string.IsNullOrWhiteSpace(LastName); return(hasValidGpgFigures && hasPersonResponsibleData); }
public static void ThrowIfReportingYearIsOutsideOfRange(int reportingYear) { if (!ReportingYearsHelper.GetReportingYears().Contains(reportingYear)) { throw new PageNotFoundException(); } }
public static FileContentResult GenerateEhrcAllOrganisationsForYearFile(IDataRepository dataRepository, int year) { // IMPORTANT: This variable isn't used, but running this query makes the next query much faster var allOrgsWithAddresses = dataRepository.GetAll <Organisation>() .Include(o => o.OrganisationAddresses) .ToList(); // IMPORTANT: This variable isn't used, but running this query makes the next query much faster var allOrgsWithScopes = dataRepository.GetAll <Organisation>() .Include(o => o.OrganisationScopes) .ToList(); // IMPORTANT: This variable isn't used, but running this query makes the next query much faster var allOrgsWithReturns = dataRepository.GetAll <Organisation>() .Include(o => o.Returns) .ToList(); // IMPORTANT: This variable isn't used, but running this query makes the next query much faster var allOrgsWithUserOrgs = dataRepository.GetAll <Organisation>() .Include(o => o.UserOrganisations) .ToList(); List <Organisation> organisations = dataRepository .GetAll <Organisation>() //.Include(org => org.OrganisationAddresses) // Moved into separate pre-load query .Include(org => org.OrganisationSicCodes) //.Include(org => org.OrganisationScopes) // Moved into separate pre-load query //.Include(org => org.Returns) // Moved into separate pre-load query //.Include(org => org.UserOrganisations) // Moved into separate pre-load query .ToList(); var records = organisations.Select( o => new { OrganisationId = o.OrganisationId, EmployerReference = o.EmployerReference, OrganisationName = o.OrganisationName, CompanyNo = o.CompanyNumber, Sector = o.SectorType, Status = o.Status, StatusDate = o.StatusDate, StatusDetails = o.StatusDetails, Address = o.GetLatestAddress()?.GetAddressString(), SicCodes = o.GetSicCodeIdsString(), LatestRegistrationDate = o.UserOrganisations.OrderByDescending(uo => uo.Created).FirstOrDefault()?.Created, LatestRegistrationMethod = o.UserOrganisations.OrderByDescending(uo => uo.Created).FirstOrDefault()?.Method.ToString(), LatestReturn = o.GetLatestReturn()?.Modified, ScopeStatus = o.GetLatestScopeForSnapshotYear(year)?.ScopeStatus, ScopeDate = o.GetLatestScopeForSnapshotYear(year)?.ScopeStatusDate, Created = o.Created, }) .ToList(); string fileDownloadName = $"GPG-Organisations_{ReportingYearsHelper.FormatYearAsReportingPeriod(year)}.csv"; FileContentResult fileContentResult = DownloadHelper.CreateCsvDownload(records, fileDownloadName); return(fileContentResult); }
public IActionResult Downloads() { var viewModel = new AdminDownloadsViewModel { ReportingYears = ReportingYearsHelper.GetReportingYears() }; return(View("Downloads", viewModel)); }
private bool ReportIsLate(Organisation organisation, int reportingYear) { // The deadline date is the final day that a return can be submitted without being considered late // The due date is a day later, the point at which a return is considered late // i.e. if the deadline date is 2021/04/01, submissions on that day are not late, any after 2021/04/02 00:00:00 are DateTime snapshotDate = organisation.SectorType.GetAccountingStartDate(reportingYear); DateTime dueDate = ReportingYearsHelper.GetDeadlineForAccountingDate(snapshotDate).AddDays(1); return(VirtualDateTime.Now > dueDate); }
public void CompareController_DownloadCompareData_WithYear_SameSortAsync() { // Arrange var routeData = new RouteData(); routeData.Values.Add("Action", nameof(CompareController.DownloadCompareData)); routeData.Values.Add("Controller", "Viewing"); var controller = UiTestHelper.GetController <CompareController>(0, routeData); controller.CompareViewService.SortColumn = "OrganisationSize"; controller.CompareViewService.SortAscending = false; var firstReportingYear = Global.FirstReportingYear; var mockOrg = OrganisationHelper.GetOrganisationInScope("MockedOrg", firstReportingYear); DateTime accountingDateTime = mockOrg.SectorType.GetAccountingStartDate(firstReportingYear); //create the comparison data var expectedModel = ViewingServiceHelper.GetCompareTestData(5).ToList(); //Setup the mocked business logic var mockOrgBL = new Mock <IOrganisationBusinessLogic>(); mockOrgBL .Setup(x => x.GetCompareData(It.IsAny <IEnumerable <string> >(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <bool>())) .Returns(expectedModel); var expectedData = expectedModel.ToDataTable(); mockOrgBL .Setup(x => x.GetCompareDatatable(It.IsAny <IEnumerable <CompareReportModel> >())) .Returns(expectedData); controller.OrganisationBusinessLogic = mockOrgBL.Object; // Act var result = controller.DownloadCompareData(firstReportingYear) as ContentResult; // Assert //Test the google analytics tracker was executed once on the controller var filename = $"Compared GPG Data {ReportingYearsHelper.FormatYearAsReportingPeriod(firstReportingYear)}.csv"; controller.WebTracker.GetMockFromObject().Verify(mock => mock.TrackPageView(It.IsAny <Controller>(), filename, null), Times.Once()); Assert.NotNull(result); Assert.AreEqual(result.ContentType, "text/csv"); Assert.AreEqual(controller.Response.Headers["Content-Disposition"], $"attachment; filename=\"{filename}\""); Assert.AreEqual(controller.CompareViewService.SortColumn, "OrganisationSize"); Assert.AreEqual(controller.CompareViewService.SortAscending, false); Assert.NotNull(result.Content); Assert.AreEqual(result.Content, expectedData.ToCSV()); }
public void IsReportingYearWithFurloughScheme_Returns_False_Given_A_Year_Without_Furlough_Scheme(int year) { // Arrange var accountingDate = SectorTypes.Private.GetAccountingStartDate(year); // Act var actualResult = ReportingYearsHelper.IsReportingYearWithFurloughScheme(accountingDate); // Assert Assert.AreEqual(false, actualResult); }
private void PopulateLateSubmissionViewModel(LateSubmissionReasonViewModel viewModel, long organisationId, int reportingYear) { Organisation organisation = dataRepository.Get <Organisation>(organisationId); DateTime snapshotDate = organisation.SectorType.GetAccountingStartDate(reportingYear); DateTime deadlineDate = ReportingYearsHelper.GetDeadlineForAccountingDate(snapshotDate); viewModel.Organisation = organisation; viewModel.ReportingYear = reportingYear; viewModel.DeadlineDate = deadlineDate; viewModel.IsEditingSubmittedReturn = organisation.HasSubmittedReturn(reportingYear); }
public IActionResult DownloadReturnDetailsCsv(long id) { Organisation organisation = dataRepository.Get <Organisation>(id); var returns = organisation.Returns.OrderByDescending(r => r.AccountingDate).ThenByDescending(r => r.StatusDate); var records = returns.Select( ret => new { OrganisationId = ret.Organisation.OrganisationId, OrganisationName = ret.Organisation.OrganisationName, ReturnId = ret.ReturnId, SnapshotDate = ret.AccountingDate, DeadlineDate = ReportingYearsHelper.GetDeadlineForAccountingDate(ret.AccountingDate), ModifiedDate = ret.Modified, Status = ret.Status, Modifications = ret.Modifications, Late = ret.IsLateSubmission, LateReason = ret.LateReason, Employees = ret.OrganisationSize.GetAttribute <DisplayAttribute>().Name, HourlyPayGapMean = ret.DiffMeanHourlyPayPercent, HourlyPayGapMedian = ret.DiffMedianHourlyPercent, BonusPayPercentMale = ret.MaleMedianBonusPayPercent, BonusPayPercentFemale = ret.FemaleMedianBonusPayPercent, BonusPayGapMean = ret.DiffMeanBonusPercent, BonusPayGapMedian = ret.DiffMedianBonusPercent, UpperQuarterPercentMale = ret.MaleUpperQuartilePayBand, UpperQuarterPercentFemale = ret.FemaleUpperQuartilePayBand, UpperMiddleQuarterPercentMale = ret.MaleUpperPayBand, UpperMiddleQuarterPercentFemale = ret.FemaleUpperPayBand, LowerMiddleQuarterPercentMale = ret.MaleMiddlePayBand, LowerMiddleQuarterPercentFemale = ret.FemaleMiddlePayBand, LowerQuarterPercentMale = ret.MaleLowerPayBand, LowerQuarterPercentFemale = ret.FemaleLowerPayBand, LinkToCompanyWebsite = ret.CompanyLinkToGPGInfo, SeniorResponsibleOfficer = ret.ResponsiblePerson }); string sanitisedOrganisationName = SanitiseOrganisationNameForFilename(organisation.OrganisationName); string fileDownloadName = $"ReturnsForOrganisation-{sanitisedOrganisationName}--{VirtualDateTime.Now:yyyy-MM-dd HH:mm}.csv"; FileContentResult fileContentResult = DownloadHelper.CreateCsvDownload(records, fileDownloadName); return(fileContentResult); }
private void UpdateDownloadFilesAction() { CustomLogger.Information($"UpdateDownloadFiles: Loading Organisations"); // IMPORTANT: This variable isn't used, but running this query makes the next query much faster List <Organisation> activeOrganisations = dataRepository.GetAll <Organisation>() .Where(o => o.Status == OrganisationStatuses.Active) .Include(o => o.OrganisationNames) .Include(o => o.OrganisationAddresses) .Include(o => o.OrganisationSicCodes) .ToList(); CustomLogger.Information($"UpdateDownloadFiles: Loading Returns"); List <Return> allReturns = dataRepository.GetAll <Return>() .Where(r => r.Organisation.Status == OrganisationStatuses.Active) .Include(r => r.Organisation) .ToList(); CustomLogger.Information($"UpdateDownloadFiles: Creating downloads for each year"); foreach (int year in ReportingYearsHelper.GetReportingYears()) { CustomLogger.Information($"UpdateDownloadFiles: Creating download for year {year}"); CustomLogger.Information($"UpdateDownloadFiles: - Filtering Returns"); List <Return> returns = allReturns .Where(r => r.AccountingDate.Year == year) .Where(r => r.Status == ReturnStatuses.Submitted) .ToList(); CustomLogger.Information($"UpdateDownloadFiles: - Converting Returns into results"); List <DownloadResult> downloadData = returns.ToList() .Select(r => r.ToDownloadResult()) .OrderBy(d => d.EmployerName) .ToList(); CustomLogger.Information($"UpdateDownloadFiles: - Saving results to file"); string filePath = Path.Combine(Global.DownloadsLocation, $"GPGData_{year}-{year + 1}.csv"); try { SaveCsvFile(downloadData, filePath); } catch (Exception ex) { CustomLogger.Error(ex.Message, new { Error = ex }); } CustomLogger.Information($"UpdateDownloadFiles: Done for year {year}"); } CustomLogger.Information($"UpdateDownloadFiles: Done"); }
public void CompareController_CompareEmployers_NoYear_DefaultSortTheMostRecentCompletedReportingYearAsync() { // Arrange var routeData = new RouteData(); routeData.Values.Add("Action", nameof(CompareController.CompareEmployers)); routeData.Values.Add("Controller", "Viewing"); var controller = UiTestHelper.GetController <CompareController>(0, routeData); //Setup the mock url helper var testUri = new Uri("https://localhost/Viewing/compare-employers"); controller.AddMockUriHelper(testUri.ToString(), "CompareEmployers"); var reportingYear = ReportingYearsHelper.GetTheMostRecentCompletedReportingYear(); var mockOrg = OrganisationHelper.GetOrganisationInScope("MockedOrg", reportingYear); DateTime accountingDateTime = mockOrg.SectorType.GetAccountingStartDate(reportingYear); //create the comparison data var expectedModel = ViewingServiceHelper.GetCompareTestData(5).ToList(); //Setup the mocked business logic var mockOrgBL = new Mock <IOrganisationBusinessLogic>(); mockOrgBL .Setup(x => x.GetCompareData(It.IsAny <IEnumerable <string> >(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <bool>())) .Returns(expectedModel); controller.OrganisationBusinessLogic = mockOrgBL.Object; // Act ViewResult result = controller.CompareEmployers(0) as ViewResult; // Assert Assert.NotNull(result); Assert.AreEqual(result.ViewName, "CompareEmployers"); Assert.AreEqual(controller.ViewBag.ReturnUrl, testUri.PathAndQuery); Assert.AreEqual(controller.CompareViewService.SortColumn, null); Assert.AreEqual(controller.CompareViewService.SortAscending, true); var lastComparedEmployerList = controller.CompareViewService.ComparedEmployers.Value.ToList().ToSortedSet().ToDelimitedString(); controller.CompareViewService.LastComparedEmployerList.Compare(lastComparedEmployerList); var actualModel = result.Model as CompareViewModel; Assert.NotNull(actualModel); Assert.NotNull(actualModel.CompareReports); Assert.IsTrue(actualModel.CompareReports.All(obj => actualModel.Year == reportingYear)); actualModel.CompareReports.Compare(expectedModel); }
public string GetByReportingDeadlineText() { OrganisationScope scopeForYear = organisation.GetScopeForYear(ReportingYear); if (scopeForYear.IsInScopeVariant()) { DateTime snapshotDate = organisation.SectorType.GetAccountingStartDate(ReportingYear); DateTime deadline = ReportingYearsHelper.GetDeadlineForAccountingDate(snapshotDate); return("by " + deadline.ToString("d MMM yyyy")); } return(null); }
private static object ConvertReturnToDownloadFormat(Return returnForYear) { Organisation organisation = returnForYear.Organisation; int year = returnForYear.AccountingDate.Year; OrganisationScope scopeForYear = organisation.GetScopeForYear(year); return(new { OrganisationId = organisation.OrganisationId, ReturnId = returnForYear.ReturnId, ReturnStatus = returnForYear.Status, OrganisationName = organisation.OrganisationName, CompanyNumber = organisation.CompanyNumber, SectorType = organisation.SectorType, ScopeStatus = scopeForYear?.ScopeStatus.ToString() ?? "(no active scope)", SnapshotDate = returnForYear.AccountingDate, DeadlineDate = ReportingYearsHelper.GetDeadlineForAccountingDate(returnForYear.AccountingDate), ModifiedDate = returnForYear.Modified, IsLateSubmission = returnForYear.IsLateSubmission, DiffMeanHourlyPayPercent = returnForYear.DiffMeanHourlyPayPercent, DiffMedianHourlyPercent = returnForYear.DiffMedianHourlyPercent, LowerQuartileFemalePercent = returnForYear.FemaleLowerPayBand, LowerQuartileMalePercent = returnForYear.MaleLowerPayBand, LowerMiddleQuartileFemalePercent = returnForYear.FemaleMiddlePayBand, LowerMiddleQuartileMalePercent = returnForYear.MaleMiddlePayBand, UpperMiddleQuartileFemalePercent = returnForYear.FemaleUpperPayBand, UpperMiddleQuartileMalePercent = returnForYear.MaleUpperPayBand, UpperQuartileFemalePercent = returnForYear.FemaleUpperQuartilePayBand, UpperQuartileMalePercent = returnForYear.MaleUpperQuartilePayBand, PercentPaidBonusFemale = returnForYear.FemaleMedianBonusPayPercent, PercentPaidBonusMale = returnForYear.MaleMedianBonusPayPercent, DiffMeanBonusPercent = returnForYear.DiffMeanBonusPercent, DiffMedianBonusPercent = returnForYear.DiffMedianBonusPercent, CompanyLinkToGPGInfo = returnForYear.CompanyLinkToGPGInfo, ResponsiblePerson = returnForYear.ResponsiblePerson, OrganisationSize = returnForYear.OrganisationSize.GetAttribute <DisplayAttribute>().Name, }); }
public List <DateTime> GetDatesOfLatestReports(List <int> years) { if (years.IsNullOrEmpty()) { years = ReportingYearsHelper.GetReportingYears(); } var latestReports = new List <DateTime>(); foreach (var year in years) { if (ReportingYearToDateOfLatestReportMap.TryGetValue(year, out DateTime latestDate)) { latestReports.Add(latestDate); } } return(latestReports); }
public List <OrganisationSizes> GetOrganisationSizes(List <int> years) { if (years.IsNullOrEmpty()) { years = ReportingYearsHelper.GetReportingYears(); } var organisationSizes = new List <OrganisationSizes>(); foreach (var year in years) { if (ReportingYearToOrganisationSizesMap.TryGetValue(year, out List <OrganisationSizes> sizes)) { organisationSizes = organisationSizes.Union(sizes).ToList(); } } return(organisationSizes); }
public bool DraftReturnWouldBeNewlyLateIfSubmittedNow(DraftReturn draftReturn) { Organisation organisation = dataRepository.Get <Organisation>(draftReturn.OrganisationId); int reportingYear = draftReturn.SnapshotYear; DateTime snapshotDate = organisation.SectorType.GetAccountingStartDate(reportingYear); // The deadline date is the final day that a return can be submitted without being considered late // The due date is a day later, the point at which a return is considered late // i.e. if the deadline date is 2021/04/01, submissions on that day are not late, any after 2021/04/02 00:00:00 are DateTime dueDate = ReportingYearsHelper.GetDeadlineForAccountingDate(snapshotDate).AddDays(1); bool isLate = VirtualDateTime.Now > dueDate; bool isMandatory = draftReturn.OrganisationSize != OrganisationSizes.Employees0To249; bool isInScope = organisation.GetScopeForYear(reportingYear).IsInScopeVariant(); bool yearIsNotExcluded = !Global.ReportingStartYearsToExcludeFromLateFlagEnforcement.Contains(reportingYear); bool isMaterialChange = IsDraftReturnAMaterialChange(draftReturn, organisation); return(isLate && isMandatory && isInScope && yearIsNotExcluded && isMaterialChange); }
private int GetRandomReportingYear(bool ignoreYearsExcludedFromLateFlagEnforcement = false) { var reportingYears = ReportingYearsHelper.GetReportingYears(); if (ignoreYearsExcludedFromLateFlagEnforcement) { reportingYears = ReportingYearsHelper.GetReportingYears() .Except(reportingStartYearsToExcludeFromLateFlagEnforcement) .ToList(); } var random = new Random(); int index = random.Next(reportingYears.Count); var reportingYear = reportingYears[index]; Console.WriteLine("Testing Reporting Year: " + reportingYear); return(reportingYear); }
public FileContentResult DownloadLateSubmissions(int year) { List <Organisation> organisationsWithLateReturns = dataRepository.GetAll <Organisation>() .Where(org => org.Status == OrganisationStatuses.Active) .Where( org => !org.OrganisationScopes.Any(s => s.SnapshotDate.Year == year) || org.OrganisationScopes.Any( s => s.SnapshotDate.Year == year && (s.ScopeStatus == ScopeStatuses.InScope || s.ScopeStatus == ScopeStatuses.PresumedInScope))) // There might not be a Return for any given year // So we search for organisations that do NOT have a non-late submission .Where( org => !org.Returns .Any( r => r.AccountingDate.Year == year && r.Status == ReturnStatuses.Submitted && !r.IsLateSubmission)) .Include(org => org.Returns) .ToList(); var records = organisationsWithLateReturns.Select( org => new { org.OrganisationId, org.OrganisationName, org.SectorType, Submitted = org.GetReturn(year) != null, ReportingDeadline = ReportingYearsHelper.GetDeadlineForAccountingDate(org.SectorType.GetAccountingStartDate(year)).ToString("d MMMM yyyy"), SubmittedDate = org.GetReturn(year)?.Created, ModifiedDate = org.GetReturn(year)?.Modified, org.GetReturn(year)?.LateReason }) .ToList(); string fileDownloadName = $"Gpg-LateSubmissions-{new GDSDateFormatter(VirtualDateTime.Now).FullStartDateTime}.csv"; FileContentResult fileContentResult = DownloadHelper.CreateCsvDownload(records, fileDownloadName); return(fileContentResult); }
public void Is_True_When_ModifiedDate_Is_Late_And_InScope(SectorTypes sector, ScopeStatuses scopeStatus) { // Arrange int testYear = GetRandomReportingYear(ignoreYearsExcludedFromLateFlagEnforcement: true); DateTime snapshotDate = sector.GetAccountingStartDate(testYear); DateTime modifiedDate = ReportingYearsHelper.GetDeadlineForAccountingDate(snapshotDate).AddDays(2); Organisation testOrganisation = sector == SectorTypes.Private ? OrganisationHelper.GetPrivateOrganisation() : OrganisationHelper.GetPublicOrganisation(); OrganisationScope testScope = ScopeHelper.CreateScope(scopeStatus, snapshotDate); Return testReturn = ReturnHelper.CreateLateReturn(testOrganisation, snapshotDate, modifiedDate, testScope); // Act bool actual = testReturn.IsLateSubmission; // Assert Assert.AreEqual(true, actual); }
public bool DraftReturnExistsAndRequiredFieldsAreComplete(long organisationId, int reportingYear) { DraftReturn draftReturn = GetDraftReturn(organisationId, reportingYear); if (draftReturn == null) { return(false); } var organisation = dataRepository.Get <Organisation>(organisationId); bool employeesByPayQuartileSectionIsComplete = (ReportingYearsHelper.IsReportingYearWithFurloughScheme(reportingYear) && draftReturn.OptedOutOfReportingPayQuarters) || EmployeesByPayQuartileSectionIsFilledIn(draftReturn); return(HourlyPaySectionIsComplete(draftReturn) && BonusPaySectionIsComplete(draftReturn) && employeesByPayQuartileSectionIsComplete && ResponsiblePersonSectionIsComplete(draftReturn, organisation) && WebsiteLinkSectionIsComplete(draftReturn)); }
public static void ValidateUserInput(ReportFiguresViewModel viewModel, HttpRequest request, int reportingYear) { ValidateBonusPayFigures(viewModel, request); ValidateHourlyPayFigures(viewModel, request); ValidatePayQuartileFigures(viewModel, request); if (viewModel.OptedOutOfReportingPayQuarters) { if (!ReportingYearsHelper.IsReportingYearWithFurloughScheme(reportingYear)) { const string errorMessage = "You cannot opt out of reporting your pay quarter figures for this reporting year"; viewModel.AddErrorFor(m => m.OptedOutOfReportingPayQuarters, errorMessage); } if (HasPayQuarterFigures(viewModel)) { const string errorMessage = "Do not enter the data for the percentage of men and women in each hourly pay quarter " + "if you have opted out of reporting your pay quarter figures"; viewModel.AddErrorFor(m => m.OptedOutOfReportingPayQuarters, errorMessage); } } }
public List <ManageOrganisationDetailsForYearViewModel> GetOrganisationDetailsForYears() { List <int> reportingYears = ReportingYearsHelper.GetReportingYears(); var detailsForYears = new List <ManageOrganisationDetailsForYearViewModel>(); 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, yearsWithDraftReturns.Contains(reportingYear) )); } } return(detailsForYears); }
public bool AllRequiredFieldsAreFilled() { bool optOutOfReporting = ReportingYearsHelper.IsReportingYearWithFurloughScheme(SnapshotDate) && OptedOutOfReportingPayQuarters; bool hasPayQuartersData = MaleLowerPayBand.HasValue && FemaleLowerPayBand.HasValue && MaleLowerMiddlePayBand.HasValue && FemaleLowerMiddlePayBand.HasValue && MaleUpperPayBand.HasValue && FemaleUpperPayBand.HasValue && MaleUpperMiddlePayBand.HasValue && FemaleUpperMiddlePayBand.HasValue; bool hasHourlyData = DiffMeanHourlyPayPercent.HasValue && DiffMedianHourlyPercent.HasValue; bool hasBonusData = MaleBonusPayPercent.HasValue && FemaleBonusPayPercent.HasValue && DiffMeanBonusPercent.HasValue && DiffMedianBonusPercent.HasValue; bool hasEnterCalculationsData = hasHourlyData && hasBonusData; bool hasValidBonusFigures = MaleBonusPayPercent == 0 || DiffMeanBonusPercent.HasValue && DiffMedianBonusPercent.HasValue; bool hasValidGpgFigures = (optOutOfReporting || hasPayQuartersData) && hasEnterCalculationsData && hasValidBonusFigures; if (Organisation.SectorType == SectorTypes.Public) { return(hasValidGpgFigures); } bool hasPersonResponsibleData = !string.IsNullOrWhiteSpace(ResponsiblePersonJobTitle) && !string.IsNullOrWhiteSpace(ResponsiblePersonFirstName) && !string.IsNullOrWhiteSpace(ResponsiblePersonLastName); return(hasValidGpgFigures && hasPersonResponsibleData); }
private static IEnumerable <dynamic> BuildOrganisationsWithNoSubmittedReturnsRecords(IEnumerable <Organisation> organisationsWithNoSubmittedReturns) { return(organisationsWithNoSubmittedReturns.Select( org => { dynamic record = new ExpandoObject(); record.OrganisationId = org.OrganisationId; record.EmployerReference = org.EmployerReference; record.OrganisationName = org.OrganisationName; record.CompanyNumber = org.CompanyNumber; record.SectorType = org.SectorType; record.Address = org.GetLatestAddress()?.GetAddressString(); UserOrganisation latestUserOrg = org.UserOrganisations .OrderByDescending(uo => uo.Modified) .FirstOrDefault( uo => uo.HasBeenActivated() && uo.User.Status == UserStatuses.Active); Return latestReturn = org.Returns .OrderByDescending(r => r.StatusDate) .FirstOrDefault(r => r.Status == ReturnStatuses.Submitted); record.Size = latestReturn?.OrganisationSize.GetAttribute <DisplayAttribute>().Name; record.FirstName = latestUserOrg?.User.Firstname; record.LastName = latestUserOrg?.User.Lastname; record.JobTitle = latestUserOrg?.User.JobTitle; record.PhoneNumber = latestUserOrg?.User.ContactPhoneNumber; record.EmailAddress = latestUserOrg?.User.EmailAddress; foreach (var repYear in ReportingYearsHelper.GetReportingYears().ToSortedSet()) { ((IDictionary <string, object>)record)["ReportDateTimeFor" + repYear] = org.GetReturn(repYear)?.StatusDate; } return record; }) .ToList()); }
public FileContentResult DownloadOrphanOrganisations() { DateTime pinExpiresDate = VirtualDateTime.Now.AddDays(0 - Global.PinInPostExpiryDays); List <Organisation> orphanOrganisations = dataRepository.GetAll <Organisation>() .Where(org => org.Status == OrganisationStatuses.Active) .Where(org => org.OrganisationScopes.OrderByDescending(s => s.SnapshotDate).FirstOrDefault(s => s.Status == ScopeRowStatuses.Active) == null || org.OrganisationScopes.OrderByDescending(s => s.SnapshotDate).FirstOrDefault(s => s.Status == ScopeRowStatuses.Active).ScopeStatus == ScopeStatuses.InScope || org.OrganisationScopes.OrderByDescending(s => s.SnapshotDate).FirstOrDefault(s => s.Status == ScopeRowStatuses.Active).ScopeStatus == ScopeStatuses.PresumedInScope) // We need the AsEnumerable here because EF gets upset about method calls - so we get the list at this point and then can filter it using a method call .AsEnumerable() .Where(org => org.UserOrganisations == null || !org.UserOrganisations.Any(uo => uo.HasBeenActivated() || // Registration complete uo.Method == RegistrationMethods.Manual || // Manual registration (uo.Method == RegistrationMethods.PinInPost && // PITP registration in progress uo.PINSentDate.HasValue && uo.PINSentDate.Value > pinExpiresDate))) .ToList(); var records = orphanOrganisations.Select( org => new { org.OrganisationId, org.OrganisationName, Address = org.GetLatestAddress()?.GetAddressString(), Sector = org.SectorType, ReportingDeadline = ReportingYearsHelper.GetDeadlineForAccountingDate(org.SectorType.GetAccountingStartDate()), }) .ToList(); string fileDownloadName = $"Gpg-OrphanOrganisations-{new GDSDateFormatter(VirtualDateTime.Now).FullStartDateTime}.csv"; FileContentResult fileContentResult = DownloadHelper.CreateCsvDownload(records, fileDownloadName); return(fileContentResult); }
// The deadline date is the final day that a return can be submitted without being considered late // The due date is a day later, the point at which a return is considered late // i.e. if the deadline date is 2021/04/01, submissions on that day are not late, any after 2021/04/02 00:00:00 are private DateTime GetDueDate() { return(ReportingYearsHelper.GetDeadlineForAccountingDate(AccountingDate).AddDays(1)); }