Search in sources :

Example 1 with EmployeeRepository

use of com.axelor.apps.hr.db.repo.EmployeeRepository 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 EmployeeRepository

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

the class AppraisalController method createAppraisals.

public void createAppraisals(ActionRequest request, ActionResponse response) {
    try {
        Context context = request.getContext();
        Set<Map<String, Object>> employeeSet = new HashSet<Map<String, Object>>();
        employeeSet.addAll((Collection<? extends Map<String, Object>>) context.get("employeeSet"));
        Set<Employee> employees = new HashSet<Employee>();
        EmployeeRepository employeeRepo = Beans.get(EmployeeRepository.class);
        for (Map<String, Object> emp : employeeSet) {
            Long empId = Long.parseLong(emp.get("id").toString());
            employees.add(employeeRepo.find(empId));
        }
        Long templateId = Long.parseLong(context.get("templateId").toString());
        Appraisal appraisalTemplate = Beans.get(AppraisalRepository.class).find(templateId);
        Boolean send = (Boolean) context.get("sendAppraisals");
        Set<Long> createdIds = Beans.get(AppraisalService.class).createAppraisals(appraisalTemplate, employees, send);
        response.setView(ActionView.define("Appraisal").model(Appraisal.class.getName()).add("grid", "appraisal-grid").add("form", "appraisal-form").param("search-filters", "appraisal-fitlers").domain("self.id in :createdIds").context("createdIds", createdIds).map());
        response.setCanClose(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) Appraisal(com.axelor.apps.talent.db.Appraisal) EmployeeRepository(com.axelor.apps.hr.db.repo.EmployeeRepository) Employee(com.axelor.apps.hr.db.Employee) AppraisalRepository(com.axelor.apps.talent.db.repo.AppraisalRepository) Map(java.util.Map) AppraisalService(com.axelor.apps.talent.service.AppraisalService) HashSet(java.util.HashSet)

Aggregations

Employee (com.axelor.apps.hr.db.Employee)2 EmployeeRepository (com.axelor.apps.hr.db.repo.EmployeeRepository)2 Context (com.axelor.rpc.Context)2 UserService (com.axelor.apps.base.service.user.UserService)1 EmploymentContract (com.axelor.apps.hr.db.EmploymentContract)1 Appraisal (com.axelor.apps.talent.db.Appraisal)1 AppraisalRepository (com.axelor.apps.talent.db.repo.AppraisalRepository)1 AppraisalService (com.axelor.apps.talent.service.AppraisalService)1 User (com.axelor.auth.db.User)1 UserRepository (com.axelor.auth.db.repo.UserRepository)1 Transactional (com.google.inject.persist.Transactional)1 HashSet (java.util.HashSet)1 Map (java.util.Map)1