示例#1
0
        MapV2Payments(List <V2PaymentAndEarning> payments, HashSet <Guid> dontCreateRequiredPaymentList)
        {
            foreach (var guid in dontCreateRequiredPaymentList)
            {
                ProcessedRequiredPayments.Add(guid);
            }

            var legacyPayments         = new List <LegacyPaymentModel>();
            var legacyRequiredPayments = new Dictionary <Guid, LegacyRequiredPaymentModel>();
            var legacyEarnings         = new List <LegacyEarningModel>();

            foreach (var paymentModel in payments)
            {
                var requiredPayment = new LegacyRequiredPaymentModel
                {
                    Id                         = paymentModel.RequiredPaymentEventId,
                    AccountId                  = paymentModel.AccountId,
                    AccountVersionId           = string.Empty,
                    AimSeqNumber               = paymentModel.LearningAimSequenceNumber,
                    AmountDue                  = paymentModel.AmountDue,
                    ApprenticeshipContractType = paymentModel.ContractType,
                    CollectionPeriodMonth      = MonthFromPeriod(paymentModel.CollectionPeriod),
                    CollectionPeriodName       =
                        $"{paymentModel.AcademicYear}-R{paymentModel.CollectionPeriod:D2}",
                    CollectionPeriodYear = YearFromPeriod(paymentModel.AcademicYear,
                                                          paymentModel.CollectionPeriod),
                    CommitmentId        = paymentModel.ApprenticeshipId,
                    CommitmentVersionId = string.Empty,
                    UseLevyBalance      = false,
                    DeliveryMonth       = MonthFromPeriod(paymentModel.DeliveryPeriod),
                    DeliveryYear        = YearFromPeriod(paymentModel.AcademicYear,
                                                         paymentModel.DeliveryPeriod),
                    FrameworkCode             = paymentModel.LearningAimFrameworkCode,
                    FundingLineType           = paymentModel.LearningAimFundingLineType,
                    IlrSubmissionDateTime     = paymentModel.IlrSubmissionDateTime,
                    LearnAimRef               = paymentModel.LearningAimReference,
                    LearnRefNumber            = paymentModel.LearnerReferenceNumber,
                    LearningStartDate         = paymentModel.StartDate,
                    PathwayCode               = paymentModel.LearningAimPathwayCode,
                    PriceEpisodeIdentifier    = paymentModel.PriceEpisodeIdentifier,
                    ProgrammeType             = paymentModel.LearningAimProgrammeType,
                    SfaContributionPercentage = paymentModel.SfaContributionPercentage,
                    StandardCode              = paymentModel.LearningAimStandardCode,
                    TransactionType           = paymentModel.TransactionType,
                    Ukprn = paymentModel.Ukprn,
                    Uln   = paymentModel.LearnerUln,
                };

                if (!ProcessedRequiredPayments.Contains(requiredPayment.Id))
                {
                    legacyRequiredPayments.Add(requiredPayment.Id, requiredPayment);
                    ProcessedRequiredPayments.Add(requiredPayment.Id);

                    if (TransactionTypesForEarnings.Contains(requiredPayment.TransactionType.Value))
                    {
                        var earning = new LegacyEarningModel
                        {
                            StartDate          = paymentModel.EarningsStartDate,
                            RequiredPaymentId  = paymentModel.RequiredPaymentEventId,
                            ActualEnddate      = paymentModel.EarningsActualEndDate,
                            CompletionAmount   = paymentModel.EarningsCompletionAmount,
                            PlannedEndDate     = paymentModel.EarningsPlannedEndDate ?? DateTime.MinValue,
                            CompletionStatus   = paymentModel.EarningsCompletionStatus,
                            MonthlyInstallment = paymentModel.EarningsInstalmentAmount ?? 0m,
                            TotalInstallments  = paymentModel.EarningsNumberOfInstalments ?? 0,
                        };
                        legacyEarnings.Add(earning);
                    }
                }

                var payment = new LegacyPaymentModel
                {
                    RequiredPaymentId     = requiredPayment.Id,
                    CollectionPeriodMonth = requiredPayment.CollectionPeriodMonth,
                    CollectionPeriodYear  = requiredPayment.CollectionPeriodYear,
                    TransactionType       = requiredPayment.TransactionType ?? 0,
                    DeliveryYear          = requiredPayment.DeliveryYear ?? 0,
                    CollectionPeriodName  = requiredPayment.CollectionPeriodName,
                    DeliveryMonth         = requiredPayment.DeliveryMonth ?? 0,
                    Amount        = paymentModel.Amount,
                    FundingSource = paymentModel.FundingSource,
                    PaymentId     = Guid.NewGuid(),
                };
                legacyPayments.Add(payment);
            }

            return(legacyPayments, legacyRequiredPayments.Values.ToList(), legacyEarnings);
        }
        MapV2Payments(List <PaymentModelWithRequiredPaymentId> payments)
        {
            var legacyPayments         = new List <LegacyPaymentModel>();
            var legacyRequiredPayments = new Dictionary <Guid, LegacyRequiredPaymentModel>();
            var legacyEarnings         = new List <LegacyEarningModel>();

            foreach (var paymentModel in payments)
            {
                LegacyRequiredPaymentModel requiredPayment;

                if (legacyRequiredPayments.ContainsKey(paymentModel.RequiredPaymentId))
                {
                    requiredPayment = legacyRequiredPayments[paymentModel.RequiredPaymentId];
                }
                else
                {
                    requiredPayment = new LegacyRequiredPaymentModel
                    {
                        Id                         = paymentModel.RequiredPaymentId,
                        AccountId                  = paymentModel.AccountId,
                        AccountVersionId           = string.Empty,
                        AimSeqNumber               = paymentModel.LearningAimSequenceNumber,
                        AmountDue                  = paymentModel.AmountDue,
                        ApprenticeshipContractType = (int)paymentModel.ContractType,
                        CollectionPeriodMonth      = MonthFromPeriod(paymentModel.CollectionPeriod),
                        CollectionPeriodName       =
                            $"{paymentModel.AcademicYear}-R{paymentModel.CollectionPeriod:D2}",
                        CollectionPeriodYear = YearFromPeriod(paymentModel.AcademicYear,
                                                              paymentModel.CollectionPeriod),
                        // TODO: Fix this when available
                        CommitmentId        = 0,
                        CommitmentVersionId = string.Empty,
                        UseLevyBalance      = false,
                        DeliveryMonth       = MonthFromPeriod(paymentModel.DeliveryPeriod),
                        DeliveryYear        = YearFromPeriod(paymentModel.AcademicYear,
                                                             paymentModel.DeliveryPeriod),
                        FrameworkCode             = paymentModel.LearningAimFrameworkCode,
                        FundingLineType           = paymentModel.LearningAimFundingLineType,
                        IlrSubmissionDateTime     = paymentModel.IlrSubmissionDateTime,
                        LearnAimRef               = paymentModel.LearningAimReference,
                        LearnRefNumber            = paymentModel.LearnerReferenceNumber,
                        LearningStartDate         = paymentModel.StartDate,
                        PathwayCode               = paymentModel.LearningAimPathwayCode,
                        PriceEpisodeIdentifier    = paymentModel.PriceEpisodeIdentifier,
                        ProgrammeType             = paymentModel.LearningAimProgrammeType,
                        SfaContributionPercentage = paymentModel.SfaContributionPercentage,
                        StandardCode              = paymentModel.LearningAimStandardCode,
                        TransactionType           = (int)paymentModel.TransactionType,
                        Ukprn = paymentModel.Ukprn,
                        Uln   = paymentModel.LearnerUln,
                    };

                    legacyRequiredPayments.Add(requiredPayment.Id, requiredPayment);

                    var earning = new LegacyEarningModel
                    {
                        StartDate          = paymentModel.StartDate,
                        RequiredPaymentId  = paymentModel.RequiredPaymentId,
                        ActualEndDate      = paymentModel.ActualEndDate,
                        CompletionAmount   = paymentModel.CompletionAmount,
                        PlannedEndDate     = paymentModel.PlannedEndDate ?? DateTime.MinValue,
                        CompletionStatus   = paymentModel.CompletionStatus,
                        MonthlyInstallment = paymentModel.InstalmentAmount ?? 0m,
                        TotalInstallments  = (paymentModel.NumberOfInstalments ?? 0),
                    };
                    legacyEarnings.Add(earning);
                }

                var payment = new LegacyPaymentModel
                {
                    RequiredPaymentId     = requiredPayment.Id,
                    CollectionPeriodMonth = requiredPayment.CollectionPeriodMonth,
                    CollectionPeriodYear  = requiredPayment.CollectionPeriodYear,
                    TransactionType       = requiredPayment.TransactionType ?? 0,
                    DeliveryYear          = requiredPayment.DeliveryYear ?? 0,
                    CollectionPeriodName  = requiredPayment.CollectionPeriodName,
                    DeliveryMonth         = requiredPayment.DeliveryMonth ?? 0,
                    Amount        = paymentModel.Amount,
                    FundingSource = (int)paymentModel.FundingSource,
                    PaymentId     = Guid.NewGuid(),
                };
                legacyPayments.Add(payment);
            }

            return(legacyPayments, legacyRequiredPayments.Values.ToList(), legacyEarnings);
        }