private void AddOnProgPayment(Payment paymentToValidate, List <PeriodisedRequiredPaymentEvent> expectedPayments, decimal amountDue, OnProgrammeEarningType type) { var deliveryPeriod = new DeliveryPeriodBuilder().WithSpecDate(paymentToValidate.DeliveryPeriod).Build(); var payment = CreateContractTypeRequiredPaymentEvent(amountDue, type, deliveryPeriod); if (payment.AmountDue != 0) { expectedPayments.Add(payment); } }
protected override IList <ProviderPaymentEvent> GetExpectedEvents() { var expectedPayments = new List <ProviderPaymentEvent>(); var payments = paymentSpec.Where(p => p.ParsedCollectionPeriod.Period == collectionPeriod.Period && p.ParsedCollectionPeriod.AcademicYear == collectionPeriod.AcademicYear); foreach (var providerPayment in payments) { var eventCollectionPeriod = new CollectionPeriodBuilder().WithSpecDate(providerPayment.CollectionPeriod).Build(); var deliveryPeriod = new DeliveryPeriodBuilder().WithSpecDate(providerPayment.DeliveryPeriod).Build(); var testLearner = testSession.GetLearner(provider.Ukprn, providerPayment.LearnerId); var learner = new Learner { ReferenceNumber = testLearner.LearnRefNumber, Uln = testLearner.Uln, }; var standardCode = providerPayment.StandardCode; if (!standardCode.HasValue) { var aim = testLearner.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(collectionPeriod); if (!aimFinishedInPreviousPeriod) { return(true); } // withdrawal but payments made during period active if (a.CompletionStatus == CompletionStatus.Withdrawn && providerPayment.LevyPayments >= 0M && providerPayment.SfaCoFundedPayments >= 0M && providerPayment.EmployerCoFundedPayments >= 0M && providerPayment.SfaFullyFundedPayments >= 0M) { return(false); } // retrospective withdrawal return(a.AimReference == "ZPROG001" && (a.CompletionStatus == CompletionStatus.Completed || a.CompletionStatus == CompletionStatus.Withdrawn)); }); standardCode = aim?.StandardCode ?? 0; } if (providerPayment.SfaCoFundedPayments != 0) { var coFundedSfa = new SfaCoInvestedProviderPaymentEvent { TransactionType = providerPayment.TransactionType, AmountDue = providerPayment.SfaCoFundedPayments, CollectionPeriod = eventCollectionPeriod, DeliveryPeriod = deliveryPeriod, Learner = learner, FundingSourceType = FundingSourceType.CoInvestedSfa, LearningAim = new LearningAim { StandardCode = standardCode.Value }, AccountId = providerPayment.AccountId }; expectedPayments.Add(coFundedSfa); } if (providerPayment.EmployerCoFundedPayments != 0) { var coFundedEmp = new EmployerCoInvestedProviderPaymentEvent { TransactionType = providerPayment.TransactionType, AmountDue = providerPayment.EmployerCoFundedPayments, CollectionPeriod = eventCollectionPeriod, DeliveryPeriod = deliveryPeriod, Learner = learner, FundingSourceType = FundingSourceType.CoInvestedEmployer, AccountId = providerPayment.AccountId, LearningAim = new LearningAim { StandardCode = standardCode.Value } }; expectedPayments.Add(coFundedEmp); } if (providerPayment.SfaFullyFundedPayments != 0) { var fullyFundedSfa = new SfaFullyFundedProviderPaymentEvent { TransactionType = providerPayment.TransactionType, AmountDue = providerPayment.SfaFullyFundedPayments, CollectionPeriod = eventCollectionPeriod, DeliveryPeriod = deliveryPeriod, Learner = learner, AccountId = providerPayment.AccountId, LearningAim = new LearningAim { StandardCode = standardCode.Value } }; expectedPayments.Add(fullyFundedSfa); } if (providerPayment.LevyPayments != 0) { var levyFunded = new LevyProviderPaymentEvent { TransactionType = providerPayment.TransactionType, AmountDue = providerPayment.LevyPayments, CollectionPeriod = eventCollectionPeriod, DeliveryPeriod = deliveryPeriod, Learner = learner, AccountId = providerPayment.AccountId, LearningAim = new LearningAim { StandardCode = standardCode.Value } }; expectedPayments.Add(levyFunded); } if (providerPayment.TransferPayments != 0) { var transferFunded = new TransferProviderPaymentEvent { TransactionType = providerPayment.TransactionType, AmountDue = providerPayment.TransferPayments, CollectionPeriod = eventCollectionPeriod, DeliveryPeriod = deliveryPeriod, Learner = learner, AccountId = providerPayment.AccountId, LearningAim = new LearningAim { StandardCode = standardCode.Value } }; expectedPayments.Add(transferFunded); } } return(expectedPayments); }