private void prepareApplications(Person person, int year, Model model) {

    // get the person's applications for the given year
    List<Application> applications =
        FluentIterable.from(
                applicationService.getApplicationsForACertainPeriodAndPerson(
                    DateUtil.getFirstDayOfYear(year), DateUtil.getLastDayOfYear(year), person))
            .filter(input -> !input.hasStatus(ApplicationStatus.REVOKED))
            .toList();

    if (!applications.isEmpty()) {
      ImmutableList<ApplicationForLeave> applicationsForLeave =
          FluentIterable.from(applications)
              .transform(input -> new ApplicationForLeave(input, calendarService))
              .toSortedList(
                  (o1, o2) -> {
                    // show latest applications at first
                    return o2.getStartDate().compareTo(o1.getStartDate());
                  });

      model.addAttribute("applications", applicationsForLeave);

      UsedDaysOverview usedDaysOverview = new UsedDaysOverview(applications, year, calendarService);
      model.addAttribute("usedDaysOverview", usedDaysOverview);
    }
  }
  private void prepareSickNoteList(Person person, int year, Model model) {

    List<SickNote> sickNotes =
        sickNoteService.getByPersonAndPeriod(
            person, DateUtil.getFirstDayOfYear(year), DateUtil.getLastDayOfYear(year));

    List<ExtendedSickNote> extendedSickNotes =
        FluentIterable.from(sickNotes)
            .transform(input -> new ExtendedSickNote(input, calendarService))
            .toSortedList(
                (o1, o2) -> {
                  // show latest sick notes at first
                  return o2.getStartDate().compareTo(o1.getStartDate());
                });

    BigDecimal sickDays = BigDecimal.ZERO;
    BigDecimal sickDaysWithAUB = BigDecimal.ZERO;
    BigDecimal childSickDays = BigDecimal.ZERO;
    BigDecimal childSickDaysWithAUB = BigDecimal.ZERO;

    for (SickNote sickNote : sickNotes) {
      if (!sickNote.isActive()) {
        continue;
      }

      if (sickNote.getType().equals(SickNoteType.SICK_NOTE_CHILD)) {
        childSickDays =
            childSickDays.add(
                calendarService.getWorkDays(
                    DayLength.FULL, sickNote.getStartDate(), sickNote.getEndDate(), person));

        if (sickNote.isAubPresent()) {
          BigDecimal workDays =
              calendarService.getWorkDays(
                  DayLength.FULL, sickNote.getAubStartDate(), sickNote.getAubEndDate(), person);
          childSickDaysWithAUB = childSickDaysWithAUB.add(workDays);
        }
      } else {
        sickDays =
            sickDays.add(
                calendarService.getWorkDays(
                    DayLength.FULL, sickNote.getStartDate(), sickNote.getEndDate(), person));

        if (sickNote.isAubPresent()) {
          BigDecimal workDays =
              calendarService.getWorkDays(
                  DayLength.FULL, sickNote.getAubStartDate(), sickNote.getAubEndDate(), person);
          sickDaysWithAUB = sickDaysWithAUB.add(workDays);
        }
      }
    }

    model.addAttribute("sickDays", sickDays);
    model.addAttribute("sickDaysWithAUB", sickDaysWithAUB);
    model.addAttribute("childSickDays", childSickDays);
    model.addAttribute("childSickDaysWithAUB", childSickDaysWithAUB);
    model.addAttribute("sickNotes", extendedSickNotes);
  }
  private void prepareHolidayAccounts(Person person, int year, Model model) {

    // get person's holidays account and entitlement for the given year
    Optional<Account> account = accountService.getHolidaysAccount(year, person);

    if (account.isPresent()) {
      model.addAttribute(
          "vacationDaysLeft", vacationDaysService.getVacationDaysLeft(account.get()));
      model.addAttribute("account", account.get());
      model.addAttribute(
          PersonConstants.BEFORE_APRIL_ATTRIBUTE, DateUtil.isBeforeApril(DateMidnight.now()));
    }
  }