Search in sources :

Example 31 with Employee

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

the class EmployeeHRRepository method populate.

@Override
public Map<String, Object> populate(Map<String, Object> json, Map<String, Object> context) {
    if (json != null && json.get("id") != null) {
        Long id = (Long) json.get("id");
        if (id != null) {
            Employee employee = super.find(id);
            AppBaseService appBaseService = Beans.get(AppBaseService.class);
            LocalDate today = appBaseService.getTodayDate(employee.getUser() != null ? employee.getUser().getActiveCompany() : AuthUtils.getUser().getActiveCompany());
            if (employee.getLeavingDate() == null && employee.getHireDate() != null && employee.getHireDate().compareTo(today.minusDays(30)) > 0) {
                json.put("$employeeStatus", "new");
            } else if (employee.getLeavingDate() != null && employee.getLeavingDate().compareTo(today) < 0) {
                json.put("$employeeStatus", "former");
            } else {
                json.put("$employeeStatus", "active");
            }
        }
    }
    return super.populate(json, context);
}
Also used : Employee(com.axelor.apps.hr.db.Employee) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) LocalDate(java.time.LocalDate)

Example 32 with Employee

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

the class AppraisalServiceImpl method createAppraisals.

@Transactional(rollbackOn = { Exception.class })
@Override
public Set<Long> createAppraisals(Appraisal appraisalTemplate, Set<Employee> employees, Boolean send) throws ClassNotFoundException, InstantiationException, IllegalAccessException, AxelorException, IOException, MessagingException {
    Set<Long> appraisalIds = new HashSet<Long>();
    if (appraisalTemplate == null) {
        return appraisalIds;
    }
    for (Employee employee : employees.stream().filter(Objects::nonNull).collect(Collectors.toList())) {
        if (EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
            continue;
        }
        Appraisal appraisal = appraisalRepo.copy(appraisalTemplate, false);
        appraisal.setEmployee(employee);
        if (appraisal.getCompany() == null) {
            EmploymentContract employmentContract = employee.getMainEmploymentContract();
            if (employmentContract != null) {
                appraisal.setCompany(employmentContract.getPayCompany());
            }
        }
        appraisal.setIsTemplate(false);
        appraisal = appraisalRepo.save(appraisal);
        if (send != null && send) {
            send(appraisal);
        }
        appraisalIds.add(appraisal.getId());
    }
    return appraisalIds;
}
Also used : EmploymentContract(com.axelor.apps.hr.db.EmploymentContract) Employee(com.axelor.apps.hr.db.Employee) Appraisal(com.axelor.apps.talent.db.Appraisal) HashSet(java.util.HashSet) Transactional(com.google.inject.persist.Transactional)

Example 33 with Employee

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

the class JobApplicationServiceImpl method createEmployee.

protected Employee createEmployee(JobApplication jobApplication) {
    Employee employee = new Employee();
    employee.setHireDate(appBaseService.getTodayDate(jobApplication.getJobPosition().getCompany()));
    employee.setContactPartner(createContact(jobApplication));
    Set<Skill> tagSkillSet = new HashSet<Skill>();
    tagSkillSet.addAll(jobApplication.getSkillSet());
    employee.setSkillSet(tagSkillSet);
    if (employee.getMainEmploymentContract() != null)
        employee.getMainEmploymentContract().setCompanyDepartment(jobApplication.getJobPosition().getCompanyDepartment());
    employee.setName(employee.getContactPartner().getName());
    return employee;
}
Also used : Skill(com.axelor.apps.talent.db.Skill) Employee(com.axelor.apps.hr.db.Employee) HashSet(java.util.HashSet)

Example 34 with Employee

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

the class TimesheetReportServiceImpl method getUserToBeReminded.

@Override
public Set<User> getUserToBeReminded(TimesheetReport timesheetReport) {
    Set<User> userSet = new HashSet<>();
    BigDecimal worksHour = BigDecimal.ZERO, workedHour = BigDecimal.ZERO;
    List<User> users = getUsers(timesheetReport);
    LocalDate fromDate = timesheetReport.getFromDate();
    LocalDate toDate = timesheetReport.getToDate();
    for (User user : users) {
        Employee employee = user.getEmployee();
        try {
            worksHour = workedHour = BigDecimal.ZERO;
            BigDecimal publicHolidays = publicHolidayService.computePublicHolidayDays(fromDate, toDate, employee.getWeeklyPlanning(), employee.getPublicHolidayEventsPlanning());
            worksHour = getTotalWeekWorksHours(user, fromDate, toDate, publicHolidays);
            workedHour = getTotalWeekWorkedHours(user, fromDate, toDate, publicHolidays);
            if (worksHour.compareTo(workedHour) != 0) {
                userSet.add(user);
            }
        } catch (Exception e) {
            TraceBackService.trace(e);
        }
    }
    return userSet;
}
Also used : User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) HashSet(java.util.HashSet)

Example 35 with Employee

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

the class TimesheetReportServiceImpl method addTimesheetReminder.

private void addTimesheetReminder(TimesheetReport timesheetReport, List<User> users, List<TimesheetReminder> timesheetReminders) throws AxelorException {
    BigDecimal worksHour = BigDecimal.ZERO, workedHour = BigDecimal.ZERO, missingHour = BigDecimal.ZERO, extraHour = BigDecimal.ZERO;
    LocalDate fromDate = timesheetReport.getFromDate();
    LocalDate toDate = null;
    do {
        toDate = fromDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
        if (toDate.until(timesheetReport.getToDate()).getDays() < 0) {
            toDate = timesheetReport.getToDate();
        }
        for (User user : users) {
            Employee employee = user.getEmployee();
            missingHour = BigDecimal.ZERO;
            extraHour = BigDecimal.ZERO;
            BigDecimal publicHolidays = publicHolidayService.computePublicHolidayDays(fromDate, toDate, employee.getWeeklyPlanning(), employee.getPublicHolidayEventsPlanning());
            worksHour = getTotalWeekWorksHours(user, fromDate, toDate, publicHolidays);
            workedHour = getTotalWeekWorkedHours(user, fromDate, toDate, publicHolidays);
            if (worksHour.compareTo(workedHour) == 1) {
                missingHour = worksHour.subtract(workedHour);
            } else if (worksHour.compareTo(workedHour) == -1) {
                extraHour = workedHour.subtract(worksHour);
            }
            if (missingHour.compareTo(BigDecimal.ZERO) == 0 && extraHour.compareTo(BigDecimal.ZERO) == 0) {
                continue;
            }
            Optional<TimesheetReminder> optReminder = timesheetReminders.stream().filter(reminder -> reminder.getEmployee().getId().compareTo(employee.getId()) == 0).findFirst();
            TimesheetReminder timesheetReminder = null;
            if (optReminder.isPresent()) {
                timesheetReminder = optReminder.get();
                timesheetReminder.addTimesheetReminderLineListItem(createTimesheetReminderLine(fromDate, toDate, worksHour, missingHour, extraHour));
            } else {
                List<TimesheetReminderLine> timesheetReminderLines = new ArrayList<>();
                timesheetReminder = new TimesheetReminder();
                timesheetReminder.setEmployee(employee);
                timesheetReminder.setTimesheetReminderLineList(timesheetReminderLines);
                timesheetReminder.addTimesheetReminderLineListItem(createTimesheetReminderLine(fromDate, toDate, worksHour, missingHour, extraHour));
                timesheetReminders.add(timesheetReminder);
            }
            timesheetReminderRepo.save(timesheetReminder);
        }
        fromDate = fromDate.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
    } while (toDate.until(timesheetReport.getToDate()).getDays() > 0);
}
Also used : IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) LeaveRequestRepository(com.axelor.apps.hr.db.repo.LeaveRequestRepository) Employee(com.axelor.apps.hr.db.Employee) Inject(com.google.inject.Inject) TimesheetReportRepository(com.axelor.apps.hr.db.repo.TimesheetReportRepository) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) LeaveReasonRepository(com.axelor.apps.hr.db.repo.LeaveReasonRepository) TimesheetReminder(com.axelor.apps.hr.db.TimesheetReminder) Duration(java.time.Duration) Map(java.util.Map) EmployeeService(com.axelor.apps.hr.service.employee.EmployeeService) RoundingMode(java.math.RoundingMode) PublicHolidayService(com.axelor.apps.base.service.publicHoliday.PublicHolidayService) Set(java.util.Set) Message(com.axelor.apps.message.db.Message) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Collectors(java.util.stream.Collectors) MessageService(com.axelor.apps.message.service.MessageService) List(java.util.List) Stream(java.util.stream.Stream) TimesheetRepository(com.axelor.apps.hr.db.repo.TimesheetRepository) LocalDate(java.time.LocalDate) TemporalAdjusters(java.time.temporal.TemporalAdjusters) Optional(java.util.Optional) LeaveService(com.axelor.apps.hr.service.leave.LeaveService) ExtraHoursRepository(com.axelor.apps.hr.db.repo.ExtraHoursRepository) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) TimesheetReminderLine(com.axelor.apps.hr.db.TimesheetReminderLine) ExtraHoursLineRepository(com.axelor.apps.hr.db.repo.ExtraHoursLineRepository) AppHumanResourceService(com.axelor.apps.hr.service.app.AppHumanResourceService) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TimesheetLineRepository(com.axelor.apps.hr.db.repo.TimesheetLineRepository) TimesheetReport(com.axelor.apps.hr.db.TimesheetReport) AxelorException(com.axelor.exception.AxelorException) I18n(com.axelor.i18n.I18n) DateTool(com.axelor.apps.tool.date.DateTool) WeekFields(java.time.temporal.WeekFields) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) QueryBuilder(com.axelor.apps.tool.QueryBuilder) TraceBackService(com.axelor.exception.service.TraceBackService) TimesheetReminderRepository(com.axelor.apps.hr.db.repo.TimesheetReminderRepository) Template(com.axelor.apps.message.db.Template) DayPlanning(com.axelor.apps.base.db.DayPlanning) Beans(com.axelor.inject.Beans) WeeklyPlanningService(com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService) DayOfWeek(java.time.DayOfWeek) TemplateMessageService(com.axelor.apps.message.service.TemplateMessageService) User(com.axelor.auth.db.User) TimesheetReminderLine(com.axelor.apps.hr.db.TimesheetReminderLine) User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) TimesheetReminder(com.axelor.apps.hr.db.TimesheetReminder) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal)

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