public async Task Handle(PausePaymentsCommand command, CancellationToken cancellationToken = default) { var incentive = await _incentiveDomainRepository.FindByUlnWithinAccountLegalEntity(command.ULN, command.AccountLegalEntityId); if (incentive == null) { throw new KeyNotFoundException($"Unable to handle pause payments command as no incentive was found for ULN {command.ULN} and Account Legal Entity {command.AccountLegalEntityId}"); } var serviceRequest = new ServiceRequest(command.ServiceRequestId, command.DecisionReferenceNumber, command.DateServiceRequestTaskCreated.Value); switch (command.Action) { case PausePaymentsAction.Pause: incentive.PauseSubsequentPayments(serviceRequest); break; case PausePaymentsAction.Resume: incentive.ResumePayments(serviceRequest); break; default: throw new PausePaymentsException("Pause and Resume are the only supported actions"); } await _incentiveDomainRepository.Save(incentive); }
public async Task Handle(CreateIncentiveCommand command, CancellationToken cancellationToken = default) { var existing = await _apprenticeshipIncentiveDomainRepository.FindByApprenticeshipId(command.IncentiveApplicationApprenticeshipId); if (existing != null) { return; } var incentive = _apprenticeshipIncentiveFactory.CreateNew( Guid.NewGuid(), command.IncentiveApplicationApprenticeshipId, new Account(command.AccountId, command.AccountLegalEntityId), new Apprenticeship( command.ApprenticeshipId, command.FirstName, command.LastName, command.DateOfBirth, command.Uln, command.ApprenticeshipEmployerTypeOnApproval, command.CourseName ), command.PlannedStartDate, command.SubmittedDate, command.SubmittedByEmail); if (command.UKPRN.HasValue) { incentive.Apprenticeship.SetProvider(new Provider(command.UKPRN.Value)); } await _apprenticeshipIncentiveDomainRepository.Save(incentive); }
public async Task Handle(CalculateEarningsCommand command, CancellationToken cancellationToken = default) { var incentive = await _domainRepository.Find(command.ApprenticeshipIncentiveId); await incentive.CalculateEarnings(_incentivePaymentProfilesService, _collectionCalendarService); await _domainRepository.Save(incentive); }
public async Task Handle(CreatePaymentCommand command, CancellationToken cancellationToken = default) { var incentive = await _domainRepository.Find(command.ApprenticeshipIncentiveId); incentive.CreatePayment(command.PendingPaymentId, command.CollectionYear, command.CollectionPeriod); await _domainRepository.Save(incentive); }
public async Task Handle(RefreshLearnerCommand command, CancellationToken cancellationToken = default) { var incentive = await _incentiveDomainRepository.Find(command.ApprenticeshipIncentiveId); var learner = await _learnerDomainRepository.GetOrCreate(incentive); _logger.LogInformation("Start Learner data refresh from Learner match service for ApprenticeshipIncentiveId: {ApprenticeshipIncentiveId}, ApprenticeshipId: {ApprenticeshipId}, UKPRN: {UKPRN}, ULN: {ULN}", learner.ApprenticeshipIncentiveId, learner.ApprenticeshipId, learner.Ukprn, learner.UniqueLearnerNumber); SubmissionData submissionData = new SubmissionData(); var learnerData = await _learnerService.Get(learner); _logger.LogInformation("End Learner data refresh from Learner match service for ApprenticeshipIncentiveId: {ApprenticeshipIncentiveId}, ApprenticeshipId: {ApprenticeshipId}, UKPRN: {UKPRN}, ULN: {ULN}", learner.ApprenticeshipIncentiveId, learner.ApprenticeshipId, learner.Ukprn, learner.UniqueLearnerNumber); if (learnerData != null) { if (LearnerAndEarningsHaveNotChanged(learnerData, learner, incentive)) { return; } submissionData.SetSubmissionDate(learnerData.IlrSubmissionDate); var learningFoundStatus = learnerData.LearningFound(incentive); submissionData.SetLearningData(new LearningData(learningFoundStatus.LearningFound, learningFoundStatus.NotFoundReason)); if (learningFoundStatus.LearningFound) { submissionData.LearningData.SetStartDate(learnerData.LearningStartDate(incentive)); submissionData.LearningData.SetHasDataLock(learnerData.HasProviderDataLocks(incentive)); submissionData.LearningData.SetIsInLearning(learnerData.IsInLearning(incentive)); submissionData.LearningData.SetIsStopped(learnerData.IsStopped(incentive)); } submissionData.SetRawJson(learnerData.RawJson); } if (submissionData.HasChangeOfCircumstances(learner.SubmissionData)) { incentive.SetHasPossibleChangeOfCircumstances(true); } learner.SetSubmissionData(submissionData); incentive.LearnerRefreshCompleted(); learner.SetLearningPeriods(learnerData.LearningPeriods(incentive)); if (!learner.SubmissionData.LearningData.LearningFound) { _logger.LogInformation("Matching ILR record not found for ApprenticeshipIncentiveId: {ApprenticeshipIncentiveId}, ApprenticeshipId: {ApprenticeshipId}, UKPRN: {UKPRN}, ULN: {ULN} with reason: {NotFoundReason}", learner.ApprenticeshipIncentiveId, learner.ApprenticeshipId, learner.Ukprn, learner.UniqueLearnerNumber, learner.SubmissionData.LearningData.NotFoundReason); } await _learnerDomainRepository.Save(learner); await _incentiveDomainRepository.Save(incentive); }
public async Task Handle(EarningsResilienceIncentivesCheckCommand command, CancellationToken cancellationToken = default) { var incentives = await _incentiveDomainRepository.FindIncentivesWithoutPendingPayments(); foreach (var incentive in incentives) { incentive.CalculatePayments(); await _incentiveDomainRepository.Save(incentive); } }
public async Task Handle(WithdrawCommand command, CancellationToken cancellationToken = default) { var incentive = await _domainRepository.FindByApprenticeshipId(command.IncentiveApplicationApprenticeshipId); if (incentive == null) { return; } await incentive.Withdraw(_collectionCalendarService); await _domainRepository.Save(incentive); }
public async Task Handle(LearnerChangeOfCircumstanceCommand command, CancellationToken cancellationToken = default) { var incentive = await _domainRepository.Find(command.ApprenticeshipIncentiveId); if (!incentive.HasPossibleChangeOfCircumstances) { return; } var learner = await _learnerDomainRepository.GetOrCreate(incentive); incentive.SetChangeOfCircumstances(learner); await _domainRepository.Save(incentive); }
public async Task Handle(CalculateEarningsCommand command, CancellationToken cancellationToken = default) { if (await ActivePeriodInProgress()) { await ScheduleCalculateEarnings(command); return; } var incentive = await _domainRepository.Find(command.ApprenticeshipIncentiveId); await incentive.CalculateEarnings(_incentivePaymentProfilesService, _collectionCalendarService); await _domainRepository.Save(incentive); }
public async Task Handle(ValidatePendingPaymentCommand command, CancellationToken cancellationToken = default) { var incentive = await _domainRepository.Find(command.ApprenticeshipIncentiveId); var account = await _accountDomainRepository.Find(incentive.Account.Id); var learner = await _learnerDomainRepository.GetOrCreate(incentive); var calendar = await _collectionCalendarService.Get(); var collectionPeriod = calendar.GetPeriod(command.CollectionYear, command.CollectionPeriod); incentive.ValidatePendingPaymentBankDetails(command.PendingPaymentId, account, collectionPeriod); incentive.ValidateLearningData(command.PendingPaymentId, learner, collectionPeriod); incentive.ValidatePaymentsNotPaused(command.PendingPaymentId, collectionPeriod); await _domainRepository.Save(incentive); }