Beispiel #1
0
        private IEnumerable <DataColumn> ProfilePeriodColumns(ProfilePeriodPattern profile)
        {
            string profilePrefix = $"{profile.Period}_{profile.PeriodType}_{profile.PeriodYear}_{profile.Occurrence}";

            return(new[]
            {
                NewDataColumn <string>($"{profilePrefix}_Period", 64, true),
                NewDataColumn <string>($"{profilePrefix}_PeriodType", 64, true),
                NewDataColumn <string>($"{profilePrefix}_Year", 64, true),
                NewDataColumn <string>($"{profilePrefix}_Occurence", 64, true),
                NewDataColumn <string>($"{profilePrefix}_DistributionPeriod", 64, true),
                NewDataColumn <string>($"{profilePrefix}_Value", allowNull: true)
            });
        }
        public async Task GetFutureInstallments_Returns_Empty_Result_Given_No_Future_ProfilePatterns_Within_The_Retrieved_ProfilePatterns_ForFundingStream_And_FundingPeriod()
        {
            ProfilePeriodPattern profilePeriodPatternInThePast = new ProfilePeriodPattern
            {
                DistributionPeriod = $"FY-{DateTime.Now.AddYears(-1).Year}",
                Occurrence         = 1,
                Period             = DateTime.Now.AddYears(-1).ToString("MMMM"),
                PeriodStartDate    = DateTime.Now.AddYears(-1),
                PeriodEndDate      = DateTime.Now.AddYears(-1).AddMonths(1),
                PeriodType         = PeriodType.CalendarMonth,
                PeriodYear         = DateTime.Now.AddYears(-1).Year
            };

            _profilingApiClient.Setup(_ =>
                                      _.GetProfilePatternsForFundingStreamAndFundingPeriod(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(new ApiResponse <IEnumerable <FundingStreamPeriodProfilePattern> >(HttpStatusCode.OK,
                                                                                             new List <FundingStreamPeriodProfilePattern>
            {
                new FundingStreamPeriodProfilePattern
                {
                    FundingPeriodId              = ValidFundingPeriodId,
                    FundingStreamId              = ValidFundingStreamId,
                    FundingStreamPeriodEndDate   = DateTime.Now,
                    FundingStreamPeriodStartDate = DateTime.Now,
                    ProfilePattern = new[]
                    {
                        profilePeriodPatternInThePast
                    },
                    ProfilePatternKey = null
                }
            }));

            IActionResult actionResult = await _profilingController.GetFutureInstallments(
                ValidFundingStreamId,
                ValidFundingPeriodId);

            actionResult.Should().BeAssignableTo <OkObjectResult>();
            List <ProfilingInstallment> futureInstallmentsResult = actionResult.As <OkObjectResult>().Value.As <List <ProfilingInstallment> >();

            futureInstallmentsResult.Should().NotBeNull();
            futureInstallmentsResult.Count.Should().Be(0);
        }
        public async Task GetFutureInstallments_Returns_OK_Result_Given_fundingStream_and_fundingPeriod_Ids()
        {
            ProfilePeriodPattern profilePeriodPatternInThePast = new ProfilePeriodPattern
            {
                DistributionPeriod = $"FY-{DateTime.Now.AddYears(-1).Year}",
                Occurrence         = 1,
                Period             = DateTime.Now.AddYears(-1).ToString("MMMM"),
                PeriodStartDate    = DateTime.Now.AddYears(-1),
                PeriodEndDate      = DateTime.Now.AddYears(-1).AddMonths(1),
                PeriodType         = PeriodType.CalendarMonth,
                PeriodYear         = DateTime.Now.AddYears(-1).Year
            };
            ProfilePeriodPattern profilePeriodPatternInTheCurrentTime = new ProfilePeriodPattern
            {
                DistributionPeriod = $"FY-{DateTime.Now.Year}",
                Occurrence         = 1,
                Period             = DateTime.Now.ToString("MMMM"),
                PeriodStartDate    = DateTime.Now,
                PeriodEndDate      = DateTime.Now.AddMonths(1),
                PeriodType         = PeriodType.CalendarMonth,
                PeriodYear         = DateTime.Now.Year
            };
            ProfilePeriodPattern profilePeriodPatternInTheFuture = new ProfilePeriodPattern
            {
                DistributionPeriod = $"FY-{DateTime.Now.AddYears(1).Year}",
                Occurrence         = 2,
                Period             = DateTime.Now.AddYears(1).ToString("MMMM"),
                PeriodStartDate    = DateTime.Now.AddYears(1),
                PeriodEndDate      = DateTime.Now.AddYears(1).AddMonths(1),
                PeriodType         = PeriodType.CalendarMonth,
                PeriodYear         = DateTime.Now.AddYears(1).Year
            };
            List <ProfilingInstallment> expectedFutureInstallments = new List <ProfilingInstallment>
            {
                new ProfilingInstallment(
                    profilePeriodPatternInTheFuture.PeriodYear,
                    profilePeriodPatternInTheFuture.Period,
                    profilePeriodPatternInTheFuture.Occurrence,
                    0)
            };

            _profilingApiClient.Setup(_ =>
                                      _.GetProfilePatternsForFundingStreamAndFundingPeriod(It.IsAny <string>(), It.IsAny <string>()))
            .ReturnsAsync(new ApiResponse <IEnumerable <FundingStreamPeriodProfilePattern> >(HttpStatusCode.OK,
                                                                                             new List <FundingStreamPeriodProfilePattern>
            {
                new FundingStreamPeriodProfilePattern
                {
                    FundingPeriodId              = ValidFundingPeriodId,
                    FundingStreamId              = ValidFundingStreamId,
                    FundingStreamPeriodEndDate   = new DateTime(2021, 3, 31),
                    FundingStreamPeriodStartDate = new DateTime(2020, 4, 1),
                    ProfilePattern = new[]
                    {
                        profilePeriodPatternInThePast,
                        profilePeriodPatternInTheCurrentTime,
                        profilePeriodPatternInTheFuture
                    },
                    ProfilePatternKey = null
                }
            }));

            IActionResult actionResult = await _profilingController.GetFutureInstallments(
                ValidFundingStreamId,
                ValidFundingPeriodId);

            actionResult.Should().BeAssignableTo <OkObjectResult>();
            List <ProfilingInstallment> futureInstallmentsResult = actionResult.As <OkObjectResult>().Value.As <List <ProfilingInstallment> >();

            futureInstallmentsResult.Should().BeEquivalentTo(expectedFutureInstallments);
        }
Beispiel #4
0
        private IReadOnlyCollection <DeliveryProfilePeriod> ApplyProfilePattern(
            decimal fundingValue,
            IReadOnlyCollection <ProfilePeriodPattern> profilePattern,
            IReadOnlyCollection <DeliveryProfilePeriod> profilePeriods,
            RoundingStrategy roundingStrategy)
        {
            List <DeliveryProfilePeriod> calculatedDeliveryProfile = new List <DeliveryProfilePeriod>();

            if (profilePeriods.Any())
            {
                decimal allocationValueToBeProfiled = Convert.ToDecimal(fundingValue);
                decimal runningTotal = 0;

                List <DeliveryProfilePeriod> profiledValues = profilePeriods.Select(pp =>
                {
                    ProfilePeriodPattern profilePeriodPattern = profilePattern.Single(
                        pattern => string.Equals(pattern.Period, pp.TypeValue) &&
                        string.Equals(pattern.DistributionPeriod, pp.DistributionPeriod) &&
                        pattern.PeriodYear == pp.Year &&
                        pattern.Occurrence == pp.Occurrence);

                    decimal profilePercentage = profilePeriodPattern
                                                .PeriodPatternPercentage;

                    decimal profiledValue = profilePercentage * allocationValueToBeProfiled;
                    if (profiledValue != 0)
                    {
                        profiledValue /= 100;
                    }

                    decimal roundedValue;


                    if (roundingStrategy == RoundingStrategy.RoundUp)
                    {
                        roundedValue = profiledValue
                                       .RoundToDecimalPlaces(2)
                                       .RoundToDecimalPlaces(0);
                    }
                    else
                    {
                        roundedValue = (int)profiledValue;
                    }

                    if (runningTotal + roundedValue > allocationValueToBeProfiled)
                    {
                        roundedValue = allocationValueToBeProfiled - runningTotal;
                    }

                    runningTotal += roundedValue;

                    return(pp.WithValue(roundedValue));
                }).ToList();

                DeliveryProfilePeriod last = profiledValues.Last();

                IEnumerable <DeliveryProfilePeriod> withoutLast = profiledValues.Take(profiledValues.Count - 1).ToList();

                calculatedDeliveryProfile.AddRange(
                    withoutLast.Append(
                        last.WithValue(allocationValueToBeProfiled - withoutLast.Sum(cdp => cdp.ProfileValue))));
            }

            return(calculatedDeliveryProfile);
        }
Beispiel #5
0
 private int GetProfilePeriodPatternHash(ProfilePeriodPattern profilePeriodPattern)
 => HashCode.Combine(profilePeriodPattern?.PeriodYear,
                     profilePeriodPattern?.Period,
                     profilePeriodPattern?.Occurrence);