Example #1
0
        public async Task Then_clawback_payment_is_created_when_earnings_with_sent_payments_are_clawed_back_and_the_earning_amount_has_changed()
        {
            // arrange
            await _sut.CalculateEarnings(_mockPaymentProfilesService.Object, _mockCollectionCalendarService.Object);

            byte  collectionPeriod = 6;
            short collectionYear   = 2020;
            var   pendingPayment   = _sutModel.PendingPaymentModels.Single(x => x.EarningType == EarningType.FirstPayment);

            pendingPayment.PendingPaymentValidationResultModels = new List <PendingPaymentValidationResultModel>();
            pendingPayment.PendingPaymentValidationResultModels.Add(_fixture.Build <PendingPaymentValidationResultModel>().With(x => x.CollectionPeriod, new CollectionPeriod(collectionPeriod, collectionYear)).With(x => x.Result, true).Create());
            _sut.CreatePayment(pendingPayment.Id, new CollectionPeriod(collectionPeriod, collectionYear));
            _sutModel.PaymentModels.First().PaidDate = DateTime.Now;

            var activePeriod = new CollectionCalendarPeriod(new CollectionPeriod(4, _fixture.Create <short>()), (byte)_collectionPeriod.AddMonths(3).Month, (short)_collectionPeriod.AddMonths(3).Year, _collectionPeriod.AddMonths(3).AddDays(1), _fixture.Create <DateTime>(), true, false);

            _collectionPeriods.Add(activePeriod);

            // act
            var apprenticeshipDob = DateTime.Now.AddYears(-26);

            _sutModel.Apprenticeship = new Apprenticeship(_apprenticehip.Id, _apprenticehip.FirstName, _apprenticehip.LastName, apprenticeshipDob, _apprenticehip.UniqueLearnerNumber, _apprenticehip.EmployerType, _apprenticehip.CourseName, _apprenticehip.EmploymentStartDate);
            await _sut.CalculateEarnings(_mockPaymentProfilesService.Object, _mockCollectionCalendarService.Object);

            // assert
            var clawback = _sutModel.ClawbackPaymentModels.Single();

            clawback.ApprenticeshipIncentiveId.Should().Be(_sutModel.Id);
            clawback.PendingPaymentId.Should().Be(pendingPayment.Id);
            clawback.PaymentId.Should().Be(_sutModel.PaymentModels.First().Id);
            clawback.Account.Should().Be(_sutModel.Account);
            clawback.Amount.Should().Be(-1 * pendingPayment.Amount);
            clawback.SubnominalCode.Should().Be(_sutModel.PaymentModels.First().SubnominalCode);
            clawback.CollectionPeriod.Should().Be(activePeriod.CollectionPeriod);
        }
Example #2
0
        public async Task Then_clawback_payment_is_created_when_paid_earnings_are_clawed_back_if_the_apprenticeship_is_no_longer_eligible()
        {
            // arrange
            await _sut.CalculateEarnings(_mockPaymentProfilesService.Object, _mockCollectionCalendarService.Object);

            byte  collectionPeriod = 6;
            short collectionYear   = 2020;
            var   pendingPayment   = _sutModel.PendingPaymentModels.Single(x => x.EarningType == EarningType.FirstPayment);

            pendingPayment.PendingPaymentValidationResultModels = new List <PendingPaymentValidationResultModel>();
            pendingPayment.PendingPaymentValidationResultModels.Add(_fixture.Build <PendingPaymentValidationResultModel>().With(x => x.CollectionPeriod, new CollectionPeriod(collectionPeriod, collectionYear)).With(x => x.Result, true).Create());
            _sut.CreatePayment(pendingPayment.Id, new CollectionPeriod(collectionPeriod, collectionYear));
            _sutModel.PaymentModels.First().PaidDate = DateTime.Now;

            var activePeriod = new CollectionCalendarPeriod(new CollectionPeriod(4, _fixture.Create <short>()), (byte)_collectionPeriod.AddMonths(3).Month, (short)_collectionPeriod.AddMonths(3).Year, _collectionPeriod.AddMonths(3).AddDays(1), _fixture.Create <DateTime>(), true, false);

            _collectionPeriods.Add(activePeriod);

            // act
            _sutModel.StartDate = Phase2Incentive.EligibilityStartDate.AddDays(-1);
            await _sut.CalculateEarnings(_mockPaymentProfilesService.Object, _mockCollectionCalendarService.Object);

            // assert
            var clawback = _sutModel.ClawbackPaymentModels.Single();

            clawback.ApprenticeshipIncentiveId.Should().Be(_sutModel.Id);
            clawback.PendingPaymentId.Should().Be(pendingPayment.Id);
            clawback.PaymentId.Should().Be(_sutModel.PaymentModels.First().Id);
            clawback.Account.Should().Be(_sutModel.Account);
            clawback.Amount.Should().Be(-1 * pendingPayment.Amount);
            clawback.SubnominalCode.Should().Be(_sutModel.PaymentModels.First().SubnominalCode);
            clawback.CollectionPeriod.Should().Be(activePeriod.CollectionPeriod);
        }
 private void ClawbackPayments(IEnumerable <PendingPayment> pendingPayments, CollectionCalendarPeriod collectionPeriod)
 {
     foreach (var paidPendingPayment in pendingPayments)
     {
         AddClawback(paidPendingPayment, collectionPeriod);
     }
 }
        public void SetDaysInLearning(CollectionCalendarPeriod collectionCalendarPeriod)
        {
            var censusDate = collectionCalendarPeriod.CensusDate;

            int days = 0;

            foreach (var learningPeriod in Model.LearningPeriods)
            {
                if (!learningPeriod.EndDate.HasValue)
                {
                    days += censusDate.Subtract(learningPeriod.StartDate.Date).Days + 1;
                }
                else
                {
                    if (learningPeriod.EndDate.Value.Date < censusDate)
                    {
                        days += learningPeriod.EndDate.Value.Date.Subtract(learningPeriod.StartDate.Date).Days + 1;
                    }
                    else
                    {
                        days += censusDate.Subtract(learningPeriod.StartDate.Date).Days + 1;
                    }
                }
            }

            var daysInLearning = new DaysInLearning(collectionCalendarPeriod.CollectionPeriod, days);
            var existing       = Model.DaysInLearnings.SingleOrDefault(d => d.CollectionPeriod == collectionCalendarPeriod.CollectionPeriod);

            if (existing != null)
            {
                Model.DaysInLearnings.Remove(existing);
            }

            Model.DaysInLearnings.Add(daysInLearning);
        }
Example #5
0
 public PendingPaymentValidationResult(
     string validationStep,
     bool validationResult,
     CollectionCalendarPeriod collectionPeriod)
 {
     ValidationStep   = validationStep;
     ValidationResult = validationResult;
     CollectionPeriod = collectionPeriod;
 }
        private static Domain.ValueObjects.CollectionPeriod Map(this CollectionCalendarPeriod model)
        {
            if (model != null)
            {
                var period = new Domain.ValueObjects.CollectionPeriod(
                    model.PeriodNumber,
                    Convert.ToInt16(model.AcademicYear));

                return(period);
            }

            return(null);
        }
        public void Arrange()
        {
            _fixture = new Fixture();

            testDate = DateTime.Now;

            var period1 = new CollectionCalendarPeriod(new CollectionPeriod(1, _fixture.Create <short>()), (byte)testDate.AddMonths(13).Month, (short)testDate.AddMonths(13).Year, testDate.AddMonths(13), _fixture.Create <DateTime>(), false, false);
            var period2 = new CollectionCalendarPeriod(new CollectionPeriod(2, _fixture.Create <short>()), (byte)testDate.Month, (short)testDate.Year, testDate, _fixture.Create <DateTime>(), false, false);
            var period3 = new CollectionCalendarPeriod(new CollectionPeriod(3, _fixture.Create <short>()), (byte)testDate.AddMonths(-13).Month, (short)testDate.AddMonths(-13).Year, testDate.AddMonths(-13), _fixture.Create <DateTime>(), false, false);

            _collectionPeriods = new List <CollectionCalendarPeriod>()
            {
                period1, period2, period3
            };

            _sut = new CollectionCalendar(_collectionPeriods);
        }
        private void AddClawback(PendingPayment pendingPayment, CollectionCalendarPeriod collectionPeriod)
        {
            pendingPayment.ClawBack();
            var payment = Model.PaymentModels.Single(p => p.PendingPaymentId == pendingPayment.Id);

            if (!Model.ClawbackPaymentModels.Any(c => c.PendingPaymentId == pendingPayment.Id))
            {
                var clawback = ClawbackPayment.New(
                    Guid.NewGuid(),
                    Model.Account,
                    Model.Id,
                    pendingPayment.Id,
                    -pendingPayment.Amount,
                    DateTime.Now,
                    payment.SubnominalCode,
                    payment.Id,
                    payment.VrfVendorId);

                clawback.SetPaymentPeriod(collectionPeriod);

                Model.ClawbackPaymentModels.Add(clawback.GetModel());
            }
        }
        public void Arrange()
        {
            _fixture = new Fixture();

            _mockIncentiveDomainRepository = new Mock <IApprenticeshipIncentiveDomainRepository>();
            _mockCollectionCalendarService = new Mock <ICollectionCalendarService>();

            _activePeriod = CollectionPeriod(2, 2020);
            _activePeriod.SetActive(true);

            var collectionPeriods = new List <Domain.ValueObjects.CollectionCalendarPeriod>()
            {
                CollectionPeriod(1, 2020),
                _activePeriod,
                CollectionPeriod(3, 2020)
            };

            _mockCollectionCalendarService.Setup(m => m.Get()).ReturnsAsync(new Domain.ValueObjects.CollectionCalendar(collectionPeriods));

            _fixture.Register(ApprenticeshipIncentiveCreator);

            _sut = new WithdrawCommandHandler(_mockIncentiveDomainRepository.Object, _mockCollectionCalendarService.Object);
        }
Example #10
0
        public void Arrange()
        {
            _fixture    = new Fixture();
            _startDate  = DateTime.Now.Date;
            _censusDate = _startDate.AddDays(17);

            _collectionCalendarPeriod = new CollectionCalendarPeriod(new CollectionPeriod(1, (short)DateTime.Now.Year), (byte)DateTime.Now.Month, (short)DateTime.Now.Year, DateTime.Now.AddMonths(-2), _censusDate, true, false);

            _learningPeriod3 = new LearningPeriod(_startDate, null);
            _learningPeriods = new List <LearningPeriod>()
            {
                new LearningPeriod(_startDate.AddDays(-60), _startDate.AddDays(-60 + 15)),
                new LearningPeriod(_startDate.AddDays(-30), _startDate.AddDays(-30 + 12)),
                _learningPeriod3
            };

            _sutModel = _fixture
                        .Build <LearnerModel>()
                        .With(l => l.LearningPeriods, _learningPeriods)
                        .With(l => l.DaysInLearnings, new List <DaysInLearning>())
                        .Create();

            _sut = Sut(_sutModel);
        }
Example #11
0
 public void SetPaymentPeriod(CollectionCalendarPeriod period)
 {
     Model.CollectionPeriod = period.CollectionPeriod;
 }
 private void ClawbackAllPayments(CollectionCalendarPeriod collectionPeriod)
 {
     RemoveUnpaidEarnings();
     ClawbackPayments(PendingPayments, collectionPeriod);
 }
        internal static Domain.ValueObjects.CollectionCalendarPeriod MapCollectionCalendarPeriod(this CollectionCalendarPeriod model)
        {
            if (model != null)
            {
                var collectionCalendarPeriod = new Domain.ValueObjects.CollectionCalendarPeriod(
                    new Domain.ValueObjects.CollectionPeriod(model.PeriodNumber, Convert.ToInt16(model.AcademicYear)),
                    model.CalendarMonth,
                    model.CalendarYear,
                    model.EIScheduledOpenDateUTC,
                    model.CensusDate,
                    model.Active,
                    model.PeriodEndInProgress);

                if (model.MonthEndProcessingCompleteUTC.HasValue)
                {
                    collectionCalendarPeriod.SetMonthEndProcessingCompletedDate(model.MonthEndProcessingCompleteUTC.Value);
                }

                return(collectionCalendarPeriod);
            }

            return(null);
        }