private int GetPayPeriodsRemainingAtBenefitStartDate(BenefitElection benefitElection, IEnumerable<PayrollScheduleDetail> payrollScheduleDetails)
 {
     var row = payrollScheduleDetails.Where(psd => psd.DeductionEndDate >= benefitElection.BenefitStartDate
                 && (psd.LastRunDate > benefitElection.DateCreated || !psd.LastRunDate.HasValue))
                 .OrderByDescending(psd => psd.NumPrePaysRemaining).FirstOrDefault();
     if (row != null) return row.NumPrePaysRemaining;
     return 0;
 }
 private int GetPrePayPeriodsForElectionSegment(BenefitElection election, IEnumerable<PayrollScheduleDetail> payrollScheduleDetails)
 {
     var prePayPeriodsAtStartDate = GetPayPeriodsRemainingAtBenefitStartDate(election, payrollScheduleDetails);
     var prePayPeriodsAtEndDate = GetPayPeriodsRemainingAtBenefitEndDate(election, payrollScheduleDetails);
     return prePayPeriodsAtStartDate - prePayPeriodsAtEndDate;
 }
 private decimal GetSummerPrePayPaidForBenefitElectionSegment(BenefitElection election, IEnumerable<PayrollScheduleDetail> payrollScheduleDetails, TierPrePayValue tierPrePayValue)
 {
     var payPeriodsForSegment = GetPrePayPeriodsForElectionSegment(election, payrollScheduleDetails);
     var summerPrePayPaidFromClientDeductionPerPay = payPeriodsForSegment * election.ClientDeductionPerPay;
     var summerPrePayPaidFromTierPrePayValue = GetSummerPrePayPaidFromTierPrePayValue(tierPrePayValue, payPeriodsForSegment);
     return summerPrePayPaidFromClientDeductionPerPay + summerPrePayPaidFromTierPrePayValue;
 }