Пример #1
0
        private PaymentModel ToPaymentModel(
            ProviderPayment paymentInfo,
            long ukprn,
            FundingSourceType fundingSource,
            decimal amount,
            long jobId,
            long?employerAccountId)
        {
            var learner = testSession.GetLearner(ukprn, paymentInfo.LearnerId);

            var standardCode = paymentInfo.StandardCode;

            if (!standardCode.HasValue)
            {
                var aim = learner.Aims.FirstOrDefault(a =>
                {
                    var aimStartDate   = a.StartDate.ToDate();
                    var aimStartPeriod = new CollectionPeriodBuilder().WithDate(aimStartDate).Build();
                    var aimDuration    = string.IsNullOrEmpty(a.ActualDuration) ? a.PlannedDuration : a.ActualDuration;

                    var aimEndPeriod = AimPeriodMatcher.GetEndPeriodForAim(aimStartPeriod, aimDuration);
                    var aimFinishedInPreviousPeriod = aimEndPeriod.FinishesBefore(currentCollectionPeriod);
                    if (!aimFinishedInPreviousPeriod)
                    {
                        return(true);
                    }

                    if (a.CompletionStatus == CompletionStatus.Withdrawn && amount >= 0M)
                    {
                        return(false);
                    }

                    return(a.AimReference == "ZPROG001" && (a.CompletionStatus == CompletionStatus.Completed || a.CompletionStatus == CompletionStatus.Withdrawn));
                });



                standardCode = aim?.StandardCode ?? 0;
            }

            return(new PaymentModel
            {
                CollectionPeriod = new CollectionPeriodBuilder().WithSpecDate(paymentInfo.CollectionPeriod).Build(),
                Ukprn = ukprn,
                DeliveryPeriod = new DeliveryPeriodBuilder().WithSpecDate(paymentInfo.DeliveryPeriod).Build(),
                TransactionType = paymentInfo.TransactionType,
                ContractType = contractType,
                Amount = amount,
                FundingSource = fundingSource,
                LearnerReferenceNumber = learner.LearnRefNumber,
                JobId = jobId,
                AccountId = employerAccountId,
                LearningAimStandardCode = standardCode.Value
            });
        }
Пример #2
0
        protected override IList <ProviderPaymentEvent> GetExpectedEvents()
        {
            var expectedPayments = new List <ProviderPaymentEvent>();
            var payments         = paymentSpec.Where(p => p.ParsedCollectionPeriod.Period == collectionPeriod.Period &&
                                                     p.ParsedCollectionPeriod.AcademicYear == collectionPeriod.AcademicYear);

            foreach (var providerPayment in payments)
            {
                var eventCollectionPeriod = new CollectionPeriodBuilder().WithSpecDate(providerPayment.CollectionPeriod).Build();
                var deliveryPeriod        = new DeliveryPeriodBuilder().WithSpecDate(providerPayment.DeliveryPeriod).Build();
                var testLearner           = testSession.GetLearner(provider.Ukprn, providerPayment.LearnerId);

                var learner = new Learner
                {
                    ReferenceNumber = testLearner.LearnRefNumber,
                    Uln             = testLearner.Uln,
                };

                var standardCode = providerPayment.StandardCode;

                if (!standardCode.HasValue)
                {
                    var aim = testLearner.Aims.FirstOrDefault(a =>
                    {
                        var aimStartDate   = a.StartDate.ToDate();
                        var aimStartPeriod = new CollectionPeriodBuilder().WithDate(aimStartDate).Build();
                        var aimDuration    = string.IsNullOrEmpty(a.ActualDuration) ? a.PlannedDuration : a.ActualDuration;

                        var aimEndPeriod = AimPeriodMatcher.GetEndPeriodForAim(aimStartPeriod, aimDuration);
                        var aimFinishedInPreviousPeriod = aimEndPeriod.FinishesBefore(collectionPeriod);
                        if (!aimFinishedInPreviousPeriod)
                        {
                            return(true);
                        }

                        // withdrawal but payments made during period active
                        if (a.CompletionStatus == CompletionStatus.Withdrawn &&
                            providerPayment.LevyPayments >= 0M &&
                            providerPayment.SfaCoFundedPayments >= 0M &&
                            providerPayment.EmployerCoFundedPayments >= 0M &&
                            providerPayment.SfaFullyFundedPayments >= 0M)
                        {
                            return(false);
                        }

                        // retrospective withdrawal
                        return(a.AimReference == "ZPROG001" && (a.CompletionStatus == CompletionStatus.Completed || a.CompletionStatus == CompletionStatus.Withdrawn));
                    });

                    standardCode = aim?.StandardCode ?? 0;
                }

                if (providerPayment.SfaCoFundedPayments != 0)
                {
                    var coFundedSfa = new SfaCoInvestedProviderPaymentEvent
                    {
                        TransactionType   = providerPayment.TransactionType,
                        AmountDue         = providerPayment.SfaCoFundedPayments,
                        CollectionPeriod  = eventCollectionPeriod,
                        DeliveryPeriod    = deliveryPeriod,
                        Learner           = learner,
                        FundingSourceType = FundingSourceType.CoInvestedSfa,
                        LearningAim       = new LearningAim {
                            StandardCode = standardCode.Value
                        },
                        AccountId = providerPayment.AccountId
                    };
                    expectedPayments.Add(coFundedSfa);
                }

                if (providerPayment.EmployerCoFundedPayments != 0)
                {
                    var coFundedEmp = new EmployerCoInvestedProviderPaymentEvent
                    {
                        TransactionType   = providerPayment.TransactionType,
                        AmountDue         = providerPayment.EmployerCoFundedPayments,
                        CollectionPeriod  = eventCollectionPeriod,
                        DeliveryPeriod    = deliveryPeriod,
                        Learner           = learner,
                        FundingSourceType = FundingSourceType.CoInvestedEmployer,
                        AccountId         = providerPayment.AccountId,
                        LearningAim       = new LearningAim {
                            StandardCode = standardCode.Value
                        }
                    };
                    expectedPayments.Add(coFundedEmp);
                }

                if (providerPayment.SfaFullyFundedPayments != 0)
                {
                    var fullyFundedSfa = new SfaFullyFundedProviderPaymentEvent
                    {
                        TransactionType  = providerPayment.TransactionType,
                        AmountDue        = providerPayment.SfaFullyFundedPayments,
                        CollectionPeriod = eventCollectionPeriod,
                        DeliveryPeriod   = deliveryPeriod,
                        Learner          = learner,
                        AccountId        = providerPayment.AccountId,
                        LearningAim      = new LearningAim {
                            StandardCode = standardCode.Value
                        }
                    };
                    expectedPayments.Add(fullyFundedSfa);
                }

                if (providerPayment.LevyPayments != 0)
                {
                    var levyFunded = new LevyProviderPaymentEvent
                    {
                        TransactionType  = providerPayment.TransactionType,
                        AmountDue        = providerPayment.LevyPayments,
                        CollectionPeriod = eventCollectionPeriod,
                        DeliveryPeriod   = deliveryPeriod,
                        Learner          = learner,
                        AccountId        = providerPayment.AccountId,
                        LearningAim      = new LearningAim {
                            StandardCode = standardCode.Value
                        }
                    };
                    expectedPayments.Add(levyFunded);
                }

                if (providerPayment.TransferPayments != 0)
                {
                    var transferFunded = new TransferProviderPaymentEvent
                    {
                        TransactionType  = providerPayment.TransactionType,
                        AmountDue        = providerPayment.TransferPayments,
                        CollectionPeriod = eventCollectionPeriod,
                        DeliveryPeriod   = deliveryPeriod,
                        Learner          = learner,
                        AccountId        = providerPayment.AccountId,
                        LearningAim      = new LearningAim {
                            StandardCode = standardCode.Value
                        }
                    };
                    expectedPayments.Add(transferFunded);
                }
            }

            return(expectedPayments);
        }