public static bool HasCompletionPayment(this RawEarning earning) { return((earning.TransactionType02 != 0 || earning.TransactionType03 != 0 || earning.TransactionType09 != 0 || earning.TransactionType10 != 0) && earning.EndDate.HasValue); }
public static bool MatchesEarning(this PriceEpisodePeriodMatchEntity source, RawEarning rhs) { return(source.AimSeqNumber == rhs.AimSeqNumber && source.LearnRefNumber == rhs.LearnRefNumber && source.PriceEpisodeIdentifier == rhs.PriceEpisodeIdentifier && source.Ukprn == rhs.Ukprn && source.Period == rhs.Period); }
private DateTime CalculateOnProgCensusDate(RawEarning earning) { int month = _periodProviderService.MonthFromPeriod(earning.Period); int year = YearFromPeriod(earning.Period, earning.EpisodeStartDate ?? new DateTime(9999, 01, 01)); int lastDayOfMonth = DateTime.DaysInMonth(year, month); return(new DateTime(year, month, lastDayOfMonth)); }
public static bool HasNonIncentiveEarnings(this RawEarning earning) { return(earning.TransactionType01 != 0 || earning.TransactionType08 != 0 || earning.TransactionType11 != 0 || earning.TransactionType12 != 0 || earning.TransactionType15 != 0 || ( earning.Period == 1 && !earning.HasFirstIncentive() && !earning.HasSecondIncentive() && !earning.HasCareLeaverApprenticePayment())); }
public static bool DoesNotAlreadyContainEarningForThisError( this List <DatalockValidationErrorByPeriod> source, RawEarning earning, string error) { if (source.FirstOrDefault(x => x.IsEqualTo(earning) && x.RuleId == error && x.Period == earning.Period) == null) { return(true); } return(false); }
public static bool DoesNotAlreadyContainEarningForCommitment( this List <PriceEpisodeMatchEntity> source, RawEarning earning, DasCommitment commitment, bool payable) { if (source.FirstOrDefault(x => x.MatchesEarning(earning) && x.MatchesCommitment(commitment) && x.IsSuccess == payable) == null) { return(true); } return(false); }
public static bool DoesNotContainEarningForCommitmentAndPaymentType( this List <PriceEpisodePeriodMatchEntity> source, RawEarning earning, DasCommitment commitment, TransactionTypesFlag paymentType) { if (source.FirstOrDefault(x => x.MatchesEarning(earning) && x.MatchesCommitment(commitment) && x.Payable && x.TransactionTypesFlag == paymentType) == null) { return(true); } return(false); }
private void AddError(string ruleName, RawEarning rawEarning, string ilrValue = "", string calculatedValue = "") { dataMatchModels.Add(new DataMatchModel { LearnRefNumber = rawEarning.LearnRefNumber, Uln = rawEarning.Uln, AimSeqNumber = rawEarning.AimSeqNumber, RuleName = ruleName, Description = DataLockValidationMessages.Validations.FirstOrDefault(x => x.RuleId == ruleName)?.ErrorMessage ?? "Description not found", ILRValue = ilrValue, ApprenticeshipServiceValue = calculatedValue, PriceEpisodeStartDate = rawEarning.EpisodeStartDate?.ToString("dd/MM/yyyy HH:mm") ?? rawEarning.EpisodeEffectiveTnpStartDate?.ToString("dd/MM/yyyy HH:mm") ?? string.Empty, PriceEpisodeActualEndDate = rawEarning.EndDate?.ToString("dd/MM/yyyy HH:mm") ?? string.Empty, PriceEpisodeIdentifier = rawEarning.PriceEpisodeIdentifier }); }
public void Add(RawEarning earning, List <string> errors, TransactionTypesFlag paymentType, DasCommitment commitment) { var payable = false; if (errors.Any()) { foreach (var error in errors) { if (ValidationErrors.DoesNotAlreadyContainEarningForThisError(earning, error) && PriceEpisodePeriodMatches.DoesNotContainEarningForCommitmentAndPaymentType(earning, commitment, paymentType)) { ValidationErrors.Add(new DatalockValidationError { LearnRefNumber = earning.LearnRefNumber, AimSeqNumber = earning.AimSeqNumber, PriceEpisodeIdentifier = earning.PriceEpisodeIdentifier, RuleId = error, Ukprn = earning.Ukprn, }); } if (ValidationErrorsByPeriod.DoesNotAlreadyContainEarningForThisError(earning, error)) { ValidationErrorsByPeriod.Add(new DatalockValidationErrorByPeriod() { LearnRefNumber = earning.LearnRefNumber, AimSeqNumber = earning.AimSeqNumber, PriceEpisodeIdentifier = earning.PriceEpisodeIdentifier, RuleId = error, Ukprn = earning.Ukprn, Period = earning.Period, }); } } } else { payable = true; } if (commitment == null) { return; } PriceEpisodePeriodMatches.Add(new PriceEpisodePeriodMatchEntity { AimSeqNumber = earning.AimSeqNumber, CommitmentId = commitment.CommitmentId, LearnRefNumber = earning.LearnRefNumber, PriceEpisodeIdentifier = earning.PriceEpisodeIdentifier, Period = earning.Period, TransactionTypesFlag = paymentType, Payable = payable, Ukprn = earning.Ukprn, VersionId = commitment.VersionId, }); if (payable) { var validationErrorsToRemove = ValidationErrors.Where(x => x.Ukprn == earning.Ukprn && x.LearnRefNumber == earning.LearnRefNumber && x.PriceEpisodeIdentifier == earning.PriceEpisodeIdentifier) .ToList(); foreach (var validationError in validationErrorsToRemove) { ValidationErrors.Remove(validationError); } } if (PriceEpisodeMatches.DoesNotAlreadyContainEarningForCommitment(earning, commitment, payable)) { PriceEpisodeMatches.Add(new PriceEpisodeMatchEntity { CommitmentId = commitment.CommitmentId, IsSuccess = payable, LearnRefNumber = earning.LearnRefNumber, PriceEpisodeIdentifier = earning.PriceEpisodeIdentifier, Ukprn = earning.Ukprn, AimSeqNumber = earning.AimSeqNumber, }); } }
public static bool HasFirstIncentive(this RawEarning earning) { return((earning.TransactionType04 != 0 || earning.TransactionType05 != 0) && earning.FirstIncentiveCensusDate.HasValue); }
public static bool HasCareLeaverApprenticePayment(this RawEarning earning) { return(earning.TransactionType16 != 0 && earning.LearnerAdditionalPaymentsDate.HasValue); }
public static bool HasSecondIncentive(this RawEarning earning) { return((earning.TransactionType06 != 0 || earning.TransactionType07 != 0) && earning.SecondIncentiveCensusDate.HasValue); }
private async Task <List <long> > GetUlnsForValidLearners( FM36Global fm36Data, List <RawEarning> rawEarnings, IReportServiceContext reportServiceContext, CancellationToken cancellationToken) { List <long> ulns = new List <long>(); foreach (FM36Learner fm36DataLearner in fm36Data.Learners) { foreach (LearningDelivery learningDelivery in fm36DataLearner.LearningDeliveries) { if (fm36DataLearner.PriceEpisodes != null) { List <PriceEpisode> priceEpisode = fm36DataLearner.PriceEpisodes.Where(x => x.PriceEpisodeValues.PriceEpisodeAimSeqNumber == learningDelivery.AimSeqNumber && x.PriceEpisodeValues.EpisodeStartDate > Constants.BeginningOfYear && x.PriceEpisodeValues.EpisodeStartDate < Constants.EndOfYear && string.Equals(x.PriceEpisodeValues.PriceEpisodeContractType, Constants.Fm36PriceEpisodeContractTypeLevyContract, StringComparison.OrdinalIgnoreCase)).ToList(); if (!priceEpisode.Any()) { _logger.LogWarning($"Can't find any price episodes for learner {fm36DataLearner.LearnRefNumber} with learning delivery aim sequence no. {learningDelivery.AimSeqNumber} skipping {nameof(DataMatchReport)} {nameof(RawEarning)} model"); continue; } foreach (PriceEpisode episode in priceEpisode) { RawEarning rawEarning = new RawEarning(); rawEarning.Uln = fm36DataLearner.ULN; rawEarning.LearnRefNumber = fm36DataLearner.LearnRefNumber; rawEarning.AimSeqNumber = learningDelivery.AimSeqNumber; rawEarning.Ukprn = fm36Data.UKPRN; rawEarning.EpisodeStartDate = episode.PriceEpisodeValues.EpisodeStartDate; rawEarning.EpisodeEffectiveTnpStartDate = episode.PriceEpisodeValues.EpisodeEffectiveTNPStartDate; rawEarning.EndDate = episode.PriceEpisodeValues.PriceEpisodeActualEndDate ?? episode.PriceEpisodeValues.PriceEpisodePlannedEndDate; rawEarning.Period = reportServiceContext.ReturnPeriod; rawEarning.ProgrammeType = learningDelivery.LearningDeliveryValues.ProgType; rawEarning.FrameworkCode = learningDelivery.LearningDeliveryValues.FworkCode; rawEarning.PathwayCode = learningDelivery.LearningDeliveryValues.PwayCode; rawEarning.StandardCode = learningDelivery.LearningDeliveryValues.StdCode; rawEarning.AgreedPrice = episode.PriceEpisodeValues.PriceEpisodeTotalTNPPrice; rawEarning.LearningDeliveryStartDate = learningDelivery.LearningDeliveryValues.LearnStartDate; rawEarning.PriceEpisodeIdentifier = episode.PriceEpisodeIdentifier; rawEarning.TransactionType01 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeOnProgPaymentAttributeName, StringComparison.OrdinalIgnoreCase))); rawEarning.TransactionType02 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeCompletionPaymentAttributeName, StringComparison.OrdinalIgnoreCase))); rawEarning.TransactionType03 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm3PriceEpisodeBalancePaymentAttributeName, StringComparison.OrdinalIgnoreCase))); rawEarning.TransactionType04 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeFirstEmp1618PayAttributeName, StringComparison.OrdinalIgnoreCase))); rawEarning.TransactionType05 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeFirstProv1618PayAttributeName, StringComparison.OrdinalIgnoreCase))); rawEarning.TransactionType06 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeSecondEmp1618PayAttributeName, StringComparison.OrdinalIgnoreCase))); rawEarning.TransactionType07 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeSecondProv1618PayAttributeName, StringComparison.OrdinalIgnoreCase))); rawEarning.TransactionType08 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeApplic1618FrameworkUpliftOnProgPaymentAttributeName, StringComparison.OrdinalIgnoreCase))); rawEarning.TransactionType09 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeApplic1618FrameworkUpliftCompletionPaymentAttributeName, StringComparison.OrdinalIgnoreCase))); rawEarning.TransactionType10 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36LDApplic1618FrameworkUpliftBalancingPayment, StringComparison.OrdinalIgnoreCase))); rawEarning.TransactionType11 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeFirstDisadvantagePaymentAttributeName, StringComparison.OrdinalIgnoreCase))); rawEarning.TransactionType12 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeSecondDisadvantagePaymentAttributeName, StringComparison.OrdinalIgnoreCase))); rawEarning.TransactionType15 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeLSFCashAttributeName, StringComparison.OrdinalIgnoreCase))); rawEarning.TransactionType16 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeLearnerAdditionalPaymentAttributeName, StringComparison.OrdinalIgnoreCase))); rawEarning.FirstIncentiveCensusDate = episode.PriceEpisodeValues.PriceEpisodeFirstAdditionalPaymentThresholdDate; rawEarning.SecondIncentiveCensusDate = episode.PriceEpisodeValues.PriceEpisodeSecondAdditionalPaymentThresholdDate; rawEarning.LearnerAdditionalPaymentsDate = episode.PriceEpisodeValues.PriceEpisodeLearnerAdditionalPaymentThresholdDate; rawEarnings.Add(rawEarning); } } } } //foreach (ILearner learner in message.Learners) //{ // FM36Learner fm36Entry = // fm36Data.Learners.SingleOrDefault(x => string.Equals(x.LearnRefNumber, learner.LearnRefNumber, StringComparison.OrdinalIgnoreCase)); // if (fm36Entry == null) // { // continue; // } // ulns.Add(learner.ULN); // ILearningDelivery[] learningDeliveries = learner.LearningDeliveries.Where(x => // x.FundModel == 36 && x.LearningDeliveryFAMs.Any(y => // string.Equals(y.LearnDelFAMType, Constants.Fm36LearnDelFAMTypeAct, StringComparison.OrdinalIgnoreCase) && // string.Equals(y.LearnDelFAMCode, Constants.Fm36LearnDelFAMCodeOne, StringComparison.OrdinalIgnoreCase))).ToArray(); // _logger.LogWarning($"Found {learningDeliveries.Length} FM36 {Constants.Fm36LearnDelFAMTypeAct} {Constants.Fm36LearnDelFAMCodeOne} learning deliveries for learner {learner.LearnRefNumber}"); // foreach (ILearningDelivery learnerLearningDelivery in learningDeliveries) // { // List<PriceEpisode> priceEpisode = fm36Entry.PriceEpisodes.Where(x => x.PriceEpisodeValues.PriceEpisodeAimSeqNumber == learnerLearningDelivery.AimSeqNumber && string.Equals(x.PriceEpisodeValues.PriceEpisodeContractType, Constants.Fm36PriceEpisodeContractTypeLevyContract, StringComparison.OrdinalIgnoreCase)).ToList(); // if (!priceEpisode.Any()) // { // _logger.LogWarning($"Can't find any price episodes for learner {learner.LearnRefNumber} with learning delivery aim sequence no. {learnerLearningDelivery.AimSeqNumber} skipping {nameof(DataMatchReport)} {nameof(RawEarning)} model"); // continue; // } // foreach (PriceEpisode episode in priceEpisode) // { // RawEarning rawEarning = new RawEarning(); // rawEarning.Uln = learner.ULN; // rawEarning.LearnRefNumber = learner.LearnRefNumber; // rawEarning.AimSeqNumber = learnerLearningDelivery.AimSeqNumber; // rawEarning.Ukprn = message.HeaderEntity.SourceEntity.UKPRN; // rawEarning.EpisodeStartDate = episode.PriceEpisodeValues.EpisodeStartDate; // rawEarning.EpisodeEffectiveTnpStartDate = // episode.PriceEpisodeValues.EpisodeEffectiveTNPStartDate; // rawEarning.EndDate = episode.PriceEpisodeValues.PriceEpisodeActualEndDate ?? // episode.PriceEpisodeValues.PriceEpisodePlannedEndDate; // rawEarning.Period = period; // rawEarning.ProgrammeType = learnerLearningDelivery.ProgTypeNullable; // rawEarning.FrameworkCode = learnerLearningDelivery.FworkCodeNullable; // rawEarning.PathwayCode = learnerLearningDelivery.PwayCodeNullable; // rawEarning.StandardCode = learnerLearningDelivery.StdCodeNullable; // rawEarning.AgreedPrice = episode.PriceEpisodeValues.PriceEpisodeTotalTNPPrice; // rawEarning.LearningDeliveryStartDate = learnerLearningDelivery.LearnStartDate; // rawEarning.PriceEpisodeIdentifier = episode.PriceEpisodeIdentifier; // rawEarning.TransactionType01 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeOnProgPaymentAttributeName, StringComparison.OrdinalIgnoreCase))); // rawEarning.TransactionType02 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeCompletionPaymentAttributeName, StringComparison.OrdinalIgnoreCase))); // rawEarning.TransactionType03 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm3PriceEpisodeBalancePaymentAttributeName, StringComparison.OrdinalIgnoreCase))); // rawEarning.TransactionType04 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeFirstEmp1618PayAttributeName, StringComparison.OrdinalIgnoreCase))); // rawEarning.TransactionType05 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeFirstProv1618PayAttributeName, StringComparison.OrdinalIgnoreCase))); // rawEarning.TransactionType06 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeSecondEmp1618PayAttributeName, StringComparison.OrdinalIgnoreCase))); // rawEarning.TransactionType07 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeSecondProv1618PayAttributeName, StringComparison.OrdinalIgnoreCase))); // rawEarning.TransactionType08 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeApplic1618FrameworkUpliftOnProgPaymentAttributeName, StringComparison.OrdinalIgnoreCase))); // rawEarning.TransactionType09 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeApplic1618FrameworkUpliftCompletionPaymentAttributeName, StringComparison.OrdinalIgnoreCase))); // rawEarning.TransactionType10 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36LDApplic1618FrameworkUpliftBalancingPayment, StringComparison.OrdinalIgnoreCase))); // rawEarning.TransactionType11 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeFirstDisadvantagePaymentAttributeName, StringComparison.OrdinalIgnoreCase))); // rawEarning.TransactionType12 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeSecondDisadvantagePaymentAttributeName, StringComparison.OrdinalIgnoreCase))); // rawEarning.TransactionType15 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeLSFCashAttributeName, StringComparison.OrdinalIgnoreCase))); // rawEarning.TransactionType16 = _totalBuilder.TotalRecords(episode.PriceEpisodePeriodisedValues.SingleOrDefault(att => string.Equals(att.AttributeName, Constants.Fm36PriceEpisodeLearnerAdditionalPaymentAttributeName, StringComparison.OrdinalIgnoreCase))); // rawEarning.FirstIncentiveCensusDate = episode.PriceEpisodeValues.PriceEpisodeFirstAdditionalPaymentThresholdDate; // rawEarning.SecondIncentiveCensusDate = episode.PriceEpisodeValues.PriceEpisodeSecondAdditionalPaymentThresholdDate; // rawEarning.LearnerAdditionalPaymentsDate = episode.PriceEpisodeValues.PriceEpisodeLearnerAdditionalPaymentThresholdDate; // rawEarnings.Add(rawEarning); // } // } //} return(ulns); }
private void AddError(string ruleName, RawEarning rawEarning, List <DasCommitment> dasCommitments) { if (rawEarning.HasNonIncentiveEarnings()) { foreach (DasCommitment dasCommitment in dasCommitments) { _datalockValidationResultBuilder.Add( rawEarning, new List <string> { ruleName }, TransactionTypesFlag.AllLearning, dasCommitment); } } if (rawEarning.HasCompletionPayment()) { foreach (DasCommitment dasCommitment in dasCommitments) { _datalockValidationResultBuilder.Add( rawEarning, new List <string> { ruleName }, TransactionTypesFlag.Completion, dasCommitment); } } if (rawEarning.HasFirstIncentive()) { foreach (DasCommitment dasCommitment in dasCommitments) { _datalockValidationResultBuilder.Add( rawEarning, new List <string> { ruleName }, TransactionTypesFlag.FirstEmployerProviderIncentives, dasCommitment); } } if (rawEarning.HasSecondIncentive()) { foreach (DasCommitment dasCommitment in dasCommitments) { _datalockValidationResultBuilder.Add( rawEarning, new List <string> { ruleName }, TransactionTypesFlag.SecondEmployerProviderIncentives, dasCommitment); } } if (rawEarning.HasCareLeaverApprenticePayment()) { foreach (DasCommitment dasCommitment in dasCommitments) { _datalockValidationResultBuilder.Add( rawEarning, new List <string> { ruleName }, TransactionTypesFlag.CareLeaverApprenticePayments, dasCommitment); } } }