Пример #1
0
        protected override IList <PayableEarningEvent> GetExpectedEvents()
        {
            var result     = new List <PayableEarningEvent>();
            var learnerIds = earningSpecs.Select(e => e.LearnerId).Distinct().ToList();

            foreach (var learnerId in learnerIds)
            {
                var learnerSpec = testSession.GetLearner(provider.Ukprn, learnerId);
                var fm36Learner = learnerSpecs.Single(l => l.LearnRefNumber == learnerSpec.LearnRefNumber);
                var learner     = new Learner
                {
                    ReferenceNumber = learnerSpec.LearnRefNumber,
                    Uln             = learnerSpec.Uln
                };

                if (learnerSpec.Aims.Count == 0)
                {
                    learnerSpec.Aims.Add(new Aim
                    {
                        LearnerId       = learnerSpec.LearnerIdentifier,
                        ProgrammeType   = learnerSpec.Course.ProgrammeType,
                        FrameworkCode   = learnerSpec.Course.FrameworkCode,
                        PathwayCode     = learnerSpec.Course.PathwayCode,
                        StandardCode    = learnerSpec.Course.StandardCode,
                        FundingLineType = learnerSpec.Course.FundingLineType,
                        AimReference    = learnerSpec.Course.LearnAimRef
                    });
                }

                foreach (var aimSpec in learnerSpec.Aims.Where(a => AimPeriodMatcher.IsStartDateValidForCollectionPeriod(a.StartDate, collectionPeriod,
                                                                                                                         a.PlannedDurationAsTimespan, a.ActualDurationAsTimespan, a.CompletionStatus, a.AimReference, a.PlannedDuration, a.ActualDuration)))
                {
                    var learningAim = new LearningAim
                    {
                        ProgrammeType   = aimSpec.ProgrammeType,
                        FrameworkCode   = aimSpec.FrameworkCode,
                        PathwayCode     = aimSpec.PathwayCode,
                        StandardCode    = aimSpec.StandardCode,
                        FundingLineType = aimSpec.FundingLineType,
                        Reference       = aimSpec.AimReference
                    };

                    var aimEarningSpecs            = earningSpecs.Where(e => e.LearnerId == learnerId && e.AimSequenceNumber.GetValueOrDefault(aimSpec.AimSequenceNumber) == aimSpec.AimSequenceNumber).ToList();
                    var fullListOfTransactionTypes = aimEarningSpecs.SelectMany(p => p.Values.Keys).Distinct().ToList();
                    var onProgEarnings             = fullListOfTransactionTypes.Where(EnumHelper.IsOnProgType).ToList();
                    var incentiveEarnings          = fullListOfTransactionTypes.Where(type => EnumHelper.IsIncentiveType(type, aimSpec.IsMainAim)).ToList();

                    if (aimSpec.AimReference == "ZPROG001" && onProgEarnings.Any())
                    {
                        var onProgEarning = new PayableEarningEvent
                        {
                            CollectionPeriod    = collectionPeriod,
                            Ukprn               = provider.Ukprn,
                            OnProgrammeEarnings = onProgEarnings.Select(tt => new OnProgrammeEarning
                            {
                                Type    = (OnProgrammeEarningType)(int)tt,
                                Periods = aimEarningSpecs.Select(e => new EarningPeriod
                                {
                                    Amount = e.Values[tt],
                                    Period = e.DeliveryCalendarPeriod,
                                    PriceEpisodeIdentifier = FindPriceEpisodeIdentifier(e.Values[tt], e, fm36Learner, tt)
                                }).ToList().AsReadOnly()
                            }).ToList(),
                            JobId       = provider.JobId,
                            Learner     = learner,
                            LearningAim = learningAim
                        };
                        result.Add(onProgEarning);
                    }

                    if (incentiveEarnings.Any())
                    {
                        var incentiveEarning = new PayableEarningEvent
                        {
                            CollectionPeriod  = collectionPeriod,
                            Ukprn             = provider.Ukprn,
                            IncentiveEarnings = incentiveEarnings.Select(tt => new IncentiveEarning
                            {
                                Type    = (IncentiveEarningType)(int)tt,
                                Periods = aimEarningSpecs.Select(e => new EarningPeriod
                                {
                                    Amount = e.Values[tt],
                                    Period = e.DeliveryCalendarPeriod,
                                    PriceEpisodeIdentifier = FindPriceEpisodeIdentifier(e.Values[tt], e, fm36Learner, tt)
                                }).ToList().AsReadOnly()
                            }).ToList(),
                            JobId       = provider.JobId,
                            Learner     = learner,
                            LearningAim = learningAim
                        };

                        result.Add(incentiveEarning);
                    }
                }
            }

            return(result);
        }
        private List <FunctionalSkillEarningsEvent> CreateFunctionalSkillEarningEvents(List <TransactionType> functionalSkillEarnings,
                                                                                       List <Earning> aimEarningSpecs, FM36Learner fm36Learner, Learner learner, LearningAim learningAim, Aim aimSpec)
        {
            var contractTypes = EnumHelper.GetContractTypes(currentIlr, currentPriceEpisodes);

            var events = new List <FunctionalSkillEarningsEvent>();

            contractTypes?.ForEach(c =>
            {
                switch (c)
                {
                case ContractType.Act1:
                    events.Add(new Act1FunctionalSkillEarningsEvent
                    {
                        CollectionPeriod = collectionPeriod,
                        Ukprn            = provider.Ukprn,
                        Earnings         = functionalSkillEarnings.Select(tt => new FunctionalSkillEarning
                        {
                            Type    = (FunctionalSkillType)(int)tt,
                            Periods = aimEarningSpecs.Select(e => new EarningPeriod
                            {
                                Amount = e.Values[tt],
                                Period = e.DeliveryCalendarPeriod,
                                PriceEpisodeIdentifier = FindPriceEpisodeIdentifier(e.Values[tt], e, fm36Learner, tt)
                            }).ToList().AsReadOnly()
                        }).ToList().AsReadOnly(),
                        JobId       = provider.JobId,
                        Learner     = learner,
                        LearningAim = learningAim
                    });
                    break;

                case ContractType.Act2:
                    events.Add(new Act2FunctionalSkillEarningsEvent
                    {
                        CollectionPeriod = collectionPeriod,
                        Ukprn            = provider.Ukprn,
                        Earnings         = functionalSkillEarnings.Select(tt => new FunctionalSkillEarning
                        {
                            Type    = (FunctionalSkillType)(int)tt,
                            Periods = aimEarningSpecs.Select(e => new EarningPeriod
                            {
                                Amount = e.Values[tt],
                                Period = e.DeliveryCalendarPeriod,
                                PriceEpisodeIdentifier = FindPriceEpisodeIdentifier(e.Values[tt], e, fm36Learner, tt)
                            }).ToList().AsReadOnly()
                        }).ToList().AsReadOnly(),
                        JobId       = provider.JobId,
                        Learner     = learner,
                        LearningAim = learningAim
                    });
                    break;

                default:
                    throw new InvalidOperationException(
                        "Cannot create the EarningEventMatcher invalid contract type ");
                }
            });


            events.ForEach(x => x.LearningAim.FundingLineType = aimSpec.FundingLineType);

            return(events);
        }
        protected override IList <EarningEvent> GetExpectedEvents()
        {
            var result     = new List <EarningEvent>();
            var learnerIds = earningSpecs.Where(e => e.Ukprn == provider.Ukprn).Select(e => e.LearnerId).Distinct().ToList();

            foreach (var learnerId in learnerIds)
            {
                var learnerSpec = testSession.GetLearner(provider.Ukprn, learnerId);
                var fm36Learner = learnerSpecs.Single(l => l.LearnRefNumber == learnerSpec.LearnRefNumber);
                var learner     = new Learner
                {
                    ReferenceNumber = learnerSpec.LearnRefNumber,
                    Uln             = learnerSpec.Uln
                };

                if (learnerSpec.Aims.Count == 0)
                {
                    learnerSpec.Aims.Add(new Aim
                    {
                        LearnerId       = learnerSpec.LearnerIdentifier,
                        ProgrammeType   = learnerSpec.Course.ProgrammeType,
                        FrameworkCode   = learnerSpec.Course.FrameworkCode,
                        PathwayCode     = learnerSpec.Course.PathwayCode,
                        StandardCode    = learnerSpec.Course.StandardCode,
                        FundingLineType = learnerSpec.Course.FundingLineType,
                        AimReference    = learnerSpec.Course.LearnAimRef
                    });
                }

                IEnumerable <Aim> currentAims;

                // AimPeriodMatcher doesn't support completed aims from the past, this is a workaround until imminent refactoring
                if (learnerSpec.Aims.Count == 1)
                {
                    currentAims = learnerSpec.Aims;
                }
                else
                {
                    currentAims = learnerSpec.Aims.Where(a => AimPeriodMatcher.IsStartDateValidForCollectionPeriod(a.StartDate, collectionPeriod,
                                                                                                                   a.PlannedDurationAsTimespan, a.ActualDurationAsTimespan, a.CompletionStatus, a.AimReference, a.PlannedDuration, a.ActualDuration));
                }

                foreach (var aimSpec in currentAims)
                {
                    var learningAim = new LearningAim
                    {
                        ProgrammeType = aimSpec.ProgrammeType,
                        FrameworkCode = aimSpec.FrameworkCode,
                        PathwayCode   = aimSpec.PathwayCode,
                        StandardCode  = aimSpec.StandardCode,
                        Reference     = aimSpec.AimReference
                    };

                    var aimEarningSpecs            = earningSpecs.Where(e => e.LearnerId == learnerId && e.AimSequenceNumber.GetValueOrDefault(aimSpec.AimSequenceNumber) == aimSpec.AimSequenceNumber).ToList();
                    var fullListOfTransactionTypes = aimEarningSpecs.SelectMany(p => p.Values.Keys).Distinct().ToList();
                    var onProgEarnings             = fullListOfTransactionTypes.Where(EnumHelper.IsOnProgType).ToList();
                    var functionalSkillEarnings    = fullListOfTransactionTypes.Where(t => EnumHelper.IsFunctionalSkillType(t, aimSpec.IsMainAim)).ToList();
                    var incentiveEarnings          = fullListOfTransactionTypes.Where(t => EnumHelper.IsIncentiveType(t, aimSpec.IsMainAim)).ToList();

                    if (aimSpec.IsMainAim && onProgEarnings.Any())
                    {
                        var contractTypeEarningsEvents = CreateContractTypeEarningsEventEarningEvent(provider.Ukprn);

                        foreach (var onProgEarning in contractTypeEarningsEvents)
                        {
                            onProgEarning.OnProgrammeEarnings = onProgEarnings.Select(tt => new OnProgrammeEarning
                            {
                                Type    = (OnProgrammeEarningType)(int)tt,
                                Periods = GetEarningPeriods(aimEarningSpecs, aimSpec, onProgEarning, tt, fm36Learner).AsReadOnly()
                            }).ToList();
                            onProgEarning.JobId       = provider.JobId;
                            onProgEarning.Learner     = learner;
                            onProgEarning.LearningAim = learningAim;


                            result.Add(onProgEarning);
                        }
                    }

                    if (!aimSpec.IsMainAim && functionalSkillEarnings.Any())
                    {
                        var functionalSkillEarningsEvents = CreateFunctionalSkillEarningEvents(functionalSkillEarnings,
                                                                                               aimEarningSpecs,
                                                                                               fm36Learner,
                                                                                               learner,
                                                                                               learningAim,
                                                                                               aimSpec);

                        result.AddRange(functionalSkillEarningsEvents);
                    }

                    if (!aimSpec.IsMainAim && incentiveEarnings.Any())
                    {
                        var contractTypeIncentiveEarnings = CreateContractTypeEarningsEventEarningEvent(provider.Ukprn);

                        foreach (var incentiveEarning in contractTypeIncentiveEarnings)
                        {
                            incentiveEarning.IncentiveEarnings = incentiveEarnings.Select(tt => new IncentiveEarning
                            {
                                Type    = (IncentiveEarningType)(int)tt,
                                Periods = GetEarningPeriods(aimEarningSpecs, aimSpec, incentiveEarning, tt, fm36Learner).AsReadOnly(),
                            }).ToList();
                            incentiveEarning.JobId       = provider.JobId;
                            incentiveEarning.Learner     = learner;
                            incentiveEarning.LearningAim = learningAim;

                            result.Add(incentiveEarning);
                        }
                    }
                }
            }

            return(result);
        }
Пример #4
0
        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);
        }