public static IEnumerable <ContractProduct> ContractProducts( ContractAmendment previousContract, List <ContractProduct> contractProducts) { return(contractProducts.Where( x => x.ContractAmendmentId == previousContract.Id)); }
public static bool IsContractHasBothStartDateAndEndDate( ContractAmendment contract) { return(!string.IsNullOrEmpty( contract.StartDate.ToLongDateString()) && contract.EndDate.HasValue); }
public static List <SiteVolume> SiteVolumesForContract( ContractAmendment contract, List <SiteVolume> siteVolumes) { return(siteVolumes .Where(x => x.BillingMonth >= contract.StartDate && x.BillingMonth <= contract.EndDate).ToList()); }
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)); }
PreviousContractForClient( ContractAmendment currentContract, IEnumerable <ContractAmendment> contracts) { return(contracts.FirstOrDefault( x => x.ClientId == currentContract.ClientId && x.EndDate < currentContract.StartDate && !x.Id.Equals(currentContract.Id))); }
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"); } }
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); }
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); }
public static bool IsContractHasStartDate(ContractAmendment contract) { return(!string.IsNullOrEmpty( contract.StartDate.ToString(CultureInfo.InvariantCulture))); }
public static bool IsContractEndDateAfterStartDate(ContractAmendment contract) { return(contract.StartDate < contract.EndDate); }
public static List <SiteVolume> CurrentContractVolumes( ContractAmendment currentContract, List <SiteVolume> siteVolumes) { return(siteVolumes .Where(x => x.BillingMonth >= currentContract.StartDate).ToList()); }
public static bool IsCurrentContractHasSomeVolume( ContractAmendment currentContract, List <SiteVolume> siteVolumes) { return(SiteVolumesForContract(currentContract, siteVolumes).Any()); }