Exemplo n.º 1
0
        private async Task <bool> HoldBackCompletionPayments(TEarningEvent earningEvent, Earning earning, int type, CancellationToken cancellationToken)
        {
            if (type != (int)OnProgrammeEarningType.Completion)
            {
                return(false);
            }

            var priceEpisode     = earningEvent.PriceEpisodes.Single(p => p.Identifier == earning.PriceEpisodeIdentifier);
            var key              = apprenticeshipKeyProvider.GetCurrentKey();
            var employerPayments = await paymentHistoryRepository.GetEmployerCoInvestedPaymentHistoryTotal(key, cancellationToken).ConfigureAwait(false);

            return(completionPaymentService.ShouldHoldBackCompletionPayment(employerPayments, priceEpisode));
        }
        private async Task <bool> HoldBackCompletionPayments(TEarningEvent earningEvent, Earning earning, int type, CancellationToken cancellationToken)
        {
            if (type != (int)OnProgrammeEarningType.Completion)
            {
                return(false);
            }

            if (earning.Amount <= 0m)
            {
                return(false);
            }

            var priceEpisode     = earningEvent.PriceEpisodes.Single(p => p.Identifier == earning.PriceEpisodeIdentifier);
            var key              = apprenticeshipKeyProvider.GetCurrentKey();
            var employerPayments = await paymentHistoryRepository.GetEmployerCoInvestedPaymentHistoryTotal(key, cancellationToken).ConfigureAwait(false);

            var shouldHoldBackCompletionPayment = completionPaymentService.ShouldHoldBackCompletionPayment(employerPayments, priceEpisode);

            if (shouldHoldBackCompletionPayment)
            {
                var properties = new Dictionary <string, string>
                {
                    { TelemetryKeys.JobId, earningEvent.JobId.ToString() },
                    { TelemetryKeys.Ukprn, earningEvent.Ukprn.ToString() },
                    { TelemetryKeys.LearnerRef, earningEvent.Learner.ReferenceNumber },
                    { "LearningAimReference", earningEvent.LearningAim.Reference },
                    { "EarningEventId", earningEvent.EventId.ToString() },
                    { TelemetryKeys.CollectionPeriod, earningEvent.CollectionPeriod.Period.ToString() },
                    { TelemetryKeys.AcademicYear, earningEvent.CollectionPeriod.AcademicYear.ToString() },
                    { "Completion HoldBack Exemption Code", employerPayments.ToString(CultureInfo.InvariantCulture) },
                    { "Expected Employer Contribution", priceEpisode.CompletionHoldBackExemptionCode.ToString() },
                    { "Reported Employer Contribution", priceEpisode.EmployerContribution.ToString() },
                };

                telemetry.TrackEvent("Holding Back Completion Payment", properties, new Dictionary <string, double>());
            }

            return(shouldHoldBackCompletionPayment);
        }