private void GetFundLineAndBandRateData(FM25Learner learnerFm25Data, ref Dictionary <string, List <FundingClaim1619Model> > fundLineAndRateBandData) { List <FundingClaim1619Model> models; string title = FundLineToTitle(learnerFm25Data.FundLine); if (!fundLineAndRateBandData.TryGetValue(title, out models)) { models = new List <FundingClaim1619Model>(); fundLineAndRateBandData[title] = models; } FundingClaim1619Model model = models.SingleOrDefault(x => string.Equals(x.Title, learnerFm25Data.RateBand, StringComparison.OrdinalIgnoreCase)); if (model == null) { model = new FundingClaim1619Model { Title = learnerFm25Data.RateBand }; models.Add(model); } model.StudentNumber += 1; model.TotalFunding += learnerFm25Data.OnProgPayment.GetValueOrDefault(0); }
private bool CheckIsApplicableLearner(ILearningDelivery learningDelivery, FM25Learner fm25Learner) { return(learningDelivery.FundModel == 25 && learningDelivery.LearningDeliveryFAMs.Any(fam => string.Equals(fam.LearnDelFAMType, Constants.LearningDeliveryFAMCodeSOF, StringComparison.OrdinalIgnoreCase) && string.Equals(fam.LearnDelFAMCode, Constants.LearningDeliveryFAMCode107, StringComparison.OrdinalIgnoreCase)) && (fm25Learner.StartFund.HasValue && fm25Learner.StartFund.Value)); }
public void BuildLearner() { var acadMonthPayment = 1; var fundLine = "FundLine"; var learnerActEndDate = new DateTime(2017, 1, 1); var learnerPlanEndDate = new DateTime(2018, 1, 1); var learnerStartDate = new DateTime(2019, 1, 1); var learnRefNumber = "LearnRefNumber"; var onProgPayment = 1.0m; var learner = new FM25Learner() { AcadMonthPayment = acadMonthPayment, FundLine = fundLine, LearnerActEndDate = learnerActEndDate, LearnerPlanEndDate = learnerPlanEndDate, LearnerStartDate = learnerStartDate, LearnRefNumber = learnRefNumber, OnProgPayment = onProgPayment, }; var dataEntity = NewService().BuildLearnerDataEntity(learner); dataEntity.EntityName.Should().Be("Learner"); dataEntity.Attributes["AcadMonthPayment"].Value.Should().Be(acadMonthPayment); dataEntity.Attributes["FundLine"].Value.Should().Be(fundLine); dataEntity.Attributes["LearnerActEndDate"].Value.Should().Be(learnerActEndDate); dataEntity.Attributes["LearnerPlanEndDate"].Value.Should().Be(learnerPlanEndDate); dataEntity.Attributes["LearnerStartDate"].Value.Should().Be(learnerStartDate); dataEntity.Attributes["LearnRefNumber"].Value.Should().Be(learnRefNumber); dataEntity.Attributes["OnProgPayment"].Value.Should().Be(onProgPayment); dataEntity.Children.Should().BeEmpty(); }
public void GetPeriodisedValuesTestFullMonths(string learnerStartDate, string learnerPlannedEndDate, string learnerActEndDate, string fundLine, bool learnerIsTrainee, int monthsBetweenDatesMock, int periodFromStartDateMock, int periodFromEndDateMock, decimal totalFunding, decimal p1, decimal p2, decimal p3, decimal p4, decimal p5, decimal p6, decimal p7, decimal p8, decimal p9, decimal p10, decimal p11, decimal p12) { var learner = new FM25Learner() { LearnerStartDate = DateTime.Parse(learnerStartDate), LearnerPlanEndDate = DateTime.Parse(learnerPlannedEndDate), LearnerActEndDate = DateTime.Parse(learnerActEndDate), OnProgPayment = totalFunding, FundLine = fundLine }; var periodisationDateServiceMock = new Mock <IPeriodisationDateService>(); periodisationDateServiceMock.Setup(pds => pds.GetPeriodisationStartDate(learner)).Returns(learner.LearnerStartDate.Value); periodisationDateServiceMock.Setup(pds => pds.GetPeriodisationEndDate(learner, learnerIsTrainee)).Returns(learner.LearnerActEndDate.Value); periodisationDateServiceMock.Setup(pds => pds.GetMonthsBetweenDatesIgnoringDaysInclusive(learner.LearnerStartDate.Value, learner.LearnerActEndDate.Value)).Returns(monthsBetweenDatesMock); periodisationDateServiceMock.Setup(pds => pds.PeriodFromDate(learner.LearnerStartDate.Value)).Returns(periodFromStartDateMock); periodisationDateServiceMock.Setup(pds => pds.PeriodFromDate(learner.LearnerActEndDate.Value)).Returns(periodFromEndDateMock); var result = PeriodisationService(periodisationDateServiceMock.Object).GetPeriodisedValues(learner).ToArray(); result[0].Should().Be(p1); result[1].Should().Be(p2); result[2].Should().Be(p3); result[3].Should().Be(p4); result[4].Should().Be(p5); result[5].Should().Be(p6); result[6].Should().Be(p7); result[7].Should().Be(p8); result[8].Should().Be(p9); result[9].Should().Be(p10); result[10].Should().Be(p11); result[11].Should().Be(p12); }
public virtual bool Filter(ILearner learner, FM25Learner fm25Learner) { return(learner != null && fm25Learner != null && FilterStartFund(fm25Learner.StartFund) && FilterFundLine(fm25Learner.FundLine) && learner?.LearningDeliveries?.Any(ld => ld?.LearningDeliveryFAMs?.Any(FilterSOF) == true) == true); }
public void GetPeriodisationEndDateTest(bool learnerIsTrainee, string learnPlannedEndDate, string learnActEndDate, string expectedResult) { var learner = new FM25Learner(); learner.LearnerPlanEndDate = DateTime.Parse(learnPlannedEndDate); learner.LearnerActEndDate = (learnActEndDate == null)?(DateTime?)null:DateTime.Parse(learnActEndDate); PeriodisationDateService().GetPeriodisationEndDate(learner, learnerIsTrainee).Should().Be(DateTime.Parse(expectedResult)); }
public void IsTraineeTrueConstants(string fundLine) { var learner = new FM25Learner() { FundLine = fundLine }; PeriodisationService().IsLearnerTrainee(learner).Should().BeTrue(); }
public void Build_One() { var learner = new TestLearner() { LearnRefNumber = "LearnRefNumber", LearningDeliveries = new List <ILearningDelivery>() { new TestLearningDelivery() { FundModel = 25, LearningDeliveryFAMs = new List <ILearningDeliveryFAM>() { new TestLearningDeliveryFAM() { LearnDelFAMType = "SOF", LearnDelFAMCode = "107", } } } } }; var fm25Learner = new FM25Learner() { LearnRefNumber = "LearnRefNumber", StartFund = true, FundLine = "14-16 Direct Funded Students", }; var message = new TestMessage() { Learners = new List <ILearner>() { learner } }; var fm25Global = new FM25Global() { Learners = new List <FM25Learner>() { fm25Learner } }; var dependentDataMock = new Mock <IReportServiceDependentData>(); dependentDataMock.Setup(d => d.Get <IMessage>()).Returns(message); dependentDataMock.Setup(d => d.Get <FM25Global>()).Returns(fm25Global); var models = NewBuilder().Build(null, dependentDataMock.Object).ToList(); models.Should().HaveCount(1); models[0].Learner.Should().Be(learner); models[0].FM25Learner.Should().Be(fm25Learner); }
public DateTime GetPeriodisationStartDate(FM25Learner learner) { if (_periodisationService.IsLearnerTrainee(learner)) { return(learner.LearnerStartDate > AcademicYearConstants.YearStartDate ? learner.LearnerStartDate.Value : AcademicYearConstants.YearStartDate); } return(AcademicYearConstants.YearStartDate); }
public void IsTraineeFalse() { var learner = new FM25Learner() { FundLine = "NotAnApprentice" }; PeriodisationService().IsLearnerTrainee(learner).Should().BeFalse(); }
public override bool Filter(ILearner learner, FM25Learner fm25Learner) { return(learner != null && fm25Learner != null && FilterFundLine(fm25Learner.FundLine) && learner.LearningDeliveries?.Any(ld => ld.FundModel == FundModelConstants.FM25 && ld.LearningDeliveryFAMs?.Any(FilterSOF) == true) == true); }
public MainOccupancyModel BuildFm25Model( ILearner learner, ILearningDelivery learningDelivery, FM25Learner fm25Data) { var onProgPayment = fm25Data?.LearnerPeriodisedValues?.SingleOrDefault(attr => string.Equals(attr.AttributeName, Constants.Fm25OnProgrammeAttributeName, StringComparison.OrdinalIgnoreCase)); var onProgPaymentTotal = onProgPayment?.Period1 + onProgPayment?.Period2 + onProgPayment?.Period3 + onProgPayment?.Period4 + onProgPayment?.Period5 + onProgPayment?.Period6 + onProgPayment?.Period7 + onProgPayment?.Period8 + onProgPayment?.Period9 + onProgPayment?.Period10 + onProgPayment?.Period11 + onProgPayment?.Period12; return(new MainOccupancyModel { LearnRefNumber = learner.LearnRefNumber, Uln = learner.ULN, AimSeqNumber = learningDelivery.AimSeqNumber, DateOfBirth = learner.DateOfBirthNullable?.ToString("dd/MM/yyyy"), PostcodePrior = learner.PostcodePrior, PmUkprn = learner.PMUKPRNNullable, CampId = learner.CampId, ProvSpecLearnMonA = learner.ProviderSpecLearnerMonitorings ?.SingleOrDefault(x => string.Equals(x.ProvSpecLearnMonOccur, "A", StringComparison.OrdinalIgnoreCase))?.ProvSpecLearnMon, ProvSpecLearnMonB = learner.ProviderSpecLearnerMonitorings ?.SingleOrDefault(x => string.Equals(x.ProvSpecLearnMonOccur, "B", StringComparison.OrdinalIgnoreCase))?.ProvSpecLearnMon, ApplicWeightFundRate = fm25Data?.NatRate, FundModel = learningDelivery.FundModel, LearnStartDate = fm25Data?.LearnerStartDate?.ToString("dd/MM/yyyy"), LearnPlanEndDate = fm25Data?.LearnerPlanEndDate?.ToString("dd/MM/yyyy"), LearnActEndDate = fm25Data?.LearnerActEndDate?.ToString("dd/MM/yyyy"), FundLine = fm25Data?.FundLine, Period1OnProgPayment = onProgPayment?.Period1, Period2OnProgPayment = onProgPayment?.Period2, Period3OnProgPayment = onProgPayment?.Period3, Period4OnProgPayment = onProgPayment?.Period4, Period5OnProgPayment = onProgPayment?.Period5, Period6OnProgPayment = onProgPayment?.Period6, Period7OnProgPayment = onProgPayment?.Period7, Period8OnProgPayment = onProgPayment?.Period8, Period9OnProgPayment = onProgPayment?.Period9, Period10OnProgPayment = onProgPayment?.Period10, Period11OnProgPayment = onProgPayment?.Period11, Period12OnProgPayment = onProgPayment?.Period12, TotalOnProgPayment = onProgPaymentTotal, TotalEarnedCash = onProgPaymentTotal }); }
/// <summary> /// Determines if the learner should be included in the report /// </summary> /// <param name="learner">The learners FM25 data</param> /// <returns>boolean indicating if they should be included or not</returns> public bool IsApplicableLearner(FM25Learner learner) { // BR1 – Applicable Learners if (!(learner.StartFund ?? false)) { return(false); } // BR2 – Applicable Funding Line Types return(_applicableFundLines.Contains(learner.FundLine)); }
public void GetPeriodisationStartDateTest(string learnStartDate, string expectedResult, string fundLine, bool expectedMock) { var learner = new FM25Learner(); learner.LearnerStartDate = DateTime.Parse(learnStartDate); learner.FundLine = fundLine; var periodisationServiceMock = new Mock <IPeriodisationService>(); periodisationServiceMock.Setup(pds => pds.IsLearnerTrainee(learner)).Returns(expectedMock); PeriodisationDateService(periodisationServiceMock.Object).GetPeriodisationStartDate(learner).Should().Be(DateTime.Parse(expectedResult)); }
public DateTime GetPeriodisationEndDate(FM25Learner learner, bool learnerIsTrainee) { if (!learnerIsTrainee) { return(AcademicYearConstants.YearEndDate); } if (learner.LearnerActEndDate.HasValue) { return(learner.LearnerPlanEndDate > AcademicYearConstants.YearStartDate ? new[] { learner.LearnerPlanEndDate.Value, learner.LearnerActEndDate.Value, AcademicYearConstants.YearEndDate }.Min() : learner.LearnerActEndDate.Value); } return(learner.LearnerPlanEndDate > AcademicYearConstants.YearStartDate ? new[] { learner.LearnerPlanEndDate.Value, AcademicYearConstants.YearEndDate }.Min() : AcademicYearConstants.YearEndDate); }
public void Condense() { var learnerOne = new FM25Learner(); var learnerTwo = new FM25Learner(); var learnerThree = new FM25Learner(); var learnerFour = new FM25Learner(); var learnerFive = new FM25Learner(); var learnerSix = new FM25Learner(); var globalOne = new FM25Global() { Learners = new List <FM25Learner>() { learnerOne, learnerTwo, }, }; var globalTwo = new FM25Global() { Learners = new List <FM25Learner> { learnerThree, learnerFour, }, }; var globalThree = new FM25Global() { Learners = new List <FM25Learner> { learnerFive, learnerSix, }, }; var fundingOutputs = new List <FM25Global>() { globalOne, globalTwo, globalThree, }; var fundingOutput = NewService().Condense(fundingOutputs, 1, "2021"); fundingOutput.Should().Be(globalOne); fundingOutput.Learners.Should().HaveCount(6); fundingOutput.Learners.Should().Contain(new[] { learnerOne, learnerTwo, learnerThree, learnerFour, learnerFive, learnerSix }); }
public IDataEntity BuildLearnerDataEntity(FM25Learner learner) { return(new DataEntity(Attributes.EntityLearner) { Attributes = new Dictionary <string, IAttributeData>() { { Attributes.AcadMonthPayment, new AttributeData(learner.AcadMonthPayment) }, { Attributes.FundLine, new AttributeData(learner.FundLine) }, { Attributes.LearnerActEndDate, new AttributeData(learner.LearnerActEndDate) }, { Attributes.LearnerPlanEndDate, new AttributeData(learner.LearnerPlanEndDate) }, { Attributes.LearnerStartDate, new AttributeData(learner.LearnerStartDate) }, { Attributes.LearnRefNumber, new AttributeData(learner.LearnRefNumber) }, { Attributes.OnProgPayment, new AttributeData(learner.OnProgPayment) }, } }); }
public MathsAndEnglishModel BuildModel(ILearner learner, FM25Learner fm25Data) { return(new MathsAndEnglishModel { FundLine = fm25Data.FundLine, LearnRefNumber = learner.LearnRefNumber, FamilyName = learner.FamilyName, GivenNames = learner.GivenNames, DateOfBirth = learner.DateOfBirthNullable?.ToString("dd/MM/yyyy"), CampId = learner.CampId, ConditionOfFundingMaths = fm25Data.ConditionOfFundingMaths, ConditionOfFundingEnglish = fm25Data.ConditionOfFundingEnglish, RateBand = fm25Data.RateBand, ProvSpecLearnMonA = learner.ProviderSpecLearnerMonitorings ?.SingleOrDefault(x => string.Equals(x.ProvSpecLearnMonOccur, "A", StringComparison.OrdinalIgnoreCase))?.ProvSpecLearnMon, ProvSpecLearnMonB = learner.ProviderSpecLearnerMonitorings ?.SingleOrDefault(x => string.Equals(x.ProvSpecLearnMonOccur, "B", StringComparison.OrdinalIgnoreCase))?.ProvSpecLearnMon, LearnerStartDate = fm25Data.LearnerStartDate }); }
public IEnumerable <decimal> GetPeriodisedValues(FM25Learner learner) { var periodisationStartDate = _periodisationDateService.GetPeriodisationStartDate(learner); var periodisationEndDate = _periodisationDateService.GetPeriodisationEndDate(learner, IsLearnerTrainee(learner)); var learnerPeriods = _periodisationDateService.GetMonthsBetweenDatesIgnoringDaysInclusive(periodisationStartDate, periodisationEndDate); var values = GetMonthlyValues(); if (IsLearnerTrainee(learner)) { var monthlyPayment = learner.OnProgPayment.Value / learnerPeriods; var startPeriod = _periodisationDateService.PeriodFromDate(periodisationStartDate); var endPeriod = _periodisationDateService.PeriodFromDate(periodisationEndDate); for (var periodIndex = startPeriod - 1; periodIndex <= endPeriod - 1; periodIndex++) { values[periodIndex] = monthlyPayment; } } return(values); }
public void ApplyUserFilters_NullFilter() { var before = new FM25Learner() { LearnerStartDate = new DateTime(2013, 1, 1), }; var after = new FM25Learner() { LearnerStartDate = new DateTime(2015, 1, 1), }; var learners = new List <FM25Learner>() { before, after, }.AsQueryable(); var queryable = NewBuilder().ApplyUserFilters(learners, null); queryable.Should().HaveCount(2); }
public FM25_Learner BuildFM25Learner(int ukprn, FM25Learner learner) { return(new FM25_Learner { UKPRN = ukprn, LearnRefNumber = learner.LearnRefNumber, AcadMonthPayment = learner.AcadMonthPayment, OnProgPayment = learner.OnProgPayment, AcadProg = learner.AcadProg, ActualDaysILCurrYear = learner.ActualDaysILCurrYear, AreaCostFact1618Hist = learner.AreaCostFact1618Hist, Block1DisadvUpliftNew = learner.Block1DisadvUpliftNew, Block2DisadvElementsNew = learner.Block2DisadvElementsNew, ConditionOfFundingEnglish = learner.ConditionOfFundingEnglish, ConditionOfFundingMaths = learner.ConditionOfFundingMaths, CoreAimSeqNumber = learner.CoreAimSeqNumber, FullTimeEquiv = learner.FullTimeEquiv, FundLine = learner.FundLine, LearnerActEndDate = learner.LearnerActEndDate, LearnerPlanEndDate = learner.LearnerPlanEndDate, LearnerStartDate = learner.LearnerStartDate, NatRate = learner.NatRate, PlannedDaysILCurrYear = learner.PlannedDaysILCurrYear, ProgWeightHist = learner.ProgWeightHist, ProgWeightNew = learner.ProgWeightNew, PrvDisadvPropnHist = learner.PrvDisadvPropnHist, PrvHistLrgProgPropn = learner.PrvHistLrgProgPropn, PrvRetentFactHist = learner.PrvRetentFactHist, PrvHistL3ProgMathEngProp = learner.PrvHistL3ProgMathEngProp, RateBand = learner.RateBand, RetentNew = learner.RetentNew, StartFund = learner.StartFund, ThresholdDays = learner.ThresholdDays, TLevelStudent = learner.TLevelStudent, L3MathsEnglish1Year = learner.L3MathsEnglish1Year, L3MathsEnglish2Year = learner.L3MathsEnglish2Year }); }
private async Task <string> GetCsv(IReportServiceContext reportServiceContext, CancellationToken cancellationToken) { Task <IMessage> ilrFileTask = _ilrProviderService.GetIlrFile(reportServiceContext, cancellationToken); Task <List <string> > validLearnersTask = _validLearnersService.GetLearnersAsync(reportServiceContext, cancellationToken); Task <FM25Global> fm25Task = _fm25ProviderService.GetFM25Data(reportServiceContext, cancellationToken); await Task.WhenAll(ilrFileTask, validLearnersTask, fm25Task); if (cancellationToken.IsCancellationRequested) { return(null); } List <string> ilrError = new List <string>(); List <MathsAndEnglishModel> mathsAndEnglishModels = new List <MathsAndEnglishModel>(); if (fm25Task.Result?.Learners != null) { foreach (string validLearnerRefNum in validLearnersTask.Result) { ILearner learner = ilrFileTask.Result?.Learners?.SingleOrDefault(x => x.LearnRefNumber == validLearnerRefNum); FM25Learner fm25Learner = fm25Task.Result.Learners.SingleOrDefault(x => x.LearnRefNumber == validLearnerRefNum); if (learner == null || fm25Learner == null) { ilrError.Add(validLearnerRefNum); continue; } if (!_mathsAndEnglishFm25Rules.IsApplicableLearner(fm25Learner)) { continue; } mathsAndEnglishModels.Add(_mathsAndEnglishModelBuilder.BuildModel(learner, fm25Learner)); } } if (ilrError.Any()) { _logger.LogWarning($"Failed to get one or more ILR learners while generating {nameof(MathsAndEnglishReport)}: {_stringUtilitiesService.JoinWithMaxLength(ilrError)}"); } mathsAndEnglishModels.Sort(MathsAndEnglishModelComparer); using (MemoryStream ms = new MemoryStream()) { UTF8Encoding utF8Encoding = new UTF8Encoding(false, true); using (TextWriter textWriter = new StreamWriter(ms, utF8Encoding)) { using (CsvWriter csvWriter = new CsvWriter(textWriter)) { WriteCsvRecords <MathsAndEnglishMapper, MathsAndEnglishModel>(csvWriter, mathsAndEnglishModels); csvWriter.Flush(); textWriter.Flush(); return(Encoding.UTF8.GetString(ms.ToArray())); } } } }
public async Task GenerateReport(IReportServiceContext reportServiceContext, ZipArchive archive, bool isFis, CancellationToken cancellationToken) { Task <IMessage> ilrFileTask = _ilrProviderService.GetIlrFile(reportServiceContext, cancellationToken); Task <FM25Global> fm25Task = _fm25ProviderService.GetFM25Data(reportServiceContext, cancellationToken); Task <List <string> > validLearnersTask = _validLearnersService.GetLearnersAsync(reportServiceContext, cancellationToken); await Task.WhenAll(ilrFileTask, fm25Task, validLearnersTask); if (cancellationToken.IsCancellationRequested) { return; } List <ILearner> learners = ilrFileTask.Result?.Learners?.Where(x => validLearnersTask.Result.Contains(x.LearnRefNumber)).ToList(); if (learners == null) { _logger.LogWarning("Failed to get learners for High Needs Students Detail Report"); return; } if (cancellationToken.IsCancellationRequested) { return; } List <HNSModel> hnsModels = new List <HNSModel>(); foreach (var learner in learners) { if (learner.LearningDeliveries == null) { continue; } FM25Global fm25Data = fm25Task.Result; foreach (ILearningDelivery learningDelivery in learner.LearningDeliveries) { FM25Learner fm25Learner = fm25Data?.Learners?.SingleOrDefault(l => string.Equals(l.LearnRefNumber, learner.LearnRefNumber, StringComparison.OrdinalIgnoreCase)); if (fm25Learner == null) { continue; } if (!CheckIsApplicableLearner(learningDelivery, fm25Learner)) { continue; } hnsModels.Add(_hnsReportModelBuilder.BuildModel( learner, learningDelivery, fm25Learner)); } } hnsModels.Sort(_hnsModelComparer); string csv = GetReportCsv(hnsModels); var jobId = reportServiceContext.JobId; var ukPrn = reportServiceContext.Ukprn.ToString(); var externalFileName = GetExternalFilename(ukPrn, jobId, reportServiceContext.SubmissionDateTimeUtc); var fileName = GetFilename(ukPrn, jobId, reportServiceContext.SubmissionDateTimeUtc); await _streamableKeyValuePersistenceService.SaveAsync($"{externalFileName}.csv", csv, cancellationToken); await WriteZipEntry(archive, $"{fileName}.csv", csv); }
public HNSModel BuildModel(ILearner learner, ILearningDelivery learningDelivery, FM25Learner fm25Data) { var returnModel = new HNSModel() { FundLine = fm25Data.FundLine, LearnRefNumber = learner.LearnRefNumber, FamilyName = learner.FamilyName, GivenNames = learner.GivenNames, CampId = learner.CampId }; var learnerFAMs = learner.LearnerFAMs?.ToList(); if (learnerFAMs != null) { returnModel.LearnerFAM_A = learner.LearnerFAMs.Any(x => string.Equals(x.LearnFAMType, Constants.LearnerFAMCodeEHC, StringComparison.OrdinalIgnoreCase) && x.LearnFAMCode == 1) ? "Y" : "N"; returnModel.LearnerFAM_B = learnerFAMs .Any(x => string.Equals(x.LearnFAMType, Constants.LearnerFAMCodeEHC, StringComparison.OrdinalIgnoreCase)) ? "N" : "Y"; returnModel.LearnerFAM_C = learnerFAMs.Any(x => !string.Equals(x.LearnFAMType, Constants.LearnerFAMCodeEHC, StringComparison.OrdinalIgnoreCase) && (string.Equals(x.LearnFAMType, Constants.LearnerFAMCodeHNS, StringComparison.OrdinalIgnoreCase) && x.LearnFAMCode == 1)) ? "Y" : "N"; returnModel.LearnerFAM_D = learnerFAMs.Any(x => (string.Equals(x.LearnFAMType, Constants.LearnerFAMCodeHNS, StringComparison.OrdinalIgnoreCase) || string.Equals(x.LearnFAMType, Constants.LearnerFAMCodeEHC, StringComparison.OrdinalIgnoreCase)) && x.LearnFAMCode == 1) ? "Y" : "N"; returnModel.LearnerFAM_E = learnerFAMs.Any(x => !string.Equals(x.LearnFAMType, Constants.LearnerFAMCodeHNS, StringComparison.OrdinalIgnoreCase) && (string.Equals(x.LearnFAMType, Constants.LearnerFAMCodeEHC, StringComparison.OrdinalIgnoreCase) && x.LearnFAMCode == 1)) ? "Y" : "N"; } else { returnModel.LearnerFAM_A = "N"; returnModel.LearnerFAM_B = "N"; returnModel.LearnerFAM_C = "N"; returnModel.LearnerFAM_D = "N"; returnModel.LearnerFAM_E = "N"; } return(returnModel); }
public bool ValidOnProgPayment(FM25Learner fm25Learner) => fm25Learner.OnProgPayment != null;
public bool Band1(FM25Learner fm25Learner) => fm25Learner.RateBand.CaseInsensitiveEquals(SixteenToNineteenFundingClaimConstants.Band1);
public async Task GenerateReport(IReportServiceContext reportServiceContext, ZipArchive archive, bool isFis, CancellationToken cancellationToken) { Task <IMessage> ilrFileTask = _ilrProviderService.GetIlrFile(reportServiceContext, cancellationToken); Task <FM25Global> fm25Task = _fm25ProviderService.GetFM25Data(reportServiceContext, cancellationToken); Task <FM35Global> fm35Task = _fm35ProviderService.GetFM35Data(reportServiceContext, cancellationToken); Task <List <string> > validLearnersTask = _validLearnersService.GetLearnersAsync(reportServiceContext, cancellationToken); await Task.WhenAll(ilrFileTask, fm25Task, fm35Task, validLearnersTask); if (cancellationToken.IsCancellationRequested) { return; } List <ILearner> learners = ilrFileTask.Result?.Learners?.Where(x => validLearnersTask.Result.Contains(x.LearnRefNumber)).ToList(); if (learners == null) { _logger.LogWarning("Failed to get learners for Main Occupancy Report"); return; } string[] learnAimRefs = learners.SelectMany(x => x.LearningDeliveries).Select(x => x.LearnAimRef).Distinct().ToArray(); Task <Dictionary <string, LarsLearningDelivery> > larsLearningDeliveriesTask = _larsProviderService.GetLearningDeliveriesAsync(learnAimRefs, cancellationToken); Task <List <LearnerAndDeliveries> > larsFrameworkAimsTask = _larsProviderService.GetFrameworkAimsAsync(learnAimRefs, learners, cancellationToken); await Task.WhenAll(larsLearningDeliveriesTask, larsFrameworkAimsTask); if (larsLearningDeliveriesTask.Result == null || larsFrameworkAimsTask.Result == null) { _logger.LogWarning("Failed to get LARS data for Main Occupancy Report"); return; } if (cancellationToken.IsCancellationRequested) { return; } List <string> larsErrors = new List <string>(); List <MainOccupancyModel> mainOccupancyModels = new List <MainOccupancyModel>(); foreach (var learner in learners) { if (learner.LearningDeliveries == null) { continue; } FM25Global fm25Data = fm25Task.Result; FM35Global fm35Data = fm35Task.Result; foreach (ILearningDelivery learningDelivery in learner.LearningDeliveries) { if (!CheckIsApplicableLearner(learningDelivery)) { continue; } if (!larsLearningDeliveriesTask.Result.TryGetValue(learningDelivery.LearnAimRef, out LarsLearningDelivery larsModel)) { larsErrors.Add(learningDelivery.LearnAimRef); continue; } LearningDelivery frameworkAim = larsFrameworkAimsTask.Result?.SingleOrDefault(x => string.Equals(x.LearnerLearnRefNumber, learner.LearnRefNumber, StringComparison.OrdinalIgnoreCase)) ?.LearningDeliveries?.SingleOrDefault(x => string.Equals(x.LearningDeliveryLearnAimRef, learningDelivery.LearnAimRef, StringComparison.OrdinalIgnoreCase) && x.LearningDeliveryAimSeqNumber == learningDelivery.AimSeqNumber); if (frameworkAim == null) { larsErrors.Add(learningDelivery.LearnAimRef); continue; } if (learningDelivery.FundModel == 35) { ILR.FundingService.FM35.FundingOutput.Model.Output.LearningDelivery learnerFm35Data = fm35Data ?.Learners?.SingleOrDefault(l => string.Equals(l.LearnRefNumber, learner.LearnRefNumber, StringComparison.OrdinalIgnoreCase)) ?.LearningDeliveries?.SingleOrDefault(l => l.AimSeqNumber == learningDelivery.AimSeqNumber); if (learnerFm35Data != null) { mainOccupancyModels.Add(_mainOccupancyReportModelBuilder.BuildFm35Model( learner, learningDelivery, larsModel, frameworkAim, learnerFm35Data, _stringUtilitiesService)); } } if (learningDelivery.FundModel != 25) { continue; } FM25Learner learnerFm25Data = fm25Data?.Learners?.SingleOrDefault(l => string.Equals(l.LearnRefNumber, learner.LearnRefNumber, StringComparison.OrdinalIgnoreCase)); mainOccupancyModels.Add(_mainOccupancyReportModelBuilder.BuildFm25Model( learner, learningDelivery, learnerFm25Data)); } } LogWarnings(larsErrors); mainOccupancyModels.Sort(MainOccupancyModelComparer); string csv = GetReportCsv(mainOccupancyModels); var jobId = reportServiceContext.JobId; var ukPrn = reportServiceContext.Ukprn.ToString(); var externalFileName = GetExternalFilename(ukPrn, jobId, reportServiceContext.SubmissionDateTimeUtc); var fileName = GetFilename(ukPrn, jobId, reportServiceContext.SubmissionDateTimeUtc); await _streamableKeyValuePersistenceService.SaveAsync($"{externalFileName}.csv", csv, cancellationToken); await WriteZipEntry(archive, $"{fileName}.csv", csv); }
public bool IsLearnerTrainee(FM25Learner learner) => learner.FundLine.CaseInsensitiveEquals(FundingLineConstants.Traineeship19Plus) || learner.FundLine.CaseInsensitiveEquals(FundingLineConstants.Traineeship1618);
public async Task GenerateReport(IReportServiceContext reportServiceContext, ZipArchive archive, bool isFis, CancellationToken cancellationToken) { Task <IMessage> ilrFileTask = _ilrProviderService.GetIlrFile(reportServiceContext, cancellationToken); Task <FM25Global> fm25DataTask = _fm25ProviderService.GetFM25Data(reportServiceContext, cancellationToken); Task <string> providerNameTask = _orgProviderService.GetProviderName(reportServiceContext, cancellationToken); Task <decimal?> cofRemovalTask = _orgProviderService.GetCofRemoval(reportServiceContext, cancellationToken); Task <ILRSourceFileInfo> lastSubmittedIlrFileTask = _ilrProviderService.GetLastSubmittedIlrFile(reportServiceContext, cancellationToken); await Task.WhenAll(ilrFileTask, fm25DataTask, providerNameTask, cofRemovalTask, lastSubmittedIlrFileTask); FundingClaim1619HeaderModel fundingSummaryHeaderModel = await GetHeaderAsync(reportServiceContext, ilrFileTask, lastSubmittedIlrFileTask, providerNameTask, cancellationToken, isFis); FundingClaim1619FooterModel fundingSummaryFooterModel = await GetFooterAsync(ilrFileTask, lastSubmittedIlrFileTask, cancellationToken); string[] applicableFundingLineTypes = _applicableFundingLineTypes.Values.SelectMany(x => x).ToArray(); // Funding factors are at provider level but are output by the funding calculation against every learner record. // All learners in one provider will have the same funding factor value so the report can pull the minimum value // of each factor from the funding calc output at provider level to populate the factors table. FundingClaim1619FundingFactorModel fundingClaim1619FundingFactorModel = null; Dictionary <string, List <FundingClaim1619Model> > fundLineAndRateBandData = new Dictionary <string, List <FundingClaim1619Model> >(); foreach (ILearner learner in ilrFileTask.Result.Learners) { FM25Learner learnerFm25Data = fm25DataTask.Result?.Learners?.SingleOrDefault(l => string.Equals(l.LearnRefNumber, learner.LearnRefNumber, StringComparison.OrdinalIgnoreCase)); if (learnerFm25Data == null) { continue; } if (!ApplicableLearner(learnerFm25Data, applicableFundingLineTypes)) { continue; } if (fundingClaim1619FundingFactorModel == null) { fundingClaim1619FundingFactorModel = new FundingClaim1619FundingFactorModel { AreaCostFact1618Hist = learnerFm25Data.AreaCostFact1618Hist.GetValueOrDefault(0).ToString("N5"), ProgWeightHist = learnerFm25Data.ProgWeightHist.GetValueOrDefault(0).ToString("N5"), PrvDisadvPropnHist = learnerFm25Data.PrvDisadvPropnHist.GetValueOrDefault(0).ToString("N5"), PrvHistLrgProgPropn = learnerFm25Data.PrvHistLrgProgPropn.GetValueOrDefault(0).ToString("N5"), PrvRetentFactHist = learnerFm25Data.PrvRetentFactHist.GetValueOrDefault(0).ToString("N5") }; } if (learner.LearningDeliveries.Any(ApplicableLearningDelivery)) { GetFundLineAndBandRateData(learnerFm25Data, ref fundLineAndRateBandData); } } // probably don't need this as this will be calculated automatically through the template //FundingClaim1619Model subTotal = TotalFundLineAndBandRateData(ref fundLineAndRateBandData); // probably don't need this as this will be calculated automatically through the template //FundingClaim1619Model total = new FundingClaim1619Model //{ // StudentNumber = subTotal.StudentNumber, // TotalFunding = 0 // Todo //}; if (cancellationToken.IsCancellationRequested) { return; } long jobId = reportServiceContext.JobId; string ukPrn = reportServiceContext.Ukprn.ToString(); var externalFileName = GetExternalFilename(ukPrn, jobId, reportServiceContext.SubmissionDateTimeUtc); var fileName = GetFilename(ukPrn, jobId, reportServiceContext.SubmissionDateTimeUtc); var assembly = Assembly.GetExecutingAssembly(); string resourceName = assembly.GetManifestResourceNames().Single(str => str.EndsWith("1619FundingClaimReportTemplate.xlsx")); var manifestResourceStream = assembly.GetManifestResourceStream(resourceName); Workbook workbook = new Workbook(manifestResourceStream); Worksheet worksheet = workbook.Worksheets[0]; Cells cells = worksheet.Cells; InsertHeaderFooter(workbook, fundingSummaryHeaderModel, fundingSummaryFooterModel); PopulateAllocationValues(cells, fundingClaim1619FundingFactorModel); PopulateMainData(cells, fundLineAndRateBandData); PopulateCofRemoval(cells, cofRemovalTask.Result); workbook.CalculateFormula(); using (MemoryStream ms = new MemoryStream()) { workbook.Save(ms, SaveFormat.Xlsx); await _streamableKeyValuePersistenceService.SaveAsync($"{externalFileName}.xlsx", ms, cancellationToken); await WriteZipEntry(archive, $"{fileName}.xlsx", ms, cancellationToken); } }
private bool ApplicableLearner(FM25Learner learnerFm25Data, string[] applicableFundingLineTypes) { return(applicableFundingLineTypes.Any(x => string.Equals(x, learnerFm25Data.FundLine, StringComparison.OrdinalIgnoreCase)) && learnerFm25Data.StartFund.GetValueOrDefault(false)); }