Пример #1
0
 // BR2
 public bool FilterReportRows(AppsCoInvestmentPaymentsInfo paymentInfo, AppsCoInvestmentRulebaseInfo rulebaseInfo, AppsCoInvestmentILRInfo ilrInfo, AppsCoInvestmentRecordKey recordKey)
 {
     return
         (EmployerCoInvestmentPaymentFilter(paymentInfo, recordKey.LearnerReferenceNumber) ||
          CompletionPaymentFilter(paymentInfo, recordKey.LearnerReferenceNumber) ||
          PMRAppFinRecordFilter(ilrInfo, recordKey.LearnerReferenceNumber) ||
          NonZeroCompletionEarningsFilter(rulebaseInfo, recordKey.LearnerReferenceNumber));
 }
Пример #2
0
 public bool NonZeroCompletionEarningsFilter(AppsCoInvestmentRulebaseInfo rulebaseInfo, string learnRefNumber)
 {
     return(rulebaseInfo.AECApprenticeshipPriceEpisodePeriodisedValues?
            .Any(
                p =>
                p.AttributeName == "PriceEpisodeCompletionPayment" &&
                p.LearnRefNumber.CaseInsensitiveEquals(learnRefNumber) &&
                (p.Periods?.Any(v => v.HasValue && v != 0) ?? false))
            ?? false);
 }
Пример #3
0
        public AECLearningDeliveryInfo GetRulebaseLearningDelivery(AppsCoInvestmentRulebaseInfo rulebaseInfo, LearningDeliveryInfo learningDelivery)
        {
            if (learningDelivery == null)
            {
                return(null);
            }

            return(rulebaseInfo
                   .AECLearningDeliveries
                   .FirstOrDefault(ld => ld.LearnRefNumber.CaseInsensitiveEquals(learningDelivery.LearnRefNumber) && ld.AimSeqNumber == learningDelivery.AimSeqNumber));
        }
Пример #4
0
        public async Task <AppsCoInvestmentRulebaseInfo> GetFM36DataForAppsCoInvestmentReportAsync(int ukPrn, CancellationToken cancellationToken)
        {
            var appsCoInvestmentRulebaseInfo = new AppsCoInvestmentRulebaseInfo()
            {
                UkPrn = ukPrn,
                AECLearningDeliveries = new List <AECLearningDeliveryInfo>(),
                AECApprenticeshipPriceEpisodePeriodisedValues = new List <AECApprenticeshipPriceEpisodePeriodisedValuesInfo>()
            };

            cancellationToken.ThrowIfCancellationRequested();

            using (var ilrContext = _ilrRulebaseContextFactory())
            {
                appsCoInvestmentRulebaseInfo.AECApprenticeshipPriceEpisodePeriodisedValues = await ilrContext
                                                                                             .AEC_ApprenticeshipPriceEpisode_PeriodisedValues
                                                                                             .Where(x => x.UKPRN == ukPrn && x.AttributeName == Generics.Fm36PriceEpisodeCompletionPaymentAttributeName)
                                                                                             .Select(p => new AECApprenticeshipPriceEpisodePeriodisedValuesInfo()
                {
                    UKPRN          = ukPrn,
                    LearnRefNumber = p.LearnRefNumber,
                    AimSeqNumber   = p.AEC_ApprenticeshipPriceEpisode.PriceEpisodeAimSeqNumber,
                    AttributeName  = p.AttributeName,
                    Periods        = new[]
                    {
                        p.Period_1,
                        p.Period_2,
                        p.Period_3,
                        p.Period_4,
                        p.Period_5,
                        p.Period_6,
                        p.Period_7,
                        p.Period_8,
                        p.Period_9,
                        p.Period_10,
                        p.Period_11,
                        p.Period_12
                    }
                }).ToListAsync(cancellationToken);

                appsCoInvestmentRulebaseInfo.AECLearningDeliveries = await ilrContext
                                                                     .AEC_LearningDeliveries
                                                                     .Where(x => x.UKPRN == ukPrn)
                                                                     .Select(ld => new AECLearningDeliveryInfo()
                {
                    UKPRN                = ukPrn,
                    LearnRefNumber       = ld.LearnRefNumber,
                    AimSeqNumber         = ld.AimSeqNumber,
                    AppAdjLearnStartDate = ld.AppAdjLearnStartDate,
                }).ToListAsync(cancellationToken);
            }

            return(appsCoInvestmentRulebaseInfo);
        }
Пример #5
0
        public IEnumerable <AppsCoInvestmentContributionsModel> BuildModel(
            AppsCoInvestmentILRInfo appsCoInvestmentIlrInfo,
            AppsCoInvestmentRulebaseInfo appsCoInvestmentRulebaseInfo,
            AppsCoInvestmentPaymentsInfo appsCoInvestmentPaymentsInfo,
            List <AppsCoInvestmentRecordKey> paymentsAppsCoInvestmentUniqueKeys,
            List <AppsCoInvestmentRecordKey> ilrAppsCoInvestmentUniqueKeys,
            IDictionary <long, string> apprenticeshipIdLegalEntityNameDictionary,
            long jobId,
            int ukprn)
        {
            string errorMessage;

            if (appsCoInvestmentIlrInfo == null || appsCoInvestmentIlrInfo.Learners == null)
            {
                errorMessage = "Error: BuildModel() - AppsCoInvestmentILRInfo is null, no data has been retrieved from the ILR1920 data store.";
                _logger.LogInfo(errorMessage, jobIdOverride: jobId);

                throw new Exception(errorMessage);
            }

            if (appsCoInvestmentRulebaseInfo == null)
            {
                errorMessage = "Error: BuildModel() - AppsCoInvestmentRulebaseInfo is null, no data has been retrieved from the ILR1920 data store.";
                _logger.LogInfo(errorMessage, jobIdOverride: jobId);

                throw new Exception(errorMessage);
            }

            if (appsCoInvestmentPaymentsInfo == null)
            {
                errorMessage = "Error: BuildModel() - appsCoInvestmentPaymentsInfo is null, no data has been retrieved from the Payments data store.";
                _logger.LogInfo(errorMessage, jobIdOverride: jobId);

                throw new Exception(errorMessage);
            }

            var paymentsDictionary = BuildPaymentInfoDictionary(appsCoInvestmentPaymentsInfo);
            var learnerDictionary  = BuildLearnerDictionary(appsCoInvestmentIlrInfo);

            var relevantLearnRefNumbers = GetRelevantLearners(appsCoInvestmentIlrInfo, appsCoInvestmentPaymentsInfo).ToList();

            var uniqueKeys = UnionKeys(relevantLearnRefNumbers, ilrAppsCoInvestmentUniqueKeys, paymentsAppsCoInvestmentUniqueKeys).ToList();

            return(uniqueKeys
                   .Where(r => FilterReportRows(appsCoInvestmentPaymentsInfo, appsCoInvestmentRulebaseInfo, appsCoInvestmentIlrInfo, r))
                   .Select(record =>
            {
                var paymentRecords = GetPaymentInfosForRecord(paymentsDictionary, record).ToList();
                var learner = GetLearnerForRecord(learnerDictionary, record);
                var learningDelivery = GetLearningDeliveryForRecord(learner, record);
                var filteredPaymentRecords = FundingSourceAndTransactionTypeFilter(paymentRecords).ToList();
                var rulebaseLearningDelivery = GetRulebaseLearningDelivery(appsCoInvestmentRulebaseInfo, learningDelivery);
                var completedPaymentRecordsInCurrentYear = paymentRecords.Where(p => p.AcademicYear == Generics.AcademicYear && p.TransactionType == 2).ToList();
                var totalsByPeriodDictionary = BuildCoinvestmentPaymentsPerPeriodDictionary(filteredPaymentRecords);
                var earliestPaymentInfo = GetEarliestPaymentInfo(paymentRecords);

                string legalEntityName = null;

                if (earliestPaymentInfo != null && earliestPaymentInfo.ApprenticeshipId.HasValue)
                {
                    apprenticeshipIdLegalEntityNameDictionary.TryGetValue(earliestPaymentInfo.ApprenticeshipId.Value, out legalEntityName);
                }

                var totalDueCurrentYear = totalsByPeriodDictionary.Sum(d => d.Value);
                var totalDuePreviousYear = filteredPaymentRecords.Where(p => p.AcademicYear < 1920).Sum(p => p.Amount);
                var totalCollectedCurrentYear = GetTotalPMRBetweenDates(learningDelivery, _academicYearStart, _nextAcademicYearStart);
                var totalCollectedPreviousYear = GetTotalPMRBetweenDates(learningDelivery, null, _academicYearStart);

                var model = new AppsCoInvestmentContributionsModel
                {
                    Ukprn = ukprn,
                    LearnRefNumber = record.LearnerReferenceNumber,
                    UniqueLearnerNumber = GetUniqueOrEmpty(paymentRecords, p => p.LearnerUln),
                    LearningStartDate = record.LearningStartDate,
                    ProgType = record.LearningAimProgrammeType,
                    StandardCode = record.LearningAimStandardCode,
                    FrameworkCode = record.LearningAimFrameworkCode,
                    ApprenticeshipPathway = record.LearningAimPathwayCode,
                    SoftwareSupplierAimIdentifier = learningDelivery?.SWSupAimId,
                    LearningDeliveryFAMTypeApprenticeshipContractType = GetUniqueOrEmpty(paymentRecords, p => p.ContractType),
                    EmployerIdentifierAtStartOfLearning = learner?.LearnerEmploymentStatus.Where(w => w.DateEmpStatApp <= record.LearningStartDate).OrderByDescending(o => o.DateEmpStatApp).FirstOrDefault()?.EmpId,
                    EmployerNameFromApprenticeshipService = legalEntityName,
                    EmployerCoInvestmentPercentage = GetEmployerCoInvestmentPercentage(filteredPaymentRecords),
                    ApplicableProgrammeStartDate = rulebaseLearningDelivery?.AppAdjLearnStartDate,
                    TotalPMRPreviousFundingYears = totalCollectedPreviousYear,
                    TotalCoInvestmentDueFromEmployerInPreviousFundingYears = totalDuePreviousYear,
                    TotalPMRThisFundingYear = totalCollectedCurrentYear,
                    TotalCoInvestmentDueFromEmployerThisFundingYear = totalDueCurrentYear,
                    PercentageOfCoInvestmentCollected = GetPercentageOfInvestmentCollected(totalDueCurrentYear, totalDuePreviousYear, totalCollectedCurrentYear, totalCollectedPreviousYear),
                    LDM356Or361 = HasLdm356Or361(learningDelivery) ? "Yes" : "No",
                    CompletionEarningThisFundingYear = CalculateCompletionEarningsThisFundingYear(learningDelivery, appsCoInvestmentRulebaseInfo),
                    CompletionPaymentsThisFundingYear = completedPaymentRecordsInCurrentYear.Sum(r => r.Amount),
                    CoInvestmentDueFromEmployerForAugust = GetPeriodisedValueFromDictionaryForPeriod(totalsByPeriodDictionary, 1),
                    CoInvestmentDueFromEmployerForSeptember = GetPeriodisedValueFromDictionaryForPeriod(totalsByPeriodDictionary, 2),
                    CoInvestmentDueFromEmployerForOctober = GetPeriodisedValueFromDictionaryForPeriod(totalsByPeriodDictionary, 3),
                    CoInvestmentDueFromEmployerForNovember = GetPeriodisedValueFromDictionaryForPeriod(totalsByPeriodDictionary, 4),
                    CoInvestmentDueFromEmployerForDecember = GetPeriodisedValueFromDictionaryForPeriod(totalsByPeriodDictionary, 5),
                    CoInvestmentDueFromEmployerForJanuary = GetPeriodisedValueFromDictionaryForPeriod(totalsByPeriodDictionary, 6),
                    CoInvestmentDueFromEmployerForFebruary = GetPeriodisedValueFromDictionaryForPeriod(totalsByPeriodDictionary, 7),
                    CoInvestmentDueFromEmployerForMarch = GetPeriodisedValueFromDictionaryForPeriod(totalsByPeriodDictionary, 8),
                    CoInvestmentDueFromEmployerForApril = GetPeriodisedValueFromDictionaryForPeriod(totalsByPeriodDictionary, 9),
                    CoInvestmentDueFromEmployerForMay = GetPeriodisedValueFromDictionaryForPeriod(totalsByPeriodDictionary, 10),
                    CoInvestmentDueFromEmployerForJune = GetPeriodisedValueFromDictionaryForPeriod(totalsByPeriodDictionary, 11),
                    CoInvestmentDueFromEmployerForJuly = GetPeriodisedValueFromDictionaryForPeriod(totalsByPeriodDictionary, 12),
                    CoInvestmentDueFromEmployerForR13 = GetPeriodisedValueFromDictionaryForPeriod(totalsByPeriodDictionary, 13),
                    CoInvestmentDueFromEmployerForR14 = GetPeriodisedValueFromDictionaryForPeriod(totalsByPeriodDictionary, 14)
                };

                return model;
            })
                   .Where(row => !IsExcludedRow(row))
                   .OrderBy(l => l.LearnRefNumber)
                   .ThenBy(t => t.LearningDeliveryFAMTypeApprenticeshipContractType));
        }
Пример #6
0
        public decimal CalculateCompletionEarningsThisFundingYear(LearningDeliveryInfo learningDelivery, AppsCoInvestmentRulebaseInfo rulebaseInfo)
        {
            if (learningDelivery != null)
            {
                return(rulebaseInfo?
                       .AECApprenticeshipPriceEpisodePeriodisedValues?
                       .Where(p =>
                              p.LearnRefNumber == learningDelivery.LearnRefNumber &&
                              p.AimSeqNumber == learningDelivery.AimSeqNumber &&
                              p.Periods != null)
                       .SelectMany(p => p.Periods)
                       .Sum()
                       ?? 0);
            }

            return(0);
        }