예제 #1
0
        public async Task GenerateReport(IReportServiceContext reportServiceContext, ZipArchive archive, bool isFis, CancellationToken cancellationToken)
        {
            Task <IMessage>   ilrFileTask = _ilrProviderService.GetIlrFile(reportServiceContext, cancellationToken);
            Task <FM81Global> fm81Task    =
                _fm81TrailBlazerProviderService.GetFM81Data(reportServiceContext, cancellationToken);
            Task <List <string> > validLearnersTask =
                _validLearnersService.GetLearnersAsync(reportServiceContext, cancellationToken);

            await Task.WhenAll(ilrFileTask, fm81Task, 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 Trailblazer Employer Incentives Report");
                return;
            }

            var fm81Data = fm81Task.Result;
            var trailblazerEmployerIncentivesModels = new List <TrailblazerEmployerIncentivesModel>();

            var fm81EmployerIdentifierList = fm81Data?.Learners?.Select(l => l.LearningDeliveries?.Select(x =>
                                                                                                          string.Join(",", x.LearningDeliveryValues.EmpIdSmallBusDate, x.LearningDeliveryValues.EmpIdFirstYoungAppDate, x.LearningDeliveryValues.EmpIdSecondYoungAppDate, x.LearningDeliveryValues.EmpIdAchDate))).FirstOrDefault();

            if (fm81EmployerIdentifierList != null)
            {
                var fm81EmployerIdentifierUniqueList = fm81EmployerIdentifierList.First().Split(',').ToArray()
                                                       .Where(x => !string.IsNullOrWhiteSpace(x)).Distinct().ToList();

                foreach (string empIdentifier in fm81EmployerIdentifierUniqueList)
                {
                    var learnerFm81Data = fm81Data?.Learners?.SelectMany(x => x.LearningDeliveries).ToList();

                    trailblazerEmployerIncentivesModels.Add(
                        _trailblazerEmployerIncentivesModelBuilder.BuildTrailblazerEmployerIncentivesModel(
                            Convert.ToInt32(empIdentifier),
                            null,
                            learnerFm81Data));
                }
            }

            trailblazerEmployerIncentivesModels.Sort(new TrailblazerEmployerIncentivesModelComparer());

            var csv = GetReportCsv(trailblazerEmployerIncentivesModels);

            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);
        }
예제 #2
0
        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 <FM36Global>     fm36Task          = _fm36ProviderService.GetFM36Data(reportServiceContext, cancellationToken);

            await Task.WhenAll(ilrFileTask, validLearnersTask, fm36Task);

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            List <AppsIndicativeEarningsModel> appsIndicativeEarningsModels = new List <AppsIndicativeEarningsModel>();

            if (ilrFileTask.Result?.Learners != null)
            {
                await GenerateRowsAsync(ilrFileTask.Result, fm36Task.Result, validLearnersTask.Result, appsIndicativeEarningsModels, cancellationToken);
            }

            using (var ms = new MemoryStream())
            {
                UTF8Encoding utF8Encoding = new UTF8Encoding(false, true);
                using (TextWriter textWriter = new StreamWriter(ms, utF8Encoding))
                {
                    using (CsvWriter csvWriter = new CsvWriter(textWriter))
                    {
                        WriteCsvRecords <AppsIndicativeEarningsMapper, AppsIndicativeEarningsModel>(csvWriter, appsIndicativeEarningsModels);
                        csvWriter.Flush();
                        textWriter.Flush();
                        return(Encoding.UTF8.GetString(ms.ToArray()));
                    }
                }
            }
        }
        public async Task GenerateReport(IReportServiceContext reportServiceContext, ZipArchive archive, bool isFis, CancellationToken cancellationToken)
        {
            Task <IMessage> ilrTask = _ilrProviderService.GetIlrFile(reportServiceContext, cancellationToken);
            Task <List <ValidationErrorDto> > validationErrorDtosTask = ReadAndDeserialiseValidationErrorsAsync(reportServiceContext, cancellationToken);
            await Task.WhenAll(ilrTask, validationErrorDtosTask);

            long   jobId = reportServiceContext.JobId;
            string ukPrn = reportServiceContext.Ukprn.ToString();

            _externalFileName = GetExternalFilename(ukPrn, jobId, reportServiceContext.SubmissionDateTimeUtc);
            _fileName         = GetFilename(ukPrn, jobId, reportServiceContext.SubmissionDateTimeUtc);

            List <ValidationErrorDto> validationErrorDtos = validationErrorDtosTask.Result;

            List <ValidationErrorModel> validationErrors = ValidationErrorModels(ilrTask.Result, validationErrorDtos);

            GenerateFrontEndValidationReport(reportServiceContext, validationErrorDtos);

            await PersistValuesToStorage(validationErrors, archive, cancellationToken);
        }
        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 async Task GenerateReport(IReportServiceContext reportServiceContext, ZipArchive archive, bool isFis, CancellationToken cancellationToken)
        {
            Task <IMessage>   ilrFileTask = _ilrProviderService.GetIlrFile(reportServiceContext, cancellationToken);
            Task <FM81Global> fm81Task    =
                _fm81TrailBlazerProviderService.GetFM81Data(reportServiceContext, cancellationToken);
            Task <List <string> > validLearnersTask =
                _validLearnersService.GetLearnersAsync(reportServiceContext, cancellationToken);

            await Task.WhenAll(ilrFileTask, fm81Task, 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 Trailblazer Apprenticeships Occupancy Report");
                return;
            }

            string[] learnAimRefs = learners.SelectMany(x => x.LearningDeliveries).Select(x => x.LearnAimRef).Distinct().ToArray();
            Dictionary <string, LarsLearningDelivery> larsLearningDeliveries = await _larsProviderService.GetLearningDeliveriesAsync(learnAimRefs, cancellationToken);

            var fm81Data = fm81Task.Result;
            var trailblazerAppsOccupancyModels = new List <TrailblazerAppsOccupancyModel>();

            foreach (var learner in learners)
            {
                FM81Learner fm81Learner = fm81Data?.Learners?.SingleOrDefault(x => string.Equals(x.LearnRefNumber, learner.LearnRefNumber, StringComparison.OrdinalIgnoreCase));
                foreach (ILearningDelivery learningDelivery in learner.LearningDeliveries)
                {
                    if (!CheckIsApplicableLearner(learningDelivery))
                    {
                        continue;
                    }

                    LarsLearningDelivery larsDelivery             = larsLearningDeliveries.SingleOrDefault(x => string.Equals(x.Key, learningDelivery.LearnAimRef, StringComparison.OrdinalIgnoreCase)).Value;
                    LearningDelivery     ruleBaseLearningDelivery = fm81Learner?.LearningDeliveries
                                                                    ?.SingleOrDefault(x => x.AimSeqNumber == learningDelivery.AimSeqNumber);
                    trailblazerAppsOccupancyModels.Add(_trailblazerAppsOccupancyModelBuilder
                                                       .BuildTrailblazerAppsOccupancyModel(
                                                           learner,
                                                           learningDelivery,
                                                           larsDelivery,
                                                           ruleBaseLearningDelivery));
                }
            }

            trailblazerAppsOccupancyModels.Sort(new TrailblazerAppsOccupancyModelComparer());

            var csv = GetReportCsv(trailblazerAppsOccupancyModels);

            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);
        }
예제 #7
0
        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);
        }
        private async Task <string> GetCsv(IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            Task <IMessage>       ilrFileTask       = _ilrProviderService.GetIlrFile(reportServiceContext, cancellationToken);
            Task <ALBGlobal>      albDataTask       = _allbProviderService.GetAllbData(reportServiceContext, cancellationToken);
            Task <List <string> > validLearnersTask = _validLearnersService.GetLearnersAsync(reportServiceContext, cancellationToken);

            await Task.WhenAll(ilrFileTask, albDataTask, validLearnersTask);

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            if (validLearnersTask.Result == null)
            {
                return(null);
            }

            string[] learnAimRefs = ilrFileTask.Result?.Learners?.Where(x => validLearnersTask.Result.Contains(x.LearnRefNumber))
                                    .SelectMany(x => x.LearningDeliveries).Select(x => x.LearnAimRef).Distinct().ToArray();

            Dictionary <string, LarsLearningDelivery> larsLearningDeliveries = await _larsProviderService.GetLearningDeliveriesAsync(learnAimRefs, cancellationToken);

            if (larsLearningDeliveries == null)
            {
                return(null);
            }

            if (cancellationToken.IsCancellationRequested)
            {
                return(null);
            }

            List <string> ilrError        = new List <string>();
            List <string> larsError       = new List <string>();
            List <string> albLearnerError = new List <string>();

            List <AllbOccupancyModel> models = new List <AllbOccupancyModel>(validLearnersTask.Result.Count);

            foreach (string validLearnerRefNum in validLearnersTask.Result)
            {
                var learner = ilrFileTask.Result?.Learners?.SingleOrDefault(x => string.Equals(x.LearnRefNumber, validLearnerRefNum, StringComparison.OrdinalIgnoreCase));
                if (learner == null)
                {
                    ilrError.Add(validLearnerRefNum);
                    continue;
                }

                ALBLearner albLearner =
                    albDataTask.Result?.Learners?.SingleOrDefault(x => string.Equals(x.LearnRefNumber, validLearnerRefNum, StringComparison.OrdinalIgnoreCase));
                if (albLearner == null)
                {
                    albLearnerError.Add(validLearnerRefNum);
                    continue;
                }

                if (learner.LearningDeliveries == null)
                {
                    ilrError.Add(validLearnerRefNum);
                    continue;
                }

                foreach (ILearningDelivery learningDelivery in learner.LearningDeliveries)
                {
                    LearningDelivery albLearningDelivery = albLearner?.LearningDeliveries
                                                           ?.SingleOrDefault(x => x.AimSeqNumber == learningDelivery.AimSeqNumber);

                    if (!ValidAllbLearningDelivery(learningDelivery, albLearningDelivery))
                    {
                        continue;
                    }

                    if (!larsLearningDeliveries.TryGetValue(learningDelivery.LearnAimRef, out LarsLearningDelivery larsModel))
                    {
                        larsError.Add(validLearnerRefNum);
                        continue;
                    }

                    LearningDeliveryValue           albLearningDeliveryValue = albLearningDelivery?.LearningDeliveryValue;
                    LearningDeliveryPeriodisedValue albSupportPaymentObj     =
                        albLearningDelivery?.LearningDeliveryPeriodisedValues?.SingleOrDefault(x =>
                                                                                               string.Equals(x.AttributeName, AlbSupportPayment, StringComparison.OrdinalIgnoreCase));
                    LearningDeliveryPeriodisedValue albAreaUpliftOnProgPaymentObj =
                        albLearningDelivery?.LearningDeliveryPeriodisedValues?.SingleOrDefault(x =>
                                                                                               string.Equals(x.AttributeName, AlbAreaUpliftOnProgPayment, StringComparison.OrdinalIgnoreCase));
                    LearningDeliveryPeriodisedValue albAreaUpliftBalPaymentObj =
                        albLearningDelivery?.LearningDeliveryPeriodisedValues?.SingleOrDefault(x =>
                                                                                               string.Equals(x.AttributeName, AlbAreaUpliftBalPayment, StringComparison.OrdinalIgnoreCase));
                    ILearningDeliveryFAM[] alb = learningDelivery.LearningDeliveryFAMs?.Where(x =>
                                                                                              string.Equals(x.LearnDelFAMType, "ALB", StringComparison.OrdinalIgnoreCase)).ToArray();
                    LearningDeliveryPeriodisedValue[] payments = albLearningDelivery?.LearningDeliveryPeriodisedValues?.Where(IsPayment).ToArray();
                    LearningDeliveryPeriodisedValue   albCode  = albLearningDelivery?.LearningDeliveryPeriodisedValues?.SingleOrDefault(x =>
                                                                                                                                        string.Equals(x.AttributeName, AlbCode, StringComparison.OrdinalIgnoreCase));
                    var ldms = _stringUtilitiesService.GetArrayEntries(learningDelivery.LearningDeliveryFAMs?.Where(x => string.Equals(x.LearnDelFAMType, "LDM", StringComparison.OrdinalIgnoreCase)), 4);

                    string albBursaryFunding = string.Empty, albDateFrom = string.Empty, albDateTo = string.Empty;
                    if (alb != null && alb.Any())
                    {
                        albBursaryFunding = alb.Max(x => _stringUtilitiesService.TryGetInt(x.LearnDelFAMCode, 0)).ToString();
                        albDateFrom       = _stringUtilitiesService.GetDateTimeAsString(alb.Min(x => x.LearnDelFAMDateFromNullable ?? DateTime.MinValue), string.Empty, DateTime.MinValue);
                        albDateTo         = _stringUtilitiesService.GetDateTimeAsString(alb.Max(x => x.LearnDelFAMDateToNullable ?? DateTime.MinValue), string.Empty, DateTime.MinValue);
                    }

                    models.Add(new AllbOccupancyModel
                    {
                        LearnRefNumber    = learner.LearnRefNumber,
                        Uln               = learner.ULN,
                        DateOfBirth       = learner.DateOfBirthNullable?.ToString("dd/MM/yyyy"),
                        PreMergerUkprn    = learner.PrevUKPRNNullable,
                        CampId            = learner.CampId,
                        ProvSpecLearnMonA = learner.ProviderSpecLearnerMonitorings
                                            ?.FirstOrDefault(x => string.Equals(x.ProvSpecLearnMonOccur, "A", StringComparison.OrdinalIgnoreCase))?.ProvSpecLearnMon,
                        ProvSpecLearnMonB = learner.ProviderSpecLearnerMonitorings
                                            ?.FirstOrDefault(x => string.Equals(x.ProvSpecLearnMonOccur, "B", StringComparison.OrdinalIgnoreCase))?.ProvSpecLearnMon,
                        AimSeqNumber           = learningDelivery.AimSeqNumber,
                        LearnAimRef            = learningDelivery.LearnAimRef,
                        LearnAimRefTitle       = larsModel.LearningAimTitle,
                        SwSupAimId             = learningDelivery.SWSupAimId,
                        WeightedRate           = albLearningDeliveryValue?.WeightedRate,
                        ApplicProgWeightFact   = albLearningDeliveryValue?.ApplicProgWeightFact,
                        NotionalNvqLevelV2     = larsModel.NotionalNvqLevel,
                        SectorSubjectAreaTier2 = larsModel.Tier2SectorSubjectArea,
                        AimType            = learningDelivery.AimType,
                        FundingModel       = learningDelivery.FundModel,
                        PriorLearnFundAdj  = learningDelivery.PriorLearnFundAdjNullable,
                        OtherFundAdj       = learningDelivery.OtherFundAdjNullable,
                        OrigLearnStartDate = learningDelivery.OrigLearnStartDateNullable?.ToString("dd/MM/yyyy"),
                        LearnStartDate     = learningDelivery.LearnStartDate.ToString("dd/MM/yyyy"),
                        LearnPlanEndDate   = learningDelivery.LearnPlanEndDate.ToString("dd/MM/yyyy"),
                        CompStatus         = learningDelivery.CompStatus,
                        LearnActEndDate    = learningDelivery.LearnActEndDateNullable?.ToString("dd/MM/yyyy"),
                        Outcome            = learningDelivery.OutcomeNullable,
                        LearnDelFamCodeAdl = learningDelivery.LearningDeliveryFAMs?.SingleOrDefault(x =>
                                                                                                    string.Equals(x.LearnDelFAMType, "ADL", StringComparison.OrdinalIgnoreCase))?.LearnDelFAMCode,
                        AlbBursaryFunding = albBursaryFunding,
                        AlbDateFrom       = albDateFrom,
                        AlbDateTo         = albDateTo,
                        LearnDelMonA      = ldms[0],
                        LearnDelMonB      = ldms[1],
                        LearnDelMonC      = ldms[2],
                        LearnDelMonD      = ldms[3],
                        ProvSpecDelMonA   = learningDelivery.ProviderSpecDeliveryMonitorings?.SingleOrDefault(x =>
                                                                                                              string.Equals(x.ProvSpecDelMonOccur, "A", StringComparison.OrdinalIgnoreCase))?.ProvSpecDelMon,
                        ProvSpecDelMonB = learningDelivery.ProviderSpecDeliveryMonitorings?.SingleOrDefault(x =>
                                                                                                            string.Equals(x.ProvSpecDelMonOccur, "B", StringComparison.OrdinalIgnoreCase))?.ProvSpecDelMon,
                        ProvSpecDelMonC = learningDelivery.ProviderSpecDeliveryMonitorings?.SingleOrDefault(x =>
                                                                                                            string.Equals(x.ProvSpecDelMonOccur, "C", StringComparison.OrdinalIgnoreCase))?.ProvSpecDelMon,
                        ProvSpecDelMonD = learningDelivery.ProviderSpecDeliveryMonitorings?.SingleOrDefault(x =>
                                                                                                            string.Equals(x.ProvSpecDelMonOccur, "D", StringComparison.OrdinalIgnoreCase))?.ProvSpecDelMon,
                        PartnerUkprn            = learningDelivery.PartnerUKPRNNullable,
                        DelLocPostCode          = learningDelivery.DelLocPostCode,
                        AreaCodeFactAdj         = albLearningDeliveryValue?.AreaCostFactAdj,
                        FundLine                = albLearningDeliveryValue?.FundLine,
                        LiabilityDate           = albLearningDeliveryValue?.LiabilityDate?.ToString("dd/MM/yyyy"),
                        PlannedNumOnProgInstalm = albLearningDeliveryValue?.PlannedNumOnProgInstalm,
                        ApplicFactDate          = albLearningDeliveryValue?.ApplicFactDate?.ToString("dd/MM/yyyy"),

                        Period1AlbCode          = albCode?.Period1,
                        Period1AlbPayment       = albSupportPaymentObj?.Period1,
                        Period1AlbOnProgPayment = albAreaUpliftOnProgPaymentObj?.Period1 ?? 0,
                        Period1AlbAreaUplift    = albAreaUpliftBalPaymentObj?.Period1 ?? 0,
                        Period1AlbTotal         = payments?.Sum(x => x.Period1) ?? 0,

                        Period2AlbCode          = albCode?.Period2 ?? 0,
                        Period2AlbPayment       = albSupportPaymentObj?.Period2 ?? 0,
                        Period2AlbOnProgPayment = albAreaUpliftOnProgPaymentObj?.Period2 ?? 0,
                        Period2AlbBalPayment    = albAreaUpliftBalPaymentObj?.Period2 ?? 0,
                        Period2AlbTotal         = payments?.Sum(x => x.Period2) ?? 0,

                        Period3AlbCode          = albCode?.Period3 ?? 0,
                        Period3AlbPayment       = albSupportPaymentObj?.Period3 ?? 0,
                        Period3AlbOnProgPayment = albAreaUpliftOnProgPaymentObj?.Period3 ?? 0,
                        Period3AlbBalPayment    = albAreaUpliftBalPaymentObj?.Period3 ?? 0,
                        Period3AlbTotal         = payments?.Sum(x => x.Period3) ?? 0,

                        Period4AlbCode          = albCode?.Period4 ?? 0,
                        Period4AlbPayment       = albSupportPaymentObj?.Period4 ?? 0,
                        Period4AlbOnProgPayment = albAreaUpliftOnProgPaymentObj?.Period4 ?? 0,
                        Period4AlbBalPayment    = albAreaUpliftBalPaymentObj?.Period4 ?? 0,
                        Period4AlbTotal         = payments?.Sum(x => x.Period4) ?? 0,

                        Period5AlbCode          = albCode?.Period5 ?? 0,
                        Period5AlbPayment       = albSupportPaymentObj?.Period5 ?? 0,
                        Period5AlbOnProgPayment = albAreaUpliftOnProgPaymentObj?.Period5 ?? 0,
                        Period5AlbBalPayment    = albAreaUpliftBalPaymentObj?.Period5 ?? 0,
                        Period5AlbTotal         = payments?.Sum(x => x.Period5) ?? 0,

                        Period6AlbCode          = albCode?.Period6 ?? 0,
                        Period6AlbPayment       = albSupportPaymentObj?.Period6 ?? 0,
                        Period6AlbOnProgPayment = albAreaUpliftOnProgPaymentObj?.Period6 ?? 0,
                        Period6AlbBalPayment    = albAreaUpliftBalPaymentObj?.Period6 ?? 0,
                        Period6AlbTotal         = payments?.Sum(x => x.Period6) ?? 0,

                        Period7AlbCode          = albCode?.Period7 ?? 0,
                        Period7AlbPayment       = albSupportPaymentObj?.Period7 ?? 0,
                        Period7AlbOnProgPayment = albAreaUpliftOnProgPaymentObj?.Period7 ?? 0,
                        Period7AlbBalPayment    = albAreaUpliftBalPaymentObj?.Period7 ?? 0,
                        Period7AlbTotal         = payments?.Sum(x => x.Period7) ?? 0,

                        Period8AlbCode          = albCode?.Period8 ?? 0,
                        Period8AlbPayment       = albSupportPaymentObj?.Period8 ?? 0,
                        Period8AlbOnProgPayment = albAreaUpliftOnProgPaymentObj?.Period8 ?? 0,
                        Period8AlbBalPayment    = albAreaUpliftBalPaymentObj?.Period8 ?? 0,
                        Period8AlbTotal         = payments?.Sum(x => x.Period8) ?? 0,

                        Period9AlbCode          = albCode?.Period9 ?? 0,
                        Period9AlbPayment       = albSupportPaymentObj?.Period9 ?? 0,
                        Period9AlbOnProgPayment = albAreaUpliftOnProgPaymentObj?.Period9 ?? 0,
                        Period9AlbBalPayment    = albAreaUpliftBalPaymentObj?.Period9 ?? 0,
                        Period9AlbTotal         = payments?.Sum(x => x.Period9) ?? 0,

                        Period10AlbCode          = albCode?.Period10 ?? 0,
                        Period10AlbPayment       = albSupportPaymentObj?.Period10 ?? 0,
                        Period10AlbOnProgPayment = albAreaUpliftOnProgPaymentObj?.Period10 ?? 0,
                        Period10AlbBalPayment    = albAreaUpliftBalPaymentObj?.Period10 ?? 0,
                        Period10AlbTotal         = payments?.Sum(x => x.Period10) ?? 0,

                        Period11AlbCode          = albCode?.Period11 ?? 0,
                        Period11AlbPayment       = albSupportPaymentObj?.Period11 ?? 0,
                        Period11AlbOnProgPayment = albAreaUpliftOnProgPaymentObj?.Period11 ?? 0,
                        Period11AlbBalPayment    = albAreaUpliftBalPaymentObj?.Period11 ?? 0,
                        Period11AlbTotal         = payments?.Sum(x => x.Period11) ?? 0,

                        Period12AlbCode          = albCode?.Period12 ?? 0,
                        Period12AlbPayment       = albSupportPaymentObj?.Period12 ?? 0,
                        Period12AlbOnProgPayment = albAreaUpliftOnProgPaymentObj?.Period12 ?? 0,
                        Period12AlbBalPayment    = albAreaUpliftBalPaymentObj?.Period12 ?? 0,
                        Period12AlbTotal         = payments?.Sum(x => x.Period12) ?? 0,

                        TotalAlbSupportPayment = (albSupportPaymentObj?.Period1 ?? 0) + (albSupportPaymentObj?.Period2 ?? 0) + (albSupportPaymentObj?.Period3 ?? 0) + (albSupportPaymentObj?.Period4 ?? 0) + (albSupportPaymentObj?.Period5 ?? 0) + (albSupportPaymentObj?.Period6 ?? 0) + (albSupportPaymentObj?.Period7 ?? 0)
                                                 + (albSupportPaymentObj?.Period8 ?? 0) + (albSupportPaymentObj?.Period9 ?? 0) + (albSupportPaymentObj?.Period10 ?? 0) + (albSupportPaymentObj?.Period11 ?? 0) + (albSupportPaymentObj?.Period12 ?? 0),
                        TotalAlbAreaUplift = (albAreaUpliftOnProgPaymentObj?.Period1 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period2 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period3 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period4 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period5 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period6 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period7 ?? 0)
                                             + (albAreaUpliftOnProgPaymentObj?.Period8 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period9 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period10 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period11 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period12 ?? 0),
                        TotalAlbBalPayment = (albAreaUpliftBalPaymentObj?.Period1 ?? 0) + (albAreaUpliftBalPaymentObj?.Period2 ?? 0) + (albAreaUpliftBalPaymentObj?.Period3 ?? 0) + (albAreaUpliftBalPaymentObj?.Period4 ?? 0) + (albAreaUpliftBalPaymentObj?.Period5 ?? 0) + (albAreaUpliftBalPaymentObj?.Period6 ?? 0) + (albAreaUpliftBalPaymentObj?.Period7 ?? 0)
                                             + (albAreaUpliftBalPaymentObj?.Period8 ?? 0) + (albAreaUpliftBalPaymentObj?.Period9 ?? 0) + (albAreaUpliftBalPaymentObj?.Period10 ?? 0) + (albAreaUpliftBalPaymentObj?.Period11 ?? 0) + (albAreaUpliftBalPaymentObj?.Period12 ?? 0),
                        TotalEarnedCash = (albSupportPaymentObj?.Period1 ?? 0) + (albSupportPaymentObj?.Period2 ?? 0) + (albSupportPaymentObj?.Period3 ?? 0) + (albSupportPaymentObj?.Period4 ?? 0) + (albSupportPaymentObj?.Period5 ?? 0) + (albSupportPaymentObj?.Period6 ?? 0) + (albSupportPaymentObj?.Period7 ?? 0)
                                          + (albSupportPaymentObj?.Period8 ?? 0) + (albSupportPaymentObj?.Period9 ?? 0) + (albSupportPaymentObj?.Period10 ?? 0) + (albSupportPaymentObj?.Period11 ?? 0) + (albSupportPaymentObj?.Period12 ?? 0)
                                          + (albAreaUpliftOnProgPaymentObj?.Period1 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period2 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period3 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period4 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period5 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period6 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period7 ?? 0)
                                          + (albAreaUpliftOnProgPaymentObj?.Period8 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period9 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period10 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period11 ?? 0) + (albAreaUpliftOnProgPaymentObj?.Period12 ?? 0)
                                          + (albAreaUpliftBalPaymentObj?.Period1 ?? 0) + (albAreaUpliftBalPaymentObj?.Period2 ?? 0) + (albAreaUpliftBalPaymentObj?.Period3 ?? 0) + (albAreaUpliftBalPaymentObj?.Period4 ?? 0) + (albAreaUpliftBalPaymentObj?.Period5 ?? 0) + (albAreaUpliftBalPaymentObj?.Period6 ?? 0) + (albAreaUpliftBalPaymentObj?.Period7 ?? 0)
                                          + (albAreaUpliftBalPaymentObj?.Period8 ?? 0) + (albAreaUpliftBalPaymentObj?.Period9 ?? 0) + (albAreaUpliftBalPaymentObj?.Period10 ?? 0) + (albAreaUpliftBalPaymentObj?.Period11 ?? 0) + (albAreaUpliftBalPaymentObj?.Period12 ?? 0)
                    });
                }
            }

            CheckWarnings(ilrError, larsError, albLearnerError);
            models.Sort(AllbOccupancyModelComparer);
            return(WriteResults(models));
        }
예제 #9
0
        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);
            }
        }
예제 #10
0
        public async Task <List <FundingSummaryModel> > BuildAsync(IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            FundingSummaryModel fundingSummaryModelAlbFunding = new FundingSummaryModel()
            {
                Title = "ILR Advanced Loans Bursary Funding (£)"
            };

            FundingSummaryModel fundingSummaryModelAlbAreaCosts = new FundingSummaryModel()
            {
                Title = "ILR Advanced Loans Bursary Area Costs (£)"
            };

            List <FundingSummaryModel> fundingSummaryModels = new List <FundingSummaryModel>()
            {
                fundingSummaryModelAlbFunding,
                fundingSummaryModelAlbAreaCosts
            };

            Task <IMessage>       ilrFile       = _ilrProviderService.GetIlrFile(reportServiceContext, cancellationToken);
            Task <List <string> > validLearners = _validLearnersService.GetLearnersAsync(reportServiceContext, cancellationToken);
            Task <ALBGlobal>      albData       = _allbProviderService.GetAllbData(reportServiceContext, cancellationToken);

            await Task.WhenAll(ilrFile, validLearners, albData);

            List <string> ilrError        = new List <string>();
            List <string> albLearnerError = new List <string>();

            try
            {
                ILearner[] learners = ilrFile.Result?.Learners?.Where(x => validLearners.Result.Contains(x.LearnRefNumber)).ToArray();

                foreach (ILearner learner in learners ?? Enumerable.Empty <ILearner>())
                {
                    ALBLearner albLearner = albData.Result?.Learners?.SingleOrDefault(x => string.Equals(x.LearnRefNumber, learner.LearnRefNumber, StringComparison.OrdinalIgnoreCase));
                    if (albLearner == null)
                    {
                        albLearnerError.Add(learner.LearnRefNumber);
                        continue;
                    }

                    foreach (ILearningDelivery learningDelivery in learner.LearningDeliveries ?? Enumerable.Empty <ILearningDelivery>())
                    {
                        LearningDelivery albLearningDeliveryAreaCosts = albLearner.LearningDeliveries?.Where(x => x.LearningDeliveryValue.FundLine == "Advanced Learner Loans Bursary").SingleOrDefault(x => x.AimSeqNumber == learningDelivery.AimSeqNumber);

                        if (learningDelivery.LearningDeliveryFAMs != null && learningDelivery.LearningDeliveryFAMs.Any(x =>
                                                                                                                       !(string.Equals(x.LearnDelFAMType, Constants.LearningDeliveryFAMCodeLDM, StringComparison.OrdinalIgnoreCase) && string.Equals(x.LearnDelFAMCode, "359", StringComparison.OrdinalIgnoreCase))))
                        {
                            TotalAlbFunding(albLearningDeliveryAreaCosts?.LearningDeliveryPeriodisedValues, reportServiceContext.ReturnPeriod, AlbSupportPayment, fundingSummaryModelAlbFunding);
                        }

                        TotalAlbAreaCosts(albLearningDeliveryAreaCosts?.LearningDeliveryPeriodisedValues, reportServiceContext.ReturnPeriod, fundingSummaryModelAlbAreaCosts);
                    }
                }

                if (ilrError.Any())
                {
                    _logger.LogWarning($"Failed to get one or more ILR learners while {nameof(AllbBuilder)}.{nameof(BuildAsync)}: {_stringUtilitiesService.JoinWithMaxLength(ilrError)}");
                }

                if (albLearnerError.Any())
                {
                    _logger.LogWarning($"Failed to get one or more ALB learners while {nameof(AllbBuilder)}.{nameof(BuildAsync)}: {_stringUtilitiesService.JoinWithMaxLength(albLearnerError)}");
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("AlbBuilder BuildAsync failed with Exception: ", ex);
            }

            return(fundingSummaryModels);
        }
예제 #11
0
        public async Task GenerateReport(IReportServiceContext reportServiceContext, ZipArchive archive, bool isFis, CancellationToken cancellationToken)
        {
            Task <IMessage> ilrFileTask      = _ilrProviderService.GetIlrFile(reportServiceContext, cancellationToken);
            Task <string>   providerNameTask = _orgProviderService.GetProviderName(reportServiceContext, cancellationToken);
            Task <List <EasSubmissionValues> > easSubmissionValuesAsync = _easProviderService.GetEasSubmissionValuesAsync(reportServiceContext, cancellationToken);
            Task <FM35Global> fm35Task      = _fm35ProviderService.GetFM35Data(reportServiceContext, cancellationToken);
            Task <ALBGlobal>  albGlobalTask = _allbProviderService.GetAllbData(reportServiceContext, cancellationToken);
            var lastSubmittedIlrFileTask    = _ilrProviderService.GetLastSubmittedIlrFile(reportServiceContext, cancellationToken);

            var organisationDataTask  = _orgProviderService.GetVersionAsync(cancellationToken);
            var largeEmployerDataTask = _largeEmployerProviderService.GetVersionAsync(cancellationToken);
            var larsDataTask          = _larsProviderService.GetVersionAsync(cancellationToken);
            var postcodeDataTask      = _postcodeProviderService.GetVersionAsync(cancellationToken);

            await Task.WhenAll(
                easSubmissionValuesAsync,
                fm35Task,
                albGlobalTask,
                providerNameTask,
                ilrFileTask,
                lastSubmittedIlrFileTask,
                organisationDataTask,
                largeEmployerDataTask,
                larsDataTask,
                postcodeDataTask);

            var fundingClaimModel = _adultFundingClaimBuilder.BuildAdultFundingClaimModel(
                _logger,
                reportServiceContext,
                fm35Task.Result,
                easSubmissionValuesAsync.Result,
                albGlobalTask.Result,
                providerNameTask.Result,
                lastSubmittedIlrFileTask.Result,
                _dateTimeProvider,
                _intUtilitiesService,
                ilrFileTask.Result,
                _versionInfo,
                organisationDataTask.Result,
                largeEmployerDataTask.Result,
                postcodeDataTask.Result,
                larsDataTask.Result);

            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("AdultFundingClaimReportTemplate.xlsx"));
            var      manifestResourceStream = assembly.GetManifestResourceStream(resourceName);
            Workbook workbook               = new Workbook(manifestResourceStream);

            PopulateWorkbook(workbook, fundingClaimModel, isFis);
            using (MemoryStream ms = new MemoryStream())
            {
                workbook.Save(ms, SaveFormat.Xlsx);
                await _streamableKeyValuePersistenceService.SaveAsync($"{externalFileName}.xlsx", ms, cancellationToken);
                await WriteZipEntry(archive, $"{fileName}.xlsx", ms, cancellationToken);
            }
        }
예제 #12
0
        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 <SummaryOfFunding1619Model> summaryOfFunding1619Models = new List <SummaryOfFunding1619Model>(validLearnersTask.Result.Count);

            foreach (string validLearnerRefNum in validLearnersTask.Result)
            {
                var learner =
                    ilrFileTask.Result?.Learners?.SingleOrDefault(x => x.LearnRefNumber == validLearnerRefNum);

                var fm25Learner = fm25Task.Result?.Learners?.SingleOrDefault(x => x.LearnRefNumber == validLearnerRefNum);

                if (learner == null || fm25Learner == null)
                {
                    ilrError.Add(validLearnerRefNum);
                    continue;
                }

                summaryOfFunding1619Models.Add(new SummaryOfFunding1619Model
                {
                    FundLine          = fm25Learner.FundLine,
                    LearnRefNumber    = learner.LearnRefNumber,
                    FamilyName        = learner.FamilyName,
                    GivenNames        = learner.GivenNames,
                    DateOfBirth       = learner.DateOfBirthNullable?.ToString("dd/MM/yyyy"),
                    CampId            = learner.CampId,
                    PlanLearnHours    = learner.PlanLearnHoursNullable,
                    PlanEepHours      = learner.PlanEEPHoursNullable,
                    TotalPlannedHours = (learner.PlanLearnHoursNullable ?? 0) + (learner.PlanEEPHoursNullable ?? 0),
                    RateBand          = fm25Learner.RateBand,
                    StartFund         = fm25Learner.StartFund ?? false,
                    OnProgPayment     = fm25Learner.OnProgPayment
                });
            }

            summaryOfFunding1619Models.Sort(SummaryOfFunding1619ModelComparer);

            if (ilrError.Any())
            {
                _logger.LogWarning($"Failed to get one or more ILR learners while generating S{nameof(MathsAndEnglishReport)}: {_stringUtilitiesService.JoinWithMaxLength(ilrError)}");
            }

            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 <SummaryOfFunding1619Mapper, SummaryOfFunding1619Model>(csvWriter, summaryOfFunding1619Models);
                        csvWriter.Flush();
                        textWriter.Flush();
                        return(Encoding.UTF8.GetString(ms.ToArray()));
                    }
                }
            }
        }