예제 #1
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);
            }
        }
예제 #2
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);
            }
        }