diff --git a/src/SFA.DAS.EmployerFinance.UnitTests/Services/CohortsServiceTests/WhenIGetACohortsCount.cs b/src/SFA.DAS.EmployerFinance.UnitTests/Services/CohortsServiceTests/WhenIGetACohortsCount.cs index 8ae58e4938..638a101fc3 100644 --- a/src/SFA.DAS.EmployerFinance.UnitTests/Services/CohortsServiceTests/WhenIGetACohortsCount.cs +++ b/src/SFA.DAS.EmployerFinance.UnitTests/Services/CohortsServiceTests/WhenIGetACohortsCount.cs @@ -17,13 +17,13 @@ namespace SFA.DAS.EmployerFinance.UnitTests.Services.CohortsServiceTests public class WhenIGetACohortsCount { private Mock _apiClient; - private CohortsService _service; + private ApprenticeshipService _service; [SetUp] public void Setup() { _apiClient = new Mock(); - _service = new CohortsService(_apiClient.Object); + _service = new ApprenticeshipService(_apiClient.Object); } [Test] @@ -31,7 +31,7 @@ public async Task ThenTheApiIsCalledWithAValidAccountIdAndTheCohortsCountIsRetur { SetupApiClient(1); - var actual = await _service.GetCohortsCount(1); + var actual = await _service.GetApprenticeshipsFor(1); Assert.AreEqual(1, actual); } @@ -41,7 +41,7 @@ public async Task ThenTheApiIsCalledWithAnInvalidAccountIdAndTheCohortsCountIsZe { SetupApiClient(0, false); - var actual = await _service.GetCohortsCount(0); + var actual = await _service.GetApprenticeshipsFor(0); Assert.AreEqual(0, actual); } @@ -62,11 +62,11 @@ private void SetupApiClient(long accountId, bool addItem = true) } _apiClient.Setup(o => - o.Get( - It.Is(i => i.GetUrl.Equals($"api/cohorts?accountId={accountId}")))) - .ReturnsAsync(new GetCohortsResponse + o.Get( + It.Is(i => i.GetUrl.Equals($"api/cohorts?accountId={accountId}")))) + .ReturnsAsync(new GetApplicationsResponse { - Cohorts = items + //Apprenticeships = items }); } } diff --git a/src/SFA.DAS.EmployerFinance.Web/Extensions/ListExtensions.cs b/src/SFA.DAS.EmployerFinance.Web/Extensions/ListExtensions.cs new file mode 100644 index 0000000000..7e38028b53 --- /dev/null +++ b/src/SFA.DAS.EmployerFinance.Web/Extensions/ListExtensions.cs @@ -0,0 +1,20 @@ +using System; +using System.Collections.Generic; +using System.Linq; +using System.Web; +using SFA.DAS.CommitmentsV2.Types; +using SFA.DAS.EmployerFinance.Models.Apprenticeships; + +namespace SFA.DAS.EmployerFinance.Web.Extensions +{ + public static class ListExtensions + { + public static long GetActivelyFundedApprenticeCount(this IEnumerable apprenticesDetails) + { + return apprenticesDetails.Count(o => + o.ApprenticeshipStatus == ApprenticeshipStatus.WaitingToStart || + o.ApprenticeshipStatus == ApprenticeshipStatus.Live || + o.ApprenticeshipStatus == ApprenticeshipStatus.Paused); + } + } +} \ No newline at end of file diff --git a/src/SFA.DAS.EmployerFinance.Web/Orchestrators/TransfersOrchestrator.cs b/src/SFA.DAS.EmployerFinance.Web/Orchestrators/TransfersOrchestrator.cs index 2c081a2fa3..132290cca0 100644 --- a/src/SFA.DAS.EmployerFinance.Web/Orchestrators/TransfersOrchestrator.cs +++ b/src/SFA.DAS.EmployerFinance.Web/Orchestrators/TransfersOrchestrator.cs @@ -7,6 +7,7 @@ using SFA.DAS.EmployerFinance.Web.ViewModels; using SFA.DAS.HashingService; using SFA.DAS.Common.Domain.Types; +using SFA.DAS.EmployerFinance.Web.Extensions; namespace SFA.DAS.EmployerFinance.Web.Orchestrators { @@ -16,7 +17,8 @@ public class TransfersOrchestrator private readonly IHashingService _hashingService; private readonly ILevyTransferMatchingService _levyTransferMatchingService; private readonly IAccountApiClient _accountApiClient; - private readonly ICohortsService _cohortsService; + private IApprenticeshipService _apprenticeshipService; + protected TransfersOrchestrator() { @@ -28,36 +30,48 @@ public TransfersOrchestrator( IHashingService hashingService, ILevyTransferMatchingService levyTransferMatchingService, IAccountApiClient accountApiClient, - ICohortsService cohortsService) + IApprenticeshipService apprenticeshipService) { _authorizationService = authorizationService; _hashingService = hashingService; _levyTransferMatchingService = levyTransferMatchingService; _accountApiClient = accountApiClient; - _cohortsService = cohortsService; + _apprenticeshipService = apprenticeshipService; } public async Task> Index(string hashedAccountId) { var accountDetail = await _accountApiClient.GetAccount(hashedAccountId).ConfigureAwait(false); - var cohortsCount = await _cohortsService.GetCohortsCount(accountDetail.AccountId).ConfigureAwait(false); - + Enum.TryParse(accountDetail.ApprenticeshipEmployerType, true, out ApprenticeshipEmployerType employerType); - if (employerType != ApprenticeshipEmployerType.Levy || cohortsCount > 0) + if (employerType != ApprenticeshipEmployerType.Levy) { - return new OrchestratorResponse() - { - Data = new TransfersIndexViewModel() - { - CanViewPledgesSection = false - } - }; + return GenerateTransfersViewIndexModelForNonLevyOrCurrentlyFundedLevyEmployers(); + } + + var fundedApprentices = await _apprenticeshipService.GetApprenticeshipsFor(accountDetail.AccountId) + .ConfigureAwait(false); + + if (fundedApprentices.GetActivelyFundedApprenticeCount() > 0) + { + return GenerateTransfersViewIndexModelForNonLevyOrCurrentlyFundedLevyEmployers(); } return await GenerateTransfersViewIndexModelForLevyAccounts(hashedAccountId); } + private static OrchestratorResponse GenerateTransfersViewIndexModelForNonLevyOrCurrentlyFundedLevyEmployers() + { + return new OrchestratorResponse() + { + Data = new TransfersIndexViewModel() + { + CanViewPledgesSection = false + } + }; + } + private async Task> GenerateTransfersViewIndexModelForLevyAccounts(string hashedAccountId) { bool renderCreateTransfersPledgeButton = diff --git a/src/SFA.DAS.EmployerFinance.Web/SFA.DAS.EmployerFinance.Web.csproj b/src/SFA.DAS.EmployerFinance.Web/SFA.DAS.EmployerFinance.Web.csproj index 86cbcdcbd5..1cd1c648f0 100644 --- a/src/SFA.DAS.EmployerFinance.Web/SFA.DAS.EmployerFinance.Web.csproj +++ b/src/SFA.DAS.EmployerFinance.Web/SFA.DAS.EmployerFinance.Web.csproj @@ -178,6 +178,7 @@ + diff --git a/src/SFA.DAS.EmployerFinance/DependencyResolution/ManageApprenticeshipsOuterApiRegistry.cs b/src/SFA.DAS.EmployerFinance/DependencyResolution/ManageApprenticeshipsOuterApiRegistry.cs index 3033ceb22e..b91f12e9a7 100644 --- a/src/SFA.DAS.EmployerFinance/DependencyResolution/ManageApprenticeshipsOuterApiRegistry.cs +++ b/src/SFA.DAS.EmployerFinance/DependencyResolution/ManageApprenticeshipsOuterApiRegistry.cs @@ -14,7 +14,7 @@ public ManageApprenticeshipsOuterApiRegistry () For().Use(c => c.GetInstance().ManageApprenticeshipsOuterApiConfiguration).Singleton(); For().Use().Ctor().Is(new HttpClient()).Singleton(); For().Add().Named("CAPI").Ctor().Is(new HttpClient()).Singleton(); - For().Use().Ctor().IsNamedInstance("CAPI").Singleton(); + For().Use().Ctor().IsNamedInstance("CAPI").Singleton(); } } } \ No newline at end of file diff --git a/src/SFA.DAS.EmployerFinance/Infrastructure/OuterApiRequests/GetCohortsRequest.cs b/src/SFA.DAS.EmployerFinance/Infrastructure/OuterApiRequests/GetApplicationsRequest.cs similarity index 53% rename from src/SFA.DAS.EmployerFinance/Infrastructure/OuterApiRequests/GetCohortsRequest.cs rename to src/SFA.DAS.EmployerFinance/Infrastructure/OuterApiRequests/GetApplicationsRequest.cs index bb5ba69ed0..a3b21c9a73 100644 --- a/src/SFA.DAS.EmployerFinance/Infrastructure/OuterApiRequests/GetCohortsRequest.cs +++ b/src/SFA.DAS.EmployerFinance/Infrastructure/OuterApiRequests/GetApplicationsRequest.cs @@ -7,15 +7,17 @@ namespace SFA.DAS.EmployerFinance.Infrastructure.OuterApiRequests { - public class GetCohortsRequest : IGetApiRequest + public class GetApplicationsRequest : IGetApiRequest { private readonly long _accountId; + private readonly int _pageSize; - public GetCohortsRequest(long accountId) + public GetApplicationsRequest(long accountId, int pageSize) { _accountId = accountId; + _pageSize = pageSize; } - public string GetUrl => $"api/cohorts?accountId={_accountId}"; + public string GetUrl => $"api/apprenticeships?accountId={_accountId}&PageItemCount={_pageSize}"; } } diff --git a/src/SFA.DAS.EmployerFinance/Infrastructure/OuterApiResponses/GetApplicationsResponse.cs b/src/SFA.DAS.EmployerFinance/Infrastructure/OuterApiResponses/GetApplicationsResponse.cs new file mode 100644 index 0000000000..74218b9131 --- /dev/null +++ b/src/SFA.DAS.EmployerFinance/Infrastructure/OuterApiResponses/GetApplicationsResponse.cs @@ -0,0 +1,10 @@ +using System.Collections.Generic; +using SFA.DAS.EmployerFinance.Models.Apprenticeships; + +namespace SFA.DAS.EmployerFinance.Infrastructure.OuterApiResponses +{ + public class GetApplicationsResponse + { + public IEnumerable Apprenticeships { get; set; } + } +} diff --git a/src/SFA.DAS.EmployerFinance/Infrastructure/OuterApiResponses/GetCohortsResponse.cs b/src/SFA.DAS.EmployerFinance/Infrastructure/OuterApiResponses/GetCohortsResponse.cs deleted file mode 100644 index 348ad75fa2..0000000000 --- a/src/SFA.DAS.EmployerFinance/Infrastructure/OuterApiResponses/GetCohortsResponse.cs +++ /dev/null @@ -1,15 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using SFA.DAS.CommitmentsV2.Types; -using SFA.DAS.EmployerFinance.Interfaces.OuterApi; - -namespace SFA.DAS.EmployerFinance.Infrastructure.OuterApiResponses -{ - public class GetCohortsResponse - { - public List Cohorts { get; set; } - } -} diff --git a/src/SFA.DAS.EmployerFinance/Models/Apprenticeships/ApprenticeshipDetail.cs b/src/SFA.DAS.EmployerFinance/Models/Apprenticeships/ApprenticeshipDetail.cs new file mode 100644 index 0000000000..57e6d4d013 --- /dev/null +++ b/src/SFA.DAS.EmployerFinance/Models/Apprenticeships/ApprenticeshipDetail.cs @@ -0,0 +1,33 @@ +using System; +using System.Collections.Generic; +using SFA.DAS.CommitmentsV2.Types; + +namespace SFA.DAS.EmployerFinance.Models.Apprenticeships +{ + public class ApprenticeshipDetail + { + public long Id { get; set; } + + public string FirstName { get; set; } + + public string LastName { get; set; } + + public string Uln { get; set; } + + public string EmployerName { get; set; } + + public string ProviderName { get; set; } + + public string CourseName { get; set; } + + public DateTime StartDate { get; set; } + + public DateTime EndDate { get; set; } + + public PaymentStatus PaymentStatus { get; set; } + + public ApprenticeshipStatus ApprenticeshipStatus { get; set; } + + public IEnumerable Alerts { get; set; } + } +} diff --git a/src/SFA.DAS.EmployerFinance/Models/Cohort/CurrentCohorts.cs b/src/SFA.DAS.EmployerFinance/Models/Cohort/CurrentCohorts.cs deleted file mode 100644 index 1773786c4e..0000000000 --- a/src/SFA.DAS.EmployerFinance/Models/Cohort/CurrentCohorts.cs +++ /dev/null @@ -1,14 +0,0 @@ -using System; -using System.Collections.Generic; -using System.Linq; -using System.Text; -using System.Threading.Tasks; -using SFA.DAS.CommitmentsV2.Types; - -namespace SFA.DAS.EmployerFinance.Models.Cohort -{ - public class CurrentCohorts - { - public List Cohorts { get; set; } - } -} diff --git a/src/SFA.DAS.EmployerFinance/SFA.DAS.EmployerFinance.csproj b/src/SFA.DAS.EmployerFinance/SFA.DAS.EmployerFinance.csproj index 7ebefc3cd5..e5564653a9 100644 --- a/src/SFA.DAS.EmployerFinance/SFA.DAS.EmployerFinance.csproj +++ b/src/SFA.DAS.EmployerFinance/SFA.DAS.EmployerFinance.csproj @@ -26,6 +26,7 @@ + diff --git a/src/SFA.DAS.EmployerFinance/Services/CohortsService.cs b/src/SFA.DAS.EmployerFinance/Services/ApprenticeshipService.cs similarity index 55% rename from src/SFA.DAS.EmployerFinance/Services/CohortsService.cs rename to src/SFA.DAS.EmployerFinance/Services/ApprenticeshipService.cs index e34ba13bfd..ea4aa6c058 100644 --- a/src/SFA.DAS.EmployerFinance/Services/CohortsService.cs +++ b/src/SFA.DAS.EmployerFinance/Services/ApprenticeshipService.cs @@ -10,24 +10,24 @@ using SFA.DAS.EmployerFinance.Infrastructure.OuterApiRequests; using SFA.DAS.EmployerFinance.Infrastructure.OuterApiResponses; using SFA.DAS.EmployerFinance.Interfaces.OuterApi; -using SFA.DAS.EmployerFinance.Models.Cohort; +using SFA.DAS.EmployerFinance.Models.Apprenticeships; namespace SFA.DAS.EmployerFinance.Services { - public class CohortsService : ICohortsService + public class ApprenticeshipService : IApprenticeshipService { private readonly IApiClient _apiClient; - public CohortsService(IApiClient apiClient) + public ApprenticeshipService(IApiClient apiClient) { _apiClient = apiClient; } - public async Task GetCohortsCount(long accountId) + public async Task> GetApprenticeshipsFor(long accountId) { - var cohortsCountResponse = await _apiClient.Get(new GetCohortsRequest(accountId)).ConfigureAwait(false); + var applicationsResponse = await _apiClient.Get(new GetApplicationsRequest(accountId, 500)).ConfigureAwait(false); - return cohortsCountResponse.Cohorts.Count; + return applicationsResponse.Apprenticeships; } } } diff --git a/src/SFA.DAS.EmployerFinance/Services/IApprenticeshipService.cs b/src/SFA.DAS.EmployerFinance/Services/IApprenticeshipService.cs new file mode 100644 index 0000000000..6195a0e19e --- /dev/null +++ b/src/SFA.DAS.EmployerFinance/Services/IApprenticeshipService.cs @@ -0,0 +1,11 @@ +using System.Collections.Generic; +using System.Threading.Tasks; +using SFA.DAS.EmployerFinance.Models.Apprenticeships; + +namespace SFA.DAS.EmployerFinance.Services +{ + public interface IApprenticeshipService + { + Task> GetApprenticeshipsFor(long accountId); + } +} \ No newline at end of file diff --git a/src/SFA.DAS.EmployerFinance/Services/ICohortsService.cs b/src/SFA.DAS.EmployerFinance/Services/ICohortsService.cs deleted file mode 100644 index 5134c420ec..0000000000 --- a/src/SFA.DAS.EmployerFinance/Services/ICohortsService.cs +++ /dev/null @@ -1,9 +0,0 @@ -using System.Threading.Tasks; - -namespace SFA.DAS.EmployerFinance.Services -{ - public interface ICohortsService - { - Task GetCohortsCount(long accountId); - } -} \ No newline at end of file