public async Task <AppsMonthlyPaymentRulebaseInfo> GetFM36DataForAppsMonthlyPaymentReportAsync(int ukPrn, CancellationToken cancellationToken)
        {
            var appsMonthlyPaymentRulebaseInfo = new AppsMonthlyPaymentRulebaseInfo()
            {
                UkPrn = ukPrn,
                AECApprenticeshipPriceEpisodes = new List <AECApprenticeshipPriceEpisodeInfo>()
            };

            cancellationToken.ThrowIfCancellationRequested();

            List <AEC_ApprenticeshipPriceEpisode> aecApprenticeshipPriceEpisodes;

            using (var ilrContext = _ilrRulebaseContextFactory())
            {
                aecApprenticeshipPriceEpisodes = await ilrContext.AEC_ApprenticeshipPriceEpisodes.Where(x => x.UKPRN == ukPrn).ToListAsync(cancellationToken);
            }

            foreach (var aecApprenticeshipPriceEpisode in aecApprenticeshipPriceEpisodes)
            {
                var periodisedValue = new AECApprenticeshipPriceEpisodeInfo()
                {
                    LearnRefNumber            = aecApprenticeshipPriceEpisode.LearnRefNumber,
                    PriceEpisodeActualEndDate = aecApprenticeshipPriceEpisode.PriceEpisodeActualEndDate,
                    PriceEpisodeAgreeId       = aecApprenticeshipPriceEpisode.PriceEpisodeAgreeId
                };
                appsMonthlyPaymentRulebaseInfo.AECApprenticeshipPriceEpisodes.Add(periodisedValue);
            }

            return(appsMonthlyPaymentRulebaseInfo);
        }
Exemple #2
0
        public IEnumerable <DataMatchModel> BuildExternalModels(
            ICollection <DataMatchLearner> dataMatchLearners,
            ICollection <AECApprenticeshipPriceEpisodeInfo> priceEpisodes,
            ICollection <DataLockValidationError> dataLockValidationErrors,
            ICollection <DasApprenticeshipInfo> dasApprenticeshipInfos,
            long jobId)
        {
            List <DataMatchModel> dataMatchModels = new List <DataMatchModel>();

            foreach (var dataLockValidationError in dataLockValidationErrors)
            {
                DataMatchLearner learner = dataMatchLearners.SingleOrDefault(
                    x => x.LearnRefNumber.CaseInsensitiveEquals(dataLockValidationError.LearnerReferenceNumber) &&
                    x.DataMatchLearningDeliveries.Any(ld => ld.AimSeqNumber == dataLockValidationError.AimSeqNumber));

                if (learner == null)
                {
                    continue;
                }

                AECApprenticeshipPriceEpisodeInfo matchedRulebaseInfo = priceEpisodes.LastOrDefault(x =>
                                                                                                    x.LearnRefNumber.CaseInsensitiveEquals(dataLockValidationError.LearnerReferenceNumber));

                DasApprenticeshipInfo matchedDasPriceInfo = dasApprenticeshipInfos.FirstOrDefault(x => x.LearnerUln == dataLockValidationError.LearnerUln);

                string ruleName = PopulateRuleName(dataLockValidationError.RuleId);

                DataMatchModel dataMatchModel = new DataMatchModel
                {
                    LearnRefNumber             = dataLockValidationError.LearnerReferenceNumber,
                    Uln                        = learner.Uln,
                    AimSeqNumber               = dataLockValidationError.AimSeqNumber,
                    RuleName                   = ruleName,
                    Description                = _dataLockValidationMessageService.ErrorMessageForRule(ruleName),
                    ILRValue                   = GetILRValue(ruleName, learner, dataLockValidationError.AimSeqNumber, jobId),
                    ApprenticeshipServiceValue = GetApprenticeshipServiceValue(ruleName, matchedDasPriceInfo),
                    PriceEpisodeStartDate      = matchedRulebaseInfo?.EpisodeStartDate?.ToString("dd/MM/yyyy"),
                    PriceEpisodeActualEndDate  = matchedRulebaseInfo?.PriceEpisodeActualEndDate?.ToString("dd/MM/yyyy"),
                    PriceEpisodeIdentifier     = matchedRulebaseInfo?.PriceEpisodeAgreeId,
                    LegalEntityName            = GetLegalEntityName(ruleName, matchedDasPriceInfo),
                };

                dataMatchModels.Add(dataMatchModel);
            }

            return(dataMatchModels);
        }