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); }
public void YearDateSpan(int yearInput, string expectedFrom, string expectedTo) { // Arrange // Act var result = DateSpan.YearDateSpan(yearInput); // Assert Assert.That(result.From, Is.EqualTo(ParseDkDateString(expectedFrom))); Assert.That(result.To, Is.EqualTo(ParseDkDateString(expectedTo))); }
public void GetRestOfYear_CanExtract() { // Arrange var user = new GenericRepository <User>(Session).SaveOrUpdate(DataGenerator.GetUser()); var client = DataGenerator.GetCustomer(user); client.Internal = true; client = new GenericRepository <Company>(Session).SaveOrUpdate(client); var project = new GenericRepository <Project>(Session).SaveOrUpdate(DataGenerator.GetProject(user, client)); var forecastType = new GenericRepository <ForecastType>(Session).SaveOrUpdate(new ForecastType("Client", "", true, true)); var illnessForecastType = new GenericRepository <ForecastType>(Session).SaveOrUpdate(new ForecastType("Illness", "", false, true) { StatisticsInclusion = false }); var forecastTypeRepo = new ForecastTypeRepository(Session); forecastTypeRepo.SaveOrUpdate(forecastType); var repo = new ForecastRepository(Session); var month = new ForecastMonth(1, 2013, 3, user, user); CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 1), forecastType, project, 7.5m, 1); CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 2), forecastType, project, 6, 1); CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 3), forecastType, project, 5, 1); CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 4), illnessForecastType, null, 0, 7.5m); var monthRepo = new ForecastMonthRepository(Session); monthRepo.SaveOrUpdate(month); // Act var all = repo.GetHourSumByCriteria(1, true, DateSpan.YearDateSpan(2013)); var allExcluded = repo.GetHourSumByCriteria(1, false, DateSpan.YearDateSpan(2013)); var twoByDateSpan = repo.GetHourSumByCriteria(1, true, new DateSpan { From = new DateTime(2013, 1, 1), To = new DateTime(2013, 1, 2) }); // Assert Assert.That(all, Is.EqualTo(21.5m)); // 7.5 + 6 + 5 + 1 + 1 + 1 (projecthours and dedicated hours (1's)) Assert.That(allExcluded, Is.EqualTo(0)); Assert.That(twoByDateSpan, Is.EqualTo(15.5m)); }
public void GetDateCountByForecastType_CanExtract() { // Arrange var user = new GenericRepository <User>(Session).SaveOrUpdate(DataGenerator.GetUser()); var client = new GenericRepository <Company>(Session).SaveOrUpdate(DataGenerator.GetCustomer(user)); var project = new GenericRepository <Project>(Session).SaveOrUpdate(DataGenerator.GetProject(user, client)); var forecastType = new GenericRepository <ForecastType>(Session).SaveOrUpdate(new ForecastType("Client", "", true, false)); var forecastTypeRepo = new ForecastTypeRepository(Session); forecastTypeRepo.SaveOrUpdate(forecastType); var clientForecastTypeId = forecastType.Id; var month = new ForecastMonth(1, 2013, 3, user, user); var repo = new ForecastRepository(Session); CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 1), forecastType, project, 3); forecastType = new GenericRepository <ForecastType>(Session).SaveOrUpdate(new ForecastType("Vacation", "", false, false)); forecastTypeRepo.SaveOrUpdate(forecastType); var vacationForecastTypeId = forecastType.Id; CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 2), forecastType, null, 0); CreateForecastWithSingleProjectRegistration(month, new DateTime(2013, 1, 3), forecastType, null, 0); var monthRepo = new ForecastMonthRepository(Session); monthRepo.SaveOrUpdate(month); // Act var clientForecastCount = repo.GetForecastCountByForecastType(1, clientForecastTypeId, DateSpan.YearDateSpan(2013)); var vacationForecastcount = repo.GetForecastCountByForecastType(1, vacationForecastTypeId, DateSpan.YearDateSpan(2013)); // Assert Assert.That(clientForecastCount, Is.EqualTo(1)); Assert.That(vacationForecastcount, Is.EqualTo(2)); }