Beispiel #1
0
        private void ValidateFunctionalSkillEarningsSplitAndType(FunctionalSkillEarningsEvent act1FsEarning, Type expectedRedundancyType)
        {
            var redundancyDate   = new DateTime(1920, 7, 1);
            var redundancyPeriod = redundancyDate.GetPeriodFromDate();

            act1FsEarning.Earnings.ToList().ForEach(fse => fse.Periods.Should().HaveCount(12));

            var events = service.SplitFunctionSkillEarningByRedundancyDate(act1FsEarning, redundancyDate);

            events.Should().HaveCount(2);
            var originalEvent = events[0];

            originalEvent.Should().BeOfType(act1FsEarning.GetType());

            var expectedOriginalCount = redundancyPeriod - 1;

            originalEvent.Earnings.ToList().ForEach(ope =>
            {
                ope.Periods.Should().HaveCount(expectedOriginalCount);
                Assert.IsTrue(ope.Periods.ToList().All(p => p.Period < redundancyPeriod));
            });

            var redundancyEvent = events[1];

            var expectedRedundancyPeriod = 12 - redundancyPeriod + 1;

            redundancyEvent.Should().BeOfType(expectedRedundancyType);
            redundancyEvent.Earnings.ToList().ForEach(ope =>
            {
                ope.Periods.Should().HaveCount(expectedRedundancyPeriod);
                Assert.IsTrue(ope.Periods.ToList().All(p => p.Period >= redundancyPeriod));
                Assert.IsTrue(ope.Periods.ToList().All(p => p.SfaContributionPercentage == 1m));
            });
        }
        public FunctionalSkillEarningsEvent CreateRedundancyFunctionalSkillTypeEarningsEvent(
            FunctionalSkillEarningsEvent functionalSkillEarning)
        {
            if (functionalSkillEarning is Act1FunctionalSkillEarningsEvent act1)
            {
                return(mapper.Map <Act1RedundancyFunctionalSkillEarningsEvent>(act1));
            }

            if (functionalSkillEarning is Act2FunctionalSkillEarningsEvent act2)
            {
                return(mapper.Map <Act2RedundancyFunctionalSkillEarningsEvent>(act2));
            }

            return(null);
        }
        public List <EarningEventPeriodModel> Resolve(FunctionalSkillEarningsEvent source, EarningEventModel destination, List <EarningEventPeriodModel> destMember, ResolutionContext context)
        {
            var periods = destination.Periods ?? new List <EarningEventPeriodModel>();

            periods.AddRange(source.Earnings
                             .SelectMany(earning => earning.Periods, (earning, period) => new { earning, period })
                             .Select(item => new EarningEventPeriodModel
            {
                TransactionType           = (TransactionType)item.earning.Type,
                DeliveryPeriod            = item.period.Period,
                Amount                    = item.period.Amount,
                PriceEpisodeIdentifier    = item.period.PriceEpisodeIdentifier,
                SfaContributionPercentage = item.period.SfaContributionPercentage,
                EarningEventId            = source.EventId
            })
                             );
            return(periods);
        }
        public List <FunctionalSkillEarningsEvent> OriginalAndRedundancyFunctionalSkillEarningEventIfRequired(FunctionalSkillEarningsEvent functionalSkillEarning, List <byte> redundancyPeriods)
        {
            var splitResults = new List <FunctionalSkillEarningsEvent> {
                functionalSkillEarning
            };

            if (!redundancyPeriods.Any())
            {
                return(splitResults);
            }

            var redundancyEarningEvent = redundancyEarningEventFactory.CreateRedundancyFunctionalSkillTypeEarningsEvent(functionalSkillEarning);

            splitResults.Add(redundancyEarningEvent);

            foreach (var earning in functionalSkillEarning.Earnings)
            {
                earning.Periods = RemoveRedundancyPeriods(earning.Periods, redundancyPeriods);
            }

            foreach (var earning in redundancyEarningEvent.Earnings)
            {
                earning.Periods = RemoveNonRedundancyPeriods(earning.Periods, redundancyPeriods);
                SetPeriodsToFullContribution(earning.Periods);
            }

            return(splitResults);
        }
Beispiel #5
0
        public List <FunctionalSkillEarningsEvent> SplitFunctionSkillEarningByRedundancyDate(FunctionalSkillEarningsEvent functionalSkillEarning,
                                                                                             DateTime priceEpisodeRedStartDate)
        {
            var splitResults     = new List <FunctionalSkillEarningsEvent>();
            var redundancyPeriod = priceEpisodeRedStartDate.GetPeriodFromDate();

            var redundancyEarningEvent = redundancyEarningEventFactory.CreateRedundancyFunctionalSkillTypeEarningsEvent(functionalSkillEarning);

            foreach (var earning in functionalSkillEarning.Earnings)
            {
                earning.Periods = RemoveRedundancyPeriods(earning.Periods, redundancyPeriod);
            }

            foreach (var earning in redundancyEarningEvent.Earnings)
            {
                earning.Periods = RemovePreRedundancyPeriods(earning.Periods, redundancyPeriod);
                SetPeriodsToFullContribution(earning.Periods);
            }

            splitResults.Add(functionalSkillEarning);
            splitResults.Add(redundancyEarningEvent);

            return(splitResults);
        }
Beispiel #6
0
 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());
 }
        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}");
        }
Beispiel #8
0
        public async Task <ReadOnlyCollection <PeriodisedRequiredPaymentEvent> > HandleFunctionalSkillEarningsEvent(FunctionalSkillEarningsEvent earningEvent, CancellationToken cancellationToken)
        {
            paymentLogger.LogVerbose($"Handling FunctionalSkillEarningsEvent for jobId:{earningEvent.JobId} with apprenticeship key based on {logSafeApprenticeshipKeyString}");

            using (var operation = telemetry.StartOperation())
            {
                var stopwatch = Stopwatch.StartNew();
                await ResetPaymentHistoryCacheIfDifferentCollectionPeriod(earningEvent.CollectionPeriod)
                .ConfigureAwait(false);

                await Initialise(earningEvent.CollectionPeriod.Period).ConfigureAwait(false);

                var requiredPaymentEvents = await functionalSkillEarningsEventProcessor.HandleEarningEvent(earningEvent, paymentHistoryCache, cancellationToken).ConfigureAwait(false);

                Log(requiredPaymentEvents);
                telemetry.TrackDuration("RequiredPaymentsService.HandleFunctionalSkillEarningsEvent", stopwatch, earningEvent);
                telemetry.StopOperation(operation);
                return(requiredPaymentEvents);
            }
        }
        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}");
        }
Beispiel #10
0
 public ReadOnlyCollection <FunctionalSkillEarning> Resolve(IntermediateLearningAim source, FunctionalSkillEarningsEvent destination, ReadOnlyCollection <FunctionalSkillEarning> destMember, ResolutionContext context)
 {
     return(FunctionalSkillEarningTypes
            .Select(type => CreateEarning(source, type))
            .ToList()
            .AsReadOnly());
 }