public async Task <int> GetDraftPayRunCount(PayrunType payRunType)
 {
     return(await _dbContext.Payruns.Where(pr =>
                                           pr.Type.Equals(payRunType) &&
                                           pr.Status == PayrunStatus.Draft)
            .CountAsync());
 }
        public async Task <ActionResult <DateTimeOffset> > GetPreviousPayRunEndDate(
            [FromServices] IGetEndDateOfLastPayRunUseCase useCase, PayrunType type)
        {
            var res = await useCase.GetAsync(type);

            return(Ok(res));
        }
        public async Task <Payrun> GetPreviousPayRunAsync(PayrunType payRunType)
        {
            var previousPayRun = await _dbContext.Payruns.Where(pr => pr.Type.Equals(payRunType)).TrackChanges(false)
                                 .OrderByDescending(pr => pr.DateCreated)
                                 .Skip(1)
                                 .FirstOrDefaultAsync();

            return(previousPayRun);
        }
        public async Task <DateTimeOffset> GetEndDateOfLastPayRun(PayrunType payRunType)
        {
            var lastPayRun = await _dbContext.Payruns.Where(pr =>
                                                            pr.Type.Equals(payRunType) && pr.Status != PayrunStatus.Archived)
                             .OrderByDescending(pr => pr.PaidUpToDate)
                             .FirstOrDefaultAsync();

            return(lastPayRun?.PaidUpToDate ?? PayrunConstants.DefaultStartDate.AddDays(-1));
        }
예제 #5
0
        public async Task ShouldCreateDraftPayRun(PayrunType type)
        {
            ClearDatabase();
            var payRunCreationRequest = new DraftPayRunCreationRequest
            {
                Type         = type,
                PaidFromDate = _periodFrom,
                PaidUpToDate = _periodTo
            };
            var url      = $"api/v1/payruns";
            var response = await _fixture.RestClient.PostAsync <object>(url, payRunCreationRequest);

            response.Message.StatusCode.Should().Be(HttpStatusCode.OK);

            var payRuns = _fixture.DatabaseContext.Payruns.ToList();

            payRuns.Should().HaveCount(1);
            payRuns.First().Status.Should().Be(PayrunStatus.Draft);
        }
예제 #6
0
        public async void ShouldCreatePayRun(PayrunType type)
        {
            var newPayRun = new Payrun();

            _payRunGateway
            .Setup(g => g.CreateDraftPayRun(It.IsAny <Payrun>()))
            .Callback <Payrun>(payRun => newPayRun = payRun).Returns(Task.CompletedTask);
            var payRunCreationDomain = new DraftPayRunCreationDomain
            {
                Type         = type,
                PaidFromDate = _periodFrom,
                PaidUpToDate = _periodTo,
                StartDate    = _periodFrom
            };

            await _useCase.CreateDraftPayRun(payRunCreationDomain);

            newPayRun.Should().BeEquivalentTo(payRunCreationDomain, options =>
                                              options.ExcludingNestedObjects().ExcludingMissingMembers());
            newPayRun.Status.Should().Be(PayrunStatus.Draft);
            _dbManager.VerifySaved();
        }
예제 #7
0
 public async Task <DateTimeOffset> GetAsync(PayrunType type)
 {
     return(await _gateway.GetEndDateOfLastPayRun());
 }
        private static void ValidatePayRunDates(DateTimeOffset startDate, DateTimeOffset endDate, PayrunType payrunType)
        {
            if (startDate > endDate)
            {
                throw new ApiException(
                          $"Pay run dates invalid. Start date {startDate:yyyy-MM-dd} is greater that end date {endDate:yyyy-MM-dd}",
                          HttpStatusCode.UnprocessableEntity);
            }

            // Start and End Date can't be same if Pay Run Type is Residential Recurring
            if (startDate == endDate && payrunType == PayrunType.ResidentialRecurring)
            {
                throw new ApiException(
                          $"Pay run dates invalid. Pay run cannot start and end on the same day",
                          HttpStatusCode.UnprocessableEntity);
            }
        }