private PaymentModel ToPayment(HistoricalPayment payment, FundingSourceType fundingSource) { var testSessionLearner = TestSession.Learners.FirstOrDefault(l => l.LearnerIdentifier == payment.LearnerId) ?? TestSession.Learner; Assert.IsNotNull(testSessionLearner, $"Test session learner with learner id: '{payment.LearnerId}' not found."); return(new PaymentModel { EventId = Guid.NewGuid(), FundingSourceEventId = Guid.NewGuid(), Ukprn = TestSession.Ukprn, LearnerReferenceNumber = testSessionLearner.LearnRefNumber, LearnerUln = testSessionLearner.Uln, PriceEpisodeIdentifier = payment.PriceEpisodeIdentifier, Amount = GetFundingAmount(payment.Amount, fundingSource), CollectionPeriod = CollectionPeriodFactory.CreateFromAcademicYearAndPeriod(AcademicYear, CollectionPeriod), DeliveryPeriod = payment.DeliveryPeriod, LearningAimReference = testSessionLearner.Course.LearnAimRef, LearningAimProgrammeType = testSessionLearner.Course.ProgrammeType, LearningAimStandardCode = testSessionLearner.Course.StandardCode, LearningAimFrameworkCode = testSessionLearner.Course.FrameworkCode, LearningAimPathwayCode = testSessionLearner.Course.PathwayCode, LearningAimFundingLineType = testSessionLearner.Course.FundingLineType, FundingSource = fundingSource, ContractType = Payments.Model.Core.Entities.ContractType.Act2, SfaContributionPercentage = SfaContributionPercentage, JobId = TestSession.JobId, TransactionType = (TransactionType)payment.Type, IlrSubmissionDateTime = TestSession.IlrSubmissionTime }); }
private PaymentHistoryEntity CreatePaymentHistoryEntity(FundingSourceType fundingSource, byte deliveryPeriod, TransactionType transactionType = TransactionType.Learning) { return(new PaymentHistoryEntity { Amount = 10, SfaContributionPercentage = .9M, TransactionType = (int)transactionType, CollectionPeriod = new CollectionPeriod { AcademicYear = 1819, Period = 1 }, LearnAimReference = "ZPROG001", LearnerReferenceNumber = "learning-ref-456", PriceEpisodeIdentifier = "pe-1", DeliveryPeriod = deliveryPeriod, Ukprn = 7, LearnerUln = 5, ActualEndDate = null, CompletionAmount = 3000, CompletionStatus = 1, ExternalId = Guid.NewGuid(), FundingSource = fundingSource, InstalmentAmount = 1000, NumberOfInstalments = 12, PlannedEndDate = DateTime.Today, StartDate = DateTime.Today.AddMonths(-12), }); }
private PaymentModel ToPaymentModel( ProviderPayment paymentInfo, long ukprn, FundingSourceType fundingSource, decimal amount, long jobId, long?employerAccountId) { var learner = testSession.GetLearner(ukprn, paymentInfo.LearnerId); var standardCode = paymentInfo.StandardCode; if (!standardCode.HasValue) { var aim = learner.Aims.FirstOrDefault(a => { var aimStartDate = a.StartDate.ToDate(); var aimStartPeriod = new CollectionPeriodBuilder().WithDate(aimStartDate).Build(); var aimDuration = string.IsNullOrEmpty(a.ActualDuration) ? a.PlannedDuration : a.ActualDuration; var aimEndPeriod = AimPeriodMatcher.GetEndPeriodForAim(aimStartPeriod, aimDuration); var aimFinishedInPreviousPeriod = aimEndPeriod.FinishesBefore(currentCollectionPeriod); if (!aimFinishedInPreviousPeriod) { return(true); } if (a.CompletionStatus == CompletionStatus.Withdrawn && amount >= 0M) { return(false); } return(a.AimReference == "ZPROG001" && (a.CompletionStatus == CompletionStatus.Completed || a.CompletionStatus == CompletionStatus.Withdrawn)); }); standardCode = aim?.StandardCode ?? 0; } return(new PaymentModel { CollectionPeriod = new CollectionPeriodBuilder().WithSpecDate(paymentInfo.CollectionPeriod).Build(), Ukprn = ukprn, DeliveryPeriod = new DeliveryPeriodBuilder().WithSpecDate(paymentInfo.DeliveryPeriod).Build(), TransactionType = paymentInfo.TransactionType, ContractType = contractType, Amount = amount, FundingSource = fundingSource, LearnerReferenceNumber = learner.LearnRefNumber, JobId = jobId, AccountId = employerAccountId, LearningAimStandardCode = standardCode.Value }); }
private decimal GetFundingAmount(decimal amount, FundingSourceType fundingSource) { switch (fundingSource) { case FundingSourceType.CoInvestedEmployer: return(amount * .2m); case FundingSourceType.CoInvestedSfa: return(amount * .8m); default: return(amount); } }
private EarningType ToEarningType(FundingSourceType fundingSource) { switch (fundingSource) { case FundingSourceType.Levy: return(EarningType.Levy); case FundingSourceType.CoInvestedEmployer: case FundingSourceType.CoInvestedSfa: return(EarningType.CoInvested); case FundingSourceType.FullyFundedSfa: return(EarningType.Incentive); } throw new NotImplementedException($"Unknown funding source: {fundingSource}"); }
public ProviderPaymentEvent Create(FundingSourceType fundingSource) { switch (fundingSource) { case FundingSourceType.CoInvestedEmployer: return(new EmployerCoInvestedProviderPaymentEvent()); case FundingSourceType.CoInvestedSfa: return(new SfaCoInvestedProviderPaymentEvent()); case FundingSourceType.FullyFundedSfa: return(new SfaFullyFundedProviderPaymentEvent()); case FundingSourceType.Levy: return(new LevyProviderPaymentEvent()); case FundingSourceType.Transfer: return(new TransferProviderPaymentEvent()); default: throw new InvalidOperationException($"Cannot create the ProviderPayment, unexpected funding source: {fundingSource:G}"); } }
public void Refunds_All_Delivery_Periods(FundingSourceType testFundingSource) { history.AddRange(Enumerable.Range(1, 12) .Select(period => new Payment { DeliveryPeriod = (byte)period, SfaContributionPercentage = .9M, Amount = period * 10, PriceEpisodeIdentifier = "pe-1", FundingSource = testFundingSource, })); var requiredPayments = sut.RefundLearningAim(history); requiredPayments.Should().HaveCount(12); for (var i = 1; i <= 12; i++) { var period = i; requiredPayments.Should() .ContainSingle(x => x.deliveryPeriod == period && x.payment.Amount == -period * 10); } }
public void Maps_FundingSource(FundingSourceType fundingSource) { PaymentEvent.FundingSourceType = fundingSource; Mapper.Map <FundingSourceEventModel>(PaymentEvent).FundingSource.Should().Be(PaymentEvent.FundingSourceType); }