diff --git a/src/SFA.DAS.EmployerFinance.Web/Orchestrators/TransfersOrchestrator.cs b/src/SFA.DAS.EmployerFinance.Web/Orchestrators/TransfersOrchestrator.cs index fe7b85862f..2b27ef87b4 100644 --- a/src/SFA.DAS.EmployerFinance.Web/Orchestrators/TransfersOrchestrator.cs +++ b/src/SFA.DAS.EmployerFinance.Web/Orchestrators/TransfersOrchestrator.cs @@ -1,6 +1,8 @@ -using System.Threading.Tasks; +using System; +using System.Threading.Tasks; using SFA.DAS.Authorization.EmployerUserRoles.Options; using SFA.DAS.Authorization.Services; +using SFA.DAS.EAS.Account.Api.Client; using SFA.DAS.EmployerFinance.Services; using SFA.DAS.EmployerFinance.Web.ViewModels; using SFA.DAS.HashingService; @@ -12,6 +14,8 @@ public class TransfersOrchestrator private readonly IAuthorizationService _authorizationService; private readonly IHashingService _hashingService; private readonly ILevyTransferMatchingService _levyTransferMatchingService; + private readonly IAccountApiClient _accountApiClient; + private readonly ICohortsService _cohortsService; protected TransfersOrchestrator() { @@ -21,16 +25,40 @@ protected TransfersOrchestrator() public TransfersOrchestrator( IAuthorizationService authorizationService, IHashingService hashingService, - ILevyTransferMatchingService levyTransferMatchingService) + ILevyTransferMatchingService levyTransferMatchingService, + IAccountApiClient accountApiClient, + ICohortsService cohortsService) { _authorizationService = authorizationService; _hashingService = hashingService; _levyTransferMatchingService = levyTransferMatchingService; + _accountApiClient = accountApiClient; + _cohortsService = cohortsService; } public async Task> Index(string hashedAccountId) { - bool renderCreateTransfersPledgeButton = await _authorizationService.IsAuthorizedAsync(EmployerUserRole.OwnerOrTransactor); + var accountDetail = await _accountApiClient.GetAccount(hashedAccountId).ConfigureAwait(false); + var cohortsCount = await _cohortsService.GetCohortsCount(accountDetail.AccountId).ConfigureAwait(false); + + if (string.Compare(accountDetail.ApprenticeshipEmployerType, "Levy", StringComparison.OrdinalIgnoreCase) != 0 || cohortsCount > 0) + { + return new OrchestratorResponse() + { + Data = new TransfersIndexViewModel() + { + CanViewTransfersSection = false + } + }; + } + + return await GenerateTransfersViewIndexModelForLevyAccounts(hashedAccountId); + } + + private async Task> GenerateTransfersViewIndexModelForLevyAccounts(string hashedAccountId) + { + bool renderCreateTransfersPledgeButton = + await _authorizationService.IsAuthorizedAsync(EmployerUserRole.OwnerOrTransactor); var accountId = _hashingService.DecodeValue(hashedAccountId); @@ -42,6 +70,7 @@ public async Task> Index(string ha { RenderCreateTransfersPledgeButton = renderCreateTransfersPledgeButton, PledgesCount = pledgesCount, + CanViewTransfersSection = true } }; diff --git a/src/SFA.DAS.EmployerFinance.Web/ViewModels/TransfersIndexViewModel.cs b/src/SFA.DAS.EmployerFinance.Web/ViewModels/TransfersIndexViewModel.cs index 145b8b11dc..dc266fdf8a 100644 --- a/src/SFA.DAS.EmployerFinance.Web/ViewModels/TransfersIndexViewModel.cs +++ b/src/SFA.DAS.EmployerFinance.Web/ViewModels/TransfersIndexViewModel.cs @@ -2,6 +2,7 @@ { public class TransfersIndexViewModel { + public bool CanViewTransfersSection { get; set; } public bool RenderCreateTransfersPledgeButton { get; set; } public int PledgesCount { get; set; } } diff --git a/src/SFA.DAS.EmployerFinance.Web/Views/Transfers/Index.cshtml b/src/SFA.DAS.EmployerFinance.Web/Views/Transfers/Index.cshtml index f5d4fb7d94..9dc83ead31 100644 --- a/src/SFA.DAS.EmployerFinance.Web/Views/Transfers/Index.cshtml +++ b/src/SFA.DAS.EmployerFinance.Web/Views/Transfers/Index.cshtml @@ -8,23 +8,26 @@ ViewBag.ZenDeskLabel = "eas-finance"; } -

Transfers

-
-
-

My pledges

-

Create a public funding pledge which is shown online so that businesses can apply to you for a transfer of funds.

-
- You have @Model.Data.PledgesCount transfer pledges. -
-
- @if (Model.Data.RenderCreateTransfersPledgeButton) - { - Create a transfers pledge - } - View my transfer pledges and applications +@if (Model.Data.CanViewTransfersSection) +{ +

Transfers

+
+
+

My pledges

+

Create a public funding pledge which is shown online so that businesses can apply to you for a transfer of funds.

+
+ You have @Model.Data.PledgesCount transfer pledges. +
+
+ @if (Model.Data.RenderCreateTransfersPledgeButton) + { + Create a transfers pledge + } + View my transfer pledges and applications +
-
+} @section breadcrumb {