use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class TimesheetReportServiceImpl method getTimesheetMap.
private Map<String, Object> getTimesheetMap(User user, LocalDate date, BigDecimal dailyWorkingHours) throws AxelorException {
Employee employee = user.getEmployee();
BigDecimal worksHour = BigDecimal.ZERO, workedHour = BigDecimal.ZERO;
boolean isPublicHoliday = publicHolidayService.checkPublicHolidayDay(date, employee.getPublicHolidayEventsPlanning());
worksHour = getTotalWorksHours(user, date, isPublicHoliday, dailyWorkingHours);
try {
workedHour = getTotalWorkedHours(user, date, isPublicHoliday, dailyWorkingHours);
} catch (Exception e) {
System.out.println(e);
}
Map<String, Object> map = new HashMap<String, Object>();
map.put("userName", user.getFullName());
map.put("date", DateTool.toDate(date));
map.put("workedHour", workedHour);
map.put("workingHour", worksHour);
return map;
}
use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method generateLines.
@Override
public Timesheet generateLines(Timesheet timesheet, LocalDate fromGenerationDate, LocalDate toGenerationDate, BigDecimal logTime, Project project, Product product) throws AxelorException {
User user = timesheet.getUser();
Employee employee = user.getEmployee();
if (fromGenerationDate == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_FROM_DATE));
}
if (toGenerationDate == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_TO_DATE));
}
if (product == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_PRODUCT));
}
if (employee == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), user.getName());
}
WeeklyPlanning planning = employee.getWeeklyPlanning();
if (planning == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_DAY_PLANNING), user.getName());
}
List<DayPlanning> dayPlanningList = planning.getWeekDays();
Map<Integer, String> correspMap = getCorresMap();
LocalDate fromDate = fromGenerationDate;
LocalDate toDate = toGenerationDate;
if (employee.getPublicHolidayEventsPlanning() == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_PUBLIC_HOLIDAY_EVENTS_PLANNING), user.getName());
}
LeaveService leaveService = Beans.get(LeaveService.class);
PublicHolidayHrService publicHolidayHrService = Beans.get(PublicHolidayHrService.class);
while (!fromDate.isAfter(toDate)) {
if (isWorkedDay(fromDate, correspMap, dayPlanningList) && !leaveService.isLeaveDay(user, fromDate) && !publicHolidayHrService.checkPublicHolidayDay(fromDate, employee)) {
TimesheetLine timesheetLine = timesheetLineService.createTimesheetLine(project, product, user, fromDate, timesheet, timesheetLineService.computeHoursDuration(timesheet, logTime, true), "");
timesheetLine.setDuration(logTime);
}
fromDate = fromDate.plusDays(1);
}
return timesheet;
}
use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method updateTimeLoggingPreference.
@Override
public void updateTimeLoggingPreference(Timesheet timesheet) throws AxelorException {
String timeLoggingPref;
if (timesheet.getUser() == null || timesheet.getUser().getEmployee() == null) {
timeLoggingPref = EmployeeRepository.TIME_PREFERENCE_HOURS;
} else {
Employee employee = timesheet.getUser().getEmployee();
timeLoggingPref = employee.getTimeLoggingPreferenceSelect();
}
timesheet.setTimeLoggingPreferenceSelect(timeLoggingPref);
if (timesheet.getTimesheetLineList() != null) {
for (TimesheetLine timesheetLine : timesheet.getTimesheetLineList()) {
timesheetLine.setDuration(Beans.get(TimesheetLineService.class).computeHoursDuration(timesheet, timesheetLine.getHoursDuration(), false));
}
}
}
use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method checkEmptyPeriod.
public void checkEmptyPeriod(Timesheet timesheet) throws AxelorException {
LeaveService leaveService = Beans.get(LeaveService.class);
PublicHolidayHrService publicHolidayHrService = Beans.get(PublicHolidayHrService.class);
User user = timesheet.getUser();
Employee employee = user.getEmployee();
if (employee == null) {
return;
}
if (employee.getPublicHolidayEventsPlanning() == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_PUBLIC_HOLIDAY_EVENTS_PLANNING), user.getName());
}
WeeklyPlanning planning = employee.getWeeklyPlanning();
if (planning == null) {
throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_DAY_PLANNING), user.getName());
}
List<DayPlanning> dayPlanningList = planning.getWeekDays();
Map<Integer, String> correspMap = getCorresMap();
List<TimesheetLine> timesheetLines = timesheet.getTimesheetLineList();
timesheetLines.sort(Comparator.comparing(TimesheetLine::getDate));
for (int i = 0; i < timesheetLines.size(); i++) {
if (i + 1 < timesheetLines.size()) {
LocalDate date1 = timesheetLines.get(i).getDate();
LocalDate date2 = timesheetLines.get(i + 1).getDate();
LocalDate missingDay = date1.plusDays(1);
while (ChronoUnit.DAYS.between(date1, date2) > 1) {
if (isWorkedDay(missingDay, correspMap, dayPlanningList) && !leaveService.isLeaveDay(user, missingDay) && !publicHolidayHrService.checkPublicHolidayDay(missingDay, employee)) {
throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "Line for %s is missing.", missingDay);
}
date1 = missingDay;
missingDay = missingDay.plusDays(1);
}
}
}
}
use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class ProjectPlanningTimeServiceImpl method addMultipleProjectPlanningTime.
@Override
@Transactional(rollbackOn = { Exception.class })
public void addMultipleProjectPlanningTime(Map<String, Object> datas) throws AxelorException {
if (datas.get("project") == null || datas.get("user") == null || datas.get("fromDate") == null || datas.get("toDate") == null) {
return;
}
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
LocalDateTime fromDate = LocalDateTime.parse(datas.get("fromDate").toString(), formatter);
LocalDateTime toDate = LocalDateTime.parse(datas.get("toDate").toString(), formatter);
ProjectTask projectTask = null;
Map<String, Object> objMap = (Map) datas.get("project");
Project project = projectRepo.find(Long.parseLong(objMap.get("id").toString()));
Integer timePercent = 0;
if (datas.get("timepercent") != null) {
timePercent = Integer.parseInt(datas.get("timepercent").toString());
}
objMap = (Map) datas.get("user");
User user = userRepo.find(Long.parseLong(objMap.get("id").toString()));
if (user.getEmployee() == null) {
return;
}
if (datas.get("task") != null) {
objMap = (Map) datas.get("task");
projectTask = projectTaskRepo.find(Long.valueOf(objMap.get("id").toString()));
}
Product activity = null;
if (datas.get("product") != null) {
objMap = (Map) datas.get("product");
activity = productRepo.find(Long.valueOf(objMap.get("id").toString()));
}
Employee employee = user.getEmployee();
BigDecimal dailyWorkHrs = employee.getDailyWorkHours();
while (fromDate.isBefore(toDate)) {
LocalDate date = fromDate.toLocalDate();
LOG.debug("Create Planning for the date: {}", date);
double dayHrs = 0;
if (employee.getWeeklyPlanning() != null) {
dayHrs = weeklyPlanningService.getWorkingDayValueInDays(employee.getWeeklyPlanning(), date);
}
if (dayHrs > 0 && !holidayService.checkPublicHolidayDay(date, employee)) {
ProjectPlanningTime planningTime = new ProjectPlanningTime();
planningTime.setProjectTask(projectTask);
planningTime.setProduct(activity);
planningTime.setTimepercent(timePercent);
planningTime.setUser(user);
planningTime.setDate(date);
planningTime.setProject(project);
planningTime.setIsIncludeInTurnoverForecast((Boolean) datas.get("isIncludeInTurnoverForecast"));
BigDecimal totalHours = BigDecimal.ZERO;
if (timePercent > 0) {
totalHours = dailyWorkHrs.multiply(new BigDecimal(timePercent)).divide(new BigDecimal(100));
}
planningTime.setPlannedHours(totalHours);
planningTimeRepo.save(planningTime);
}
fromDate = fromDate.plusDays(1);
}
}
Aggregations