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