public RequiredPaymentsService(ActorService actorService, ActorId actorId, IPaymentLogger paymentLogger, IApprenticeshipKeyService apprenticeshipKeyService, Func <IPaymentHistoryRepository> paymentHistoryRepositoryFactory, IApprenticeshipContractType2EarningsEventProcessor contractType2EarningsEventProcessor, IApprenticeshipAct1RedundancyEarningsEventProcessor act1RedundancyEarningsEventProcessor, IFunctionalSkillEarningsEventProcessor functionalSkillEarningsEventProcessor, IPayableEarningEventProcessor payableEarningEventProcessor, IRefundRemovedLearningAimProcessor refundRemovedLearningAimProcessor, ITelemetry telemetry) : base(actorService, actorId) { this.paymentLogger = paymentLogger; this.paymentHistoryRepositoryFactory = paymentHistoryRepositoryFactory; this.contractType2EarningsEventProcessor = contractType2EarningsEventProcessor; this.act1RedundancyEarningsEventProcessor = act1RedundancyEarningsEventProcessor; this.functionalSkillEarningsEventProcessor = functionalSkillEarningsEventProcessor; this.payableEarningEventProcessor = payableEarningEventProcessor; this.refundRemovedLearningAimProcessor = refundRemovedLearningAimProcessor; this.telemetry = telemetry; apprenticeshipKeyString = actorId.GetStringId(); apprenticeshipKey = apprenticeshipKeyService.ParseApprenticeshipKey(apprenticeshipKeyString); logSafeApprenticeshipKeyString = CreateLogSafeApprenticeshipKeyString(apprenticeshipKey); }
private string CreateLogSafeApprenticeshipKeyString(ApprenticeshipKey key) { return($"learnerRef:{key.LearnerReferenceNumber}, frameworkCode:{key.FrameworkCode}, " + $"pathwayCode:{key.PathwayCode}, programmeType:{key.ProgrammeType}, " + $"standardCode:{key.StandardCode}, learningAimReference:{key.LearnAimRef}, " + $"academicYear:{key.AcademicYear}, contractType:{key.ContractType}"); }
public ApprenticeshipKey GetCurrentKey() { if (apprenticeshipKey == null) { apprenticeshipKey = apprenticeshipKeyService.ParseApprenticeshipKey(actorIdProvider.Current.GetStringId()); } return(apprenticeshipKey); }
public async Task <decimal> GetEmployerCoInvestedPaymentHistoryTotal(ApprenticeshipKey apprenticeshipKey, CancellationToken cancellationToken = default(CancellationToken)) { return(await dataContext.Payment .Where(payment => apprenticeshipKey.Ukprn == payment.Ukprn && apprenticeshipKey.FrameworkCode == payment.LearningAimFrameworkCode && apprenticeshipKey.LearnAimRef == payment.LearningAimReference && apprenticeshipKey.LearnerReferenceNumber == payment.LearnerReferenceNumber && apprenticeshipKey.PathwayCode == payment.LearningAimPathwayCode && apprenticeshipKey.ProgrammeType == payment.LearningAimProgrammeType && apprenticeshipKey.StandardCode == payment.LearningAimStandardCode && payment.FundingSource == FundingSourceType.CoInvestedEmployer && apprenticeshipKey.ContractType == payment.ContractType) .Select(payment => payment.Amount) .DefaultIfEmpty(0) .SumAsync(cancellationToken)); }
public async Task<List<PaymentHistoryEntity>> GetPaymentHistory(ApprenticeshipKey apprenticeshipKey, byte currentCollectionPeriod, CancellationToken cancellationToken = default(CancellationToken)) { return await dataContext.Payment .Where(payment => apprenticeshipKey.Ukprn == payment.Ukprn && apprenticeshipKey.FrameworkCode == payment.LearningAimFrameworkCode && apprenticeshipKey.LearnAimRef == payment.LearningAimReference && apprenticeshipKey.LearnerReferenceNumber == payment.LearnerReferenceNumber && apprenticeshipKey.PathwayCode == payment.LearningAimPathwayCode && (int)apprenticeshipKey.ProgrammeType == payment.LearningAimProgrammeType && apprenticeshipKey.StandardCode == payment.LearningAimStandardCode && apprenticeshipKey.AcademicYear == payment.CollectionPeriod.AcademicYear && apprenticeshipKey.ContractType == payment.ContractType && currentCollectionPeriod > payment.CollectionPeriod.Period) .Select(payment => new PaymentHistoryEntity { ExternalId = payment.EventId, AccountId = payment.AccountId, TransferSenderAccountId = payment.TransferSenderAccountId, ContractType = payment.ContractType, Ukprn = payment.Ukprn, LearnerReferenceNumber = payment.LearnerReferenceNumber, LearnerUln = payment.LearnerUln, LearnAimReference = payment.LearningAimReference, LearningAimFundingLineType = payment.LearningAimFundingLineType, TransactionType = (int)payment.TransactionType, PriceEpisodeIdentifier = payment.PriceEpisodeIdentifier, DeliveryPeriod = payment.DeliveryPeriod, CollectionPeriod = payment.CollectionPeriod, Amount = payment.Amount, FundingSource = payment.FundingSource, SfaContributionPercentage = payment.SfaContributionPercentage, StartDate = payment.StartDate, PlannedEndDate = payment.PlannedEndDate, ActualEndDate = payment.ActualEndDate, CompletionStatus = payment.CompletionStatus ?? 0, CompletionAmount = payment.CompletionAmount ?? 0, InstalmentAmount = payment.InstalmentAmount ?? 0, NumberOfInstalments = payment.NumberOfInstalments ?? 0, ApprenticeshipId = payment.ApprenticeshipId, ApprenticeshipPriceEpisodeId = payment.ApprenticeshipPriceEpisodeId, ApprenticeshipEmployerType = payment.ApprenticeshipEmployerType, LearningStartDate = payment.LearningStartDate, }) .ToListAsync(cancellationToken); }
public async Task <decimal> GetEmployerCoInvestedPaymentHistoryTotal(ApprenticeshipKey apprenticeshipKey, CancellationToken cancellationToken = default(CancellationToken)) { return(await dataContext.Payment .Where(payment => apprenticeshipKey.Ukprn == payment.Ukprn && apprenticeshipKey.FrameworkCode == payment.LearningAimFrameworkCode && apprenticeshipKey.LearnAimRef == payment.LearningAimReference && apprenticeshipKey.LearnerReferenceNumber == payment.LearnerReferenceNumber && apprenticeshipKey.PathwayCode == payment.LearningAimPathwayCode && apprenticeshipKey.ProgrammeType == payment.LearningAimProgrammeType && apprenticeshipKey.StandardCode == payment.LearningAimStandardCode && apprenticeshipKey.ContractType == payment.ContractType && payment.TransactionType == TransactionType.Learning && payment.FundingSource == FundingSourceType.CoInvestedEmployer ) //NOTE: do not remove cast to (int) this is used to remove decimal places from expectedContribution Amount i.e. 123.9997 becomes 123 .Select(payment => (int)payment.Amount) .DefaultIfEmpty(0) .SumAsync(cancellationToken)); }
public async Task When_HoldingBackCompletionPayment_Then_Log_a_Custom_Event() { // arrange var period = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2); var priceEpisodes = new List <PriceEpisode>(new [] { new PriceEpisode { Identifier = "1", EmployerContribution = 100, CompletionHoldBackExemptionCode = 0 }, new PriceEpisode { Identifier = "2", EmployerContribution = 1, CompletionHoldBackExemptionCode = 2 } }); var earningEvent = new PayableEarningEvent { Ukprn = 1, CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2), CollectionYear = period.AcademicYear, Learner = EarningEventDataHelper.CreateLearner(), LearningAim = EarningEventDataHelper.CreateLearningAim(), PriceEpisodes = priceEpisodes, OnProgrammeEarnings = new List <OnProgrammeEarning> { new OnProgrammeEarning { Type = OnProgrammeEarningType.Completion, Periods = new ReadOnlyCollection <EarningPeriod>(new List <EarningPeriod> { new EarningPeriod { Amount = 200, Period = period.Period, PriceEpisodeIdentifier = "2", SfaContributionPercentage = 0.9m, } }) } } }; var requiredPayments = new List <RequiredPayment> { new RequiredPayment { Amount = 100, EarningType = EarningType.Levy, }, }; var paymentHistoryEntities = new[] { new PaymentHistoryEntity { CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(1819, 2), DeliveryPeriod = 2, LearnAimReference = "ZPROG001" } }; var key = new ApprenticeshipKey(); paymentHistoryCacheMock.Setup(c => c.TryGet(It.Is <string>(k => k == CacheKeys.PaymentHistoryKey), It.IsAny <CancellationToken>())) .ReturnsAsync(new ConditionalValue <PaymentHistoryEntity[]>(true, paymentHistoryEntities)) .Verifiable(); requiredPaymentsService.Setup(p => p.GetRequiredPayments(It.IsAny <Earning>(), It.IsAny <List <Payment> >())).Returns(requiredPayments).Verifiable(); apprenticeshipKeyProviderMock.Setup(a => a.GetCurrentKey()).Returns(key).Verifiable(); paymentHistoryRepositoryMock.Setup(repo => repo.GetEmployerCoInvestedPaymentHistoryTotal(key, It.IsAny <CancellationToken>())).ReturnsAsync(11).Verifiable(); holdingBackCompletionPaymentServiceMock.Setup(h => h.ShouldHoldBackCompletionPayment(11, priceEpisodes[1])).Returns(true).Verifiable(); // act var actualRequiredPayment = await processor.HandleEarningEvent(earningEvent, paymentHistoryCacheMock.Object, CancellationToken.None); // assert actualRequiredPayment.Should().HaveCount(1); mocker.Mock <ITelemetry>().Verify(t => t.TrackEvent("Holding Back Completion Payment", It.Is <Dictionary <string, string> >(d => d.Contains(new KeyValuePair <string, string>("Expected Employer Contribution", "2")) && d.Contains(new KeyValuePair <string, string>("Reported Employer Contribution", "1"))), It.IsAny <Dictionary <string, double> >())); }