public void ReturnsFalseWhenNotCurrentYear(SectorTypes testSector, int testYear) { // Arrange DateTime testSnapshotDate = mockSharedBusinessLogic.GetAccountingStartDate(testSector); var expectCalledGetSnapshotDate = false; // Mocks var mockService = new Mock <SubmissionPresenter>( mockDataRepo.Object, mockScopeBL.Object, mockFileRepo.Object, mockDraftFileBL.Object, null); mockService.CallBase = true; // Override GetPreviousReportingStartDate and return expectedYear mockService.Setup(ss => ss.GetSnapshotDate(It.IsIn(testSector), It.IsAny <int>())) .Returns( () => { expectCalledGetSnapshotDate = true; return(testSnapshotDate); }); // Assert SubmissionPresenter testService = mockService.Object; bool actual = testService.IsCurrentSnapshotYear(testSector, testYear); Assert.IsTrue(expectCalledGetSnapshotDate, "Expected to call GetSnapshotDate"); Assert.IsFalse(actual, "Expected IsCurrentSnapshotYear to return true"); }
public void PresumesOutOfScopeForSnapshotYearsBeforeOrgCreatedDate(SectorTypes testSectorType) { // setup var testOrg = CreateOrgWithNoScopes(1, testSectorType, VirtualDateTime.Now); // act var actualChanged = scopeBusinessLogic.FillMissingScopes(testOrg); // assert Assert.IsTrue(actualChanged, "Expected change for missing scopes"); // test the count of scopes set is correct var currentSnapshotDate = mockSharedBusinessLogic.GetAccountingStartDate(testOrg.SectorType); var expectedScopeCount = currentSnapshotDate.Year - ConfigHelpers.SharedOptions.FirstReportingYear + 1; Assert.AreEqual(expectedScopeCount, testOrg.OrganisationScopes.Count); // check each scope before current snapshot year are set to presumed out of scope var actualScopesArray = testOrg.OrganisationScopes.ToArray(); for (var i = 0; i < actualScopesArray.Length - 1; i++) { var scope = actualScopesArray[i]; Assert.AreEqual(ScopeStatuses.PresumedOutOfScope, scope.ScopeStatus); } // assert current year is presumed in scope Assert.AreEqual(ScopeStatuses.PresumedInScope, actualScopesArray[actualScopesArray.Length - 1].ScopeStatus); Assert.NotNull(testOrg.LatestScope, "Expected latest scope to be set"); }
public virtual ScopingViewModel CreateScopingViewModel(Organisation org, User currentUser) { if (org == null) { throw new ArgumentNullException(nameof(org)); } var model = new ScopingViewModel { OrganisationId = org.OrganisationId, DUNSNumber = org.DUNSNumber, OrganisationName = org.OrganisationName, OrganisationAddress = org.LatestAddress?.GetAddressString(), AccountingDate = _sharedBusinessLogic.GetAccountingStartDate(org.SectorType) }; model.EnterCodes.EmployerReference = org.EmployerReference; // get the scope info for this year var scope = ScopeBusinessLogic.GetLatestScopeBySnapshotYear(org, model.AccountingDate.Year); if (scope != null) { model.ThisScope = new ScopeViewModel { OrganisationScopeId = scope.OrganisationScopeId, ScopeStatus = scope.ScopeStatus, StatusDate = scope.ScopeStatusDate, RegisterStatus = scope.RegisterStatus, SnapshotDate = scope.SnapshotDate } } ; // get the scope info for last year scope = ScopeBusinessLogic.GetLatestScopeBySnapshotYear(org, model.AccountingDate.Year - 1); if (scope != null) { model.LastScope = new ScopeViewModel { OrganisationScopeId = scope.OrganisationScopeId, ScopeStatus = scope.ScopeStatus, StatusDate = scope.ScopeStatusDate, RegisterStatus = scope.RegisterStatus, SnapshotDate = scope.SnapshotDate } } ; //Check if the user is registered for this organisation model.UserIsRegistered = currentUser != null && org.UserOrganisations.Any(uo => uo.UserId == currentUser.UserId); return(model); }
public async Task ReportCountIsControlledBySubmissionOptions(SectorTypes testSector, int testEditableReportCount) { // Arrange var testConfig = new SubmissionOptions { EditableReportCount = testEditableReportCount }; var testOrg = new Organisation { OrganisationId = 1, SectorType = testSector }; var testUserOrg = new UserOrganisation { Organisation = testOrg }; DateTime testSnapshotDate = mockSharedBusinessLogic.GetAccountingStartDate(testOrg.SectorType); var mockService = new Mock <SubmissionPresenter>( mockDataRepo.Object, mockScopeBL.Object, null, mockDraftFileBL.Object, MoqHelpers.CreateIOptionsSnapshotMock(testConfig)); // Call the real functions unless overridden mockService.CallBase = true; // Act SubmissionPresenter testService = mockService.Object; List <ReportInfoModel> actualResults = await testService.GetAllEditableReportsAsync(testUserOrg, testSnapshotDate); // Assert Assert.AreEqual( testEditableReportCount, actualResults.Count, $"Expected editable report count to be {testEditableReportCount}"); }
public List <OptionSelect> GetReportingYearOptions(IEnumerable <int> filterSnapshotYears) { // setup the filters var firstYear = _sharedBusinessLogic.SharedOptions.FirstReportingYear; var currentYear = _sharedBusinessLogic.GetAccountingStartDate(SectorTypes.Public).Year; var allYears = new List <int>(); for (var year = firstYear; year <= currentYear; year++) { allYears.Add(year); } var sources = new List <OptionSelect>(); for (var year = currentYear; year >= firstYear; year--) { var isChecked = filterSnapshotYears != null && filterSnapshotYears.Any(x => x == year); sources.Add( new OptionSelect { Id = year.ToString(), Label = $"{year} to {year + 1}", Value = year.ToString(), Checked = isChecked // Disabled = facetResults.Count == 0 && !isChecked }); } return(sources); }
public virtual async Task <CustomResult <OrganisationScope> > AddScopeAsync(Organisation organisation, ScopeStatuses newStatus, User currentUser, int snapshotYear, string comment, bool saveToDatabase) { snapshotYear = _sharedBusinessLogic.GetAccountingStartDate(organisation.SectorType, snapshotYear) .Year; var oldOrgScope = organisation.GetScopeOrThrow(snapshotYear); if (oldOrgScope.ScopeStatus == newStatus) { return(new CustomResult <OrganisationScope>( InternalMessages.SameScopesCannotBeUpdated(newStatus, oldOrgScope.ScopeStatus, snapshotYear))); } // When Organisation is Found Then Save New Scope Record With New Status var newScope = new OrganisationScope { OrganisationId = oldOrgScope.OrganisationId, Organisation = organisation, /* Updated by the current user */ ContactEmailAddress = currentUser.EmailAddress, ContactFirstname = currentUser.Firstname, ContactLastname = currentUser.Lastname, ReadGuidance = oldOrgScope.ReadGuidance, Reason = !string.IsNullOrEmpty(comment) ? comment : oldOrgScope.Reason, ScopeStatus = newStatus, ScopeStatusDate = VirtualDateTime.Now, StatusDetails = _sharedBusinessLogic.AuthorisationBusinessLogic.IsAdministrator(currentUser) ? "Changed by Admin" : null, RegisterStatus = oldOrgScope.RegisterStatus, RegisterStatusDate = oldOrgScope.RegisterStatusDate, // carry the snapshot date over SnapshotDate = oldOrgScope.SnapshotDate }; await SaveScopeAsync(organisation, saveToDatabase, newScope); return(new CustomResult <OrganisationScope>(newScope)); }
public async Task FindsOrgsWhereScopeIsMissing(int expectedMissingOrgId, SectorTypes testSector) { // act var actualMissingOrgScopes = await scopeBusinessLogic.FindOrgsWhereScopeNotSetAsync(); // assert var actualMissingEntry = actualMissingOrgScopes.Where( missing => missing.Organisation.OrganisationId == expectedMissingOrgId) .FirstOrDefault(); Assert.IsNotNull(actualMissingEntry, "Expected to find organisations who have null scopes"); var currentSnapshotDate = mockSharedBusinessLogic.GetAccountingStartDate(testSector); var testYears = GetAllSnapshotYearsForSector(currentSnapshotDate); foreach (var testYear in testYears) { Assert.IsTrue(actualMissingEntry.MissingSnapshotYears.Contains(testYear), "Expected missing year"); } }
/// <summary> /// Gets a list of late submissions that were in scope /// </summary> /// <returns></returns> public virtual IEnumerable <LateSubmissionsFileModel> GetLateSubmissions() { // get the snapshot dates to filter submissions by var curPrivateSnapshotDate = _sharedBusinessLogic.GetAccountingStartDate(SectorTypes.Private); var curPublicSnapshotDate = _sharedBusinessLogic.GetAccountingStartDate(SectorTypes.Public); var prevPrivateSnapshotDate = curPrivateSnapshotDate.AddYears(-1); var prevPublicSnapshotDate = curPublicSnapshotDate.AddYears(-1); // create return table query var lateSubmissions = _sharedBusinessLogic.DataRepository.GetAll <Return>() // filter only reports for the previous sector reporting start date and modified after their previous sector reporting end date .Where( r => r.Organisation.SectorType == SectorTypes.Private && r.AccountingDate == prevPrivateSnapshotDate && r.Modified >= curPrivateSnapshotDate || r.Organisation.SectorType == SectorTypes.Public && r.AccountingDate == prevPublicSnapshotDate && r.Modified >= curPublicSnapshotDate) // ensure we only return new, modified figures or modified SRO records .Where( r => string.IsNullOrEmpty(r.Modifications) || r.Modifications.ToLower().Contains("figures") || r.Modifications.ToLower().Contains("personresponsible")) .Where(r => r.Status == ReturnStatuses.Submitted) .Select( r => new { r.OrganisationId, r.Organisation.OrganisationName, r.Organisation.SectorType, r.ReturnId, r.AccountingDate, r.LateReason, r.Created, r.Modified, r.Modifications, r.FirstName, r.LastName, r.JobTitle, r.EHRCResponse }).ToList(); // create scope table query var activeScopes = _sharedBusinessLogic.DataRepository.GetAll <OrganisationScope>() .Where(os => os.SnapshotDate.Year == prevPrivateSnapshotDate.Year && os.Status == ScopeRowStatuses.Active) .Select(os => new { os.OrganisationId, os.ScopeStatus, os.ScopeStatusDate, os.SnapshotDate }).ToList(); // perform a left join on lateSubmissions and activeScopes var records = lateSubmissions.AsQueryable().GroupJoin( // join with activeScopes.AsQueryable(), // on // inner r => new { r.OrganisationId, r.AccountingDate.Year }, // outer os => new { os.OrganisationId, os.SnapshotDate.Year }, // into (r, os) => new { r, os = os.FirstOrDefault() }) // ensure we only have in scope returns .Where( j => j.os == null || j.os.ScopeStatus != ScopeStatuses.OutOfScope && j.os.ScopeStatus != ScopeStatuses.PresumedOutOfScope); return(records .ToList() .Select( j => new LateSubmissionsFileModel { OrganisationId = j.r.OrganisationId, OrganisationName = j.r.OrganisationName, OrganisationSectorType = j.r.SectorType, ReportId = j.r.ReturnId, ReportSnapshotDate = j.r.AccountingDate, ReportLateReason = j.r.LateReason, ReportSubmittedDate = j.r.Created, ReportModifiedDate = j.r.Modified, ReportModifiedFields = j.r.Modifications, ReportPersonResonsible = j.r.SectorType == SectorTypes.Public ? "Not required" : $"{j.r.FirstName} {j.r.LastName} ({j.r.JobTitle})", ReportEHRCResponse = j.r.EHRCResponse })); }
public string GetOrganisationSicSectorsString(Organisation organisation, DateTime?maxDate = null, string delimiter = ", ") { if (maxDate == null || maxDate.Value == DateTime.MinValue) { maxDate = _sharedBusinessLogic.GetAccountingStartDate(organisation.SectorType).AddYears(1); } return(organisation.GetSicSectorsString(maxDate.Value, delimiter)); }