Search in sources :

Example 16 with Employee

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

Example 17 with Employee

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

the class JobApplicationController method hire.

public void hire(ActionRequest request, ActionResponse response) {
    JobApplication jobApplication = request.getContext().asType(JobApplication.class);
    jobApplication = Beans.get(JobApplicationRepository.class).find(jobApplication.getId());
    Employee employee = Beans.get(JobApplicationService.class).hire(jobApplication);
    response.setReload(true);
    response.setView(ActionView.define(I18n.get("Employee")).model(Employee.class.getName()).add("grid", "employee-grid").add("form", "employee-form").param("search-filters", "employee-filters").context("_showRecord", employee.getId()).map());
}
Also used : Employee(com.axelor.apps.hr.db.Employee) JobApplicationService(com.axelor.apps.talent.service.JobApplicationService) JobApplication(com.axelor.apps.talent.db.JobApplication)

Example 18 with Employee

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

the class EmployeeBonusService method compute.

@Transactional(rollbackOn = { Exception.class })
public void compute(EmployeeBonusMgt bonus) throws AxelorException {
    Map<Employee, EmployeeBonusMgtLine> employeeStatus = new HashMap<>();
    for (EmployeeBonusMgtLine line : bonus.getEmployeeBonusMgtLineList()) {
        employeeStatus.put(line.getEmployee(), line);
    }
    List<Employee> allEmployee = Beans.get(EmployeeRepository.class).all().filter("self.mainEmploymentContract.payCompany = ?1", bonus.getCompany()).fetch();
    TemplateMaker maker = new TemplateMaker(bonus.getCompany().getTimezone(), AppFilter.getLocale(), TEMPLATE_DELIMITER, TEMPLATE_DELIMITER);
    String eval;
    CompilerConfiguration conf = new CompilerConfiguration();
    ImportCustomizer customizer = new ImportCustomizer();
    customizer.addStaticStars("java.lang.Math");
    conf.addCompilationCustomizers(customizer);
    Binding binding = new Binding();
    GroovyShell shell = new GroovyShell(binding, conf);
    Integer employeeBonusStatus = EmployeeBonusMgtRepository.STATUS_CALCULATED;
    for (Employee employee : allEmployee) {
        if (EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
            continue;
        }
        // check if line is already calculated
        if (employeeStatus.get(employee) != null) {
            if (employeeStatus.get(employee).getStatusSelect().equals(EmployeeBonusMgtLineRepository.STATUS_CALCULATED)) {
                continue;
            } else {
                bonus.removeEmployeeBonusMgtLineListItem(employeeStatus.get(employee));
            }
        }
        maker.setContext(employee, "Employee");
        EmployeeBonusMgtLine line = new EmployeeBonusMgtLine();
        line.setEmployeeBonusMgt(bonus);
        line.setEmployee(employee);
        maker.addInContext("EmployeeBonusMgtLine", line);
        String formula = bonus.getEmployeeBonusType().getApplicationCondition();
        Integer lineStatus = EmployeeBonusMgtLineRepository.STATUS_CALCULATED;
        try {
            formula = replaceExpressionInFormula(formula, bonus.getCompany().getHrConfig(), employee, bonus.getPayPeriod());
        } catch (Exception e) {
            TraceBackService.trace(e);
            formula = "true";
            lineStatus = EmployeeBonusMgtLineRepository.STATUS_ANOMALY;
        }
        maker.setTemplate(formula);
        eval = maker.make();
        if (shell.evaluate(eval).toString().equals("true")) {
            try {
                formula = replaceExpressionInFormula(bonus.getEmployeeBonusType().getFormula(), bonus.getCompany().getHrConfig(), employee, bonus.getPayPeriod());
            } catch (Exception e) {
                lineStatus = EmployeeBonusMgtLineRepository.STATUS_ANOMALY;
            }
            line.setStatusSelect(lineStatus);
            if (lineStatus.equals(EmployeeBonusMgtLineRepository.STATUS_ANOMALY)) {
                employeeBonusStatus = EmployeeBonusMgtRepository.STATUS_ANOMALY;
                employeeBonusMgtLineRepo.save(line);
                continue;
            }
            line.setSeniorityDate(employee.getSeniorityDate());
            line.setCoef(employee.getBonusCoef());
            line.setWeeklyPlanning(employee.getWeeklyPlanning());
            maker.setTemplate(formula);
            eval = maker.make();
            line.setAmount(new BigDecimal(shell.evaluate(eval).toString()));
            employeeBonusMgtLineRepo.save(line);
        }
    }
    bonus.setStatusSelect(employeeBonusStatus);
    employeeBonusMgtRepo.save(bonus);
}
Also used : Binding(groovy.lang.Binding) HashMap(java.util.HashMap) GroovyShell(groovy.lang.GroovyShell) AxelorException(com.axelor.exception.AxelorException) BigDecimal(java.math.BigDecimal) EmployeeRepository(com.axelor.apps.hr.db.repo.EmployeeRepository) Employee(com.axelor.apps.hr.db.Employee) EmployeeBonusMgtLine(com.axelor.apps.hr.db.EmployeeBonusMgtLine) TemplateMaker(com.axelor.tool.template.TemplateMaker) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) ImportCustomizer(org.codehaus.groovy.control.customizers.ImportCustomizer) Transactional(com.google.inject.persist.Transactional)

Example 19 with Employee

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

the class ExpenseServiceImpl method validate.

@Override
@Transactional(rollbackOn = { Exception.class })
public void validate(Expense expense) throws AxelorException {
    Employee employee = expense.getUser().getEmployee();
    if (employee == null) {
        throw new AxelorException(expense, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), expense.getUser().getFullName());
    }
    if (expense.getPeriod() == null) {
        throw new AxelorException(expense, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.EXPENSE_MISSING_PERIOD));
    }
    List<ExpenseLine> kilometricExpenseLineList = expense.getKilometricExpenseLineList();
    KilometricService kilometricService = Beans.get(KilometricService.class);
    if (ObjectUtils.notEmpty(kilometricExpenseLineList)) {
        for (ExpenseLine line : kilometricExpenseLineList) {
            BigDecimal amount = kilometricService.computeKilometricExpense(line, employee);
            line.setTotalAmount(amount);
            line.setUntaxedAmount(amount);
            kilometricService.updateKilometricLog(line, employee);
        }
        compute(expense);
    }
    Beans.get(EmployeeAdvanceService.class).fillExpenseWithAdvances(expense);
    expense.setStatusSelect(ExpenseRepository.STATUS_VALIDATED);
    expense.setValidatedBy(AuthUtils.getUser());
    expense.setValidationDate(appAccountService.getTodayDate(expense.getCompany()));
    if (expense.getUser().getPartner() != null) {
        PaymentMode paymentMode = expense.getUser().getPartner().getOutPaymentMode();
        expense.setPaymentMode(paymentMode);
    }
    expenseRepository.save(expense);
}
Also used : AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) EmployeeAdvanceService(com.axelor.apps.hr.service.EmployeeAdvanceService) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) KilometricService(com.axelor.apps.hr.service.KilometricService) BigDecimal(java.math.BigDecimal) PaymentMode(com.axelor.apps.account.db.PaymentMode) Transactional(com.google.inject.persist.Transactional)

Example 20 with Employee

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

the class LeaveServiceImpl method manageCancelLeaves.

@Override
@Transactional(rollbackOn = { Exception.class })
public void manageCancelLeaves(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.getStatusSelect() == LeaveRequestRepository.STATUS_VALIDATED) {
        if (leave.getInjectConsumeSelect() == LeaveRequestRepository.SELECT_CONSUME) {
            leaveLine.setQuantity(leaveLine.getQuantity().add(leave.getDuration()));
        } else {
            leaveLine.setQuantity(leaveLine.getQuantity().subtract(leave.getDuration()));
        }
        leaveLine.setDaysValidated(leaveLine.getDaysValidated().subtract(leave.getDuration()));
    } else if (leave.getStatusSelect() == LeaveRequestRepository.STATUS_AWAITING_VALIDATION) {
        if (leave.getInjectConsumeSelect() == LeaveRequestRepository.SELECT_CONSUME) {
            leaveLine.setDaysToValidate(leaveLine.getDaysToValidate().subtract(leave.getDuration()));
        } else {
            leaveLine.setDaysToValidate(leaveLine.getDaysToValidate().add(leave.getDuration()));
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) LeaveLine(com.axelor.apps.hr.db.LeaveLine) Transactional(com.google.inject.persist.Transactional)

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