use of com.autentia.tnt.businessobject.RequestHoliday in project TNTConcept by autentia.
the class UserHolidaysStateManager method calculateUserHolidaysState.
public UserHolidaysState calculateUserHolidaysState(User usuario, Date year) {
UserHolidaysState uhs = new UserHolidaysState();
uhs.setUser(usuario);
// WorkingAgreement attribute is an HB proxy not initialized, we need to get it
// from DB
WorkingAgreementDAO workingAgreementDao = WorkingAgreementDAO.getDefault();
WorkingAgreement agreement = workingAgreementDao.loadById(usuario.getAgreement().getId());
// and refresh the user instance agreement attribute
usuario.setAgreement(agreement);
uhs.setTotalYear(agreement.getHolidays());
int acceptedHolidays = 0;
if (year != null) {
HolidayManager fiestasManager = HolidayManager.getDefault();
// We must take in account previous year holidays and next year holidays
Date firstDayOfYear = com.autentia.tnt.util.DateUtils.getFirstDayOfYear(year);
Date lastDayOfYear = com.autentia.tnt.util.DateUtils.getLastDayOfYear(year);
Calendar calendarFirstDayOfYear = Calendar.getInstance();
calendarFirstDayOfYear.setTime(firstDayOfYear);
calendarFirstDayOfYear.add(Calendar.YEAR, -1);
Calendar calendarLastDayOfYear = Calendar.getInstance();
calendarLastDayOfYear.setTime(lastDayOfYear);
calendarLastDayOfYear.add(Calendar.YEAR, 1);
HolidaySearch fiestaSearch = new HolidaySearch();
fiestaSearch.setStartDate(calendarFirstDayOfYear.getTime());
fiestaSearch.setEndDate(calendarLastDayOfYear.getTime());
List<Holiday> allFiestas = fiestasManager.getAllEntities(fiestaSearch, null);
firstDayOfYear = com.autentia.tnt.util.DateUtils.getFirstDayOfYear(year);
calendarFirstDayOfYear.setTime(firstDayOfYear);
lastDayOfYear = com.autentia.tnt.util.DateUtils.getLastDayOfYear(year);
calendarLastDayOfYear.setTime(lastDayOfYear);
RequestHolidayManager holyManager = RequestHolidayManager.getDefault();
RequestHolidaySearch holSearch = new RequestHolidaySearch();
holSearch.setUserRequest(uhs.getUser());
holSearch.setState(HolidayState.ACCEPT);
holSearch.setStartChargeYear(calendarFirstDayOfYear.getTime());
holSearch.setEndChargeYear(calendarLastDayOfYear.getTime());
List<RequestHoliday> listH = holyManager.getAllEntities(holSearch, 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) {
boolean isFiesta = false;
for (Holiday fiest : allFiestas) {
Calendar cFiesta = Calendar.getInstance();
cFiesta.setTime(fiest.getDate());
if (cFiesta.get(Calendar.YEAR) == cActual.get(Calendar.YEAR) && cFiesta.get(Calendar.MONTH) == cActual.get(Calendar.MONTH) && cFiesta.get(Calendar.DAY_OF_MONTH) == cActual.get(Calendar.DAY_OF_MONTH)) {
isFiesta = true;
}
}
if (!isFiesta) {
acceptedHolidays++;
}
}
cActual.add(Calendar.DAY_OF_MONTH, 1);
}
}
uhs.setTotalAccepted(acceptedHolidays);
Calendar calAuxCont = Calendar.getInstance();
calAuxCont.setTime(uhs.getUser().getStartDate());
Calendar calAux = Calendar.getInstance();
calAux.setTime(year);
int yearCharge = calAux.get(Calendar.YEAR);
int yearContract = calAuxCont.get(Calendar.YEAR);
if (yearCharge == yearContract) {
// Dividimos los días de cada usuario entre los dias del año.
double ratio = uhs.getUser().getAgreement().getHolidays() / 360.0;
int dayContract = calAuxCont.get(Calendar.DAY_OF_YEAR);
int workedDays = (360 - dayContract);
double holidayDays = workedDays * ratio;
double aux = Math.round(holidayDays);
uhs.setTotalYear((int) aux);
}
}
return uhs;
}
use of com.autentia.tnt.businessobject.RequestHoliday in project TNTConcept by autentia.
the class ActivityBean_IT method getMonthTotalHours_HolidayRequestWithinMonth.
@Test
public void getMonthTotalHours_HolidayRequestWithinMonth() {
// create a holiday request within a month
RequestHolidayManager rhManager = RequestHolidayManager.getDefault();
RequestHoliday requestWithinMonth = new RequestHoliday();
requestWithinMonth.setState(HolidayState.ACCEPT);
LocalDate startRequest = LocalDate.of(2017, 8, 25);
Date startRequestDate = Date.from(startRequest.atStartOfDay(ZoneId.systemDefault()).toInstant());
requestWithinMonth.setBeginDate(startRequestDate);
LocalDate endRequest = LocalDate.of(2017, 8, 31);
Date endRequestDate = Date.from(endRequest.atStartOfDay(ZoneId.systemDefault()).toInstant());
requestWithinMonth.setFinalDate(endRequestDate);
rhManager.insertEntity(requestWithinMonth);
// verify total hours for the month
ActivityBeanNoJSF sut = new ActivityBeanNoJSF();
LocalDate august = LocalDate.of(2017, 8, 1);
Date augustDate = Date.from(august.atStartOfDay(ZoneId.systemDefault()).toInstant());
sut.setSelectedDate(augustDate);
double augustHours = sut.getMonthTotalHours();
assertThat(augustHours, closeTo(144.0, 0.1));
}
use of com.autentia.tnt.businessobject.RequestHoliday in project TNTConcept by autentia.
the class RequestHolidayBean method create.
/**
* Go to create page
*
* @return forward to CREATE page
*/
public String create() {
requestHoliday = new RequestHoliday();
// Inicializa el estado a pendiente
this.setState(HolidayState.PENDING);
if (getUserRequest() == null) {
setUserRequest(authMgr.getCurrentPrincipal().getUser());
}
return NavigationResults.CREATE;
}
use of com.autentia.tnt.businessobject.RequestHoliday in project TNTConcept by autentia.
the class AvailabilityBean method fillModelHolidays.
/**
* Fill holidays in listOccupations for that user.
*
* @param user
* @param model
*/
private void fillModelHolidays(User user, OcupationModel model) {
Calendar calendarFirstDayOfMonth = Calendar.getInstance();
Calendar calendarLastDayOfMonth = Calendar.getInstance();
Date firstDayOfMonth = DateUtils.getFirstDayOfMonth(selectedDate);
Date lastDayOfMonth = DateUtils.getLastDayOfMonth(selectedDate);
calendarFirstDayOfMonth.setTime(firstDayOfMonth);
calendarLastDayOfMonth.setTime(lastDayOfMonth);
calendarFirstDayOfMonth.add(Calendar.MONTH, -1);
calendarLastDayOfMonth.add(Calendar.MONTH, 1);
RequestHolidayManager rhManager = RequestHolidayManager.getDefault();
RequestHolidaySearch rhSearch = new RequestHolidaySearch();
rhSearch.setUserRequest(user);
rhSearch.setState(HolidayState.ACCEPT);
rhSearch.setStartBeginDate(calendarFirstDayOfMonth.getTime());
rhSearch.setEndBeginDate(calendarLastDayOfMonth.getTime());
rhSearch.setStartFinalDate(calendarFirstDayOfMonth.getTime());
rhSearch.setEndFinalDate(calendarLastDayOfMonth.getTime());
List<RequestHoliday> listH = rhManager.getAllEntities(rhSearch, null);
for (RequestHoliday rH : listH) {
OcupationEntryImpl oc = new OcupationEntryImpl();
oc.setStart(DateUtils.minHourInDate(rH.getBeginDate()));
oc.setEnd(DateUtils.maxHourInDate(rH.getFinalDate()));
oc.setVacances(true);
oc.setHoliday(false);
oc.setDescription(FacesUtils.getMessage("activity.acceptedHolidays"));
model.addOcupationEntry(oc);
}
HolidaySearch monthSearch = new HolidaySearch();
HolidayManager holidayManager = HolidayManager.getDefault();
monthSearch.setStartDate(calendarFirstDayOfMonth.getTime());
monthSearch.setEndDate(calendarLastDayOfMonth.getTime());
List<Holiday> allHolidays = holidayManager.getAllEntities(monthSearch, null);
for (Holiday holiday : allHolidays) {
OcupationEntryImpl oc = new OcupationEntryImpl();
oc.setStart(DateUtils.minHourInDate(holiday.getDate()));
oc.setEnd(DateUtils.maxHourInDate(holiday.getDate()));
oc.setVacances(false);
oc.setHoliday(true);
oc.setDescription(holiday.getDescription());
model.addOcupationEntry(oc);
}
}
use of com.autentia.tnt.businessobject.RequestHoliday in project TNTConcept by autentia.
the class ActivityBean_IT method getMonthTotalHours_HolidayRequestOverMonths.
@Test
public void getMonthTotalHours_HolidayRequestOverMonths() {
// create a holiday request over two months
RequestHolidayManager rhManager = RequestHolidayManager.getDefault();
RequestHoliday requestOverMonths = new RequestHoliday();
requestOverMonths.setState(HolidayState.ACCEPT);
LocalDate startRequest = LocalDate.of(2017, 8, 31);
Date startRequestDate = Date.from(startRequest.atStartOfDay(ZoneId.systemDefault()).toInstant());
requestOverMonths.setBeginDate(startRequestDate);
LocalDate endRequest = LocalDate.of(2017, 9, 1);
Date endRequestDate = Date.from(endRequest.atStartOfDay(ZoneId.systemDefault()).toInstant());
requestOverMonths.setFinalDate(endRequestDate);
rhManager.insertEntity(requestOverMonths);
// verify total hours for the first month
ActivityBeanNoJSF sut = new ActivityBeanNoJSF();
LocalDate august = LocalDate.of(2017, 8, 1);
Date augustDate = Date.from(august.atStartOfDay(ZoneId.systemDefault()).toInstant());
sut.setSelectedDate(augustDate);
double augustHours = sut.getMonthTotalHours();
assertThat("First Month Hours", augustHours, closeTo(176.0, 0.1));
// verify total hours for the second month
LocalDate september = LocalDate.of(2017, 9, 1);
Date septemberDate = Date.from(september.atStartOfDay(ZoneId.systemDefault()).toInstant());
sut.setSelectedDate(septemberDate);
double septHours = sut.getMonthTotalHours();
assertThat("Second Month Hours", septHours, closeTo(160.0, 0.1));
}
Aggregations