public async Task <ICollection <DasApprenticeshipInfo> > GetDasApprenticeshipInfoForDataMatchReport(int ukPrn, CancellationToken cancellationToken)
        {
            var dataMatchDasApprenticeshipInfo = new List <DasApprenticeshipInfo>();

            cancellationToken.ThrowIfCancellationRequested();
            using (IDASPaymentsContext dasPaymentsContext = _dasPaymentsContextFactory())
            {
                var dataMatchDasApprenticeshipPrices =
                    await(from a in dasPaymentsContext.Apprenticeships
                          join ape in dasPaymentsContext.ApprenticeshipPriceEpisodes on a.Id equals ape.ApprenticeshipId
                          into appPriceEpisodesJoin
                          from apej in appPriceEpisodesJoin.DefaultIfEmpty()
                          join ap in dasPaymentsContext.ApprenticeshipPauses on a.Id equals ap.ApprenticeshipId
                          into appPriceEpisodePausesJoin
                          from apepj in appPriceEpisodePausesJoin.DefaultIfEmpty()
                          where a.Ukprn == ukPrn
                          select new DasApprenticeshipInfo
                {
                    UkPrn           = ukPrn,
                    LearnerUln      = a.Uln,
                    WithdrawnOnDate = a.StopDate,
                    PausedOnDate    = apepj != null ? apepj.PauseDate : (DateTime?)null,
                    Cost            = apej != null ? apej.Cost : 0,
                    LegalEntityName = a.LegalEntityName,
                    ProgrammeType   = a.ProgrammeType,
                    StandardCode    = a.StandardCode,
                    FrameworkCode   = a.FrameworkCode,
                    PathwayCode     = a.PathwayCode,
                }).Distinct().ToListAsync(cancellationToken);

                dataMatchDasApprenticeshipInfo.AddRange(dataMatchDasApprenticeshipPrices);
            }

            return(dataMatchDasApprenticeshipInfo);
        }
        public async Task <LearnerLevelViewHBCPInfo> GetHBCPInfoAsync(
            int ukPrn,
            CancellationToken cancellationToken)
        {
            LearnerLevelViewHBCPInfo hbcpInfo = null;

            using (IDASPaymentsContext dasPaymentsContext = _dasPaymentsContextFactory())
            {
                hbcpInfo = new LearnerLevelViewHBCPInfo()
                {
                    UkPrn      = ukPrn,
                    HBCPModels = new List <LearnerLevelViewHBCPModel>()
                };

                var hbcpRecords = await dasPaymentsContext.RequiredPaymentEvents
                                  .Where(x => x.Ukprn == ukPrn)
                                  .Select(x => new LearnerLevelViewHBCPModel
                {
                    UkPrn = x.Ukprn,
                    LearnerReferenceNumber = x.LearnerReferenceNumber,
                    LearnerUln             = x.LearnerUln,
                    CollectionPeriod       = x.CollectionPeriod,
                    DeliveryPeriod         = x.DeliveryPeriod,
                    LearningAimReference   = x.LearningAimReference,
                    NonPaymentReason       = x.NonPaymentReason,
                })
                                  .Distinct()
                                  .ToListAsync(cancellationToken);

                hbcpInfo.HBCPModels.AddRange(hbcpRecords);
            }

            return(hbcpInfo);
        }
        public async Task <ICollection <DataLockValidationError> > GetDataLockValidationErrorInfoForUkprnAsync(int collectionPeriod, int ukPrn, string collectionYear, CancellationToken cancellationToken)
        {
            var academicYear = Convert.ToInt32(collectionYear);

            using (IDASPaymentsContext dasPaymentsContext = _dasPaymentsContextFactory())
            {
                return(await dasPaymentsContext.DataMatchReport
                       .Where(x => x.UkPrn == ukPrn &&
                              x.AcademicYear == academicYear &&
                              x.CollectionPeriod == collectionPeriod)
                       .Select(x => new DataLockValidationError
                {
                    UkPrn = x.UkPrn,
                    LearnerReferenceNumber = x.LearnerReferenceNumber,
                    LearnerUln = x.LearnerUln,
                    RuleId = x.DataLockFailureId,
                    AimSeqNumber = x.LearningAimSequenceNumber,
                    Collection = x.DataLockSourceId == Constants.SubmissionInMonth ? Constants.ILR : Constants.PeriodEnd,
                    CollectionPeriod = x.CollectionPeriod,
                    LastSubmission = x.IlrSubmissionDateTime
                })
                       .Distinct()
                       .ToListAsync(cancellationToken));
            }
        }
        public async Task <IDictionary <long, string> > GetLegalEntityNameApprenticeshipIdDictionaryAsync(IEnumerable <long?> apprenticeshipIds, CancellationToken cancellationToken)
        {
            var uniqueApprenticeshipIds = apprenticeshipIds.Where(id => id.HasValue).Distinct().OrderBy(a => a).ToList();

            List <Tuple <long, string> > apprenticeshipIdLegalEntityNameCollection = new List <Tuple <long, string> >();

            var count    = uniqueApprenticeshipIds.Count;
            var pageSize = 1000;

            using (IDASPaymentsContext context = _dasPaymentsContextFactory())
            {
                for (var i = 0; i < count; i += pageSize)
                {
                    var page = await context
                               .Apprenticeships
                               .Where(a => uniqueApprenticeshipIds.Skip(i).Take(pageSize).Contains(a.Id))
                               .Select(a => new Tuple <long, string>(a.Id, a.LegalEntityName))
                               .ToListAsync(cancellationToken);

                    apprenticeshipIdLegalEntityNameCollection.AddRange(page);
                }

                return(apprenticeshipIdLegalEntityNameCollection.ToDictionary(a => a.Item1, a => a.Item2));
            }
        }
 public async Task <List <AppsCoInvestmentRecordKey> > GetUniqueCombinationsOfKeyFromPaymentsAsync(int ukprn, CancellationToken cancellationToken)
 {
     using (IDASPaymentsContext context = _dasPaymentsContextFactory())
     {
         return(await context.Payments
                .Where(p => p.Ukprn == ukprn &&
                       p.AcademicYear <= Generics.AcademicYear)
                .GroupBy(p =>
                         new
         {
             p.LearnerReferenceNumber,
             p.LearningStartDate,
             p.LearningAimProgrammeType,
             p.LearningAimStandardCode,
             p.LearningAimFrameworkCode,
             p.LearningAimPathwayCode,
         })
                .Select(
                    g =>
                    new AppsCoInvestmentRecordKey(
                        g.Key.LearnerReferenceNumber,
                        g.Key.LearningStartDate,
                        g.Key.LearningAimProgrammeType,
                        g.Key.LearningAimStandardCode,
                        g.Key.LearningAimFrameworkCode,
                        g.Key.LearningAimPathwayCode))
                .ToListAsync(cancellationToken));
     }
 }
        public async Task <AppsCoInvestmentPaymentsInfo> GetPaymentsInfoForAppsCoInvestmentReportAsync(int ukPrn, CancellationToken cancellationToken)
        {
            var appsCoInvestmentPaymentsInfo = new AppsCoInvestmentPaymentsInfo
            {
                UkPrn    = ukPrn,
                Payments = new List <PaymentInfo>()
            };

            cancellationToken.ThrowIfCancellationRequested();
            using (IDASPaymentsContext context = _dasPaymentsContextFactory())
            {
                appsCoInvestmentPaymentsInfo.Payments =
                    await context.Payments
                    .Where(p =>
                           p.Ukprn == ukPrn &&
                           p.AcademicYear <= Generics.AcademicYear &&
                           (p.FundingSource == AppsCoInvestmentFundingType ||
                            _appsCoInvestmentTransactionTypes.Contains(p.TransactionType)))
                    .Select(payment =>
                            new PaymentInfo()
                {
                    FundingSource            = payment.FundingSource,
                    TransactionType          = payment.TransactionType,
                    AcademicYear             = payment.AcademicYear,
                    CollectionPeriod         = payment.CollectionPeriod,
                    ContractType             = payment.ContractType,
                    DeliveryPeriod           = payment.DeliveryPeriod,
                    LearnerReferenceNumber   = payment.LearnerReferenceNumber,
                    LearnerUln               = payment.LearnerUln,
                    LearningAimFrameworkCode = payment.LearningAimFrameworkCode,
                    LearningAimPathwayCode   = payment.LearningAimPathwayCode,
                    LearningAimProgrammeType = payment.LearningAimProgrammeType,
                    LearningAimReference     = payment.LearningAimReference,
                    LearningAimStandardCode  = payment.LearningAimStandardCode,
                    LearningStartDate        = payment.LearningStartDate,
                    UkPrn  = payment.Ukprn,
                    Amount = payment.Amount,
                    PriceEpisodeIdentifier    = payment.PriceEpisodeIdentifier,
                    SfaContributionPercentage = payment.SfaContributionPercentage,
                    ApprenticeshipId          = payment.ApprenticeshipId,
                }).ToListAsync(cancellationToken);
            }

            return(appsCoInvestmentPaymentsInfo);
        }
        public async Task <LearnerLevelViewDASDataLockInfo> GetDASDataLockInfoAsync(
            int ukPrn,
            CancellationToken cancellationToken)
        {
            LearnerLevelViewDASDataLockInfo dataLockInfo = null;

            try
            {
                using (IDASPaymentsContext dasPaymentsContext = _dasPaymentsContextFactory())
                {
                    dataLockInfo = new LearnerLevelViewDASDataLockInfo()
                    {
                        UkPrn        = ukPrn,
                        DASDataLocks = new List <LearnerLevelViewDASDataLockModel>()
                    };

                    if (dasPaymentsContext.DataMatchReport.Any(x => x.UkPrn == ukPrn))
                    {
                        var dataLockValidationErrors = await dasPaymentsContext.DataMatchReport
                                                       .Where(x => x.UkPrn == ukPrn)
                                                       .Select(x => new LearnerLevelViewDASDataLockModel
                        {
                            UkPrn = x.UkPrn,
                            LearnerReferenceNumber    = x.LearnerReferenceNumber,
                            LearnerUln                = x.LearnerUln,
                            DataLockFailureId         = x.DataLockFailureId,
                            LearningAimSequenceNumber = x.LearningAimSequenceNumber,
                            CollectionPeriod          = x.CollectionPeriod,
                            DeliveryPeriod            = x.DeliveryPeriod
                        })
                                                       .Distinct()
                                                       .ToListAsync(cancellationToken);

                        dataLockInfo.DASDataLocks.AddRange(dataLockValidationErrors);
                    }
                }
            }
            catch (Exception ex)
            {
                _logger.LogError("Failed to get DASDataLockInfo data", ex);
                throw;
            }

            return(dataLockInfo);
        }
Пример #8
0
        public async Task <AppsCoInvestmentPaymentsInfo> GetPaymentsInfoForAppsCoInvestmentReportAsync(int ukPrn, CancellationToken cancellationToken)
        {
            var appsCoInvestmentPaymentsInfo = new AppsCoInvestmentPaymentsInfo
            {
                UkPrn    = ukPrn,
                Payments = new List <PaymentInfo>()
            };

            cancellationToken.ThrowIfCancellationRequested();
            List <Payment> paymentsList;

            using (IDASPaymentsContext context = _dasPaymentsContextFactory())
            {
                paymentsList = await context.Payments.Where(x => x.Ukprn == ukPrn &&
                                                            x.FundingSource == FundingSource &&
                                                            TransactionTypes.Contains(x.TransactionType)).ToListAsync(cancellationToken);
            }

            foreach (var payment in paymentsList)
            {
                var paymentInfo = new PaymentInfo
                {
                    FundingSource            = payment.FundingSource,
                    TransactionType          = payment.TransactionType,
                    AcademicYear             = payment.AcademicYear,
                    CollectionPeriod         = payment.CollectionPeriod,
                    ContractType             = payment.ContractType,
                    DeliveryPeriod           = payment.DeliveryPeriod,
                    LearnerReferenceNumber   = payment.LearnerReferenceNumber,
                    LearnerUln               = payment.LearnerUln,
                    LearningAimFrameworkCode = payment.LearningAimFrameworkCode,
                    LearningAimPathwayCode   = payment.LearningAimPathwayCode,
                    LearningAimProgrammeType = payment.LearningAimProgrammeType,
                    LearningAimReference     = payment.LearningAimReference,
                    LearningAimStandardCode  = payment.LearningAimStandardCode
                };

                appsCoInvestmentPaymentsInfo.Payments.Add(paymentInfo);
            }

            return(appsCoInvestmentPaymentsInfo);
        }