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);
}
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;
}
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()));
}
}
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);
}
}
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());
}
Aggregations