Search in sources :

Example 1 with EmploymentContract

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

the class EmploymentContractController method addAmendment.

public void addAmendment(ActionRequest request, ActionResponse response) {
    EmploymentContract employmentContract = request.getContext().asType(EmploymentContract.class);
    try {
        Beans.get(EmploymentContractService.class).addAmendment(Beans.get(EmploymentContractRepository.class).find(employmentContract.getId()));
        response.setFlash(String.format("Contrat %s - avenant %s", employmentContract.getFullName(), employmentContract.getEmploymentContractVersion()));
        response.setReload(true);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : EmploymentContract(com.axelor.apps.hr.db.EmploymentContract) EmploymentContractService(com.axelor.apps.hr.service.EmploymentContractService) IOException(java.io.IOException)

Example 2 with EmploymentContract

use of com.axelor.apps.hr.db.EmploymentContract 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 3 with EmploymentContract

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

the class KilometricService method computeKilometricExpense.

public BigDecimal computeKilometricExpense(ExpenseLine expenseLine, Employee employee) throws AxelorException {
    BigDecimal distance = expenseLine.getDistance();
    EmploymentContract mainEmploymentContract = employee.getMainEmploymentContract();
    if (mainEmploymentContract == null || mainEmploymentContract.getPayCompany() == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.EMPLOYEE_CONTRACT_OF_EMPLOYMENT), employee.getName());
    }
    Company company = mainEmploymentContract.getPayCompany();
    KilometricLog log = getKilometricLog(employee, expenseLine.getExpenseDate());
    BigDecimal previousDistance = log == null ? BigDecimal.ZERO : log.getDistanceTravelled();
    KilometricAllowanceRate allowance = expenseLine.getKilometricAllowParam() != null ? Beans.get(KilometricAllowanceRateRepository.class).all().filter("self.kilometricAllowParam.id = :_kilometricAllowParamId " + "and self.hrConfig.id = :_hrConfigId").bind("_kilometricAllowParamId", expenseLine.getKilometricAllowParam().getId()).bind("_hrConfigId", Beans.get(HRConfigService.class).getHRConfig(company).getId()).fetchOne() : null;
    if (allowance == null) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.KILOMETRIC_ALLOWANCE_RATE_MISSING), expenseLine.getKilometricAllowParam() != null ? expenseLine.getKilometricAllowParam().getName() : "", company.getName());
    }
    List<KilometricAllowanceRule> ruleList = new ArrayList<>();
    List<KilometricAllowanceRule> allowanceRuleList = allowance.getKilometricAllowanceRuleList();
    if (ObjectUtils.notEmpty(allowanceRuleList)) {
        for (KilometricAllowanceRule rule : allowanceRuleList) {
            if (rule.getMinimumCondition().compareTo(previousDistance.add(distance)) <= 0 && rule.getMaximumCondition().compareTo(previousDistance) >= 0) {
                ruleList.add(rule);
            }
        }
    }
    if (ruleList.isEmpty()) {
        throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.KILOMETRIC_ALLOWANCE_NO_RULE), allowance.getKilometricAllowParam().getName());
    }
    BigDecimal price = BigDecimal.ZERO;
    if (ruleList.size() == 1) {
        price = distance.multiply(ruleList.get(0).getRate());
    } else {
        Collections.sort(ruleList, (object1, object2) -> object1.getMinimumCondition().compareTo(object2.getMinimumCondition()));
        for (KilometricAllowanceRule rule : ruleList) {
            BigDecimal min = rule.getMinimumCondition().max(previousDistance);
            BigDecimal max = rule.getMaximumCondition().min(previousDistance.add(distance));
            price = price.add(max.subtract(min).multiply(rule.getRate()));
        }
    }
    return price.setScale(2, RoundingMode.HALF_UP);
}
Also used : EmploymentContract(com.axelor.apps.hr.db.EmploymentContract) AxelorException(com.axelor.exception.AxelorException) Company(com.axelor.apps.base.db.Company) ArrayList(java.util.ArrayList) KilometricAllowanceRate(com.axelor.apps.hr.db.KilometricAllowanceRate) HRConfigService(com.axelor.apps.hr.service.config.HRConfigService) KilometricLog(com.axelor.apps.hr.db.KilometricLog) KilometricAllowanceRule(com.axelor.apps.hr.db.KilometricAllowanceRule) BigDecimal(java.math.BigDecimal)

Example 4 with EmploymentContract

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

the class BatchEmploymentContractExport method employmentContractExportSilae.

@Transactional(rollbackOn = { Exception.class })
public MetaFile employmentContractExportSilae(List<EmploymentContract> employmentContractList) throws IOException {
    List<String[]> list = new ArrayList<>();
    for (EmploymentContract employmentContract : employmentContractList) {
        Beans.get(EmploymentContractService.class).employmentContractExportSilae(employmentContract, list);
        total++;
        incrementDone();
    }
    File tempFile = MetaFiles.createTempFile(Beans.get(EmploymentContractService.class).employmentContractExportName(), ".csv").toFile();
    String[] headers = Beans.get(EmploymentContractService.class).employmentContractExportHeaders();
    CsvTool.csvWriter(tempFile.getParent(), tempFile.getName(), ';', headers, list);
    MetaFiles metaFiles = Beans.get(MetaFiles.class);
    MetaFile metaFile = metaFiles.upload(tempFile);
    tempFile.delete();
    return metaFile;
}
Also used : EmploymentContract(com.axelor.apps.hr.db.EmploymentContract) EmploymentContractService(com.axelor.apps.hr.service.EmploymentContractService) MetaFiles(com.axelor.meta.MetaFiles) ArrayList(java.util.ArrayList) MetaFile(com.axelor.meta.db.MetaFile) File(java.io.File) MetaFile(com.axelor.meta.db.MetaFile) Transactional(com.google.inject.persist.Transactional)

Example 5 with EmploymentContract

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

the class BatchSeniorityLeaveManagement method createLeaveManagement.

@Transactional(rollbackOn = { Exception.class })
public void createLeaveManagement(Employee employee) throws AxelorException {
    if (employee == null || EmployeeHRRepository.isEmployeeFormerNewOrArchived(employee)) {
        return;
    }
    batch = batchRepo.find(batch.getId());
    int count = 0;
    String eval = null;
    LeaveLine leaveLine = null;
    BigDecimal quantity = BigDecimal.ZERO;
    if (!employee.getLeaveLineList().isEmpty()) {
        for (LeaveLine line : employee.getLeaveLineList()) {
            if (line.getLeaveReason().equals(batch.getHrBatch().getLeaveReason())) {
                count++;
                leaveLine = line;
            }
        }
    }
    if (count == 0) {
        throw new AxelorException(employee, TraceBackRepository.CATEGORY_NO_VALUE, I18n.get(IExceptionMessage.EMPLOYEE_NO_LEAVE_MANAGEMENT), employee.getName(), batch.getHrBatch().getLeaveReason().getName());
    }
    if (count > 1) {
        throw new AxelorException(employee, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.EMPLOYEE_DOUBLE_LEAVE_MANAGEMENT), employee.getName(), batch.getHrBatch().getLeaveReason().getName());
    }
    if (count == 1) {
        EmploymentContract contract = employee.getMainEmploymentContract();
        if (contract == null) {
            throw new AxelorException(TraceBackRepository.CATEGORY_NO_VALUE, IExceptionMessage.EMPLOYEE_CONTRACT_OF_EMPLOYMENT);
        }
        Integer executiveStatusSelect = contract.getExecutiveStatusSelect();
        for (LeaveManagementBatchRule rule : Beans.get(HRConfigRepository.class).all().filter("self.company.id = ?1", batch.getHrBatch().getCompany().getId()).fetchOne().getLeaveManagementBatchRuleList()) {
            if (rule.getExecutiveStatusSelect().equals(executiveStatusSelect)) {
                maker.setContext(employee, "Employee");
                String formula = rule.getFormula();
                formula = formula.replace(hrConfig.getSeniorityVariableName(), String.valueOf(Beans.get(EmployeeService.class).getLengthOfService(employee, batch.getHrBatch().getReferentialDate())));
                formula = formula.replace(hrConfig.getAgeVariableName(), String.valueOf(Beans.get(EmployeeService.class).getAge(employee, batch.getHrBatch().getReferentialDate())));
                maker.setTemplate(formula);
                eval = maker.make();
                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);
                if (shell.evaluate(eval).toString().equals("true")) {
                    quantity = rule.getLeaveDayNumber();
                    break;
                }
            }
        }
        if (quantity.signum() == 0) {
            // If the quantity equals 0, no need to create a leaveManagement and to update the employee,
            // since we won't give them any leaves
            incrementDone();
            return;
        }
        LeaveManagement leaveManagement = leaveManagementService.createLeaveManagement(leaveLine, AuthUtils.getUser(), batch.getHrBatch().getComments(), null, batch.getHrBatch().getStartDate(), batch.getHrBatch().getEndDate(), quantity);
        leaveLine.setQuantity(leaveLine.getQuantity().add(quantity));
        leaveLine.setTotalQuantity(leaveLine.getTotalQuantity().add(quantity));
        leaveManagementRepository.save(leaveManagement);
        leaveLineRepository.save(leaveLine);
        updateEmployee(employee);
    }
}
Also used : EmploymentContract(com.axelor.apps.hr.db.EmploymentContract) Binding(groovy.lang.Binding) AxelorException(com.axelor.exception.AxelorException) BigDecimal(java.math.BigDecimal) GroovyShell(groovy.lang.GroovyShell) LeaveManagement(com.axelor.apps.hr.db.LeaveManagement) LeaveLine(com.axelor.apps.hr.db.LeaveLine) CompilerConfiguration(org.codehaus.groovy.control.CompilerConfiguration) LeaveManagementBatchRule(com.axelor.apps.hr.db.LeaveManagementBatchRule) ImportCustomizer(org.codehaus.groovy.control.customizers.ImportCustomizer) Transactional(com.google.inject.persist.Transactional)

Aggregations

EmploymentContract (com.axelor.apps.hr.db.EmploymentContract)10 Transactional (com.google.inject.persist.Transactional)5 EmploymentContractService (com.axelor.apps.hr.service.EmploymentContractService)3 AxelorException (com.axelor.exception.AxelorException)3 Company (com.axelor.apps.base.db.Company)2 Partner (com.axelor.apps.base.db.Partner)2 Employee (com.axelor.apps.hr.db.Employee)2 EmployeeRepository (com.axelor.apps.hr.db.repo.EmployeeRepository)2 EmploymentContractRepository (com.axelor.apps.hr.db.repo.EmploymentContractRepository)2 BigDecimal (java.math.BigDecimal)2 ArrayList (java.util.ArrayList)2 PartnerService (com.axelor.apps.base.service.PartnerService)1 UserService (com.axelor.apps.base.service.user.UserService)1 DPAE (com.axelor.apps.hr.db.DPAE)1 KilometricAllowanceRate (com.axelor.apps.hr.db.KilometricAllowanceRate)1 KilometricAllowanceRule (com.axelor.apps.hr.db.KilometricAllowanceRule)1 KilometricLog (com.axelor.apps.hr.db.KilometricLog)1 LeaveLine (com.axelor.apps.hr.db.LeaveLine)1 LeaveManagement (com.axelor.apps.hr.db.LeaveManagement)1 LeaveManagementBatchRule (com.axelor.apps.hr.db.LeaveManagementBatchRule)1