예제 #1
0
 public void CalculateNighRate()
 {
     ApplicableRates.Add(GetRateTemplate(RateNames.NightRate, NightRates.Rate));
 }
예제 #2
0
        public void CalculateStandardAndWeekendRates()
        {
            var      dateRanges = Helper.GetDatesBetween(StartDate, EndDate);
            RateType rateTemplate;

            //start and end date are same
            if (StartDate.Date == EndDate.Date)
            {
                //check if it is a Business Day/ WeekDay
                var isBusinessDay = Helper.IsBusinessDay(StartDate.Date);

                if (isBusinessDay)
                {
                    rateTemplate = GetRateTemplate(RateNames.StandardRate, Helper.CalculateStandardRate(EndDate.Subtract(StartDate).TotalHours), StartDate.Date);
                    ApplicableRates.Add(rateTemplate);
                }
                else
                {
                    //If Weekend
                    rateTemplate = GetRateTemplate(RateNames.WeekendRate, Helper.CalculateWeekendRate(), StartDate.Date);
                    ApplicableRates.Add(rateTemplate);
                }
            }
            else
            {
                if (Helper.IsBusinessDay(StartDate))
                {
                    var fee = Helper.CalculateStandardRate((StartDate.Date.AddDays(1).AddSeconds(-1)).Subtract(StartDate).TotalHours);
                    rateTemplate = GetRateTemplate(RateNames.StandardRate, fee, StartDate.Date);
                    ApplicableRates.Add(rateTemplate);
                }
                else
                {
                    rateTemplate = GetRateTemplate(RateNames.WeekendRate, Helper.CalculateWeekendRate(), StartDate.Date);
                    ApplicableRates.Add(rateTemplate);
                }


                foreach (var dt in dateRanges)
                {
                    rateTemplate = null;
                    if (dt.IsBusinessDay)
                    {
                        rateTemplate = GetRateTemplate(RateNames.StandardRate, BusinessDayRates.DayRate, dt.DateEntity);
                        ApplicableRates.Add(rateTemplate);
                    }
                    else
                    {
                        var previousDay = dt.DateEntity.AddDays(-1);
                        if (previousDay >= StartDate.Date)
                        {
                            //don't charge if the previous day was Sat/Non business day
                            // you can only charge once 10 dollars for the whole weekend (sat+sun)
                            var fee = !Helper.IsBusinessDay(previousDay) ? 0 : WeekendRates.Rate;
                            rateTemplate = GetRateTemplate(RateNames.WeekendRate, fee, dt.DateEntity);
                            ApplicableRates.Add(rateTemplate);
                        }
                    }
                }

                if (Helper.IsBusinessDay(EndDate))
                {
                    var fee = Helper.CalculateStandardRate(EndDate.Subtract(EndDate.Date).TotalHours);
                    rateTemplate = GetRateTemplate(RateNames.StandardRate, fee, EndDate.Date);
                    ApplicableRates.Add(rateTemplate);
                }
                else
                {
                    var previousDay = EndDate.Date.AddDays(-1);
                    if (previousDay >= StartDate.Date)
                    {
                        //don't charge if the previous day was Sat/Non business day
                        // you can only charge once 10 dollars for the whole weekend (sat+sun)
                        var fee = !Helper.IsBusinessDay(previousDay) ? 0 : WeekendRates.Rate;
                        rateTemplate = GetRateTemplate(RateNames.WeekendRate, fee, EndDate.Date);
                        ApplicableRates.Add(rateTemplate);
                    }
                }
            }
        }
예제 #3
0
 public void CalculateEarlyBirdRate()
 {
     ApplicableRates.Add(GetRateTemplate(RateNames.EarlyBird, EarlyBirdRates.Rate));
 }