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());
 }
        private (List <IncentiveEarning> validIncentiveEarnings, List <IncentiveEarning> invalidIncentiveEarning) GetIncentiveEarnings(
            ApprenticeshipContractTypeEarningsEvent earningEvent,
            List <ApprenticeshipModel> apprenticeshipsForUln)
        {
            var validIncentiveEarnings  = new List <IncentiveEarning>();
            var invalidIncentiveEarning = new List <IncentiveEarning>();

            foreach (var incentiveEarning in earningEvent.IncentiveEarnings)
            {
                var validationResult = earningPeriodsValidationProcessor
                                       .ValidatePeriods(
                    earningEvent.Ukprn,
                    earningEvent.Learner.Uln,
                    earningEvent.PriceEpisodes,
                    incentiveEarning.Periods.ToList(),
                    (TransactionType)incentiveEarning.Type,
                    apprenticeshipsForUln,
                    earningEvent.LearningAim,
                    earningEvent.CollectionYear);

                if (validationResult.ValidPeriods.Any())
                {
                    validIncentiveEarnings.Add(CreateIncentiveEarning(incentiveEarning, validationResult.ValidPeriods));
                }

                if (validationResult.InValidPeriods.Any())
                {
                    invalidIncentiveEarning.Add(CreateIncentiveEarning(incentiveEarning, validationResult.InValidPeriods));
                }
            }

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

            periods.AddRange(source.OnProgrammeEarnings?
                             .SelectMany(onProgEarning => onProgEarning.Periods, (onProgEarning, period) => new { onProgEarning, period })
                             .Select(item => new EarningEventPeriodModel
            {
                TransactionType           = (TransactionType)item.onProgEarning.Type,
                DeliveryPeriod            = item.period.Period,
                Amount                    = item.period.Amount,
                PriceEpisodeIdentifier    = item.period.PriceEpisodeIdentifier,
                SfaContributionPercentage = item.period.SfaContributionPercentage,
                EarningEventId            = source.EventId,
                CensusDate                = item.onProgEarning.CensusDate
            }) ?? new List <EarningEventPeriodModel>()
                             );

            periods.AddRange(source.IncentiveEarnings?
                             .SelectMany(incentiveEarning => incentiveEarning.Periods, (incentiveEarning, period) => new { incentiveEarning, period })
                             .Select(item => new EarningEventPeriodModel
            {
                TransactionType        = (TransactionType)item.incentiveEarning.Type,
                DeliveryPeriod         = item.period.Period,
                Amount                 = item.period.Amount,
                PriceEpisodeIdentifier = item.period.PriceEpisodeIdentifier,
                EarningEventId         = source.EventId,
                CensusDate             = item.incentiveEarning.CensusDate
            }) ?? new List <EarningEventPeriodModel>()
                             );
            return(periods);
        }
        private void ValidateContractTypeEarningsSplitAndType(ApprenticeshipContractTypeEarningsEvent earning, Type expectedRedundancyType
                                                              )
        {
            var redundancyDate   = new DateTime(1920, 5, 1);
            var redundancyPeriod = redundancyDate.GetPeriodFromDate();

            earning.OnProgrammeEarnings.ForEach(ope => { ope.Periods.Should().HaveCount(12); });
            earning.IncentiveEarnings.ForEach(ie => { ie.Periods.Should().HaveCount(12); });


            var events = service.OriginalAndRedundancyEarningEventIfRequired(earning, new List <byte> {
                10, 11, 12
            });

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

            originalEarningEvent.Should().BeOfType(earning.GetType());
            originalEarningEvent.OnProgrammeEarnings.Should().HaveCount(3);

            var expectedOriginalCount = redundancyPeriod - 1;

            originalEarningEvent.OnProgrammeEarnings.ForEach(ope =>
            {
                ope.Periods.Should().HaveCount(expectedOriginalCount);
                Assert.IsTrue(ope.Periods.ToList().All(p => p.Period < redundancyPeriod));
            });
            originalEarningEvent.IncentiveEarnings.ForEach(ie =>
            {
                ie.Periods.Should().HaveCount(expectedOriginalCount);
                Assert.IsTrue(ie.Periods.ToList().All(p => p.Period < redundancyPeriod));
            });

            var expectedRedundancyPeriod = 12 - redundancyPeriod + 1;

            var redundancyEvent = events[1];

            redundancyEvent.Should().BeOfType(expectedRedundancyType);
            redundancyEvent.OnProgrammeEarnings.Should().HaveCount(3);
            redundancyEvent.OnProgrammeEarnings.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));
            });
            redundancyEvent.IncentiveEarnings.ForEach(ie =>
            {
                ie.Periods.Should().HaveCount(expectedRedundancyPeriod);
                Assert.IsTrue(ie.Periods.ToList().All(p => p.Period >= redundancyPeriod));
            });
        }
        private bool MatchOnProgrammeEarnings(ApprenticeshipContractTypeEarningsEvent expectedEvent, ApprenticeshipContractTypeEarningsEvent actualEvent)
        {
            if (expectedEvent == null)
            {
                return(true);
            }

            var expectedEventOnProgrammeEarnings = expectedEvent.OnProgrammeEarnings ?? new List <OnProgrammeEarning>();
            var actualEventOnProgrammeEarnings   = actualEvent.OnProgrammeEarnings ?? new List <OnProgrammeEarning>();

            foreach (var expectedEarning in expectedEventOnProgrammeEarnings)
            {
                var actualEarning = actualEventOnProgrammeEarnings.FirstOrDefault(a => a.Type == expectedEarning.Type);

                if (actualEarning == null || !MatchEarningPeriods(actualEarning.Periods, expectedEarning.Periods))
                {
                    return(false);
                }
            }

            var expectedEventIncentiveEarnings = expectedEvent.IncentiveEarnings ?? new List <IncentiveEarning>();
            var actualEventIncentiveEarnings   = actualEvent.IncentiveEarnings ?? new List <IncentiveEarning>();

            // Remove any all 0 value records from the "last academic year"
            foreach (var actualIncentiveEarning in actualEventIncentiveEarnings)
            {
                // assume 24 periods means 2 years of data
                if (actualIncentiveEarning.Periods.Count() == 24)
                {
                    // assume the first 12 are the previous year (sequencing is taken care of outside of this).
                    if (actualIncentiveEarning.Periods.Take(12).All(p => p.Amount == 0))
                    {
                        var secondYear = actualIncentiveEarning.Periods.Skip(12).Take(12);
                        actualIncentiveEarning.Periods = new ReadOnlyCollection <EarningPeriod>(secondYear.ToList());
                    }
                }
            }

            foreach (var expectedEarning in expectedEventIncentiveEarnings)
            {
                var actualEarning = actualEventIncentiveEarnings.FirstOrDefault(a => a.Type == expectedEarning.Type);

                if (actualEarning == null || !MatchEarningPeriods(actualEarning.Periods, expectedEarning.Periods))
                {
                    return(false);
                }
            }

            return(true);
        }
        public ApprenticeshipContractTypeEarningsEvent CreateRedundancyContractTypeEarningsEvent(
            ApprenticeshipContractTypeEarningsEvent earningEvent)
        {
            if (earningEvent is ApprenticeshipContractType1EarningEvent act1)
            {
                return(mapper.Map <ApprenticeshipContractType1RedundancyEarningEvent>(act1));
            }

            if (earningEvent is ApprenticeshipContractType2EarningEvent act2)
            {
                return(mapper.Map <ApprenticeshipContractType2RedundancyEarningEvent>(act2));
            }

            return(null);
        }
        public List <ApprenticeshipContractTypeEarningsEvent> OriginalAndRedundancyEarningEventIfRequired(ApprenticeshipContractTypeEarningsEvent earningEvent,
                                                                                                          List <byte> redundancyPeriods)
        {
            var splitResults = new List <ApprenticeshipContractTypeEarningsEvent> {
                earningEvent
            };

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

            var redundancyEarningEvent = redundancyEarningEventFactory.CreateRedundancyContractTypeEarningsEvent(earningEvent);

            splitResults.Add(redundancyEarningEvent);

            earningEvent.OnProgrammeEarnings.ForEach(ope => { ope.Periods = RemoveRedundancyPeriods(ope.Periods, redundancyPeriods); });
            earningEvent.IncentiveEarnings.ForEach(ie => { ie.Periods = RemoveRedundancyPeriods(ie.Periods, redundancyPeriods); });

            redundancyEarningEvent.OnProgrammeEarnings.ForEach(ope =>
            {
                ope.Periods = RemoveNonRedundancyPeriods(ope.Periods, redundancyPeriods);
                SetPeriodsToFullContribution(ope.Periods);
            });
            redundancyEarningEvent.IncentiveEarnings.ForEach(ie =>
            {
                ie.Periods = RemoveNonRedundancyPeriods(ie.Periods, redundancyPeriods);
                SetPeriodsToFullContribution(ie.Periods);
            });

            return(splitResults);
        }
Exemplo n.º 8
0
        public List <ApprenticeshipContractTypeEarningsEvent> SplitContractEarningByRedundancyDate(ApprenticeshipContractTypeEarningsEvent earningEvent, DateTime redundancyDate)
        {
            var splitResults = new List <ApprenticeshipContractTypeEarningsEvent>();

            var redundancyPeriod = redundancyDate.GetPeriodFromDate();

            var redundancyEarningEvent = redundancyEarningEventFactory.CreateRedundancyContractTypeEarningsEvent(earningEvent);

            earningEvent.OnProgrammeEarnings.ForEach(ope => { ope.Periods = RemoveRedundancyPeriods(ope.Periods, redundancyPeriod); });
            earningEvent.IncentiveEarnings.ForEach(ie => { ie.Periods = RemoveRedundancyPeriods(ie.Periods, redundancyPeriod); });

            redundancyEarningEvent.OnProgrammeEarnings.ForEach(ope =>
            {
                ope.Periods = RemovePreRedundancyPeriods(ope.Periods, redundancyPeriod);
                SetPeriodsToFullContribution(ope.Periods);
            });
            redundancyEarningEvent.IncentiveEarnings.ForEach(ie =>
            {
                ie.Periods = RemovePreRedundancyPeriods(ie.Periods, redundancyPeriod);
                SetPeriodsToFullContribution(ie.Periods);
            });

            splitResults.Add(earningEvent);
            splitResults.Add(redundancyEarningEvent);

            return(splitResults);
        }
 private List <EarningPeriod> GetEarningPeriods(List <Earning> aimEarningSpecs, Aim aimSpec, ApprenticeshipContractTypeEarningsEvent onProgEarning, TransactionType tt, FM36Learner fm36Learner)
 {
     return(aimEarningSpecs
            .Select(e => new EarningPeriod
     {
         Amount = PriceEpisodeContractTypeMatchesAim(aimSpec.PriceEpisodes, e.PriceEpisodeIdentifier, onProgEarning) ? e.Values[tt] : 0M,
         Period = e.DeliveryCalendarPeriod,
         PriceEpisodeIdentifier = FindPriceEpisodeIdentifier(e.Values[tt], e, fm36Learner, tt)
     })
            .Where(p => p.Period <= collectionPeriod.Period)
            .OrderBy(p => p.Period)
            .ToList());
 }
 public List <OnProgrammeEarning> Resolve(IntermediateLearningAim source, ApprenticeshipContractTypeEarningsEvent destination, List <OnProgrammeEarning> destMember, ResolutionContext context)
 {
     return(OnProgrammeEarningTypes
            .Select(type => CreateOnProgrammeEarning(source, type))
            .ToList());
 }