use of org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService in project urlaubsverwaltung by synyx.
the class ApplicationForLeaveDetailsViewController method prepareDetailView.
private void prepareDetailView(Application application, int year, String action, boolean shortcut, Model model, Person signedInUser) {
// signed in user
model.addAttribute("signedInUser", signedInUser);
// COMMENTS
final List<ApplicationComment> comments = commentService.getCommentsByApplication(application);
model.addAttribute("comment", new ApplicationCommentForm());
model.addAttribute("comments", comments);
model.addAttribute("lastComment", comments.get(comments.size() - 1));
// SPECIAL ATTRIBUTES FOR BOSSES / DEPARTMENT HEADS
boolean isNotYetAllowed = application.hasStatus(WAITING) || application.hasStatus(TEMPORARY_ALLOWED);
boolean isPrivilegedUser = signedInUser.hasRole(BOSS) || signedInUser.hasRole(DEPARTMENT_HEAD) || signedInUser.hasRole(SECOND_STAGE_AUTHORITY);
if (isNotYetAllowed && isPrivilegedUser) {
model.addAttribute("bosses", personService.getActivePersonsByRole(BOSS));
model.addAttribute("referredPerson", new ReferredPerson());
}
// APPLICATION FOR LEAVE
model.addAttribute("application", new ApplicationForLeave(application, workDaysCountService));
final Map<DateRange, WorkingTime> workingTime = workingTimeService.getWorkingTimesByPersonAndDateRange(application.getPerson(), new DateRange(application.getStartDate(), application.getEndDate())).entrySet().stream().sorted(Map.Entry.comparingByKey(comparing(DateRange::getStartDate))).collect(toMap(Map.Entry::getKey, Map.Entry::getValue, (oldValue, newValue) -> newValue, LinkedHashMap::new));
model.addAttribute("dateRangeWorkingTimes", workingTime);
// DEPARTMENT APPLICATIONS FOR LEAVE
final List<Application> departmentApplications = departmentService.getApplicationsForLeaveOfMembersInDepartmentsOfPerson(application.getPerson(), application.getStartDate(), application.getEndDate());
model.addAttribute("departmentApplications", departmentApplications);
// HOLIDAY ACCOUNT
final Optional<Account> account = accountService.getHolidaysAccount(year, application.getPerson());
if (account.isPresent()) {
final Account acc = account.get();
final Optional<Account> accountNextYear = accountService.getHolidaysAccount(year + 1, application.getPerson());
model.addAttribute("vacationDaysLeft", vacationDaysService.getVacationDaysLeft(account.get(), accountNextYear));
model.addAttribute("account", acc);
model.addAttribute(BEFORE_APRIL_ATTRIBUTE, DateUtil.isBeforeApril(LocalDate.now(clock), acc.getYear()));
}
// Signed in person is allowed to manage
final boolean isDepartmentHead = departmentService.isDepartmentHeadAllowedToManagePerson(signedInUser, application.getPerson());
model.addAttribute("isDepartmentHeadOfPerson", isDepartmentHead);
final boolean isSecondStageAuthority = departmentService.isSecondStageAuthorityAllowedToManagePerson(signedInUser, application.getPerson());
model.addAttribute("isSecondStageAuthorityOfPerson", isSecondStageAuthority);
model.addAttribute("isBoss", signedInUser.hasRole(BOSS));
model.addAttribute("isOffice", signedInUser.hasRole(OFFICE));
// UNSPECIFIC ATTRIBUTES
model.addAttribute("year", year);
model.addAttribute("action", action);
model.addAttribute("shortcut", shortcut);
}
use of org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService in project urlaubsverwaltung by synyx.
the class VacationDaysServiceTest method testGetUsedDaysBeforeApril.
@Test
void testGetUsedDaysBeforeApril() {
final String expectedUsedDays = "4";
final Person person = new Person("muster", "Muster", "Marlene", "muster@example.org");
when(applicationService.getApplicationsForACertainPeriodAndPerson(any(), any(), eq(person))).thenReturn(Collections.singletonList(getSomeApplication(person)));
final WorkDaysCountService workDaysCountService = mock(WorkDaysCountService.class);
when(workDaysCountService.getWorkDaysCount(any(), any(), any(), eq(person))).thenReturn(new BigDecimal(expectedUsedDays));
final Clock clock = Clock.systemUTC();
VacationDaysService sut = new VacationDaysService(workDaysCountService, applicationService, clock);
final Account account = new Account();
account.setPerson(person);
account.setValidFrom(LocalDate.now(clock));
account.setValidTo(ZonedDateTime.now(clock).plusDays(10).toLocalDate());
final BigDecimal usedDaysBeforeApril = sut.getUsedDaysBeforeApril(account);
assertThat(usedDaysBeforeApril).isEqualTo(new BigDecimal(expectedUsedDays));
}
use of org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService in project urlaubsverwaltung by synyx.
the class VacationDaysServiceTest method testGetUsedDaysAfterApril.
@Test
void testGetUsedDaysAfterApril() {
final String expectedUsedDays = "4";
final Person person = new Person("muster", "Muster", "Marlene", "muster@example.org");
when(applicationService.getApplicationsForACertainPeriodAndPerson(any(), any(), eq(person))).thenReturn(Collections.singletonList(getSomeApplication(person)));
final WorkDaysCountService workDaysCountService = mock(WorkDaysCountService.class);
when(workDaysCountService.getWorkDaysCount(any(), any(), any(), eq(person))).thenReturn(new BigDecimal(expectedUsedDays));
final Clock clock = Clock.systemUTC();
VacationDaysService sut = new VacationDaysService(workDaysCountService, applicationService, clock);
final Account account = new Account();
account.setPerson(person);
account.setValidFrom(LocalDate.now(clock));
account.setValidTo(ZonedDateTime.now(clock).plusDays(10).toLocalDate());
final BigDecimal usedDaysAfterApril = sut.getUsedDaysAfterApril(account);
assertThat(usedDaysAfterApril).isEqualTo(new BigDecimal(expectedUsedDays));
}
use of org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService in project urlaubsverwaltung by synyx.
the class CalculationServiceTest method setUp.
@BeforeEach
void setUp() {
final PublicHolidaysService publicHolidaysService = new PublicHolidaysServiceImpl(settingsService, Map.of("de", getHolidayManager()));
final WorkDaysCountService workDaysCountService = new WorkDaysCountService(publicHolidaysService, workingTimeService);
sut = new CalculationService(vacationDaysService, accountService, accountInteractionService, workDaysCountService, new OverlapService(null, null), applicationService);
}
use of org.synyx.urlaubsverwaltung.workingtime.WorkDaysCountService in project urlaubsverwaltung by synyx.
the class VacationDaysServiceTest method setUp.
@BeforeEach
void setUp() {
workDaysCountService = new WorkDaysCountService(new PublicHolidaysServiceImpl(settingsService, Map.of("de", getHolidayManager())), workingTimeService);
sut = new VacationDaysService(workDaysCountService, applicationService, Clock.systemUTC());
}
Aggregations