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);
        }
Exemplo n.º 3
0
        public List <DasCommitment> Build(IEnumerable <DasCommitments> commitments)
        {
            List <DasCommitment>          dasCommitments  = new List <DasCommitment>(commitments.Select(x => new DasCommitment(x)));
            ILookup <long, DasCommitment> commitmentsById = dasCommitments.ToLookup(x => x.CommitmentId);

            foreach (var commitmentsForId in commitmentsById)
            {
                var commitmentList = commitmentsForId.ToList();

                if (commitmentList.Count == 1)
                {
                    // No 'versions'
                    commitmentList[0].EffectiveStartDate = commitmentList[0].StartDate.LastDayOfMonth();
                    commitmentList[0].EffectiveEndDate   = commitmentList[0].EndDate.LastDayOfMonth().AddDays(-1);
                }
                else
                {
                    foreach (var commitment in commitmentList)
                    {
                        commitment.EffectiveStartDate = commitment.EffectiveFromDate;
                        commitment.EffectiveEndDate   = commitment.EffectiveToDate;
                        commitment.IsVersioned        = true;
                    }
                }

                foreach (var commitment in commitmentList)
                {
                    if (commitment.WithdrawnOnDate.HasValue)
                    {
                        commitment.EffectiveEndDate = commitment.WithdrawnOnDate;
                    }
                }
            }

            DasCommitment lastCommitment = dasCommitments
                                           .OrderByDescending(x => x.EffectiveStartDate)
                                           .ThenByDescending(x => x.CommitmentId)
                                           .FirstOrDefault();

            if (lastCommitment != null)
            {
                lastCommitment.EffectiveEndDate = null;
            }

            return(dasCommitments);
        }
 public static bool MatchesCommitment(this PriceEpisodePeriodMatchEntity source, DasCommitment rhs)
 {
     return(source.CommitmentId == rhs.CommitmentId &&
            source.VersionId == rhs.VersionId);
 }
 public static bool MatchesCommitment(this PriceEpisodeMatchEntity source, DasCommitment rhs)
 {
     return(source.CommitmentId == rhs.CommitmentId);
 }
        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,
                });
            }
        }