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); }
@PreAuthorize(SecurityRules.IS_OFFICE) @RequestMapping(value = "/sicknote", method = RequestMethod.GET) public String periodsSickNotes( @RequestParam(value = "from", required = false) String from, @RequestParam(value = "to", required = false) String to, Model model) { FilterPeriod period = new FilterPeriod(Optional.ofNullable(from), Optional.ofNullable(to)); List<SickNote> sickNoteList = sickNoteService.getByPeriod(period.getStartDate(), period.getEndDate()); fillModel(model, sickNoteList, period); return "sicknote/sick_notes"; }