private static string GetFirstMatchingFundingLineTypeForContractType(IntermediateLearningAim intermediateLearningAim, FunctionalSkillEarningsEvent functionalSkillEarning) { var periodisedFundingLineTypeValues = intermediateLearningAim .Aims .SelectMany(x => x.LearningDeliveryPeriodisedTextValues) .Where(x => x.AttributeName.Equals("FundLineType")) .Select(x => x); if (periodisedFundingLineTypeValues != null) { var periodWithActiveEarning = functionalSkillEarning .Earnings .SelectMany(x => x.Periods) .Select(x => x.Period) .First(); var fundingLineType = periodisedFundingLineTypeValues .Select(x => x.GetPeriodTextValue(periodWithActiveEarning)) .FirstOrDefault(f => !f.Equals(GlobalConstants.Fm36NoneText, StringComparison.OrdinalIgnoreCase)); return(fundingLineType); } throw new InvalidOperationException($"Can't find a valid FundingLineType for aim {intermediateLearningAim.Aims.First().LearningDeliveryValues.LearnAimRef}"); }
public List <IncentiveEarning> Resolve(IntermediateLearningAim source, ApprenticeshipContractTypeEarningsEvent destination, List <IncentiveEarning> destMember, ResolutionContext context) { return(IncentiveTypes .Select(type => CreateIncentiveEarning(source.PriceEpisodes, type)) .Where(earning => earning.Periods.Any()) .ToList()); }
public IntermediateLearningAim CopyReplacingPriceEpisodes(IEnumerable <PriceEpisode> priceEpisodes) { var copy = new IntermediateLearningAim(Learner, Aim, priceEpisodes, Ukprn, AcademicYear, CollectionPeriod, IlrSubmissionDateTime, IlrFileName, JobId); return(copy); }
private OnProgrammeEarning CreateOnProgrammeEarning(IntermediateLearningAim source, OnProgrammeEarningType onProgrammeEarningType) { var attributeName = OnProgrammeEarningTypeToFM36AttributeName(onProgrammeEarningType); var allPeriods = source.PriceEpisodes.Select(p => p.PriceEpisodePeriodisedValues.SingleOrDefault(v => v.AttributeName == attributeName)) .Where(p => p != null) .ToArray(); var periods = new EarningPeriod[12]; for (byte i = 1; i <= 12; i++) { var periodValues = allPeriods.Select(p => p.GetPeriodValue(i)).ToArray(); var periodValue = periodValues.SingleOrDefault(v => v.GetValueOrDefault(0) != 0).GetValueOrDefault(0); var priceEpisodeIdentifier = periodValue == 0 ? null : source.PriceEpisodes[periodValues.IndexOf(periodValue)].PriceEpisodeIdentifier; var sfaContributionPercentage = source.PriceEpisodes.CalculateSfaContributionPercentage(i, priceEpisodeIdentifier); periods[i - 1] = new EarningPeriod { Period = i, Amount = periodValue.AsRounded(), PriceEpisodeIdentifier = priceEpisodeIdentifier, SfaContributionPercentage = sfaContributionPercentage, }; } return(new OnProgrammeEarning { Type = onProgrammeEarningType, Periods = new ReadOnlyCollection <EarningPeriod>(periods) }); }
private static List <IntermediateLearningAim> GetMathsAndEnglishAim(ProcessLearnerCommand learnerSubmission, List <LearningDelivery> learningDeliveries, bool singleContractType) { if (singleContractType) { return new List <IntermediateLearningAim> { new IntermediateLearningAim(learnerSubmission, new List <PriceEpisode>(), learningDeliveries) } } ; var results = new List <IntermediateLearningAim>(); var contractTypes = learningDeliveries.GetContractTypesForLearningDeliveries(); var distinctContractTypes = contractTypes.Distinct().ToList(); distinctContractTypes.ForEach(c => { var mathsAndEnglishAim = new IntermediateLearningAim(learnerSubmission, new List <PriceEpisode>(), learningDeliveries) { ContractType = c }; results.Add(mathsAndEnglishAim); }); return(results); } }
private FunctionalSkillEarning CreateEarning(IntermediateLearningAim source, FunctionalSkillType functionalSkillEarningType) { var attributeName = FunctionalSkillEarningTypeToFM36AttributeName(functionalSkillEarningType); var allPeriods = source.Aims.Select(p => p.LearningDeliveryPeriodisedValues.SingleOrDefault(v => v.AttributeName == attributeName)) .Where(p => p != null) .ToArray(); var periods = new EarningPeriod[12]; for (byte i = 1; i <= 12; i++) { var periodValues = allPeriods.Select(p => p.GetPeriodValue(i)).ToArray(); var periodValue = periodValues.SingleOrDefault(v => v.GetValueOrDefault(0) != 0).GetValueOrDefault(0); periods[i - 1] = new EarningPeriod { Period = i, Amount = periodValue.AsRounded(), SfaContributionPercentage = 1 }; } return(new FunctionalSkillEarning { Type = functionalSkillEarningType, Periods = new ReadOnlyCollection <EarningPeriod>(periods) }); }
public ReadOnlyCollection <FunctionalSkillEarning> Resolve(IntermediateLearningAim source, FunctionalSkillEarningsEvent destination, ReadOnlyCollection <FunctionalSkillEarning> destMember, ResolutionContext context) { return(FunctionalSkillEarningTypes .Select(type => CreateEarning(source, type)) .ToList() .AsReadOnly()); }
public ReadOnlyCollection <FunctionalSkillEarning> Resolve(IntermediateLearningAim source, FunctionalSkillEarningsEvent destination, ReadOnlyCollection <FunctionalSkillEarning> destMember, ResolutionContext context) { return(source.Aim.LearningDeliveryPeriodisedValues .Where(periodisedValues => TypeMap.ContainsKey(periodisedValues.AttributeName)) .GroupBy(v => v.AttributeName) .Select(CreateEarning) .ToList() .AsReadOnly()); }
protected static List <IntermediateLearningAim> InitialLearnerTransform(ProcessLearnerCommand learnerSubmission, bool?mainAim) { var results = new List <IntermediateLearningAim>(); var groupedLearningDeliveries = learnerSubmission.Learner.LearningDeliveries .GroupBy(ld => new { ld.LearningDeliveryValues.LearnAimRef, ld.LearningDeliveryValues.FworkCode, ld.LearningDeliveryValues.ProgType, ld.LearningDeliveryValues.PwayCode, ld.LearningDeliveryValues.StdCode }); foreach (var groupedLearningDelivery in groupedLearningDeliveries) { var orderedGroupedLearningDelivery = groupedLearningDelivery.OrderByDescending(x => x.LearningDeliveryValues.LearnStartDate).ToList(); var learningDelivery = orderedGroupedLearningDelivery.First(); if (mainAim.HasValue && mainAim.Value != learningDelivery.IsMainAim()) { continue; } var priceEpisodes = learnerSubmission.Learner.PriceEpisodes .Where(x => orderedGroupedLearningDelivery.Any(g => g.AimSeqNumber == x.PriceEpisodeValues.PriceEpisodeAimSeqNumber)) .ToList(); if (!learningDelivery.IsMainAim()) { // Maths & English var mathsAndEnglishAims = GetMathsAndEnglishAim(learnerSubmission, orderedGroupedLearningDelivery, mainAim.HasValue); results.AddRange(mathsAndEnglishAims); continue; } var group = priceEpisodes.Where(pe => IsCurrentAcademicYear(pe.PriceEpisodeValues, learnerSubmission.CollectionYear)) .GroupBy(p => p.PriceEpisodeValues.PriceEpisodeContractType); foreach (var episodes in group) { var intermediateAim = new IntermediateLearningAim(learnerSubmission, episodes, orderedGroupedLearningDelivery) { ContractType = MappingExtensions.GetContractType(episodes.Key) }; results.Add(intermediateAim); } } return(results); }
private FunctionalSkillEarningsEvent GetContractTypeFunctionalSkillEarningEvent( IntermediateLearningAim intermediateLearningAim, ContractType contractType) { switch (contractType) { case ContractType.Act1: return(mapper.Map <Act1FunctionalSkillEarningsEvent>(intermediateLearningAim)); case ContractType.Act2: return(mapper.Map <Act2FunctionalSkillEarningsEvent>(intermediateLearningAim)); } return(null); }
private static string GetFirstMatchingFundingLineTypeForContractType(IntermediateLearningAim intermediateLearningAim, FunctionalSkillEarningsEvent functionalSkillEarning) { var periodisedFundingLineTypeValues = intermediateLearningAim .Aim .LearningDeliveryPeriodisedTextValues .FirstOrDefault(x => x.AttributeName.Equals("FundLineType")); if (periodisedFundingLineTypeValues != null) { var periodWithActiveEarning = functionalSkillEarning .Earnings .SelectMany(x => x.Periods) .Select(x => x.Period) .First(); return(periodisedFundingLineTypeValues.GetPeriodTextValue(periodWithActiveEarning)); } throw new InvalidOperationException($"Can't find a valid FundingLineType for aim {intermediateLearningAim.Aim.LearningDeliveryValues.LearnAimRef}"); }
protected static List <IntermediateLearningAim> InitialLearnerTransform(ProcessLearnerCommand learnerSubmission, bool?mainAim) { var results = new List <IntermediateLearningAim>(); foreach (var learningDelivery in learnerSubmission.Learner.LearningDeliveries) { if (mainAim.HasValue && mainAim.Value != learningDelivery.IsMainAim()) { continue; } var priceEpisodes = learnerSubmission.Learner.PriceEpisodes .Where(x => x.PriceEpisodeValues.PriceEpisodeAimSeqNumber == learningDelivery.AimSeqNumber) .ToList(); if (!learningDelivery.IsMainAim()) { // Maths & English var mathsAndEnglishAims = GetMathsAndEnglishAim(learnerSubmission, learningDelivery, mainAim.HasValue); results.AddRange(mathsAndEnglishAims); continue; } var group = priceEpisodes.GroupBy(p => p.PriceEpisodeValues.PriceEpisodeContractType); foreach (var episodes in group) { var intermediateAim = new IntermediateLearningAim(learnerSubmission, episodes, learningDelivery) { ContractType = MappingExtensions.GetContractType(episodes.Key) }; results.Add(intermediateAim); } } return(results); }
public List <OnProgrammeEarning> Resolve(IntermediateLearningAim source, ApprenticeshipContractTypeEarningsEvent destination, List <OnProgrammeEarning> destMember, ResolutionContext context) { return(OnProgrammeEarningTypes .Select(type => CreateOnProgrammeEarning(source, type)) .ToList()); }