public bool IsExcludedRow(AppsCoInvestmentContributionsModel row) { return(IsNullOrZero(row.TotalPMRPreviousFundingYears) && IsNullOrZero(row.TotalPMRThisFundingYear) && IsNullOrZero(row.TotalCoInvestmentDueFromEmployerInPreviousFundingYears) && IsNullOrZero(row.TotalCoInvestmentDueFromEmployerThisFundingYear) && IsNullOrZero(row.CompletionEarningThisFundingYear) && IsNullOrZero(row.CompletionPaymentsThisFundingYear)); }
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)); }