Example #1
0
        public void GivenTheFollowingPaymentsHaveBeenMadeToTheProviderAForLearnerA(string providerName, string learnerRefererenceNumber, Table table)
        {
            var context = new EarningsAndPaymentsContext();

            TransactionTypeTableParser.ParseTransactionTypeTableIntoContext(context, providerName, table);


            var learningDetails = SubmissionContext.HistoricalLearningDetails.Where(x => x.LearnerReference.Equals(learnerRefererenceNumber, StringComparison.InvariantCultureIgnoreCase)).Single();

            long learnerUln;

            if (!string.IsNullOrEmpty(learningDetails.Uln))
            {
                learnerUln = long.Parse(learningDetails.Uln);
                LookupContext.AddUln(learnerRefererenceNumber, learnerUln);
            }
            else
            {
                learnerUln = LookupContext.AddOrGetUln(learnerRefererenceNumber);
            }


            var provider = LookupContext.AddOrGetUkprn(providerName);

            var commitment = CommitmentsContext.Commitments.FirstOrDefault(x => x.ProviderId == providerName && x.LearnerId == learnerRefererenceNumber);

            CreatePayment(context.ProviderEarnedForOnProgramme, provider, learnerUln, learnerRefererenceNumber, commitment, learningDetails, TransactionType.OnProgram, commitment == null ? FundingSource.CoInvestedSfa : FundingSource.Levy);
            CreatePayment(context.ProviderEarnedForLearningSupport, provider, learnerUln, learnerRefererenceNumber, commitment, learningDetails, TransactionType.LearningSupport, FundingSource.FullyFundedSfa);
            CreatePayment(context.ProviderEarnedForFrameworkUpliftOnProgramme, provider, learnerUln, learnerRefererenceNumber, commitment, learningDetails, TransactionType.OnProgramme16To18FrameworkUplift, FundingSource.FullyFundedSfa);
        }
Example #2
0
 private static ProviderSubmissionDetails[] GroupLearnersByProvider(List <IlrLearnerReferenceData> ilrLearnerDetails, LookupContext lookupContext)
 {
     return((from x in ilrLearnerDetails
             group x by x.Provider into g
             select new ProviderSubmissionDetails
     {
         ProviderId = g.Key,
         Ukprn = lookupContext.AddOrGetUkprn(g.Key),
         LearnerDetails = g.ToArray()
     }).ToArray());
 }
        private static CommitmentReferenceData ParseCommitmentsTableRow(TableRow row, CommitmentsTableColumnStructure structure, int rowIndex, LookupContext lookupContext)
        {
            var learnerId  = row[structure.UlnIndex];
            var uln        = lookupContext.AddOrGetUln(learnerId);
            var providerId = structure.ProviderIndex > -1 ? row[structure.ProviderIndex] : Defaults.ProviderId;
            var ukprn      = lookupContext.AddOrGetUkprn(providerId);
            var status     = (CommitmentPaymentStatus)row.ReadRowColumnValue <string>(structure.StatusIndex, "status", Defaults.CommitmentStatus).ToEnumByDescription(typeof(CommitmentPaymentStatus));

            int priority = Defaults.CommitmentPriority;

            if (structure.PriorityIndex > -1 && !int.TryParse(row[structure.PriorityIndex], out priority))
            {
                throw new ArgumentException($"'{row[structure.PriorityIndex]}' is not a valid priority");
            }

            var employerAccountId = Defaults.EmployerAccountId;

            if (structure.EmployerIndex > -1 && (row[structure.EmployerIndex].Length < 10 || !int.TryParse(row[structure.EmployerIndex].Substring(9), out employerAccountId)))
            {
                throw new ArgumentException($"'{row[structure.EmployerIndex]}' is not a valid employer reference");
            }

            var price = Defaults.AgreePrice;

            if (structure.PriceIndex > -1 && !int.TryParse(row[structure.PriceIndex], out price))
            {
                throw new ArgumentException($"'{row[structure.PriceIndex]}' is not a valid agreed price");
            }

            var commitmentId = rowIndex + 1;

            if (structure.CommitmentIdIndex > -1 && !int.TryParse(row[structure.CommitmentIdIndex], out commitmentId))
            {
                throw new ArgumentException($"'{row[structure.CommitmentIdIndex]}' is not a valid commitment id");
            }

            var versionId = Defaults.CommitmentVersionId;

            if (structure.VersionIdIndex > -1)
            {
                if (string.IsNullOrEmpty(row[structure.VersionIdIndex]))
                {
                    throw new ArgumentException($"'{row[structure.VersionIdIndex]}' is not a valid version id");
                }
                else
                {
                    versionId = row[structure.VersionIdIndex];
                }
                if (!versionId.Contains('-'))
                {
                    versionId = int.Parse(versionId).ToString("000");
                    versionId = $"{commitmentId}-{versionId}";
                }
            }

            DateTime startDate;

            if (!DateTime.TryParse(row[structure.StartDateIndex], out startDate))
            {
                throw new ArgumentException($"'{row[structure.StartDateIndex]}' is not a valid start date");
            }

            DateTime endDate;

            if (!DateTime.TryParse(row[structure.EndDateIndex], out endDate))
            {
                throw new ArgumentException($"'{row[structure.EndDateIndex]}' is not a valid end date");
            }

            DateTime?effectiveFrom = null;

            if (structure.EffectiveFromIndex > -1 && !TryParseNullableDateTime(row[structure.EffectiveFromIndex], out effectiveFrom))
            {
                throw new ArgumentException($"'{row[structure.EffectiveFromIndex]}' is not a valid effective from");
            }

            DateTime?effectiveTo = null;

            if (structure.EffectiveToIndex > -1 && string.IsNullOrEmpty(row[structure.EffectiveToIndex]))
            {
                effectiveTo = null;
            }
            else if (structure.EffectiveToIndex > -1 && !TryParseNullableDateTime(row[structure.EffectiveToIndex], out effectiveTo))
            {
                throw new ArgumentException($"'{row[structure.EffectiveToIndex]}' is not a valid effective to");
            }

            var standardCode  = row.ReadRowColumnValue <long>(structure.StandardCodeIndex, "standard code", Defaults.StandardCode);
            var frameworkCode = row.ReadRowColumnValue <int>(structure.FrameworkCodeIndex, "framework code");
            var programmeType = row.ReadRowColumnValue <int>(structure.ProgrammeTypeIndex, "programme type");
            var pathwayCode   = row.ReadRowColumnValue <int>(structure.PathwayCodeIndex, "pathway code");

            if (effectiveFrom == null)
            {
                effectiveFrom = startDate;
            }

            return(new CommitmentReferenceData
            {
                EmployerAccountId = employerAccountId,
                LearnerId = learnerId,
                Uln = uln,
                Priority = priority,
                ProviderId = providerId,
                Ukprn = ukprn,
                AgreedPrice = price,
                CommitmentId = commitmentId,
                VersionId = versionId,
                StartDate = startDate,
                EndDate = endDate,
                EffectiveFrom = effectiveFrom.Value,
                EffectiveTo = effectiveTo,
                Status = status,
                StandardCode = standardCode,
                FrameworkCode = frameworkCode == 0 ? 0 : frameworkCode,
                ProgrammeType = programmeType == 0 ? 0 : programmeType,
                PathwayCode = pathwayCode == 0 ? 0 : pathwayCode,
            });
        }
Example #4
0
        private void CreatePreviousEarningsAndPayments(string providerName, string learnerRefererenceNumber, Table table, AimType paymentsAimType)
        {
            var learnerBreakdown = new EarningsAndPaymentsBreakdown {
                ProviderId = providerName
            };

            EarningAndPaymentTableParser.ParseEarningsAndPaymentsTableIntoContext(learnerBreakdown, table);

            var learningDetails = SubmissionContext.HistoricalLearningDetails.Where(x => x.AimType == paymentsAimType && x.LearnerReference.Equals(learnerRefererenceNumber, StringComparison.InvariantCultureIgnoreCase)).Single();

            long learnerUln;

            if (!string.IsNullOrEmpty(learningDetails.Uln))
            {
                learnerUln = long.Parse(learningDetails.Uln);
                LookupContext.AddUln(learnerRefererenceNumber, learnerUln);
            }
            else
            {
                learnerUln = LookupContext.AddOrGetUln(learnerRefererenceNumber);
            }


            var provider = LookupContext.AddOrGetUkprn(learnerBreakdown.ProviderId);

            var commitment = CommitmentsContext.Commitments.FirstOrDefault(x => x.ProviderId == learnerBreakdown.ProviderId && x.LearnerId == learnerRefererenceNumber);

            foreach (var earned in learnerBreakdown.ProviderEarnedTotal)
            {
                var requiredPaymentId = Guid.NewGuid().ToString();
                var month             = int.Parse(earned.PeriodName.Substring(0, 2));
                var year         = int.Parse(earned.PeriodName.Substring(3, 2)) + 2000;
                var date         = new DateTime(year, month, 1);
                var periodNumber = date.GetPeriodNumber();
                var periodName   = $"{TestEnvironment.Variables.OpaRulebaseYear}-R" + periodNumber.ToString("00");

                if (earned.Value > 0)
                {
                    PaymentsManager.SavePaymentDue(requiredPaymentId, provider, learnerUln,
                                                   commitment, learnerRefererenceNumber, periodName,
                                                   month, year, learningDetails.AimType == AimType.Programme ? (int)TransactionType.OnProgram : (int)TransactionType.OnProgrammeMathsAndEnglish
                                                   , earned.Value, learningDetails);

                    var levyPayment = learnerBreakdown.SfaLevyBudget.Where(x => x.PeriodName == earned.PeriodName).SingleOrDefault();
                    if (levyPayment != null && levyPayment.Value > 0)
                    {
                        PaymentsManager.SavePayment(requiredPaymentId, periodName, month, year,
                                                    learningDetails.AimType == AimType.Programme ? (int)TransactionType.OnProgram : (int)TransactionType.OnProgrammeMathsAndEnglish, FundingSource.Levy, levyPayment.Value);
                    }

                    var earnedFromEmployer = learnerBreakdown.ProviderEarnedFromEmployers.Where(x => x.PeriodName == earned.PeriodName).SingleOrDefault();
                    if (earnedFromEmployer != null && earnedFromEmployer.Value > 0)
                    {
                        PaymentsManager.SavePayment(requiredPaymentId, periodName, month, year,
                                                    learningDetails.AimType == AimType.Programme ? (int)TransactionType.OnProgram : (int)TransactionType.OnProgrammeMathsAndEnglish, FundingSource.CoInvestedEmployer, earnedFromEmployer.Value);
                    }

                    var coInvestedBySfaLevy = learnerBreakdown.SfaLevyCoFundBudget.Where(x => x.PeriodName == earned.PeriodName).SingleOrDefault();
                    if (coInvestedBySfaLevy != null && coInvestedBySfaLevy.Value > 0)
                    {
                        PaymentsManager.SavePayment(requiredPaymentId, periodName, month, year,
                                                    learningDetails.AimType == AimType.Programme ? (int)TransactionType.OnProgram : (int)TransactionType.OnProgrammeMathsAndEnglish, FundingSource.CoInvestedSfa, coInvestedBySfaLevy.Value);
                    }

                    var coInvestedBySfaNonLevy = learnerBreakdown.SfaNonLevyCoFundBudget.Where(x => x.PeriodName == earned.PeriodName).SingleOrDefault();
                    if (coInvestedBySfaNonLevy != null && coInvestedBySfaNonLevy.Value > 0)
                    {
                        PaymentsManager.SavePayment(requiredPaymentId, periodName, month, year,
                                                    learningDetails.AimType == AimType.Programme ? (int)TransactionType.OnProgram : (int)TransactionType.OnProgrammeMathsAndEnglish, FundingSource.CoInvestedSfa, coInvestedBySfaNonLevy.Value);
                    }

                    var aditionalPayments = learnerBreakdown.SfaLevyAdditionalPayments.Where(x => x.PeriodName == earned.PeriodName).SingleOrDefault();
                    if (aditionalPayments != null && aditionalPayments.Value > 0)
                    {
                        PaymentsManager.SavePayment(requiredPaymentId, periodName, month, year,
                                                    learningDetails.AimType == AimType.Programme ? (int)TransactionType.OnProgram : (int)TransactionType.OnProgrammeMathsAndEnglish, FundingSource.FullyFundedSfa, aditionalPayments.Value);
                    }
                }
            }
        }
Example #5
0
        public void GivenTheFollowingEarningsAndPaymentsHaveBeenMadeToTheProviderForLearner(string learnerName, Table table)
        {
            var learnerBreakdown = new EarningsAndPaymentsBreakdown {
                ProviderId = "provider " + Defaults.ProviderIdSuffix
            };

            EarningAndPaymentTableParser.ParseEarningsAndPaymentsTableIntoContext(learnerBreakdown, table);

            var learner  = LookupContext.AddOrGetUln(learnerName);
            var provider = LookupContext.AddOrGetUkprn(learnerBreakdown.ProviderId);


            var commitment = CommitmentsContext.Commitments.FirstOrDefault();

            foreach (var earned in learnerBreakdown.ProviderEarnedTotal)
            {
                var requiredPaymentId = Guid.NewGuid().ToString();
                var month             = int.Parse(earned.PeriodName.Substring(0, 2));
                var year         = int.Parse(earned.PeriodName.Substring(3, 2)) + 2000;
                var date         = new DateTime(year, month, 1);
                var periodNumber = date.GetPeriodNumber();
                var periodName   = $"1718-R" + periodNumber.ToString("00");

                if (earned.Value > 0)
                {
                    PaymentsManager.SavePaymentDue(requiredPaymentId, provider, learner, null, null, null, Defaults.StandardCode,
                                                   commitment, learnerName, periodName,
                                                   month, year,
                                                   (int)TransactionType.OnProgram,
                                                   commitment == null ? ContractType.ContractWithSfa : ContractType.ContractWithEmployer,
                                                   earned.Value);
                    var levyPayment = learnerBreakdown.SfaLevyBudget.Where(x => x.PeriodName == earned.PeriodName).SingleOrDefault();
                    if (levyPayment != null && levyPayment.Value > 0)
                    {
                        PaymentsManager.SavePayment(requiredPaymentId, periodName, month, year,
                                                    (int)TransactionType.OnProgram, FundingSource.Levy, levyPayment.Value);
                    }

                    var earnedFromEmployer = learnerBreakdown.ProviderEarnedFromEmployers.Where(x => x.PeriodName == earned.PeriodName).SingleOrDefault();
                    if (earnedFromEmployer != null && earnedFromEmployer.Value > 0)
                    {
                        PaymentsManager.SavePayment(requiredPaymentId, periodName, month, year,
                                                    (int)TransactionType.OnProgram, FundingSource.CoInvestedEmployer, earnedFromEmployer.Value);
                    }

                    var coInvestedBySfaLevy = learnerBreakdown.SfaLevyCoFundBudget.Where(x => x.PeriodName == earned.PeriodName).SingleOrDefault();
                    if (coInvestedBySfaLevy != null && coInvestedBySfaLevy.Value > 0)
                    {
                        PaymentsManager.SavePayment(requiredPaymentId, periodName, month, year,
                                                    (int)TransactionType.OnProgram, FundingSource.CoInvestedSfa, coInvestedBySfaLevy.Value);
                    }

                    var coInvestedBySfaNonLevy = learnerBreakdown.SfaNonLevyCoFundBudget.Where(x => x.PeriodName == earned.PeriodName).SingleOrDefault();
                    if (coInvestedBySfaNonLevy != null && coInvestedBySfaNonLevy.Value > 0)
                    {
                        PaymentsManager.SavePayment(requiredPaymentId, periodName, month, year,
                                                    (int)TransactionType.OnProgram, FundingSource.CoInvestedSfa, coInvestedBySfaNonLevy.Value);
                    }
                }
            }
        }