Search in sources :

Example 6 with RequestHoliday

use of com.autentia.tnt.businessobject.RequestHoliday in project TNTConcept by autentia.

the class ActivityBean method fillHolidays.

private void fillHolidays(SimpleScheduleModel model) {
    Calendar calMin = Calendar.getInstance();
    Calendar calMax = Calendar.getInstance();
    calMin = getMinimumSearchTime(selectedDate);
    calMax = getMaximumSearchTime(selectedDate);
    RequestHolidayManager rhManager = RequestHolidayManager.getDefault();
    RequestHolidaySearch rhSearch = new RequestHolidaySearch();
    rhSearch.setUserRequest(authManager.getCurrentPrincipal().getUser());
    rhSearch.setState(HolidayState.ACCEPT);
    rhSearch.setStartBeginDate(calMin.getTime());
    rhSearch.setEndBeginDate(calMax.getTime());
    rhSearch.setStartFinalDate(calMin.getTime());
    rhSearch.setEndFinalDate(calMax.getTime());
    List<RequestHoliday> listH = rhManager.getAllEntities(rhSearch, null);
    for (RequestHoliday rH : listH) {
        Calendar cActual = Calendar.getInstance();
        cActual.setTime(rH.getBeginDate());
        while (!cActual.getTime().after(rH.getFinalDate())) {
            if (cActual.get(Calendar.DAY_OF_WEEK) != Calendar.SATURDAY && cActual.get(Calendar.DAY_OF_WEEK) != Calendar.SUNDAY) {
                model.setHoliday(cActual.getTime(), FacesUtils.getMessage("activity.acceptedHolidays"));
            }
            cActual.add(Calendar.DAY_OF_MONTH, 1);
        }
    }
    HolidaySearch monthSearch = new HolidaySearch();
    monthSearch.setStartDate(calMin.getTime());
    monthSearch.setEndDate(calMax.getTime());
    List<Holiday> allHolidays = holidayManager.getAllEntities(monthSearch, null);
    for (Holiday holiday : allHolidays) {
        model.setHoliday(holiday.getDate(), holiday.getDescription());
    }
}
Also used : RequestHoliday(com.autentia.tnt.businessobject.RequestHoliday) Holiday(com.autentia.tnt.businessobject.Holiday) RequestHoliday(com.autentia.tnt.businessobject.RequestHoliday) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) RequestHolidayManager(com.autentia.tnt.manager.holiday.RequestHolidayManager) HolidaySearch(com.autentia.tnt.dao.search.HolidaySearch) RequestHolidaySearch(com.autentia.tnt.dao.search.RequestHolidaySearch) RequestHolidaySearch(com.autentia.tnt.dao.search.RequestHolidaySearch)

Example 7 with RequestHoliday

use of com.autentia.tnt.businessobject.RequestHoliday in project TNTConcept by autentia.

the class ActivityBean method calculateRequestedHolidays.

private int calculateRequestedHolidays(List<Integer> nonWorkingDays, Date date, int daysInMonth) {
    LocalDate selectedDay = LocalDateTime.ofInstant(date.toInstant(), ZoneId.systemDefault()).toLocalDate();
    LocalDate firstDaySelectedMonth = selectedDay.withDayOfMonth(1);
    LocalDate lastDaySelectedMonth = selectedDay.with(TemporalAdjusters.lastDayOfMonth());
    Date beginOfMonth = Date.from(firstDaySelectedMonth.atStartOfDay(ZoneId.systemDefault()).toInstant());
    Date endOfMonth = Date.from(lastDaySelectedMonth.atStartOfDay(ZoneId.systemDefault()).toInstant());
    // holiday request starting in selected month
    int requestedHolidays = 0;
    RequestHolidayManager rhManager = RequestHolidayManager.getDefault();
    RequestHolidaySearch rhSearch = new RequestHolidaySearch();
    rhSearch.setUserRequest(authManager.getCurrentPrincipal().getUser());
    rhSearch.setState(HolidayState.ACCEPT);
    rhSearch.setStartBeginDate(beginOfMonth);
    rhSearch.setEndBeginDate(endOfMonth);
    List<RequestHoliday> requestsInSelectedMonth = rhManager.getAllEntities(rhSearch, null);
    // holiday requests ending in selected month
    rhSearch.reset();
    rhSearch.setUserRequest(authManager.getCurrentPrincipal().getUser());
    rhSearch.setState(HolidayState.ACCEPT);
    rhSearch.setStartFinalDate(beginOfMonth);
    rhSearch.setEndFinalDate(endOfMonth);
    requestsInSelectedMonth.addAll(rhManager.getAllEntities(rhSearch, null));
    for (RequestHoliday request : requestsInSelectedMonth) {
        LocalDate iter = LocalDateTime.ofInstant(request.getBeginDate().toInstant(), ZoneId.systemDefault()).toLocalDate();
        LocalDate endOfRequest = LocalDateTime.ofInstant(request.getFinalDate().toInstant(), ZoneId.systemDefault()).toLocalDate();
        while (iter.compareTo(endOfRequest) < 1) {
            if (iter.getMonthValue() == selectedDay.getMonthValue()) {
                int day = iter.getDayOfMonth();
                if (!nonWorkingDays.contains(day) && day <= daysInMonth) {
                    requestedHolidays++;
                    nonWorkingDays.add(day);
                }
            }
            iter = iter.plusDays(1);
        }
    }
    return requestedHolidays;
}
Also used : RequestHoliday(com.autentia.tnt.businessobject.RequestHoliday) RequestHolidayManager(com.autentia.tnt.manager.holiday.RequestHolidayManager) RequestHolidaySearch(com.autentia.tnt.dao.search.RequestHolidaySearch) LocalDate(java.time.LocalDate) Date(java.util.Date) LocalDate(java.time.LocalDate)

Aggregations

RequestHoliday (com.autentia.tnt.businessobject.RequestHoliday)7 RequestHolidayManager (com.autentia.tnt.manager.holiday.RequestHolidayManager)5 Date (java.util.Date)5 RequestHolidaySearch (com.autentia.tnt.dao.search.RequestHolidaySearch)4 Holiday (com.autentia.tnt.businessobject.Holiday)3 HolidaySearch (com.autentia.tnt.dao.search.HolidaySearch)3 LocalDate (java.time.LocalDate)3 Calendar (java.util.Calendar)3 Test (org.junit.Test)2 UserHolidaysState (com.autentia.tnt.businessobject.UserHolidaysState)1 WorkingAgreement (com.autentia.tnt.businessobject.WorkingAgreement)1 WorkingAgreementDAO (com.autentia.tnt.dao.hibernate.WorkingAgreementDAO)1 HolidayManager (com.autentia.tnt.manager.holiday.HolidayManager)1 GregorianCalendar (java.util.GregorianCalendar)1