public async Task PublishLearnerRequest(List <Training> currentIlr, List <Learner> learners, string collectionPeriodText, string featureNumber, Func <Task> clearCache) { var collectionYear = collectionPeriodText.ToDate().Year; var collectionPeriod = new CollectionPeriodBuilder().WithSpecDate(collectionPeriodText).Build().Period; if (currentIlr != null && currentIlr.Any()) { // convert to TestSession.Learners learners = new List <Learner>(); learners.AddRange(currentIlr.DistinctBy(ilr => ilr.LearnerId).Select(dist => new Learner() { Ukprn = dist.Ukprn, Uln = dist.Uln, LearnerIdentifier = dist.LearnerId, PostcodePrior = dist.PostcodePrior, SmallEmployer = dist.SmallEmployer })); foreach (var learner in learners) { CreateAimsForIlrLearner(learner, currentIlr.SingleOrDefault(c => c.LearnerId == learner.LearnerIdentifier)); } } var learnerMutator = LearnerMutatorFactory.Create(featureNumber, learners); var ilrFile = await tdgService.GenerateIlrTestData(learnerMutator, (int)testSession.Provider.Ukprn); await RefreshTestSessionLearnerFromIlr(ilrFile.Value, learners); // this needs to be called here as the LearnRefNumber is updated to match the ILR in RefreshTestSessionLearnerFromIlr above await clearCache(); await StoreAndPublishIlrFile((int)testSession.Provider.Ukprn, ilrFileName : ilrFile.Key, ilrFile : ilrFile.Value, collectionYear : collectionYear, collectionPeriod : collectionPeriod); }
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 }); }
public async Task ThenTheCollectionPeriodDataForRCurrentAcademicYearShouldNOTBeStoredInTheDb(string specDate) { var collectionPeriod = new CollectionPeriodBuilder().WithSpecDate(specDate).Build(); var paymentDataContext = Container.Resolve <IPaymentsDataContext>(); await WaitForUnexpected(() => { var matchingPeriods = paymentDataContext.CollectionPeriod.Where(x => x.Period == collectionPeriod.Period && x.AcademicYear == collectionPeriod.AcademicYear); return(!matchingPeriods.Any(), "No PeriodEnd was recorded"); }, "Failed to find matching collection period in database"); }
public void GivenThePaymentsAreForTheCurrentCollectionYear() { AcademicYear = new CollectionPeriodBuilder().WithDate(DateTime.Today).Build().AcademicYear;; }
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); }
protected override IList <EarningFailedDataLockMatching> GetExpectedEvents() { var earningFailedDataLockEvents = new List <EarningFailedDataLockMatching>(); var learnerIds = expectedDataLockErrorsSpec.Select(e => e.LearnerId).Distinct().ToList(); foreach (var learnerId in learnerIds) { var learner = testSession.GetLearner(provider.Ukprn, learnerId); var learnerEarnings = expectedDataLockErrorsSpec.Where(x => x.LearnerId == learnerId).ToList(); var groupedEarningPerTransactionTypes = learnerEarnings.GroupBy(x => x.TransactionType); var earningFailedDataLockEvent = new EarningFailedDataLockMatching { CollectionPeriod = collectionPeriod, Ukprn = provider.Ukprn, Learner = new Model.Core.Learner { Uln = learner.Uln, }, LearningAim = new LearningAim { ProgrammeType = learnerEarnings.First().ProgrammeType, //May need to move to another Matcher StandardCode = learnerEarnings.First().StandardCode, FrameworkCode = learnerEarnings.First().FrameworkCode, PathwayCode = learnerEarnings.First().PathwayCode }, OnProgrammeEarnings = new List <OnProgrammeEarning>() }; foreach (var earningPerTransactionTypes in groupedEarningPerTransactionTypes) { var groupedEarningPerPeriods = earningPerTransactionTypes.GroupBy(x => x.DeliveryPeriod); var earningPeriods = new List <EarningPeriod>(); foreach (var earningPerPeriods in groupedEarningPerPeriods) { var period = new CollectionPeriodBuilder().WithDate(earningPerPeriods.Key.ToDate()).Build().Period; if (period > collectionPeriod.Period) { continue; } earningPeriods.Add(new EarningPeriod { PriceEpisodeIdentifier = earningPerPeriods.First().PriceEpisodeIdentifier, Period = period, DataLockFailures = earningPerPeriods.Select(x => new DataLockFailure { ApprenticeshipId = learnerEarnings.First().ApprenticeshipId, DataLockError = x.ErrorCode, ApprenticeshipPriceEpisodeIds = new List <long>() }).ToList() }); } if (EnumHelper.IsOnProgType(earningPerTransactionTypes.Key)) { earningFailedDataLockEvent.OnProgrammeEarnings.Add(new OnProgrammeEarning { Type = (OnProgrammeEarningType)earningPerTransactionTypes.Key, Periods = earningPeriods.AsReadOnly() }); } if (EnumHelper.IsIncentiveType(earningPerTransactionTypes.Key, true)) { earningFailedDataLockEvent.IncentiveEarnings.Add(new IncentiveEarning { Type = (IncentiveEarningType)earningPerTransactionTypes.Key, Periods = earningPeriods.AsReadOnly() }); } } earningFailedDataLockEvents.Add(earningFailedDataLockEvent); } return(earningFailedDataLockEvents); }