use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class LeaveController method validateLeave.
public void validateLeave(ActionRequest request, ActionResponse response) {
try {
User user = AuthUtils.getUser();
Employee employee = user.getEmployee();
ActionViewBuilder actionView = ActionView.define(I18n.get("Leave Requests to Validate")).model(LeaveRequest.class.getName()).add("grid", "leave-request-validate-grid").add("form", "leave-request-form").param("search-filters", "leave-request-filters");
Beans.get(HRMenuValidateService.class).createValidateDomain(user, employee, actionView);
response.setView(actionView.map());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class LeaveServiceImpl method computeDuration.
/**
* Compute the duration of a given leave request. The duration can be in hours or in days,
* depending of the leave reason of the leave.
*
* @param leave
* @param from, the beginning of the leave request inside the period
* @param to, the end of the leave request inside the period
* @param startOn If the period starts in the morning or in the afternoon
* @param endOn If the period ends in the morning or in the afternoon
* @return the computed duration in days
* @throws AxelorException
*/
@Override
public BigDecimal computeDuration(LeaveRequest leave, LocalDateTime from, LocalDateTime to, int startOn, int endOn) throws AxelorException {
BigDecimal duration = BigDecimal.ZERO;
if (from != null && to != null && leave.getLeaveReason() != null) {
Employee employee = leave.getUser().getEmployee();
if (employee == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), leave.getUser().getName());
}
switch(leave.getLeaveReason().getUnitSelect()) {
case LeaveReasonRepository.UNIT_SELECT_DAYS:
LocalDate fromDate = from.toLocalDate();
LocalDate toDate = to.toLocalDate();
duration = computeDurationInDays(leave, employee, fromDate, toDate, startOn, endOn);
break;
case LeaveReasonRepository.UNIT_SELECT_HOURS:
duration = computeDurationInHours(leave, employee, from, to);
break;
default:
throw new AxelorException(leave.getLeaveReason(), TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.LEAVE_REASON_NO_UNIT), leave.getLeaveReason().getName());
}
}
return duration.signum() != -1 ? duration : BigDecimal.ZERO;
}
use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class LeaveServiceImpl method manageSentLeaves.
@Override
@Transactional(rollbackOn = { Exception.class })
public void manageSentLeaves(LeaveRequest leave) throws AxelorException {
Employee employee = leave.getUser().getEmployee();
if (employee == null) {
throw new AxelorException(leave, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), leave.getUser().getName());
}
LeaveLine leaveLine = leaveLineRepo.all().filter("self.employee = ?1 AND self.leaveReason = ?2", employee, leave.getLeaveReason()).fetchOne();
if (leaveLine == null) {
throw new AxelorException(leave, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_LINE), employee.getName(), leave.getLeaveReason().getName());
}
if (leave.getInjectConsumeSelect() == LeaveRequestRepository.SELECT_CONSUME) {
leaveLine.setDaysToValidate(leaveLine.getDaysToValidate().add(leave.getDuration()));
} else {
leaveLine.setDaysToValidate(leaveLine.getDaysToValidate().subtract(leave.getDuration()));
}
}
use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class LeaveServiceImpl method createEvents.
@Override
@Transactional(rollbackOn = { Exception.class })
public LeaveRequest createEvents(LeaveRequest leave) throws AxelorException {
Employee employee = leave.getUser().getEmployee();
if (employee == null) {
throw new AxelorException(leave, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), leave.getUser().getName());
}
WeeklyPlanning weeklyPlanning = employee.getWeeklyPlanning();
if (weeklyPlanning == null) {
throw new AxelorException(leave, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.EMPLOYEE_PLANNING), employee.getName());
}
LocalDateTime fromDateTime;
LocalDateTime toDateTime;
if (leave.getLeaveReason().getUnitSelect() == LeaveReasonRepository.UNIT_SELECT_DAYS) {
fromDateTime = getDefaultStart(weeklyPlanning, leave);
toDateTime = getDefaultEnd(weeklyPlanning, leave);
} else {
fromDateTime = leave.getFromDateT();
toDateTime = leave.getToDateT();
}
ICalendarEvent event = icalendarService.createEvent(fromDateTime, toDateTime, leave.getUser(), leave.getComments(), 4, leave.getLeaveReason().getName() + " " + leave.getUser().getFullName());
icalEventRepo.save(event);
leave.setIcalendarEvent(event);
return leave;
}
use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class UserHrServiceImpl method createEmployee.
@Transactional
public void createEmployee(User user) {
if (user.getPartner() == null) {
Beans.get(UserService.class).createPartner(user);
}
AppBase appBase = appHumanResourceService.getAppBase();
AppLeave appLeave = appHumanResourceService.getAppLeave();
Employee employee = new Employee();
employee.setContactPartner(user.getPartner());
employee.setTimeLoggingPreferenceSelect(appBase.getTimeLoggingPreferenceSelect());
employee.setDailyWorkHours(appBase.getDailyWorkHours());
employee.setNegativeValueLeave(appLeave.getAllowNegativeLeaveEmployees());
EventsPlanning planning = null;
Company company = user.getActiveCompany();
if (company != null) {
HRConfig hrConfig = company.getHrConfig();
if (hrConfig != null) {
planning = hrConfig.getPublicHolidayEventsPlanning();
}
}
employee.setPublicHolidayEventsPlanning(planning);
employee.setUser(user);
Beans.get(EmployeeRepository.class).save(employee);
user.setEmployee(employee);
userRepo.save(user);
}
Aggregations