Search in sources :

Example 41 with Employee

use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.

the class TimesheetLineServiceImpl method computeHoursDuration.

@Override
public BigDecimal computeHoursDuration(Timesheet timesheet, BigDecimal duration, boolean toHours) throws AxelorException {
    if (duration == null) {
        return null;
    }
    AppBaseService appBaseService = Beans.get(AppBaseService.class);
    BigDecimal dailyWorkHrs;
    String timePref;
    log.debug("Get user duration for duration: {}, timesheet: {}", duration, timesheet == null ? "null" : timesheet.getFullName());
    if (timesheet != null) {
        User user = timesheet.getUser();
        timePref = timesheet.getTimeLoggingPreferenceSelect();
        if (user.getEmployee() != null) {
            Employee employee = employeeRepository.find(user.getEmployee().getId());
            log.debug("Employee: {}", employee);
            dailyWorkHrs = employee.getDailyWorkHours();
            if (timePref == null) {
                timePref = employee.getTimeLoggingPreferenceSelect();
            }
        } else {
            dailyWorkHrs = appBaseService.getAppBase().getDailyWorkHours();
        }
    } else {
        timePref = appBaseService.getAppBase().getTimeLoggingPreferenceSelect();
        dailyWorkHrs = appBaseService.getAppBase().getDailyWorkHours();
    }
    return computeHoursDuration(timePref, duration, dailyWorkHrs, toHours);
}
Also used : User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) BigDecimal(java.math.BigDecimal)

Example 42 with Employee

use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.

the class TimesheetReportServiceImpl method getTimesheetReportList.

public List<Map<String, Object>> getTimesheetReportList(String timesheetReportId) {
    List<Map<String, Object>> list = new ArrayList<>();
    WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY, 5);
    TimesheetReport timesheetReport = timesheetReportRepository.find(Long.parseLong(timesheetReportId.toString()));
    int numOfDays = timesheetReport.getFromDate().until(timesheetReport.getToDate()).getDays();
    List<LocalDate> daysRange = Stream.iterate(timesheetReport.getFromDate(), date -> date.plusDays(1)).limit(numOfDays + 1).collect(Collectors.toList());
    List<User> users = getUsers(timesheetReport);
    for (User user : users) {
        Employee employee = user.getEmployee();
        BigDecimal dailyWorkingHours = employee.getDailyWorkHours();
        WeeklyPlanning weeklyPlanning = employee.getWeeklyPlanning();
        Integer weekNumber = 1;
        int lastDayIndex = -1;
        int daysInWeek = 0;
        try {
            for (LocalDate date : daysRange) {
                DayPlanning dayPlanning = weeklyPlanningService.findDayPlanning(weeklyPlanning, date);
                if (dayPlanning == null) {
                    continue;
                }
                int dayIndex = date.get(weekFields.dayOfWeek()) - 1;
                if (lastDayIndex < dayIndex) {
                    lastDayIndex = dayIndex;
                    if (weeklyPlanningService.getWorkingDayValueInDays(weeklyPlanning, date) != 0) {
                        daysInWeek++;
                    }
                } else {
                    lastDayIndex = -1;
                    daysInWeek = 1;
                    weekNumber++;
                }
                BigDecimal weeklyWorkHours = daysInWeek <= 5 ? employee.getWeeklyWorkHours().multiply(BigDecimal.valueOf(daysInWeek / 5.00)).setScale(2, RoundingMode.HALF_UP) : employee.getWeeklyWorkHours();
                Map<String, Object> map = getTimesheetMap(user, date, dailyWorkingHours);
                map.put("weeklyWorkHours", weeklyWorkHours);
                map.put("weekNumber", weekNumber.toString());
                list.add(map);
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }
    return list;
}
Also used : User(com.axelor.auth.db.User) TimesheetReport(com.axelor.apps.hr.db.TimesheetReport) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) ArrayList(java.util.ArrayList) DayPlanning(com.axelor.apps.base.db.DayPlanning) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) WeekFields(java.time.temporal.WeekFields) Map(java.util.Map) HashMap(java.util.HashMap)

Example 43 with Employee

use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.

the class LeaveServiceImpl method manageRefuseLeaves.

@Override
@Transactional(rollbackOn = { Exception.class })
public void manageRefuseLeaves(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().subtract(leave.getDuration()));
    } else {
        leaveLine.setDaysToValidate(leaveLine.getDaysToValidate().add(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 44 with Employee

use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.

the class LeaveController method leaveCalendar.

public void leaveCalendar(ActionRequest request, ActionResponse response) {
    try {
        User user = AuthUtils.getUser();
        Employee employee = user.getEmployee();
        ActionViewBuilder actionView = ActionView.define(I18n.get("Leaves calendar")).model(ICalendarEvent.class.getName()).add("calendar", "calendar-event-leave-request").add("grid", "calendar-event-grid").add("form", "calendar-event-form");
        actionView.domain("self.typeSelect = 4 AND self.id IN (SELECT leaveRequest.icalendarEvent FROM LeaveRequest leaveRequest WHERE leaveRequest.statusSelect = 3");
        if (employee == null || !employee.getHrManager()) {
            actionView.domain(actionView.get().getDomain() + " AND leaveRequest.user.employee.managerUser = :_user").context("_user", user);
        }
        actionView.domain(actionView.get().getDomain() + ")");
        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) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException)

Example 45 with Employee

use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.

the class TimesheetController method allTimesheetLine.

public void allTimesheetLine(ActionRequest request, ActionResponse response) {
    User user = AuthUtils.getUser();
    Employee employee = user.getEmployee();
    ActionViewBuilder actionView = ActionView.define(I18n.get("See timesheet lines")).model(TimesheetLine.class.getName()).add("grid", "timesheet-line-grid").add("form", "timesheet-line-form");
    Beans.get(TimesheetService.class).createDomainAllTimesheetLine(user, employee, actionView);
    response.setView(actionView.map());
}
Also used : User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)

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