Search in sources :

Example 1 with Employee

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

the class UserHrController method createUser.

@Transactional
public void createUser(ActionRequest request, ActionResponse response) {
    Context context = request.getContext();
    User user = context.asType(User.class);
    EmployeeRepository employeeRepository = Beans.get(EmployeeRepository.class);
    User employeeUser = new User();
    employeeUser.setActivateOn(user.getActivateOn());
    employeeUser.setExpiresOn(user.getExpiresOn());
    employeeUser.setCode(user.getCode());
    employeeUser.setGroup(user.getGroup());
    if (context.containsKey("_id")) {
        Object employeeId = context.get("_id");
        if (employeeId != null) {
            Employee employee = employeeRepository.find(Long.parseLong(employeeId.toString()));
            employeeUser.setEmployee(employeeRepository.find(employee.getId()));
            if (employee.getContactPartner() != null) {
                String employeeName = employee.getContactPartner().getName();
                if (employee.getContactPartner().getFirstName() != null) {
                    employeeName += " " + employee.getContactPartner().getFirstName();
                }
                employeeUser.setName(employeeName);
                if (employee.getContactPartner().getEmailAddress() != null) {
                    employeeUser.setEmail(employee.getContactPartner().getEmailAddress().getAddress());
                }
            }
            if (employee.getMainEmploymentContract() != null) {
                employeeUser.setActiveCompany(employee.getMainEmploymentContract().getPayCompany());
            }
            List<EmploymentContract> contractList = employee.getEmploymentContractList();
            if (contractList != null && !contractList.isEmpty()) {
                for (EmploymentContract employmentContract : contractList) {
                    employeeUser.addCompanySetItem(employmentContract.getPayCompany());
                }
            }
            CharSequence password = Beans.get(UserService.class).generateRandomPassword();
            employeeUser.setPassword(password.toString());
            employee.setUser(employeeUser);
        }
    }
    Beans.get(UserRepository.class).save(employeeUser);
    response.setCanClose(true);
}
Also used : Context(com.axelor.rpc.Context) EmploymentContract(com.axelor.apps.hr.db.EmploymentContract) EmployeeRepository(com.axelor.apps.hr.db.repo.EmployeeRepository) User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) UserRepository(com.axelor.auth.db.repo.UserRepository) UserService(com.axelor.apps.base.service.user.UserService) Transactional(com.google.inject.persist.Transactional)

Example 2 with Employee

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

the class ExpenseController method validateExpense.

public void validateExpense(ActionRequest request, ActionResponse response) {
    User user = AuthUtils.getUser();
    Employee employee = user.getEmployee();
    ActionViewBuilder actionView = ActionView.define(I18n.get("Expenses to Validate")).model(Expense.class.getName()).add("grid", "expense-validate-grid").add("form", "expense-form").param("search-filters", "expense-filters");
    Beans.get(HRMenuValidateService.class).createValidateDomain(user, employee, actionView);
    response.setView(actionView.map());
}
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)

Example 3 with Employee

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

the class ExpenseController method computeDistanceAndKilometricExpense.

public void computeDistanceAndKilometricExpense(ActionRequest request, ActionResponse response) throws AxelorException {
    // Compute distance.
    try {
        if (!Beans.get(AppHumanResourceService.class).getAppExpense().getComputeDistanceWithWebService()) {
            return;
        }
        Context context = request.getContext();
        ExpenseLine expenseLine = context.asType(ExpenseLine.class);
        if (Strings.isNullOrEmpty(expenseLine.getFromCity()) || Strings.isNullOrEmpty(expenseLine.getToCity())) {
            return;
        }
        KilometricService kilometricService = Beans.get(KilometricService.class);
        BigDecimal distance = kilometricService.computeDistance(expenseLine);
        expenseLine.setDistance(distance);
        response.setValue("distance", distance);
        if (expenseLine.getKilometricAllowParam() == null || expenseLine.getExpenseDate() == null || expenseLine.getKilometricTypeSelect() == 0) {
            return;
        }
        Expense expense = expenseLine.getExpense();
        if (expense == null) {
            expense = context.getParent().asType(Expense.class);
        }
        Employee employee = expense.getUser().getEmployee();
        if (employee == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), expense.getUser().getName());
        }
        BigDecimal amount = kilometricService.computeKilometricExpense(expenseLine, employee);
        response.setValue("totalAmount", amount);
        response.setValue("untaxedAmount", amount);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) AppHumanResourceService(com.axelor.apps.hr.service.app.AppHumanResourceService) Expense(com.axelor.apps.hr.db.Expense) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) KilometricService(com.axelor.apps.hr.service.KilometricService) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 4 with Employee

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

the class TimesheetReportServiceImpl method getTotalWeekWorkedHours.

private BigDecimal getTotalWeekWorkedHours(User user, LocalDate fromDate, LocalDate toDate, BigDecimal publicHolidays) throws AxelorException {
    BigDecimal totalHours = BigDecimal.ZERO;
    Employee employee = user.getEmployee();
    List<TimesheetLine> timesheetLineList = timesheetLineRepository.all().filter("self.user = ? AND (self.date BETWEEN ? AND ?) AND (self.timesheet.statusSelect = ? OR self.timesheet.statusSelect = ?)", user, fromDate, toDate, TimesheetRepository.STATUS_VALIDATED, TimesheetRepository.STATUS_CONFIRMED).fetch();
    Duration totalDuration = timesheetLineService.computeTotalDuration(timesheetLineList);
    totalHours = new BigDecimal(totalDuration.getSeconds()).divide(BigDecimal.valueOf(3600)).setScale(2, RoundingMode.HALF_UP);
    totalHours = totalHours.add(publicHolidays.multiply(employee.getDailyWorkHours()));
    totalHours = totalHours.add(getWeekLeaveHours(user, fromDate, toDate, employee.getDailyWorkHours()));
    return totalHours.setScale(2, RoundingMode.HALF_UP);
}
Also used : Employee(com.axelor.apps.hr.db.Employee) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Duration(java.time.Duration) BigDecimal(java.math.BigDecimal)

Example 5 with Employee

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

the class TimesheetReportServiceImpl method getTotalWorksHours.

private BigDecimal getTotalWorksHours(User user, LocalDate date, boolean isPublicHoliday, BigDecimal dailyWorkingHours) throws AxelorException {
    Employee employee = user.getEmployee();
    BigDecimal worksHour = employeeService.getDaysWorksInPeriod(employee, date, date).multiply(employee.getDailyWorkHours()).setScale(2, RoundingMode.HALF_UP);
    if (isPublicHoliday) {
        worksHour = worksHour.add(dailyWorkingHours);
    }
    double extraHours = extraHoursLineRepository.all().filter("self.user = ? AND self.date = ? AND (self.extraHours.statusSelect = ? OR self.extraHours.statusSelect = ?)", user, date, ExtraHoursRepository.STATUS_VALIDATED, ExtraHoursRepository.STATUS_CONFIRMED).fetchStream().mapToDouble(ehl -> Double.parseDouble(ehl.getQty().toString())).sum();
    worksHour = worksHour.add(new BigDecimal(extraHours));
    return worksHour.setScale(2, RoundingMode.HALF_UP);
}
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) Employee(com.axelor.apps.hr.db.Employee) 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