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);
}
}
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);
}
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);
}
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;
}
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);
}
}
Aggregations