Search in sources :

Example 51 with Employee

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);
    }
}
Also used : User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) HRMenuValidateService(com.axelor.apps.hr.service.HRMenuValidateService) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException)

Example 52 with Employee

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;
}
Also used : AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal)

Example 53 with Employee

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()));
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) LeaveLine(com.axelor.apps.hr.db.LeaveLine) Transactional(com.google.inject.persist.Transactional)

Example 54 with Employee

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;
}
Also used : LocalDateTime(java.time.LocalDateTime) ICalendarEvent(com.axelor.apps.base.db.ICalendarEvent) AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) Transactional(com.google.inject.persist.Transactional)

Example 55 with Employee

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);
}
Also used : EmployeeRepository(com.axelor.apps.hr.db.repo.EmployeeRepository) Company(com.axelor.apps.base.db.Company) Employee(com.axelor.apps.hr.db.Employee) HRConfig(com.axelor.apps.hr.db.HRConfig) UserService(com.axelor.apps.base.service.user.UserService) AppLeave(com.axelor.apps.base.db.AppLeave) EventsPlanning(com.axelor.apps.base.db.EventsPlanning) AppBase(com.axelor.apps.base.db.AppBase) Transactional(com.google.inject.persist.Transactional)

Aggregations

Employee (com.axelor.apps.hr.db.Employee)71 AxelorException (com.axelor.exception.AxelorException)34 User (com.axelor.auth.db.User)28 Transactional (com.google.inject.persist.Transactional)21 BigDecimal (java.math.BigDecimal)18 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)14 LocalDate (java.time.LocalDate)13 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)9 EmployeeRepository (com.axelor.apps.hr.db.repo.EmployeeRepository)9 WeeklyPlanning (com.axelor.apps.base.db.WeeklyPlanning)8 Message (com.axelor.apps.message.db.Message)8 LeaveRequest (com.axelor.apps.hr.db.LeaveRequest)7 ArrayList (java.util.ArrayList)7 HashSet (java.util.HashSet)7 DayPlanning (com.axelor.apps.base.db.DayPlanning)6 LeaveLine (com.axelor.apps.hr.db.LeaveLine)6 LeaveService (com.axelor.apps.hr.service.leave.LeaveService)6 HashMap (java.util.HashMap)6 Map (java.util.Map)6 Company (com.axelor.apps.base.db.Company)5