Пример #1
0
 public static IEnumerable <ContractProduct> ContractProducts(
     ContractAmendment previousContract,
     List <ContractProduct> contractProducts)
 {
     return(contractProducts.Where(
                x => x.ContractAmendmentId == previousContract.Id));
 }
Пример #2
0
 public static bool IsContractHasBothStartDateAndEndDate(
     ContractAmendment contract)
 {
     return(!string.IsNullOrEmpty(
                contract.StartDate.ToLongDateString()) &&
            contract.EndDate.HasValue);
 }
Пример #3
0
 public static List <SiteVolume> SiteVolumesForContract(
     ContractAmendment contract,
     List <SiteVolume> siteVolumes)
 {
     return(siteVolumes
            .Where(x => x.BillingMonth >= contract.StartDate &&
                   x.BillingMonth <= contract.EndDate).ToList());
 }
Пример #4
0
 public decimal TotalContractedVolume(ContractAmendment contract,
                                      List <ContractAmendment> contracts,
                                      List <ContractProduct> contractProducts,
                                      List <ContractProductSite> contractProductSites,
                                      List <SiteVolume> siteVolumes)
 {
     return(_calculator.TotalContractedVolume(contract,
                                              contracts, contractProducts, contractProductSites, siteVolumes));
 }
Пример #5
0
 PreviousContractForClient(
     ContractAmendment currentContract,
     IEnumerable <ContractAmendment> contracts)
 {
     return(contracts.FirstOrDefault(
                x => x.ClientId == currentContract.ClientId &&
                x.EndDate < currentContract.StartDate &&
                !x.Id.Equals(currentContract.Id)));
 }
Пример #6
0
 public static void NoProductAvailableForContract(ContractAmendment contract,
                                                  IEnumerable <ContractProduct> products)
 {
     if (contract == null)
     {
         throw new ArgumentNullException(nameof(contract));
     }
     if (products.All(product => product.ContractAmendmentId != contract.Id))
     {
         throw new Exception("No product available for the contract");
     }
 }
Пример #7
0
        ExpectedBillingMonthsForTheContract(ContractAmendment contract)
        {
            var startDate        = contract.StartDate;
            var endDate          = contract.EndDate;
            var monthsForTheYear = new List <Tuple <int, int> >();

            while (startDate <= endDate)
            {
                var month = startDate.Month;
                var year  = startDate.Year;
                startDate = startDate.AddMonths(1);
                monthsForTheYear.Add(new Tuple <int, int>(month, year));
            }
            return(monthsForTheYear);
        }
Пример #8
0
        public decimal TotalContractedVolume(
            ContractAmendment contract, List <ContractAmendment> contracts,
            List <ContractProduct> contractProducts,
            List <ContractProductSite> contractProductSites,
            List <SiteVolume> siteVolumes)
        {
            decimal total = 0;

            NoProductAvailableForContract(contract, contractProducts);
            NoSiteAvailableForProduct(contractProducts, contractProductSites);


            if (!IsVolumeAvailableForContractProductSite(contractProductSites,
                                                         siteVolumes))
            {
                return(total);
            }

            var siteVolumesForTheContract =
                SiteVolumesForContract(contract,
                                       siteVolumes);

            var expectedBillingMonths =
                ExpectedBillingMonthsForTheContract(contract);

            var actualBillingMonths =
                BillingMonths(siteVolumes);

            var missingBillingMonths =
                MissingBillingMonths(
                    expectedBillingMonths, actualBillingMonths);

            if (IsContractHasBothStartDateAndEndDate(contract) &&
                IsContractEndDateAfterStartDate(contract))
            {
                if (IsAllVolumesExistForTheContract(
                        missingBillingMonths))
                {
                    var groupedSiteVolumes =
                        GroupedSiteVolumes(siteVolumesForTheContract);

                    total =
                        TotalSiteVolume(groupedSiteVolumes);
                }
                else if (IsNoVolumeContract(siteVolumesForTheContract))
                {
                    var previousContract =
                        PreviousContractForClient(contract, contracts);

                    var previousProducts =
                        ContractProducts(previousContract,
                                         contractProducts);

                    var previousProductSites =
                        ProductSites(previousProducts,
                                     contractProductSites);

                    var previousSiteVolumes =
                        SiteVolumes(previousProductSites,
                                    siteVolumes);

                    var groupedPerviousSiteVolumes =
                        GroupedSiteVolumes(previousSiteVolumes);

                    total = TotalSiteVolume(groupedPerviousSiteVolumes);
                }
            }

            var contractHasSomeVolume =
                IsCurrentContractHasSomeVolume(contract, siteVolumes) &&
                IsContractHasStartDate(contract) &&
                !IsAllVolumesExistForTheContract(missingBillingMonths) &&
                !IsNoVolumeContract(siteVolumesForTheContract);

            if (!contractHasSomeVolume)
            {
                return(total);
            }
            {
                //calculate total contracted volume for the current contract
                var currentContractVolumes =
                    CurrentContractVolumes(contract, siteVolumes);

                var groupedCurrentContractVolume =
                    GroupedSiteVolumes(currentContractVolumes);

                var totalVolumeForCurrentContract =
                    TotalSiteVolume(groupedCurrentContractVolume);


                //calculate total contracted volume for the previous contract
                var previousContractForTheClient =
                    PreviousContractForClient(contract,
                                              contracts);

                var volumesForPreviousContract = SiteVolumesForContract(
                    previousContractForTheClient,
                    siteVolumes);

                var currentContractBillingMonths =
                    BillingMonths(
                        currentContractVolumes);


                var volumesExcludedCurrentBillingMonths =
                    VolumesExcludedCurrentContractBillingMonths(
                        currentContractBillingMonths, volumesForPreviousContract);


                var groupedPreviousContractVolumes =
                    GroupedSiteVolumes(volumesExcludedCurrentBillingMonths);

                var totalVolumePreviousContract =
                    TotalSiteVolume(
                        groupedPreviousContractVolumes);

                //sum up both current contract volume and previous contract volume totals
                total = totalVolumeForCurrentContract + totalVolumePreviousContract;
            }

            return(total);
        }
Пример #9
0
 public static bool IsContractHasStartDate(ContractAmendment contract)
 {
     return(!string.IsNullOrEmpty(
                contract.StartDate.ToString(CultureInfo.InvariantCulture)));
 }
Пример #10
0
 public static bool IsContractEndDateAfterStartDate(ContractAmendment contract)
 {
     return(contract.StartDate < contract.EndDate);
 }
Пример #11
0
 public static List <SiteVolume> CurrentContractVolumes(
     ContractAmendment currentContract, List <SiteVolume> siteVolumes)
 {
     return(siteVolumes
            .Where(x => x.BillingMonth >= currentContract.StartDate).ToList());
 }
Пример #12
0
 public static bool IsCurrentContractHasSomeVolume(
     ContractAmendment currentContract,
     List <SiteVolume> siteVolumes)
 {
     return(SiteVolumesForContract(currentContract, siteVolumes).Any());
 }