public static CollectionPeriod GetEndPeriodForAim(CollectionPeriod aimStartDate, string duration)
        {
            var startPeriod = aimStartDate.Period;

            var options  = RegexOptions.None;
            var regex    = new Regex("[ ]{2,}", options);
            var cleanStr = regex.Replace(duration, " ");

            var durationElements = cleanStr.Split(' ');

            if (Array.Exists(durationElements, x => x.Contains("month")))
            {
                var months = int.Parse(durationElements[0]);

                if (durationElements.Contains("-") && Array.Exists(durationElements, x => x.Contains("day")))
                {
                    // for now assume the number of days is irrelevant as it should never go back more than 1 month, so no calc required.
                    months -= 1;
                }

                return(new CollectionPeriod
                {
                    AcademicYear = aimStartDate.AcademicYear, Period = (byte)(startPeriod + months - 1)
                });
            }

            return(aimStartDate);
        }
        public void CreatePayment(Guid pendingPaymentId, CollectionPeriod collectionPeriod)
        {
            var pendingPayment = GetPendingPayment(pendingPaymentId);

            if (!pendingPayment.IsValidated(collectionPeriod))
            {
                return;
            }

            var paymentDate = DateTime.Today;

            var existingPayment = Model.PaymentModels.SingleOrDefault(x => x.PendingPaymentId == pendingPaymentId);

            if (existingPayment != null)
            {
                existingPayment.CalculatedDate = paymentDate;
                existingPayment.PaymentPeriod  = collectionPeriod.PeriodNumber;
                existingPayment.PaymentYear    = collectionPeriod.AcademicYear;
                existingPayment.SubnominalCode = DetermineSubnominalCode();
                existingPayment.Amount         = pendingPayment.Amount;
            }
            else
            {
                AddPayment(pendingPaymentId, collectionPeriod, pendingPayment, paymentDate);
            }

            pendingPayment.SetPaymentMadeDate(paymentDate);
        }
Exemplo n.º 3
0
 public ProviderPaymentEventMatcher(Provider provider, CollectionPeriod collectionPeriod, TestSession testSession, List <ProviderPayment> paymentSpec = null)
 {
     this.paymentSpec      = paymentSpec;
     this.provider         = provider;
     this.collectionPeriod = collectionPeriod;
     this.testSession      = testSession;
 }
        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, collectionPeriod, collectionPeriod);
            _sutModel.PaymentModels.First().PaidDate = DateTime.Now;

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

            _collectionPeriods.Add(activePeriod);

            // act
            _sutModel.StartDate = Incentive.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.PeriodNumber);
            clawback.CollectionPeriodYear.Should().Be(activePeriod.AcademicYear);
        }
Exemplo n.º 5
0
        public void Arrange()
        {
            _fixture = new Fixture();

            _collectionYear = _fixture.Create <short>();


            _collectionPeriod = new CollectionPeriod(1, _collectionYear);

            _accountLegalEntityId = _fixture.Create <long>();
            _account = Accounts.Account.Create(_fixture.Build <AccountModel>().Without(a => a.LegalEntityModels).Create());

            var startDate = DateTime.Now.Date;
            var dueDate   = startDate.AddDays(90).Date;

            _sutModel = _fixture
                        .Build <ApprenticeshipIncentiveModel>()
                        .With(a => a.Account, new Account(_account.Id, _accountLegalEntityId))
                        .With(a => a.StartDate, startDate)
                        .With(a => a.PendingPaymentModels, new List <PendingPaymentModel>()
            {
                _fixture.Build <PendingPaymentModel>()
                .With(p => p.DueDate, dueDate)
                .With(p => p.PendingPaymentValidationResultModels, new List <PendingPaymentValidationResultModel>())
                .With(p => p.Account, new Account(_account.Id, _accountLegalEntityId))
                .Create()
            })
                        .Create();

            _sutModel.Apprenticeship.SetProvider(_fixture.Create <Provider>());

            _sut = Sut(_sutModel);
        }
 public EarningFailedDataLockMatcher(Provider provider, TestSession testSession, CollectionPeriod collectionPeriod, IList <DataLockError> expectedDataLockErrorsSpec)
 {
     this.expectedDataLockErrorsSpec = expectedDataLockErrorsSpec;
     this.provider         = provider;
     this.testSession      = testSession;
     this.collectionPeriod = collectionPeriod;
 }
Exemplo n.º 7
0
        public void Reports_dash_for_absent_pause_datalock([Frozen] CollectionPeriod period, PauseDateDataLockRowModel sut)
        {
            period.DataLocks.Clear();

            sut.IsLocked.Should().BeFalse();
            sut.ActiveDataLock.Should().Be("-");
        }
        public void SetDaysInLearning(CollectionPeriod collectionPeriod)
        {
            var censusDate = collectionPeriod.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(collectionPeriod.PeriodNumber, collectionPeriod.AcademicYear, days);
            var existing       = Model.DaysInLearnings.SingleOrDefault(d => d.CollectionPeriodNumber == collectionPeriod.PeriodNumber && d.CollectionYear == collectionPeriod.AcademicYear);

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

            Model.DaysInLearnings.Add(daysInLearning);
        }
 private bool AllPendingPaymentsForPeriodAreValid(CollectionPeriod collectionPeriod)
 {
     return(Model.PendingPaymentValidationResultModels
            .Where(v =>
                   v.CollectionPeriod == collectionPeriod)
            .All(r => r.Result));
 }
Exemplo n.º 10
0
        public void Arrange()
        {
            _fixture = new Fixture();

            _collectionYear = _fixture.Create <short>();

            _collectionPeriod = new CollectionPeriod(1, _collectionYear);

            _fixture.Build <PendingPaymentModel>().With(p => p.PendingPaymentValidationResultModels, new List <PendingPaymentValidationResultModel>()).Create();

            _sutModel = _fixture
                        .Build <ApprenticeshipIncentiveModel>()
                        .With(a => a.PendingPaymentModels, new List <PendingPaymentModel>()
            {
                _fixture.Build <PendingPaymentModel>().With(p => p.PendingPaymentValidationResultModels, new List <PendingPaymentValidationResultModel>()).Create()
            })
                        .Create();

            _sutModel.Apprenticeship.SetProvider(_fixture.Create <Provider>());

            _learner = Learner.New(
                Guid.NewGuid(),
                _sutModel.Id,
                _sutModel.Apprenticeship.Id,
                _sutModel.Apprenticeship.Provider.Ukprn,
                _sutModel.Apprenticeship.UniqueLearnerNumber);

            var submisssionData = new SubmissionData();

            submisssionData.SetSubmissionDate(DateTime.Now);
            _learner.SetSubmissionData(submisssionData);

            _sut = Sut(_sutModel);
        }
Exemplo n.º 11
0
        public CollectionPeriod Build()
        {
            short academicYear;

            if (Month < 8)
            {
                academicYear = (short)((Year - 2000 - 1) * 100 + (Year - 2000));
            }
            else
            {
                academicYear = (short)((Year - 2000) * 100 + (Year - 2000 + 1));
            }

            if (Period == byte.MaxValue)
            {
                if (Month < 8)
                {
                    Period = (byte)(Month + 5);
                }
                else
                {
                    Period = (byte)(Month - 7);
                }
            }

            var instance = new CollectionPeriod
            {
                AcademicYear = academicYear,
                Period       = Period,
            };

            return(instance);
        }
 public DataLockRowModel(
     CollectionPeriod period,
     string heading,
     Func <DataMatch, object?> value)
     : this(period, 0, heading, value)
 {
 }
        public async Task PerformMonthEndTrigger(CollectionPeriod collectionPeriod)
        {
            logger.LogVerbose($"Triggering month end flag for {collectionPeriod}");
            await legacyPaymentsRepository.WriteMonthEndTrigger(collectionPeriod);

            logger.LogVerbose($"Completed month end flag set for {collectionPeriod}");
        }
Exemplo n.º 14
0
        public async Task <IHttpActionResult> GetTransfers(string periodId = null, long?senderAccountId = null, long?receiverAccountId = null, int page = 1)
        {
            try
            {
                CollectionPeriod period = null;
                if (!string.IsNullOrEmpty(periodId))
                {
                    period = await GetPeriodAsync(periodId).ConfigureAwait(false);

                    if (period == null)
                    {
                        return(Ok(new PageOfResults <AccountTransfer>
                        {
                            PageNumber = page,
                            TotalNumberOfPages = 0,
                            Items = new AccountTransfer[0]
                        }));
                    }
                }

                var transfersQueryResponse = await GetTransfersInternal(senderAccountId, receiverAccountId, page, period).ConfigureAwait(false);

                return(Ok(transfersQueryResponse.Result));
            }
            catch (ValidationException ex)
            {
                return(BadRequest(ex.Message));
            }
            catch (Exception ex)
            {
                _logger.Error(ex, ex.Message);
                return(InternalServerError());
            }
        }
Exemplo n.º 15
0
        public void ValidatePaymentsNotPaused(Guid pendingPaymentId, CollectionPeriod collectionPeriod)
        {
            var pendingPayment = GetPendingPaymentForValidationCheck(pendingPaymentId);

            var isValid = !Model.PausePayments;

            pendingPayment.AddValidationResult(PendingPaymentValidationResult.New(Guid.NewGuid(), collectionPeriod, ValidationStep.PaymentsNotPaused, isValid));
        }
Exemplo n.º 16
0
 private void ClawbackAllPayments(CollectionPeriod collectionPeriod)
 {
     RemoveUnpaidEarnings();
     foreach (var paidPendingPayment in PendingPayments)
     {
         AddClawback(paidPendingPayment, collectionPeriod);
     }
 }
Exemplo n.º 17
0
 public List <PaymentModel> GetPayments(long ukprn, CollectionPeriod collectionPeriod)
 {
     return(dataContext.Payment
            .Where(x => x.Ukprn == ukprn &&
                   x.CollectionPeriod.Period == collectionPeriod.Period &&
                   x.CollectionPeriod.AcademicYear == collectionPeriod.AcademicYear)
            .ToList());
 }
Exemplo n.º 18
0
 public PayableEarningEventMatcher(Provider provider, IList <Earning> earningSpecs, TestSession testSession, CollectionPeriod collectionPeriod, IList <FM36Learner> learnerSpecs)
 {
     this.provider         = provider;
     this.earningSpecs     = earningSpecs;
     this.testSession      = testSession;
     this.collectionPeriod = collectionPeriod;
     this.learnerSpecs     = learnerSpecs;
 }
Exemplo n.º 19
0
        public void Copes_with_null_apprenticeship(CollectionPeriod period)
        {
            period.Apprenticeship = null;

            var sut = new DataLockRowModel(period, "", m => m.Cost);

            sut.ApprenticeValue.Should().Be("-");
        }
Exemplo n.º 20
0
        public void Reports_not_resumed(CollectionPeriod period)
        {
            period.Apprenticeship.ResumedOn = null;

            var sut = new PauseDateDataLockRowModel(period, DataLock.Dlock12, "");

            sut.ResumedOnDate.Should().Be("Present");
        }
 private void AssertPeriodForDomainObject(CollectionPeriod period, PeriodEnd periodEnd)
 {
     Assert.AreEqual(period.Id, period.Id);
     Assert.AreEqual(period.CalendarMonth, periodEnd.CalendarPeriod.Month);
     Assert.AreEqual(period.CalendarYear, periodEnd.CalendarPeriod.Year);
     Assert.AreEqual(period.AccountDataValidAt, periodEnd.ReferenceData.AccountDataValidAt);
     Assert.AreEqual(period.CommitmentDataValidAt, periodEnd.ReferenceData.CommitmentDataValidAt);
     Assert.AreEqual(period.CompletionDateTime, periodEnd.CompletionDateTime);
 }
Exemplo n.º 22
0
 public async Task <List <PaymentModel> > GetMonthEndPayments(CollectionPeriod collectionPeriod, long ukprn,
                                                              CancellationToken cancellationToken = default(CancellationToken))
 {
     return(await paymentsDataContext.Payment
            .Where(p => p.Ukprn == ukprn &&
                   p.CollectionPeriod.Period == collectionPeriod.Period &&
                   p.CollectionPeriod.AcademicYear == collectionPeriod.AcademicYear)
            .ToListAsync(cancellationToken));
 }
Exemplo n.º 23
0
        public void Reports_dash_for_absent_datalock(CollectionPeriod period)
        {
            period.DataLocks.Clear();

            var sut = new DataLockRowModel(period, DataLock.Dlock01, "", _ => null);

            sut.IsLocked.Should().BeFalse();
            sut.ActiveDataLock.Should().Be("-");
        }
Exemplo n.º 24
0
        public void Extracts_values_from_correct_datamatch(CollectionPeriod period)
        {
            period.Apprenticeship.Cost.Should().NotBe(period.Ilr.Cost);

            var sut = new DataLockRowModel(period, "", m => m.Cost);

            sut.ApprenticeValue.Should().Be(period.Apprenticeship.Cost.ToString());
            sut.IlrValue.Should().Be(period.Ilr.Cost.ToString());
        }
Exemplo n.º 25
0
        public void Reports_not_paused(CollectionPeriod period)
        {
            period.Apprenticeship.PausedOn = null;

            var sut = new PauseDateDataLockRowModel(period, DataLock.Dlock12, "");

            sut.HasPausedDate.Should().BeFalse();
            sut.PausedOnDate.Should().BeNull();
        }
 public List <PaymentModel> GetPayments(long ukprn, CollectionPeriod collectionPeriod)
 {
     using (dataContext.Database.BeginTransaction(IsolationLevel.ReadUncommitted))
         return(dataContext.Payment
                .Where(x => x.Ukprn == ukprn &&
                       x.CollectionPeriod.Period == collectionPeriod.Period &&
                       x.CollectionPeriod.AcademicYear == collectionPeriod.AcademicYear)
                .ToList());
 }
Exemplo n.º 27
0
 public PendingPaymentValidationResult(
     string validationStep,
     bool validationResult,
     CollectionPeriod collectionPeriod)
 {
     ValidationStep   = validationStep;
     ValidationResult = validationResult;
     CollectionPeriod = collectionPeriod;
 }
Exemplo n.º 28
0
        public void Reports_pause_datalock_name(CollectionPeriod period)
        {
            var datalock = period.DataLocks[0];

            var sut = new PauseDateDataLockRowModel(period, datalock, "");

            sut.IsLocked.Should().BeTrue();
            sut.ActiveDataLock.Should().Be(datalock.ToString());
        }
 public CompletionPaymentHeldBackEventMatcher(
     Provider provider,
     CollectionPeriod collectionPeriod,
     List <Payment> paymentSpec)
 {
     this.provider         = provider;
     this.collectionPeriod = collectionPeriod;
     this.paymentSpec      = paymentSpec;
 }
 public RequiredPaymentEventMatcher(Provider provider,
                                    CollectionPeriod collectionPeriod,
                                    List <Payment> paymentSpec,
                                    List <Training> currentIlr,
                                    List <Price> currentPriceEpisodes) : this(provider, collectionPeriod)
 {
     this.paymentSpec          = paymentSpec;
     this.currentIlr           = currentIlr;
     this.currentPriceEpisodes = currentPriceEpisodes;
 }