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);
            }
        }
Beispiel #2
0
        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);
        }
        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);
        }
Beispiel #4
0
        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);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        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 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);
        }
Beispiel #8
0
        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);
        }
Beispiel #9
0
        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);
        }
Beispiel #10
0
        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);
        }
Beispiel #11
0
 // 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));
 }
        private DateTime GetReportingDeadline()
        {
            DateTime snapshotDate = GetAccountingDate();

            return(ReportingYearsHelper.GetDeadlineForAccountingDate(snapshotDate));
        }
Beispiel #13
0
 private static DateTime GetDeadlineDateForReportingYear(SectorTypes sectorType, int year)
 {
     return(ReportingYearsHelper.GetDeadlineForAccountingDate(sectorType.GetAccountingStartDate(year)).AddDays(1));
 }