private async Task UpdateEnglishFraction(string payeRef,
                                                 GetEnglishFractionUpdateRequiredResponse englishFractionUpdateResponse)
        {
            if (HmrcProcessingEnabled || FractionProcessingOnly)
            {
                _logger.Debug($"Getting update for english fraction for PAYE scheme {payeRef}");
                await _mediator.SendAsync(new UpdateEnglishFractionsCommand
                {
                    EmployerReference             = payeRef,
                    EnglishFractionUpdateResponse = englishFractionUpdateResponse
                });

                _logger.Debug($"Updating english fraction for PAYE scheme {payeRef}");
                await _dasAccountService.UpdatePayeScheme(payeRef);
            }

            if (englishFractionUpdateResponse.UpdateRequired)
            {
                _logger.Debug($"Updating english fraction calculation date to " +
                              $"{englishFractionUpdateResponse.DateCalculated.ToShortDateString()} for PAYE scheme {payeRef}");

                await _mediator.SendAsync(new CreateEnglishFractionCalculationDateCommand
                {
                    DateCalculated = englishFractionUpdateResponse.DateCalculated
                });
            }
        }
        private async Task ProcessScheme(string payeRef, GetEnglishFractionUpdateRequiredResponse englishFractionUpdateResponse, ICollection <EmployerLevyData> employerDataList)
        {
            if (HmrcProcessingEnabled || FractionProcessingOnly)
            {
                await _mediator.SendAsync(new UpdateEnglishFractionsCommand
                {
                    EmployerReference             = payeRef,
                    EnglishFractionUpdateResponse = englishFractionUpdateResponse
                });

                await _dasAccountService.UpdatePayeScheme(payeRef);
            }

            var levyDeclarationQueryResult = HmrcProcessingEnabled || DeclarationProcessingOnly ?
                                             await _mediator.SendAsync(new GetHMRCLevyDeclarationQuery { EmpRef = payeRef }) : null;

            var employerData = new EmployerLevyData();

            if (levyDeclarationQueryResult?.LevyDeclarations?.Declarations != null)
            {
                foreach (var declaration in levyDeclarationQueryResult.LevyDeclarations.Declarations)
                {
                    var dasDeclaration = new DasDeclaration
                    {
                        SubmissionDate           = DateTime.Parse(declaration.SubmissionTime),
                        Id                       = declaration.Id,
                        PayrollMonth             = declaration.PayrollPeriod?.Month,
                        PayrollYear              = declaration.PayrollPeriod?.Year,
                        LevyAllowanceForFullYear = declaration.LevyAllowanceForFullYear,
                        LevyDueYtd               = declaration.LevyDueYearToDate,
                        NoPaymentForPeriod       = declaration.NoPaymentForPeriod,
                        DateCeased               = declaration.DateCeased,
                        InactiveFrom             = declaration.InactiveFrom,
                        InactiveTo               = declaration.InactiveTo,
                        SubmissionId             = declaration.SubmissionId
                    };

                    employerData.EmpRef = payeRef;
                    employerData.Declarations.Declarations.Add(dasDeclaration);
                }

                employerDataList.Add(employerData);
            }
        }
        private async Task <ICollection <EmployerLevyData> > ProcessScheme(string payeRef, GetEnglishFractionUpdateRequiredResponse englishFractionUpdateResponse)
        {
            var payeSchemeDeclarations = new List <EmployerLevyData>();

            await UpdateEnglishFraction(payeRef, englishFractionUpdateResponse);

            _logger.Debug($"Getting levy declarations from HMRC for PAYE scheme {payeRef}");

            var levyDeclarationQueryResult = HmrcProcessingEnabled || DeclarationProcessingOnly ?
                                             await _mediator.SendAsync(new GetHMRCLevyDeclarationQuery { EmpRef = payeRef }) : null;

            _logger.Debug($"Processing levy declarations retrieved from HMRC for PAYE scheme {payeRef}");

            if (levyDeclarationQueryResult?.LevyDeclarations?.Declarations != null)
            {
                var declarations = CreateDasDeclarations(levyDeclarationQueryResult);

                var employerData = new EmployerLevyData
                {
                    EmpRef       = payeRef,
                    Declarations = { Declarations = declarations }
                };

                payeSchemeDeclarations.Add(employerData);
            }

            return(payeSchemeDeclarations);
        }