private async Task <IDictionary <string, string> > BuildHeaderData(IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            var organisationName = await _referenceDataService.GetProviderNameAsync(reportServiceContext.Ukprn, cancellationToken) ?? string.Empty;

            var easLastUpdate = await _referenceDataService.GetLastestEasSubmissionDateTimeAsync(reportServiceContext.Ukprn, cancellationToken);

            var fileName = ExtractFileName(await _referenceDataService.GetLatestIlrSubmissionFileNameAsync(reportServiceContext.Ukprn, cancellationToken));

            string easLastUpdateUk = null;

            if (easLastUpdate != null)
            {
                easLastUpdateUk = _dateTimeProvider.ConvertUtcToUk(easLastUpdate.Value).LongDateStringFormat();
            }

            return(new Dictionary <string, string>()
            {
                { SummaryPageConstants.ProviderName, organisationName },
                { SummaryPageConstants.UKPRN, reportServiceContext.Ukprn.ToString() },
                { SummaryPageConstants.ILRFile, fileName },
                { SummaryPageConstants.LastILRFileUpdate, ExtractDisplayDateTimeFromFileName(fileName) },
                { SummaryPageConstants.LastEASUpdate, easLastUpdateUk },
                { SummaryPageConstants.SecurityClassification, SummaryPageConstants.OfficialSensitive }
            });
        }
        private IDictionary <string, string> BuildFooterData(IReportServiceContext reportServiceContext, IMessage message, ReferenceDataRoot referenceDataRoot)
        {
            var filePreparationDate = message?.HeaderEntity?.CollectionDetailsEntity?.FilePreparationDate.ShortDateStringFormat();
            var orgVersion          = referenceDataRoot.MetaDatas.ReferenceDataVersions.OrganisationsVersion.Version;
            var larsVersion         = referenceDataRoot.MetaDatas.ReferenceDataVersions.LarsVersion.Version;
            var employersVersion    = referenceDataRoot.MetaDatas.ReferenceDataVersions.Employers.Version;
            var postcodesVersion    = referenceDataRoot.MetaDatas.ReferenceDataVersions.PostcodesVersion.Version;
            var applicationversion  = reportServiceContext.ServiceReleaseVersion;

            DateTime dateTimeNowUtc = _dateTimeProvider.GetNowUtc();
            DateTime dateTimeNowUk  = _dateTimeProvider.ConvertUtcToUk(dateTimeNowUtc);

            var reportGeneratedAt = dateTimeNowUk.TimeOfDayOnDateStringFormat();

            return(new Dictionary <string, string>()
            {
                { SummaryPageConstants.ApplicationVersion, reportServiceContext.ServiceReleaseVersion },
                { SummaryPageConstants.FilePreparationDate, filePreparationDate },
                { SummaryPageConstants.LARSVersion, larsVersion },
                { SummaryPageConstants.PostcodeVersion, postcodesVersion },
                { SummaryPageConstants.OrganisationVersion, orgVersion },
                { SummaryPageConstants.LargeEmployersVersion, employersVersion },
                { SummaryPageConstants.ReportGeneratedAt, reportGeneratedAt }
            });
        }
Example #3
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 IEnumerable <UYPSummaryViewReport> Map(IReportServiceContext reportServiceContext, IEnumerable <LearnerLevelViewSummaryModel> summaryModels)
 {
     return(summaryModels.Select(m => new UYPSummaryViewReport
     {
         Ukprn = reportServiceContext.Ukprn,
         ReturnPeriod = reportServiceContext.ReturnPeriod,
         CoInvestmentPaymentsToCollectForThisPeriod = m.CoInvestmentPaymentsToCollectForThisPeriod,
         ESFAPlannedPaymentsForThisPeriod = m.ESFAPlannedPaymentsForThisPeriod,
         EarningsReleased = m.EarningsReleased,
         NumberofClawbacks = m.NumberofClawbacks,
         NumberofCoInvestmentsToCollect = m.NumberofCoInvestmentsToCollect,
         NumberofDatalocks = m.NumberofDatalocks,
         NumberofEarningsReleased = m.NumberofEarningsReleased,
         NumberofHBCP = m.NumberofHBCP,
         NumberofLearners = m.NumberofLearners,
         NumberofOthers = m.NumberofOthers,
         TotalCoInvestmentCollectedToDate = m.TotalCoInvestmentCollectedToDate,
         TotalCostOfDataLocksForThisPeriod = m.TotalCostOfDataLocksForThisPeriod,
         TotalCostOfHBCPForThisPeriod = m.TotalCostOfHBCPForThisPeriod,
         TotalCostofClawbackForThisPeriod = m.TotalCostofClawbackForThisPeriod,
         TotalCostofOthersForThisPeriod = m.TotalCostofOthersForThisPeriod,
         TotalEarningsForThisPeriod = m.TotalEarningsForThisPeriod,
         TotalEarningsToDate = m.TotalEarningsToDate,
         TotalPaymentsToDate = m.TotalPaymentsToDate,
         SummaryTotal = m.CoInvestmentPaymentsToCollectForThisPeriod.GetValueOrDefault() + m.ESFAPlannedPaymentsForThisPeriod.GetValueOrDefault()
     }));
 }
        private async Task <IPeriodisedValuesLookup> ProvidePeriodisedValuesAsync(
            IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            var fm35   = _fm35DataProvider.ProvideAsync(reportServiceContext.Ukprn, cancellationToken);
            var fm25   = _fm25DataProvider.ProvideAsync(reportServiceContext.Ukprn, cancellationToken);
            var fm81   = _fm81DataProvider.ProvideAsync(reportServiceContext.Ukprn, cancellationToken);
            var fm99   = _fm99DataProvider.ProvideAsync(reportServiceContext.Ukprn, cancellationToken);
            var eas    = _easDataProvider.ProvideAsync(reportServiceContext.Ukprn, cancellationToken);
            var das    = _dasDataProvider.ProvideAsync(reportServiceContext.CollectionYear, reportServiceContext.Ukprn, cancellationToken);
            var easdas = _dasEasDataProvider.ProvideAsync(reportServiceContext.Ukprn, cancellationToken);

            await Task.WhenAll(fm35, fm25, fm81, fm99, eas, das, easdas);

            var periodisedValuesLookup = new PeriodisedValuesLookup();

            periodisedValuesLookup.Add(FundingDataSource.FM35, fm35.Result);
            periodisedValuesLookup.Add(FundingDataSource.FM25, fm25.Result);
            periodisedValuesLookup.Add(FundingDataSource.FM81, fm81.Result);
            periodisedValuesLookup.Add(FundingDataSource.FM99, fm99.Result);
            periodisedValuesLookup.Add(FundingDataSource.EAS, eas.Result);
            periodisedValuesLookup.Add(FundingDataSource.DAS, das.Result);
            periodisedValuesLookup.Add(FundingDataSource.EASDAS, easdas.Result);

            return(periodisedValuesLookup);
        }
 private void BuildHeader(IReportServiceContext reportServiceContext, HighNeedsStudentSummaryReportModel model, string organisationName)
 {
     model.ProviderName = organisationName;
     model.Ukprn        = reportServiceContext.Ukprn.ToString();
     model.IlrFile      = ExtractFileName(reportServiceContext.IlrReportingFilename);
     model.Year         = ReportingConstants.Year;
 }
        public async Task <decimal?> GetCofRemoval(IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            await _getDataLock.WaitAsync(cancellationToken);

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

                string ukPrnStr = reportServiceContext.Ukprn.ToString();
                long   ukPrn    = Convert.ToInt64(ukPrnStr);
                DbContextOptions <OrganisationsContext> options = new DbContextOptionsBuilder <OrganisationsContext>().UseSqlServer(_orgConfiguration.OrgConnectionString).Options;
                using (OrganisationsContext organisations = new OrganisationsContext(options))
                {
                    _cofRemoval = organisations.ConditionOfFundingRemovals.Where(x => x.Ukprn == ukPrn).OrderByDescending(x => x.EffectiveFrom).Select(x => x.CoFremoval).SingleOrDefault();
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Failed to get org provider name", ex);
            }
            finally
            {
                _getDataLock.Release();
            }

            return(_cofRemoval);
        }
        public async Task <object> ProvideAsync(IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            using (var context = _easContext())
            {
                var easFundingLines = await context.FundingLines?
                                      .Select(f => new EasFundingLine
                {
                    FundLine            = f.Name,
                    EasSubmissionValues = f.PaymentTypes
                                          .Select(p => new EasSubmissionValue
                    {
                        PaymentName        = p.PaymentName,
                        AdjustmentTypeName = p.AdjustmentType.Name,
                    }).ToList()
                }).ToListAsync(cancellationToken);

                var easValuesList = await context.EasSubmissions?
                                    .Where(u => u.Ukprn == reportServiceContext.Ukprn.ToString())
                                    .SelectMany(es => es.EasSubmissionValues
                                                .Select(esv => new EasSubmissionDecodedValue
                {
                    FundingLine     = esv.Payment.FundingLine.Name,
                    AdjustmentName  = esv.Payment.AdjustmentType.Name,
                    PaymentName     = esv.Payment.PaymentName,
                    Period          = esv.CollectionPeriod,
                    PaymentValue    = esv.PaymentValue,
                    DevolvedAreaSof = esv.DevolvedAreaSoF
                }))
                                    .ToListAsync(cancellationToken);

                var easValuesDictionary = BuildEasDictionary(easValuesList);

                return(MapEasValues(easFundingLines, easValuesDictionary));
            }
        }
Example #9
0
        public async Task <IEnumerable <string> > GenerateAsync(
            IReportServiceContext reportServiceContext,
            IReportServiceDependentData reportsDependentData,
            CancellationToken cancellationToken)
        {
            var fundingSummaryReportModel = _devolvedFundingSummaryReportBuilder.Build(reportServiceContext, reportsDependentData);

            var fileName = _fileNameService.GetFilename(reportServiceContext, ReportName, OutputTypes.Excel);

            using (var workbook = _excelService.NewWorkbook())
            {
                workbook.Worksheets.Clear();

                foreach (var reportModel in fundingSummaryReportModel)
                {
                    var worksheet = _excelService.GetWorksheetFromWorkbook(workbook, reportModel.SofLookup.SofCode);

                    _devolvedFundingSummaryReportRenderService.Render(reportModel, worksheet);
                }

                await _excelService.SaveWorkbookAsync(workbook, fileName, reportServiceContext.Container, cancellationToken);
            }

            return(new[] { fileName });
        }
        public async Task <DataQualityProviderModel> ProvideAsync(IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            var ukprns = new List <long>();

            var collectionId = await _jobManagementDataProvider.ProvideCollectionIdAsync($"ILR{reportServiceContext.CollectionYear}");

            var fileDetails = await _jobManagementDataProvider.ProvideFilePeriodInfoForCollectionAsync(collectionId);

            var ruleViolations = await _ilrDataProvider.ProvideTop20RuleViolationsAsync();

            var validationRules = await _ilrRefDataProvider.ProvideAsync(cancellationToken);

            var providersWithoutValidLearners = await _ilrDataProvider.ProvideProvidersWithoutValidLearners(cancellationToken);

            var providersWithMostInvalidLearners = await _ilrDataProvider.ProvideProvidersWithMostInvalidLearners(cancellationToken);

            ukprns.AddRange(providersWithoutValidLearners.Select(x => x.Ukprn));
            ukprns.AddRange(providersWithMostInvalidLearners.Select(x => x.Ukprn));

            var organisations = await _organisationDataProvider.ProvideAsync(ukprns);

            return(new DataQualityProviderModel
            {
                CollectionId = collectionId, FileDetails = fileDetails, RuleViolations = ruleViolations,
                ProvidersWithoutValidLearners = providersWithoutValidLearners,
                ProvidersWithMostInvalidLearners = providersWithMostInvalidLearners,
                Organistions = organisations,
                ValidationRules = validationRules
            });
        }
        public IEnumerable <HighNeedsStudentDetailReportModel> Build(IReportServiceContext reportServiceContext, IReportServiceDependentData reportServiceDependentData)
        {
            var message = reportServiceDependentData.Get <IMessage>();
            var fm25    = reportServiceDependentData.Get <FM25Global>();

            var fm25LearnerDictionary = BuildFm25LearnerDictionary(fm25);

            var models = new List <HighNeedsStudentDetailReportModel>();

            foreach (var learner in message?.Learners ?? Enumerable.Empty <ILearner>())
            {
                var fm25Learner = fm25LearnerDictionary.GetValueOrDefault(learner.LearnRefNumber);

                if (Filter(learner, fm25Learner))
                {
                    var ehc = FamCodeForType(learner.LearnerFAMs, LearnerFAMTypeConstants.EHC);
                    var hns = FamCodeForType(learner.LearnerFAMs, LearnerFAMTypeConstants.HNS);

                    models.Add(new HighNeedsStudentDetailReportModel()
                    {
                        Learner                        = learner,
                        FM25Learner                    = fm25Learner,
                        DerivedFundline                = _derivedFundLineDictionary.GetValueOrDefault(fm25Learner.FundLine),
                        StudentsWithAnEhcp             = StudentWithAnEhcp(ehc),
                        StudentsWithoutAnEhcp          = StudentWithoutAnEhcp(ehc),
                        HighNeedsStudentsWithoutAnEhcp = HighNeedsStudentWithoutAnEhcp(hns, ehc),
                        StudentsWithAnEhcpAndHns       = StudentWithAnEhcpAndHns(hns, ehc),
                        StudentWithAnEhcpAndNotHns     = StudentWithAnEhcpAndNotHns(hns, ehc),
                    });
                }
            }

            return(Order(models));
        }
        public async Task <IPeriodisedValuesLookup> ProvideAsync(IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            var ukprn = reportServiceContext.Ukprn;

            var fm35   = BuildFm35DictionaryAsync(ukprn, cancellationToken);
            var fm25   = BuildFm25DictionaryAsync(ukprn, cancellationToken);
            var fm81   = BuildFm81DictionaryAsync(ukprn, cancellationToken);
            var fm99   = BuildFm99DictionaryAsync(ukprn, cancellationToken);
            var eas    = BuildEasDictionaryAsync(ukprn, cancellationToken);
            var das    = BuildDasDictionaryAsync(ukprn, cancellationToken);
            var easdas = BuildEasDasDictionaryAsync(ukprn, cancellationToken);

            await Task.WhenAll(fm35, fm25, fm81, fm99, eas, das, easdas);

            var periodisedValuesLookup = new PeriodisedValuesLookup();

            periodisedValuesLookup.Add(FundingDataSource.FM35, fm35.Result);
            periodisedValuesLookup.Add(FundingDataSource.FM25, fm25.Result);
            periodisedValuesLookup.Add(FundingDataSource.FM81, fm81.Result);
            periodisedValuesLookup.Add(FundingDataSource.FM99, fm99.Result);
            periodisedValuesLookup.Add(FundingDataSource.EAS, eas.Result);
            periodisedValuesLookup.Add(FundingDataSource.DAS, das.Result);
            periodisedValuesLookup.Add(FundingDataSource.EASDAS, easdas.Result);

            return(periodisedValuesLookup);
        }
Example #13
0
        public FundingClaimReportModel Build(IReportServiceContext reportServiceContext, IReportServiceDependentData reportServiceDependentData)
        {
            var message           = reportServiceDependentData.Get <IMessage>();
            var fm25Data          = reportServiceDependentData.Get <FM25Global>();
            var referenceDataRoot = reportServiceDependentData.Get <ReferenceDataRoot>();

            var referenceDateFilter = RetrieveReportFilterValueFromContext <DateTime?>(reportServiceContext, ReportNameConstants.SixteenNineteenFundingClaim, ReportingConstants.ReferenceDateFilterPropertyName);

            var organisation = referenceDataRoot.Organisations.FirstOrDefault(o => o.UKPRN == reportServiceContext.Ukprn);
            var learners     = message?.Learners ?? Enumerable.Empty <ILearner>();

            var model = new FundingClaimReportModel();

            var applicableLearners = FilterLearners(learners);

            // Header
            var referenceDate = referenceDateFilter.HasValue ? referenceDateFilter.Value.ShortDateStringFormat() : "(ALL)";

            BuildHeader(reportServiceContext, model, organisation, referenceDate);

            // Body
            BuildBody(model, fm25Data.Learners, applicableLearners, referenceDateFilter);

            // Footer
            BuildFooter(model, referenceDataRoot.MetaDatas.ReferenceDataVersions, reportServiceContext.ServiceReleaseVersion, message?.HeaderEntity.CollectionDetailsEntity.FilePreparationDate);

            return(model);
        }
Example #14
0
        private async Task <bool> GenerateReportAsync(string task, IReportServiceContext reportServiceContext, ZipArchive archive, CancellationToken cancellationToken)
        {
            bool needZip     = false;
            bool foundReport = false;

            foreach (var report in _reports)
            {
                if (!report.IsMatch(task))
                {
                    continue;
                }

                Stopwatch stopWatch = new Stopwatch();
                stopWatch.Start();
                _logger.LogDebug($"Attempting to generate {report.GetType().Name}", jobIdOverride: reportServiceContext.JobId);
                needZip = await report.GenerateReport(reportServiceContext, archive, cancellationToken);

                stopWatch.Stop();
                _logger.LogDebug($"Persisted {report.GetType().Name} to csv/json in: {stopWatch.ElapsedMilliseconds}", jobIdOverride: reportServiceContext.JobId);

                foundReport = true;
                break;
            }

            if (!foundReport)
            {
                _logger.LogDebug($"Unable to find Data Match report '{task}'", jobIdOverride: reportServiceContext.JobId);
            }

            return(needZip);
        }
Example #15
0
        public AEBSTFFundingSummaryReportModel Build(IReportServiceContext reportServiceContext, IReportServiceDependentData reportServiceDependentData)
        {
            var message           = reportServiceDependentData.Get <IMessage>();
            var referenceDataRoot = reportServiceDependentData.Get <ReferenceDataRoot>();

            var periodisedValues = _periodisedValuesLookupProvider.Provide(FundingDataSources, reportServiceDependentData);

            var reportCurrentPeriod = reportServiceContext.ReturnPeriod > 12 ? 12 : reportServiceContext.ReturnPeriod;

            var description = "ESFA AEB - Short Term Funding Initiative";

            return(new AEBSTFFundingSummaryReportModel(
                       BuildHeaderData(reportServiceContext, referenceDataRoot),
                       new List <IFundingCategory>()
            {
                new FundingCategory(
                    @"ESFA Adult Education Budget - Short Term Funding Initiatives", reportCurrentPeriod,
                    new List <IFundingSubCategory>()
                {
                    new FundingSubCategory($@"{description} 1", reportCurrentPeriod)
                    .WithFundLineGroup(BuildIlrStfiFundLineGroup($@"{description} 1", reportCurrentPeriod, new [] { FundLineConstants.STFI1 }, periodisedValues))
                    .WithFundLineGroup(BuildEasStfiFundLineGroup($@"{description} 1", reportCurrentPeriod, new [] { FundLineConstants.STFI1 }, periodisedValues)),
                    new FundingSubCategory($@"{description} 2", reportCurrentPeriod)
                    .WithFundLineGroup(BuildIlrStfiFundLineGroup($@"{description} 2", reportCurrentPeriod, new [] { FundLineConstants.STFI2 }, periodisedValues))
                    .WithFundLineGroup(BuildEasStfiFundLineGroup($@"{description} 2", reportCurrentPeriod, new [] { FundLineConstants.STFI2 }, periodisedValues)),
                    new FundingSubCategory($@"{description} 3", reportCurrentPeriod)
                    .WithFundLineGroup(BuildIlrStfiFundLineGroup($@"{description} 3", reportCurrentPeriod, new [] { FundLineConstants.STFI3 }, periodisedValues))
                    .WithFundLineGroup(BuildEasStfiFundLineGroup($@"{description} 3", reportCurrentPeriod, new [] { FundLineConstants.STFI3 }, periodisedValues)),
                    new FundingSubCategory($@"{description} 4", reportCurrentPeriod)
                    .WithFundLineGroup(BuildIlrStfiFundLineGroup($@"{description} 4", reportCurrentPeriod, new [] { FundLineConstants.STFI4 }, periodisedValues))
                    .WithFundLineGroup(BuildEasStfiFundLineGroup($@"{description} 4", reportCurrentPeriod, new [] { FundLineConstants.STFI4 }, periodisedValues))
                })
            },
                       BuildFooterData(reportServiceContext, message, referenceDataRoot)));
        }
        public async Task <IReadOnlyCollection <IPreviousYearLearner> > ProvideAsync(IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            using (var connection = _sqlConnectionFunc())
            {
                using (var results = await connection.QueryMultipleAsync(_sql, new { ukprn = reportServiceContext.Ukprn, currentYearStart = _currentYearStart }))
                {
                    var learners         = (await results.ReadAsync <PreviousYearLearner>()).ToList();
                    var learnDelFAMS     = (await results.ReadAsync <LearningDeliveryFAM>()).GroupBy(x => x.LearnRefNumber, StringComparer.OrdinalIgnoreCase).ToDictionary(x => x.Key, x => x.GroupBy(y => y.AimSeqNumber).ToDictionary(d => d.Key, d => d));
                    var provSpecLearnMon = (await results.ReadAsync <ProviderSpecLearnerMonitoring>()).GroupBy(x => x.LearnRefNumber, StringComparer.OrdinalIgnoreCase).ToDictionary(x => x.Key, x => x, StringComparer.OrdinalIgnoreCase);
                    var provSpecDelMon   = (await results.ReadAsync <ProviderSpecDeliveryMonitoring>()).GroupBy(x => x.LearnRefNumber, StringComparer.OrdinalIgnoreCase).ToDictionary(x => x.Key, x => x.GroupBy(y => y.AimSeqNumber).ToDictionary(d => d.Key, d => d));

                    foreach (var learner in learners)
                    {
                        learner.LearningDeliveryFAMs = learnDelFAMS.GetValueOrDefault(learner.LearnRefNumber)
                                                       .GetValueOrDefault(learner.AimSeqNumber).ToList();

                        learner.ProviderSpecLearnerMonitorings = provSpecLearnMon.GetValueOrDefault(learner.LearnRefNumber).ToList();

                        learner.ProvSpecDeliveryMonitorings = provSpecDelMon.GetValueOrDefault(learner.LearnRefNumber)
                                                              .GetValueOrDefault(learner.AimSeqNumber).ToList();
                    }

                    return(learners.ToList());
                }
            }
        }
        public async Task <IReportServiceContext> MutateAsync(IReportServiceContext reportServiceContext, IReportServiceDependentData reportServiceDependentData, CancellationToken cancellationToken)
        {
            await AddIlrReportingFilename(reportServiceContext, cancellationToken);
            await AddEasReportingFilename(reportServiceContext, reportServiceDependentData, cancellationToken);

            return(reportServiceContext);
        }
        public async Task <string> GenerateReport(IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            if (!_reportGenerationPeriods.Contains(reportServiceContext.ReturnPeriod))
            {
                return(string.Empty);
            }

            IncludeInZip = reportServiceContext.PublishReportToZip;

            var fileName = _fileNameService.GetFilename(reportServiceContext, ReportName, OutputTypes.Excel);

            var data = await _crossYearDataProvider.ProvideAsync(reportServiceContext, cancellationToken);

            var model = _crossYearModelBuilder.Build(data, reportServiceContext);

            var    assembly     = Assembly.GetExecutingAssembly();
            string resourceName = assembly.GetManifestResourceNames().Single(str => str.EndsWith(TemplateName));

            using (Stream manifestResourceStream = assembly.GetManifestResourceStream(resourceName))
                using (var workbook = _excelFileService.GetWorkbookFromTemplate(manifestResourceStream))
                {
                    var worksheet = _excelFileService.GetWorksheetFromWorkbook(workbook, WorksheetName);

                    _crossYearRenderService.Render(reportServiceContext, model, worksheet, workbook);

                    await _excelFileService.SaveWorkbookAsync(workbook, fileName, reportServiceContext.Container, cancellationToken);
                }

            return(fileName);
        }
        private async Task AddEasReportingFilename(IReportServiceContext reportServiceContext, IReportServiceDependentData reportServiceDependentData, CancellationToken cancellationToken)
        {
            var referenceDataEASFile = new EasFileDetails();

            if (reportServiceDependentData.Contains <ReferenceDataRoot>())
            {
                referenceDataEASFile = reportServiceDependentData.Get <ReferenceDataRoot>()?.MetaDatas.ReferenceDataVersions.EasFileDetails;
            }

            var easFileName = !string.IsNullOrWhiteSpace(referenceDataEASFile?.FileName) && referenceDataEASFile.FileName != _defaultEASValue?Path.GetFileName(referenceDataEASFile?.FileName) : _defaultEASValue;

            reportServiceContext.EasReportingFilename = easFileName;

            if (referenceDataEASFile?.UploadDateTime != null)
            {
                var easLastUpdated = (DateTime)referenceDataEASFile?.UploadDateTime.Value;

                reportServiceContext.LastEasFileUpdate = _dateTimeProvider.ConvertUtcToUk(easLastUpdated).ToString(ReportServiceConstants.LastFileUpdateDateTimeFormat);
            }

            if (referenceDataEASFile?.UploadDateTime == null)
            {
                reportServiceContext.LastEasFileUpdate = _defaultEASValue;
            }
        }
        public HighNeedsStudentSummaryReportModel Build(IReportServiceContext reportServiceContext, IReportServiceDependentData reportServiceDependentData)
        {
            var message           = reportServiceDependentData.Get <IMessage>();
            var fm25Data          = reportServiceDependentData.Get <FM25Global>();
            var referenceDataRoot = reportServiceDependentData.Get <ReferenceDataRoot>();

            var organisationName = referenceDataRoot.Organisations.FirstOrDefault(o => o.UKPRN == reportServiceContext.Ukprn)?.Name ?? string.Empty;
            var learners         = message?.Learners ?? Enumerable.Empty <ILearner>();
            var model            = new HighNeedsStudentSummaryReportModel();

            var applicableLearners = learners.Where(LearnerFilter).ToList();
            var applicableStudyProgrammeLearners = fm25Data.Learners?.Where(x => x.StartFund == true && StudyProgrammePredicate(x)).ToList();
            var applicableTLevelLearners         = fm25Data.Learners?.Where(x => x.StartFund == true && TLevelPredicate(x)).ToList();

            // Header
            BuildHeader(reportServiceContext, model, organisationName);

            // Body
            model.StudyProgramme = BuildBody(applicableStudyProgrammeLearners, applicableLearners);
            model.TLevel         = BuildBody(applicableTLevelLearners, applicableLearners);

            // Footer
            BuildFooter(model, referenceDataRoot.MetaDatas.ReferenceDataVersions, reportServiceContext.ServiceReleaseVersion, message?.HeaderEntity.CollectionDetailsEntity.FilePreparationDate);

            return(model);
        }
Example #21
0
        public async Task CreateOrUpdateZipWithReportAsync(string reportFileNameKey, IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            if (string.IsNullOrEmpty(reportFileNameKey))
            {
                return;
            }

            var reportZipFileKey = _fileNameService.GetFilename(reportServiceContext, ReportsZipName, OutputTypes.Zip, false);

            using (var memoryStream = new MemoryStream())
                using (var zipSteam = await GetStreamAsync(reportZipFileKey, reportServiceContext, cancellationToken))
                {
                    await zipSteam.CopyToAsync(memoryStream, BufferSize, cancellationToken);

                    using (var zipArchive = new ZipArchive(memoryStream, ZipArchiveMode.Update, true))
                    {
                        using (var readStream = await _fileService.OpenReadStreamAsync(reportFileNameKey, reportServiceContext.Container, cancellationToken))
                        {
                            await _zipArchiveService.AddEntryToZip(zipArchive, readStream, PrepareFileName(reportFileNameKey), cancellationToken);
                        }
                    }

                    using (var writeStream = await _fileService.OpenWriteStreamAsync(reportZipFileKey, reportServiceContext.Container, cancellationToken))
                    {
                        memoryStream.Position = 0;
                        await memoryStream.CopyToAsync(writeStream, BufferSize, cancellationToken);
                    }
                }
        }
        private async Task GenerateReportAsync(string task, IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            var foundReport = false;

            foreach (var report in _internalReports)
            {
                if (!report.IsMatch(task))
                {
                    continue;
                }

                var stopWatch = new Stopwatch();
                stopWatch.Start();
                _logger.LogDebug($"Attempting to generate internal report {report.GetType().Name}");
                await report.GenerateReport(reportServiceContext, cancellationToken);

                stopWatch.Stop();
                _logger.LogDebug($"Persisted {report.GetType().Name} to csv/json/xlsx in: {stopWatch.ElapsedMilliseconds}");

                foundReport = true;
                break;
            }

            if (!foundReport)
            {
                _logger.LogDebug($"Unable to find report '{task}'");
            }
        }
Example #23
0
        public async Task <bool> Callback(IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            _logger.LogInfo("Reporting callback invoked");

            var reportZipFileKey = $"{reportServiceContext.Ukprn}_{reportServiceContext.JobId}_Reports.zip";

            cancellationToken.ThrowIfCancellationRequested();

            MemoryStream memoryStream  = new MemoryStream();
            var          zipFileExists = await _streamableKeyValuePersistenceService.ContainsAsync(reportZipFileKey, cancellationToken);

            if (zipFileExists)
            {
                await _streamableKeyValuePersistenceService.GetAsync(reportZipFileKey, memoryStream, cancellationToken);
            }

            using (memoryStream)
            {
                using (var archive = new ZipArchive(memoryStream, ZipArchiveMode.Update, true))
                {
                    await ExecuteTasks(reportServiceContext, archive, cancellationToken);
                }

                await _streamableKeyValuePersistenceService.SaveAsync(reportZipFileKey, memoryStream, cancellationToken);
            }

            return(true);
        }
 public IEnumerable <LearnerLevelViewReport> Map(IReportServiceContext reportServiceContext, IEnumerable <LearnerLevelViewModel> learnerLevelViewRecords, CancellationToken cancellationToken)
 {
     return(learnerLevelViewRecords.Select(m => new LearnerLevelViewReport
     {
         Ukprn = reportServiceContext.Ukprn,
         PaymentLearnerReferenceNumber = m.PaymentLearnerReferenceNumber,
         PaymentUniqueLearnerNumber = long.Parse(m.PaymentUniqueLearnerNumbers.Split(';')[0]),
         FamilyName = m.FamilyName,
         GivenNames = m.GivenNames,
         LearnerEmploymentStatusEmployerId = m.LearnerEmploymentStatusEmployerId,
         EmployerName = m.EmployerName,
         TotalEarningsToDate = m.TotalEarningsToDate,
         PlannedPaymentsToYouToDate = m.PlannedPaymentsToYouToDate,
         TotalCoInvestmentCollectedToDate = m.TotalCoInvestmentCollectedToDate,
         CoInvestmentOutstandingFromEmplToDate = m.CoInvestmentOutstandingFromEmplToDate,
         TotalEarningsForPeriod = m.TotalEarningsForPeriod,
         ESFAPlannedPaymentsThisPeriod = m.ESFAPlannedPaymentsThisPeriod,
         CoInvestmentPaymentsToCollectThisPeriod = m.CoInvestmentPaymentsToCollectThisPeriod,
         IssuesAmount = m.IssuesAmount,
         ReasonForIssues = m.ReasonForIssues,
         PaymentFundingLineType = m.PaymentFundingLineType,
         RuleDescription = m.RuleDescription,
         ReturnPeriod = reportServiceContext.ReturnPeriod
     }));
 }
Example #25
0
 public async Task <IReadOnlyCollection <IMcaGlaSofLookup> > ProvideAsync(IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
 {
     using (var connection = _sqlConnectionFunc())
     {
         return((await connection.QueryAsync <McaGlaSofLookup>(_sql, cancellationToken)).ToList());
     }
 }
        public IEnumerable <FundingSummaryReport> Map(IReportServiceContext reportServiceContext, FundingSummaryReportModel fundingSummaryReportModel, CancellationToken cancellationToken)
        {
            var persistModels = fundingSummaryReportModel.FundingCategories.SelectMany(fc => fc.FundingSubCategories.SelectMany(fsc =>
                                                                                                                                fsc.FundLineGroups.SelectMany(flg => flg.FundLines.Select(fl => new FundingSummaryReport
            {
                Ukprn              = reportServiceContext.Ukprn,
                ReturnPeriod       = reportServiceContext.ReturnPeriod,
                ContractNo         = fc.ContractAllocationNumber,
                FundingCategory    = fc.FundingCategoryTitle,
                FundingSubCategory = fsc.FundingSubCategoryTitle,
                FundLine           = fl.Title,
                Aug20              = fl.Period1,
                Sep20              = fl.Period2,
                Oct20              = fl.Period3,
                Nov20              = fl.Period4,
                Dec20              = fl.Period5,
                Jan21              = fl.Period6,
                Feb21              = fl.Period7,
                Mar21              = fl.Period8,
                Apr21              = fl.Period9,
                May21              = fl.Period10,
                Jun21              = fl.Period11,
                Jul21              = fl.Period12,
                AugMar             = fl.Period1To8,
                AprJul             = fl.Period9To12,
                YearToDate         = fl.YearToDate,
                Total              = fl.Total
            })))).ToList();

            return(persistModels);
        }
        public async Task <string> GenerateAsync(IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            var fileName = _fileNameService.GetFilename(reportServiceContext, FileName, OutputTypes.Excel);

            var reportData = await _reportDataProvider.ProvideAsync(reportServiceContext, cancellationToken);

            using (var workbook = _excelFileService.NewWorkbook())
            {
                workbook.Worksheets.Clear();
                var summaries        = new List <ISummaryRow>();
                var summaryWorksheet = _excelFileService.GetWorksheetFromWorkbook(workbook, SummaryName);

                foreach (var worksheetTask in reportServiceContext.Tasks)
                {
                    var worksheet = _worksheets.GetValueOrDefault(worksheetTask);

                    summaries.Add(worksheet.Generate(workbook, reportServiceContext, reportData, cancellationToken));
                }

                var summaryModel = _summaryPageModelBuilder.Build(reportServiceContext, reportData);
                summaryModel.SummaryRows = summaries;

                _summarPageRenderService.Render(summaryModel, summaryWorksheet);

                await _excelFileService.SaveWorkbookAsync(workbook, fileName, reportServiceContext.Container, cancellationToken);
            }

            return(fileName);
        }
Example #28
0
 public EntryPoint(IImmutableDictionary <string, IReport> reports, IReportServiceContext reportServiceContext, IReportZipService reportZipService, ILogger logger)
 {
     _reports = reports;
     _reportServiceContext = reportServiceContext;
     _reportZipService     = reportZipService;
     _logger = logger;
 }
Example #29
0
        public IEnumerable <MathsAndEnglishReportModel> Build(IReportServiceContext reportServiceContext, IReportServiceDependentData reportServiceDependentData)
        {
            var message = reportServiceDependentData.Get <IMessage>();
            var fm25    = reportServiceDependentData.Get <FM25Global>();

            var fm25LearnerDictionary = BuildFm25LearnerDictionary(fm25);

            var models = new List <MathsAndEnglishReportModel>();

            foreach (var learner in message?.Learners ?? Enumerable.Empty <ILearner>())
            {
                var fm25Learner = fm25LearnerDictionary.GetValueOrDefault(learner.LearnRefNumber);

                if (Filter(learner, fm25Learner))
                {
                    models.Add(new MathsAndEnglishReportModel()
                    {
                        Learner     = learner,
                        FM25Learner = fm25Learner,
                    });
                }
            }

            return(Order(models));
        }
Example #30
0
        public async Task <IMessage> GetIlrFile(IReportServiceContext reportServiceContext, CancellationToken cancellationToken)
        {
            await _getIlrLock.WaitAsync(cancellationToken);

            try
            {
                if (_message != null)
                {
                    return(_message);
                }

                cancellationToken.ThrowIfCancellationRequested();

                string filename = reportServiceContext.Filename;
                int    ukPrn    = reportServiceContext.Ukprn;
                if (string.Equals(reportServiceContext.CollectionName, "ILR1819", StringComparison.OrdinalIgnoreCase))
                {
                    using (MemoryStream ms = new MemoryStream())
                    {
                        await _storage.GetAsync(filename, ms, cancellationToken);

                        ms.Seek(0, SeekOrigin.Begin);
                        _message = _xmlSerializationService.Deserialize <Message>(ms);
                    }
                }
                else
                {
                    DateTime submittedDate;
                    DateTime filePreparationDate;

                    using (var ilrContext = _ilrValidContextFactory())
                    {
                        submittedDate       = ilrContext.Sources.SingleOrDefault(x => x.UKPRN == ukPrn)?.DateTime ?? _dateTimeProvider.ConvertUtcToUk(_dateTimeProvider.GetNowUtc());
                        filePreparationDate = ilrContext.CollectionDetails.SingleOrDefault(x => x.UKPRN == ukPrn)?.FilePreparationDate ?? _dateTimeProvider.ConvertUtcToUk(_dateTimeProvider.GetNowUtc());
                    }

                    _message = new Message
                    {
                        Header = new MessageHeader
                        {
                            Source = new MessageHeaderSource
                            {
                                UKPRN    = ukPrn,
                                DateTime = submittedDate
                            },
                            CollectionDetails = new MessageHeaderCollectionDetails
                            {
                                FilePreparationDate = filePreparationDate
                            }
                        }
                    };
                }
            }
            finally
            {
                _getIlrLock.Release();
            }

            return(_message);
        }
 public OrdersRepository(IUnitOfWork uow)
 {
     _context = uow.Context as IReportServiceContext;
 }