public async Task <List <FunctionalSkillDataLockEvent> > GetFunctionalSkillPaymentEvents(
            Act1FunctionalSkillEarningsEvent earningEvent, CancellationToken cancellationToken)
        {
            var dataLockEvents = new List <FunctionalSkillDataLockEvent>();

            var learnerMatchResult = await learnerMatcher.MatchLearner(earningEvent.Ukprn, earningEvent.Learner.Uln).ConfigureAwait(false);

            if (learnerMatchResult.DataLockErrorCode.HasValue)
            {
                dataLockEvents = CreateDataLockEvents(earningEvent, learnerMatchResult.DataLockErrorCode.Value);
                return(dataLockEvents);
            }

            var apprenticeshipsForUln   = learnerMatchResult.Apprenticeships;
            var functionalSkillEarnings = GetFunctionalSkillEarnings(earningEvent, apprenticeshipsForUln);

            if (functionalSkillEarnings.validEarnings.Any())
            {
                var payableEarningEvent = mapper.Map <PayableFunctionalSkillEarningEvent>(earningEvent);
                payableEarningEvent.Earnings = functionalSkillEarnings.validEarnings.AsReadOnly();
                dataLockEvents.Add(payableEarningEvent);
            }

            if (functionalSkillEarnings.invalidEarnings.Any())
            {
                var earningFailedDataLockEvent = mapper.Map <FunctionalSkillEarningFailedDataLockMatching>(earningEvent);
                earningFailedDataLockEvent.Earnings = functionalSkillEarnings.invalidEarnings.AsReadOnly();
                dataLockEvents.Add(earningFailedDataLockEvent);
            }

            return(dataLockEvents);
        }
Exemple #2
0
        private Act1FunctionalSkillEarningsEvent CreateTestFunctionalSkillEarningEvent(byte periodsToCreate, decimal earningPeriodAmount, LearningAim testAim)
        {
            var testEarningEvent = new Act1FunctionalSkillEarningsEvent
            {
                Ukprn   = Ukprn,
                Learner = new Learner {
                    Uln = Uln,
                },
                PriceEpisodes  = new List <PriceEpisode>(),
                CollectionYear = AcademicYear
            };

            var functionalSkillEarnings = new List <FunctionalSkillEarning>
            {
                new FunctionalSkillEarning
                {
                    Periods = new ReadOnlyCollection <EarningPeriod>(GenerateEarningPeriod(periodsToCreate, earningPeriodAmount, testEarningEvent))
                }
            };

            testEarningEvent.Earnings = functionalSkillEarnings.AsReadOnly();

            testEarningEvent.LearningAim = testAim;

            return(testEarningEvent);
        }
        private (List <FunctionalSkillEarning> validEarnings, List <FunctionalSkillEarning> invalidEarnings) GetFunctionalSkillEarnings(
            Act1FunctionalSkillEarningsEvent earningEvent,
            List <ApprenticeshipModel> apprenticeshipsForUln)
        {
            var validEarnings   = new List <FunctionalSkillEarning>();
            var invalidEarnings = new List <FunctionalSkillEarning>();

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

                if (validationResult.ValidPeriods.Any())
                {
                    validEarnings.Add(CreateFunctionalSkillEarning(functionalSkillEarning, validationResult.ValidPeriods));
                }

                if (validationResult.InValidPeriods.Any())
                {
                    invalidEarnings.Add(CreateFunctionalSkillEarning(functionalSkillEarning, validationResult.InValidPeriods));
                }
            }

            return(validEarnings, invalidEarnings);
        }
        public void CreateRedundancyContractType_ForAct1RedundancyFunctionalSkillEarningsEvent_ShouldCreateANewEventId()
        {
            var factory      = new RedundancyEarningEventFactory(Mapper.Instance);
            var earningEvent = new Act1FunctionalSkillEarningsEvent
            {
                EventId  = Guid.NewGuid(),
                Earnings = new ReadOnlyCollection <FunctionalSkillEarning>(new List <FunctionalSkillEarning>())
            };

            var createdEvent = factory.CreateRedundancyFunctionalSkillTypeEarningsEvent(earningEvent);

            createdEvent.EventId.Should().NotBe(earningEvent.EventId);
            createdEvent.EventId.Should().NotBe(Guid.Empty);
        }
Exemple #5
0
        public async Task <List <FunctionalSkillDataLockEvent> > HandleFunctionalSkillEarning(
            Act1FunctionalSkillEarningsEvent message, CancellationToken cancellationToken)
        {
            using (var operation =
                       telemetry.StartOperation("DataLockService.HandleFunctionalSkillEarning", message.EventId.ToString()))
            {
                var stopwatch = Stopwatch.StartNew();
                await Initialise().ConfigureAwait(false);

                var dataLockEvents =
                    await dataLockProcessor.GetFunctionalSkillPaymentEvents(message, cancellationToken);

                telemetry.TrackDuration("DataLockService.HandleFunctionalSkillEarning", stopwatch, message);
                telemetry.StopOperation(operation);
                return(dataLockEvents);
            }
        }
Exemple #6
0
        public void TestBuild()
        {
            // arrange
            var expectedResult = new Act1FunctionalSkillEarningsEvent
            {
                Earnings = new List <FunctionalSkillEarning>().AsReadOnly()
            };
            var builder = new FunctionalSkillEarningEventBuilder(mapper);
            var learnerSubmissionModel = new ProcessLearnerCommand
            {
                CollectionPeriod = 1,
                CollectionYear   = 1920,
                Learner          = new FM36Learner
                {
                    LearningDeliveries = new EditableList <LearningDelivery>
                    {
                        new LearningDelivery {
                            AimSeqNumber = 1, LearningDeliveryValues = new LearningDeliveryValues {
                                LearnAimRef = "ZPROG001"
                            }
                        },
                        new LearningDelivery
                        {
                            AimSeqNumber           = 2,
                            LearningDeliveryValues = new LearningDeliveryValues {
                                LearnAimRef = "M&E"
                            },
                            LearningDeliveryPeriodisedValues = new EditableList <LearningDeliveryPeriodisedValues>
                            {
                                new LearningDeliveryPeriodisedValues
                                {
                                    AttributeName = "MathEngBalPayment",
                                    Period1       = 1,
                                    Period2       = 2
                                }
                            },
                            LearningDeliveryPeriodisedTextValues = new EditableList <LearningDeliveryPeriodisedTextValues>
                            {
                                new LearningDeliveryPeriodisedTextValues
                                {
                                    AttributeName = "LearnDelContType",
                                    Period1       = "Levy Contract",
                                    Period2       = "Levy Contract",
                                    Period3       = "Levy Contract",
                                    Period4       = "Levy Contract",
                                    Period5       = "Levy Contract",
                                    Period6       = "Levy Contract",
                                    Period7       = "Levy Contract",
                                    Period8       = "Levy Contract",
                                    Period9       = "Levy Contract",
                                    Period10      = "Levy Contract",
                                    Period11      = "Levy Contract",
                                    Period12      = "Levy Contract"
                                },
                                new LearningDeliveryPeriodisedTextValues
                                {
                                    AttributeName = "FundLineType",
                                    Period1       = "16-18 Apprenticeship (Employer on App Service)",
                                    Period2       = "16-18 Apprenticeship (Employer on App Service)",
                                    Period3       = "16-18 Apprenticeship (Employer on App Service)",
                                    Period4       = "16-18 Apprenticeship (Employer on App Service)",
                                    Period5       = "16-18 Apprenticeship (Employer on App Service)",
                                    Period6       = "16-18 Apprenticeship (Employer on App Service)",
                                    Period7       = "16-18 Apprenticeship (Employer on App Service)",
                                    Period8       = "16-18 Apprenticeship (Employer on App Service)",
                                    Period9       = "16-18 Apprenticeship (Employer on App Service)",
                                    Period10      = "16-18 Apprenticeship (Employer on App Service)",
                                    Period11      = "16-18 Apprenticeship (Employer on App Service)",
                                    Period12      = "16-18 Apprenticeship (Employer on App Service)"
                                }
                            }
                        }
                    },
                    PriceEpisodes = new EditableList <PriceEpisode>
                    {
                        new PriceEpisode
                        {
                            PriceEpisodeValues = new PriceEpisodeValues
                            {
                                EpisodeStartDate         = DateTime.Today,
                                PriceEpisodeAimSeqNumber = 1,
                                PriceEpisodeContractType = "Levy Contract",
                            },
                            PriceEpisodePeriodisedValues = new EditableList <PriceEpisodePeriodisedValues>
                            {
                                new PriceEpisodePeriodisedValues
                                {
                                    AttributeName = "PriceEpisodeOnProgPayment",
                                    Period1       = 10,
                                    Period2       = 20
                                }
                            }
                        }
                    }
                }
            };

            // act
            var events = builder.Build(learnerSubmissionModel);

            // assert
            events.Should().NotBeNull();
            events.Should().HaveCount(1);
        }
Exemple #7
0
        private static List <EarningPeriod> GenerateEarningPeriod(byte periodsToCreate, decimal earningPeriodAmount, Act1FunctionalSkillEarningsEvent testEarningEvent)
        {
            var earningPeriods = new List <EarningPeriod>();

            for (byte i = 1; i <= periodsToCreate; i++)
            {
                testEarningEvent.PriceEpisodes.Add(new PriceEpisode
                {
                    EffectiveTotalNegotiatedPriceStartDate = DateTime.UtcNow.AddDays(1),
                    Identifier = $"pe-{i}"
                });

                earningPeriods.Add(new EarningPeriod
                {
                    Amount = earningPeriodAmount,
                    Period = i,
                    PriceEpisodeIdentifier = $"pe-{i}"
                });
            }

            return(earningPeriods);
        }
Exemple #8
0
        public void Setup()
        {
            var earnings = new List <EarningPeriod>();

            for (byte i = 1; i < 13; i++)
            {
                earnings.Add(new EarningPeriod
                {
                    Amount = 100,
                    Period = i,
                    PriceEpisodeIdentifier    = "p-1",
                    SfaContributionPercentage = 0.9m
                });
            }

            var incentiveEarnings = new List <IncentiveEarning>();

            foreach (var incentiveEarningType in Enum.GetValues(typeof(IncentiveEarningType)))
            {
                incentiveEarnings.Add(new IncentiveEarning
                {
                    CensusDate = DateTime.MaxValue,
                    Periods    = earnings.AsReadOnly(),
                    Type       = (IncentiveEarningType)incentiveEarningType
                });
            }

            earningEventPayment = new ApprenticeshipContractType1EarningEvent()
            {
                Ukprn = 12345,
                SfaContributionPercentage = 0.9m,
                JobId            = 123,
                CollectionPeriod = new CollectionPeriod {
                    Period = 12, AcademicYear = 1819
                },
                Learner = new Learner {
                    ReferenceNumber = "1234-ref", Uln = 123456
                },
                CollectionYear = 2019,
                LearningAim    = new LearningAim
                {
                    PathwayCode     = 12,
                    FrameworkCode   = 1245,
                    FundingLineType = "Non-DAS 16-18 Learner",
                    StandardCode    = 1209,
                    ProgrammeType   = 7890,
                    Reference       = "ZPROG001"
                },
                IlrSubmissionDateTime = DateTime.MaxValue,
                EventTime             = DateTimeOffset.MaxValue,
                AgreementId           = "12120002",
                IncentiveEarnings     = incentiveEarnings,
                OnProgrammeEarnings   = (new List <OnProgrammeEarning>
                {
                    new OnProgrammeEarning
                    {
                        CensusDate = DateTime.MaxValue,
                        Type = OnProgrammeEarningType.Learning,
                        Periods = earnings.AsReadOnly()
                    },
                    new OnProgrammeEarning
                    {
                        CensusDate = DateTime.MaxValue,
                        Type = OnProgrammeEarningType.Balancing,
                        Periods = earnings.AsReadOnly()
                    },
                    new OnProgrammeEarning
                    {
                        CensusDate = DateTime.MaxValue,
                        Type = OnProgrammeEarningType.Completion,
                        Periods = earnings.AsReadOnly()
                    }
                }),
                PriceEpisodes = (new List <PriceEpisode>
                {
                    new PriceEpisode
                    {
                        ActualEndDate = DateTime.MaxValue,
                        Completed = true,
                        CompletionAmount = 300m,
                        Identifier = "p-1",
                        EffectiveTotalNegotiatedPriceStartDate = DateTime.MinValue,
                        InstalmentAmount = 100m,
                        NumberOfInstalments = 12,
                        PlannedEndDate = DateTime.MaxValue,
                        TotalNegotiatedPrice1 = 25.0m,
                        TotalNegotiatedPrice2 = 25.0m,
                        TotalNegotiatedPrice3 = 25.0m,
                        TotalNegotiatedPrice4 = 25.0m,
                        FundingLineType = "19+ Apprenticeship Levy Contract (procured)",
                    }
                }),
                EventId   = Guid.NewGuid(),
                StartDate = DateTime.Today.AddDays(-5)
            };

            var functionalSkillEarnings = new List <FunctionalSkillEarning>
            {
                new FunctionalSkillEarning
                {
                    Type    = FunctionalSkillType.OnProgrammeMathsAndEnglish,
                    Periods = earnings.AsReadOnly()
                }
            };

            functionalSkillEarningEvent = new Act1FunctionalSkillEarningsEvent
            {
                EventId          = Guid.NewGuid(),
                Ukprn            = 12345,
                JobId            = 123,
                CollectionPeriod = new CollectionPeriod {
                    Period = 12, AcademicYear = 1819
                },
                Learner = new Learner {
                    ReferenceNumber = "1234-ref", Uln = 123456
                },
                CollectionYear = 2019,
                LearningAim    = new LearningAim
                {
                    PathwayCode     = 12,
                    FrameworkCode   = 1245,
                    FundingLineType = "Non-DAS 16-18 Learner",
                    StandardCode    = 1209,
                    ProgrammeType   = 7890,
                    Reference       = "ZPROG001"
                },
                IlrSubmissionDateTime = DateTime.MaxValue,
                EventTime             = DateTimeOffset.MaxValue,
                Earnings      = functionalSkillEarnings.AsReadOnly(),
                PriceEpisodes = new List <PriceEpisode>
                {
                    new PriceEpisode
                    {
                        ActualEndDate    = DateTime.MaxValue,
                        Completed        = true,
                        CompletionAmount = 300m,
                        Identifier       = "p-1",
                        EffectiveTotalNegotiatedPriceStartDate = DateTime.MinValue,
                        InstalmentAmount      = 100m,
                        NumberOfInstalments   = 12,
                        PlannedEndDate        = DateTime.MaxValue,
                        TotalNegotiatedPrice1 = 25.0m,
                        TotalNegotiatedPrice2 = 25.0m,
                        TotalNegotiatedPrice3 = 25.0m,
                        TotalNegotiatedPrice4 = 25.0m
                    }
                }
            };
        }