private ForecastStatisticsDto GetForecastStatistics(int userId, int displayedMonth, int displayedYear, DateTime now, bool workPlanRealizedHourBillableOnly) { var result = new ForecastStatisticsDto(); var startDate = new DateTime(displayedYear, displayedMonth, 1); var endDate = startDate.AddMonths(1); DateSpan currentYearDateSpan = DateSpan.YearDateSpan(now.Year); DateSpan next12MonthsDateSpan = DateSpan.Next12MonthsDatespan(now); result.Next12MonthsDateSpan = new DateSpanDto { From = next12MonthsDateSpan.From, To = next12MonthsDateSpan.To }; DateSpan currentMonthDateSpan = DateSpan.CurrentMonthDateSpan(startDate); // Vacation int vacationTypeId = _domainSettings.VacationForecastTypeId; DateSpan currentVacationYearSpan = DateSpan.VacationCurrentPeriodDateSpan(now); result.PlannedVacationCurrentDateSpan = new DateSpanDto { From = currentVacationYearSpan.From, To = currentVacationYearSpan.To }; DateSpan nextVacationYearSpan = DateSpan.VacationNextPeriodDateSpan(now); result.PlannedVacationNextDateSpan = new DateSpanDto { From = nextVacationYearSpan.From, To = nextVacationYearSpan.To }; DateSpan vacationHeldToDateSpan = DateSpan.VacationPeriodUntilDateDateSpan(now); result.CurrentYearExternal = _forecastRepo.GetHourSumByCriteria(userId, false, currentYearDateSpan); result.CurrentYearInternal = _forecastRepo.GetHourSumByCriteria(userId, true, currentYearDateSpan); result.Next12MonthsExternal = _forecastRepo.GetHourSumByCriteria(userId, false, next12MonthsDateSpan); result.Next12MonthsInternal = _forecastRepo.GetHourSumByCriteria(userId, true, next12MonthsDateSpan); result.DisplayedMonthExternal = _forecastRepo.GetHourSumByCriteria(userId, false, currentMonthDateSpan); result.DisplayedMonthInternal = _forecastRepo.GetHourSumByCriteria(userId, true, currentMonthDateSpan); result.PlannedVacationCurrent = _forecastRepo.GetForecastCountByForecastType(userId, vacationTypeId, currentVacationYearSpan); result.PlannedVacationNext = _forecastRepo.GetForecastCountByForecastType(userId, vacationTypeId, nextVacationYearSpan); result.UsedVacationToDateCurrent = _forecastRepo.GetForecastCountByForecastType(userId, vacationTypeId, vacationHeldToDateSpan); // DISABLED FOR H&B //var timeEntriesByPeriodAndUser = _timeEntryRepository.GetTimeEntriesByPeriodAndUser(userId, startDate, endDate) // .Where(x => x.StartTime < endDate); //if (workPlanRealizedHourBillableOnly) //{ // timeEntriesByPeriodAndUser = timeEntriesByPeriodAndUser.Where(x => x.Billable); //} //var forecastMonth = _forecastMonthRepository.GetByUserAndMonth(userId, displayedMonth, displayedYear); //var forecasts = forecastMonth != null ? forecastMonth.Forecasts.ToList() : new List<Trex.Server.Core.Model.Forecast.Forecast>(); //CreateStatisticsForCurrentMonth(timeEntriesByPeriodAndUser.ToList(), result, forecasts); return(result); }
[TestCase("29-02-2012", "01-02-2012", "29-02-2012")] // Leap year public void CurrentMonthDateSpan(string dateInput, string expectedFrom, string expectedTo) { // Arrange // Act var result = DateSpan.CurrentMonthDateSpan(ParseDkDateString(dateInput)); // Assert Assert.That(result.From, Is.EqualTo(ParseDkDateString(expectedFrom))); Assert.That(result.To, Is.EqualTo(ParseDkDateString(expectedTo))); }