Пример #1
0
        private async Task <FundingClaim1619FooterModel> GetFooterAsync(Task <IMessage> messageTask, Task <ILRSourceFileInfo> lastSubmittedIlrFileTask, CancellationToken cancellationToken)
        {
            DateTime dateTimeNowUtc = _dateTimeProvider.GetNowUtc();
            DateTime dateTimeNowUk  = _dateTimeProvider.ConvertUtcToUk(dateTimeNowUtc);
            FundingClaim1619FooterModel fundingSummaryFooterModel = new FundingClaim1619FooterModel
            {
                ReportGeneratedAt   = "Report generated at " + dateTimeNowUk.ToString("HH:mm:ss") + " on " + dateTimeNowUk.ToString("dd/MM/yyyy"),
                ApplicationVersion  = _versionInfo.ServiceReleaseVersion,
                ComponentSetVersion = "NA",
                OrganisationData    = await _orgProviderService.GetVersionAsync(cancellationToken),
                LargeEmployerData   = await _largeEmployerProviderService.GetVersionAsync(cancellationToken),
                LarsData            = await _larsProviderService.GetVersionAsync(cancellationToken),
                PostcodeData        = await _postcodeProviderService.GetVersionAsync(cancellationToken),
                CofRemovalData      = string.Empty // todo: populate this
            };

            if (messageTask.Result != null)
            {
                fundingSummaryFooterModel.FilePreparationDate = messageTask.Result.HeaderEntity.SourceEntity.DateTime.ToString("dd/MM/yyyy");
            }
            else
            {
                fundingSummaryFooterModel.FilePreparationDate = lastSubmittedIlrFileTask.Result != null?
                                                                lastSubmittedIlrFileTask.Result.FilePreparationDate.GetValueOrDefault().ToString("dd/MM/yyyy") : string.Empty;
            }

            return(fundingSummaryFooterModel);
        }
Пример #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);
            }
        }