コード例 #1
0
        private static IList <FcsContractAllocation> GetContractAllocation()
        {
            var fcsContractAllocations = new List <FcsContractAllocation>();
            var fundingStreams         = GetFundingTypes().SelectMany(ft => ft.FundingStreams);

            foreach (var item in fundingStreams)
            {
                if (!fcsContractAllocations.Any(f => f.FundingStreamPeriodCode == item.PeriodCode))
                {
                    FcsContractAllocation allocation1 = new FcsContractAllocation()
                    {
                        ContractAllocationNumber = $"Alloc{item.PeriodCode}-1",
                        FundingStreamPeriodCode  = item.PeriodCode,
                        ContractStartDate        = 20180101,
                        DeliveryUkprn            = ukprn,
                        DeliveryOrganisation     = $"Org{ukprn}",
                    };
                    fcsContractAllocations.Add(allocation1);

                    FcsContractAllocation allocation2 = new FcsContractAllocation()
                    {
                        ContractAllocationNumber = $"Alloc{item.PeriodCode}-2",
                        FundingStreamPeriodCode  = item.PeriodCode,
                        ContractStartDate        = 20180128,
                        DeliveryUkprn            = ukprn,
                        DeliveryOrganisation     = $"Org{ukprn}",
                    };
                    fcsContractAllocations.Add(allocation2);
                }
            }

            return(fcsContractAllocations);
        }
        public void Summarise_FundingStreams()
        {
            List <FundingStream> fundingStreams = GetFundingTypes()
                                                  .Where(w => w.SummarisationType == "ESF_ILR_And_Supp")
                                                  .SelectMany(ft => ft.FundingStreams).ToList();

            int ukprn = GetProviders().First();

            FcsContractAllocation allocation = GetContractAllocation(ukprn);

            var task = new SummarisationDeliverableProcess();

            var result = task.Summarise(fundingStreams, GetTestProvider(ukprn), allocation, GetCollectionPeriods());

            result.Count(w => w.DeliverableCode == 1).Should().Be(12);

            result.Count(w => w.DeliverableCode == 4).Should().Be(12);

            result.Count(w => w.DeliverableCode == 18).Should().Be(12);

            foreach (var item in result.Where(w => w.DeliverableCode == 1 || w.DeliverableCode == 4 || w.DeliverableCode == 18))
            {
                item.ActualValue.Should().Be(100);

                var fl = fundingStreams.Where(s => s.DeliverableLineCode == item.DeliverableCode).Select(s => s.DeliverableLines).FirstOrDefault();

                item.ActualVolume.Should().Be(fl.FirstOrDefault()?.CalculateVolume == true ? 100 : 0);
            }
        }
 private FCSContractAllocation MapFCSContractAllocation(FcsContractAllocation fcsContractAllocation)
 {
     return(new FCSContractAllocation
     {
         ContractAllocationNumber = fcsContractAllocation.ContractAllocationNumber,
         ContractStartDate = fcsContractAllocation.StartDate,
         ContractEndDate = fcsContractAllocation.EndDate,
         FundingStreamPeriodCode = fcsContractAllocation.FundingStreamPeriodCode,
         LearningRatePremiumFactor = fcsContractAllocation.LearningRatePremiumFactor,
         TenderSpecReference = fcsContractAllocation.TenderSpecReference,
         LotReference = fcsContractAllocation.LotReference,
         CalcMethod = fcsContractAllocation.EsfEligibilityRule?.CalcMethod,
         FCSContractDeliverables = fcsContractAllocation.FCSContractDeliverables?
                                   .Select(cd =>
                                           new FCSContractDeliverable
         {
             DeliverableCode = cd.DeliverableCode,
             DeliverableDescription = cd.DeliverableDescription,
             PlannedValue = cd.PlannedValue,
             PlannedVolume = cd.PlannedVolume,
             UnitCost = cd.UnitCost,
             ExternalDeliverableCode = cd.ExternalDeliverableCode
         }).ToList()
     });
 }
        private IReadOnlyDictionary <string, IReadOnlyCollection <IFcsContractAllocation> > GetContractAllocations(HashSet <string> fspCodes)
        {
            Dictionary <string, IReadOnlyCollection <IFcsContractAllocation> > fspContractAllocations = new Dictionary <string, IReadOnlyCollection <IFcsContractAllocation> >();

            if (fspCodes == null)
            {
                fspCodes = GetFundingStreamPeriodCodes();
            }

            foreach (var fspCode in fspCodes)
            {
                List <IFcsContractAllocation> allocations = new List <IFcsContractAllocation>();

                foreach (var ukprn in GetTestProviders())
                {
                    var fcsContractAllocation = new FcsContractAllocation
                    {
                        ContractAllocationNumber = $"Alloc{ukprn}",
                        DeliveryUkprn            = ukprn,
                        DeliveryOrganisation     = $"Org{ukprn}",
                        FundingStreamPeriodCode  = fspCode
                    };

                    allocations.Add(fcsContractAllocation);
                }

                fspContractAllocations.Add(fspCode, allocations);
            }

            return(fspContractAllocations);
        }
コード例 #5
0
        private static FcsContractAllocation GetContractAllocation(int ukprn)
        {
            FcsContractAllocation allocation = new FcsContractAllocation()
            {
                ContractAllocationNumber = $"All{ukprn}-1",
                FundingStreamPeriodCode  = "ESF1420",
                DeliveryUkprn            = ukprn,
                DeliveryOrganisation     = $"Org{ukprn}",
                ActualsSchemaPeriodStart = 201601,
                ActualsSchemaPeriodEnd   = 202107,
            };

            return(allocation);
        }
        public void Summarise_Providers()
        {
            List <FundingStream> fundingStreams = GetFundingTypes()
                                                  .Where(w => w.SummarisationType == "ESF_ILR_And_Supp")
                                                  .SelectMany(ft => ft.FundingStreams).ToList();

            foreach (var ukprn in GetProviders())
            {
                ICollection <FcsContractAllocation> fcsContractAllocations = new List <FcsContractAllocation>();

                for (int i = 1; i <= Contracts; i++)
                {
                    FcsContractAllocation allocation = new FcsContractAllocation()
                    {
                        ContractAllocationNumber = $"All{ukprn}-{i}",
                        FundingStreamPeriodCode  = "ESF1420",
                        DeliveryUkprn            = ukprn,
                        DeliveryOrganisation     = $"Org{ukprn}",
                        ActualsSchemaPeriodStart = 201808,
                        ActualsSchemaPeriodEnd   = 201907,
                    };

                    fcsContractAllocations.Add(allocation);
                }

                var summarisationMessageMock = new Mock <ISummarisationMessage>();

                var task = new SummarisationDeliverableProcess();

                var result = task.Summarise(fundingStreams, GetTestProvider(ukprn), fcsContractAllocations, GetCollectionPeriods(), summarisationMessageMock.Object);

                foreach (var allocation in fcsContractAllocations)
                {
                    result.Count(w => w.ContractAllocationNumber == allocation.ContractAllocationNumber && w.DeliverableCode == 1).Should().Be(12);

                    result.Count(w => w.ContractAllocationNumber == allocation.ContractAllocationNumber && w.DeliverableCode == 4).Should().Be(12);

                    result.Count(w => w.ContractAllocationNumber == allocation.ContractAllocationNumber && w.DeliverableCode == 18).Should().Be(12);

                    foreach (var item in result.Where(w => w.DeliverableCode == 1 || w.DeliverableCode == 4 || w.DeliverableCode == 18))
                    {
                        item.ActualValue.Should().Be(100);

                        var fl = fundingStreams.Where(s => s.DeliverableLineCode == item.DeliverableCode).Select(s => s.DeliverableLines).FirstOrDefault();

                        item.ActualVolume.Should().Be(fl?.FirstOrDefault()?.CalculateVolume == true ? 100 : 0);
                    }
                }
            }
        }
        private static IList <FcsContractAllocation> GetContractAllocation()
        {
            IList <FcsContractAllocation> fcsContractAllocations = new List <FcsContractAllocation>();
            var fundingStreams = GetFundingTypes().SelectMany(ft => ft.FundingStreams);

            foreach (var item in fundingStreams)
            {
                if (!fcsContractAllocations.Any(f => f.FundingStreamPeriodCode == item.PeriodCode))
                {
                    FcsContractAllocation allocation1 = new FcsContractAllocation()
                    {
                        ContractAllocationNumber = $"Alloc{item.PeriodCode}-1",
                        FundingStreamPeriodCode  = item.PeriodCode,
                        ActualsSchemaPeriodStart = 201901,
                        DeliveryUkprn            = ukprn,
                        DeliveryOrganisation     = $"Org{ukprn}",
                        ContractStartDate        = 20190101,
                        ContractEndDate          = 20200101
                    };
                    fcsContractAllocations.Add(allocation1);

                    FcsContractAllocation allocation2 = new FcsContractAllocation()
                    {
                        ContractAllocationNumber = $"Alloc{item.PeriodCode}-2",
                        FundingStreamPeriodCode  = item.PeriodCode,
                        ActualsSchemaPeriodStart = 202001,
                        DeliveryUkprn            = ukprn,
                        DeliveryOrganisation     = $"Org{ukprn}",
                        ContractStartDate        = 20200102,
                        ContractEndDate          = 99991231
                    };
                    fcsContractAllocations.Add(allocation2);

                    FcsContractAllocation allocation3 = new FcsContractAllocation()
                    {
                        ContractAllocationNumber = $"Alloc{item.PeriodCode}-3",
                        FundingStreamPeriodCode  = item.PeriodCode,
                        ActualsSchemaPeriodStart = 202001,
                        DeliveryUkprn            = ukprn,
                        DeliveryOrganisation     = $"Org{ukprn}",
                        ContractStartDate        = 20200102,
                        ContractEndDate          = 20201002
                    };
                    fcsContractAllocations.Add(allocation3);
                }
            }

            return(fcsContractAllocations);
        }
        public ICollection <SummarisedActual> SummarisePeriods(ICollection <Period> periods, DeliverableLine fundLine, ICollection <CollectionPeriod> collectionPeriods, FcsContractAllocation allocation)
        {
            if (periods.All(p => (p.Value == 0 && p.Volume == 0)))
            {
                return(Array.Empty <SummarisedActual>());
            }

            var filteredCollectonPeriods = collectionPeriods.Where(cp => cp.ActualsSchemaPeriod >= allocation.ActualsSchemaPeriodStart && cp.ActualsSchemaPeriod <= allocation.ActualsSchemaPeriodEnd);

            var summarisedPeriods = periods
                                    .GroupBy(g => new { g.CalendarYear, g.CalendarMonth })
                                    .Select(pg => new
            {
                CalendarYear  = pg.Key.CalendarYear,
                CalendarMonth = pg.Key.CalendarMonth,
                ActualValue   = pg.Where(w => w.Value.HasValue).Sum(sw => sw.Value.Value),
                ActualVolume  = fundLine.CalculateVolume ? pg.Where(w => w.Volume.HasValue).Sum(sw => sw.Volume.Value) : 0
            }).ToList();

            return((filteredCollectonPeriods
                    .GroupJoin(summarisedPeriods,
                               cp => new { cp.CalendarYear, cp.CalendarMonth },
                               p => new { p.CalendarYear, p.CalendarMonth },
                               (cp, p) => new { Period = p, CollectionPeriod = cp }
                               )).SelectMany(grp => grp.Period.DefaultIfEmpty(), (outGrp, outPeriod) => new
            {
                ActualsSchemaPeriod = outGrp.CollectionPeriod.ActualsSchemaPeriod,
                ActualValue = outPeriod == null ? decimal.Zero : outPeriod.ActualValue,
                ActualVolume = outPeriod == null ? 0 : outPeriod.ActualVolume,
            })
                   .GroupBy(pg => pg.ActualsSchemaPeriod)
                   .Select(g => new SummarisedActual
            {
                Period = g.Key,
                ActualValue = g.Sum(sw => sw.ActualValue),
                ActualVolume = g.Sum(sw => sw.ActualVolume),
            }).ToList());
        }
        public ICollection <SummarisedActual> Summarise(FundingStream fundingStream, LearningProvider provider, FcsContractAllocation allocation, ICollection <CollectionPeriod> collectionPeriods)
        {
            var summarisedActuals = new List <SummarisedActual>();

            foreach (var fundLine in fundingStream.DeliverableLines)
            {
                var periodisedData = provider
                                     .LearningDeliveries
                                     .Where(ld => ld.ConRefNumber != null && ld.ConRefNumber.Trim().Equals(allocation.ContractAllocationNumber, StringComparison.OrdinalIgnoreCase))
                                     .SelectMany(x => x.PeriodisedData.Where(w => w.DeliverableCode == fundLine.DeliverableCode));

                var periods = GetPeriodsForFundLine(periodisedData, fundLine);

                summarisedActuals.AddRange(SummarisePeriods(periods, fundLine, collectionPeriods, allocation));
            }

            return(summarisedActuals
                   .GroupBy(grp => grp.Period)
                   .Select(g =>
                           new SummarisedActual
            {
                OrganisationId = allocation.DeliveryOrganisation,
                DeliverableCode = fundingStream.DeliverableLineCode,
                FundingStreamPeriodCode = fundingStream.PeriodCode,
                Period = g.Key,
                ActualValue = Math.Round(g.Sum(x => x.ActualValue), 2),
                ActualVolume = g.Sum(x => x.ActualVolume),
                ContractAllocationNumber = allocation.ContractAllocationNumber,
                PeriodTypeCode = PeriodTypeCodeConstants.CalendarMonth
            }).ToList());
        }
        public ICollection <SummarisedActual> Summarise(ICollection <FundingStream> fundingStreams, LearningProvider provider, FcsContractAllocation allocation, ICollection <CollectionPeriod> collectionPeriods)
        {
            var summarisedActuals = new List <SummarisedActual>();

            foreach (var fundingStream in fundingStreams)
            {
                var fundingStreamSummarisedActuals = Summarise(fundingStream, provider, allocation, collectionPeriods);

                summarisedActuals.AddRange(fundingStreamSummarisedActuals);
            }

            return(summarisedActuals);
        }