use of com.axelor.apps.hr.db.Employee 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.Employee in project axelor-open-suite by axelor.
the class ExpenseController method validateExpense.
public void validateExpense(ActionRequest request, ActionResponse response) {
User user = AuthUtils.getUser();
Employee employee = user.getEmployee();
ActionViewBuilder actionView = ActionView.define(I18n.get("Expenses to Validate")).model(Expense.class.getName()).add("grid", "expense-validate-grid").add("form", "expense-form").param("search-filters", "expense-filters");
Beans.get(HRMenuValidateService.class).createValidateDomain(user, employee, actionView);
response.setView(actionView.map());
}
use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class ExpenseController method computeDistanceAndKilometricExpense.
public void computeDistanceAndKilometricExpense(ActionRequest request, ActionResponse response) throws AxelorException {
// Compute distance.
try {
if (!Beans.get(AppHumanResourceService.class).getAppExpense().getComputeDistanceWithWebService()) {
return;
}
Context context = request.getContext();
ExpenseLine expenseLine = context.asType(ExpenseLine.class);
if (Strings.isNullOrEmpty(expenseLine.getFromCity()) || Strings.isNullOrEmpty(expenseLine.getToCity())) {
return;
}
KilometricService kilometricService = Beans.get(KilometricService.class);
BigDecimal distance = kilometricService.computeDistance(expenseLine);
expenseLine.setDistance(distance);
response.setValue("distance", distance);
if (expenseLine.getKilometricAllowParam() == null || expenseLine.getExpenseDate() == null || expenseLine.getKilometricTypeSelect() == 0) {
return;
}
Expense expense = expenseLine.getExpense();
if (expense == null) {
expense = context.getParent().asType(Expense.class);
}
Employee employee = expense.getUser().getEmployee();
if (employee == null) {
throw new AxelorException(TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), expense.getUser().getName());
}
BigDecimal amount = kilometricService.computeKilometricExpense(expenseLine, employee);
response.setValue("totalAmount", amount);
response.setValue("untaxedAmount", amount);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class TimesheetReportServiceImpl method getTotalWeekWorkedHours.
private BigDecimal getTotalWeekWorkedHours(User user, LocalDate fromDate, LocalDate toDate, BigDecimal publicHolidays) throws AxelorException {
BigDecimal totalHours = BigDecimal.ZERO;
Employee employee = user.getEmployee();
List<TimesheetLine> timesheetLineList = timesheetLineRepository.all().filter("self.user = ? AND (self.date BETWEEN ? AND ?) AND (self.timesheet.statusSelect = ? OR self.timesheet.statusSelect = ?)", user, fromDate, toDate, TimesheetRepository.STATUS_VALIDATED, TimesheetRepository.STATUS_CONFIRMED).fetch();
Duration totalDuration = timesheetLineService.computeTotalDuration(timesheetLineList);
totalHours = new BigDecimal(totalDuration.getSeconds()).divide(BigDecimal.valueOf(3600)).setScale(2, RoundingMode.HALF_UP);
totalHours = totalHours.add(publicHolidays.multiply(employee.getDailyWorkHours()));
totalHours = totalHours.add(getWeekLeaveHours(user, fromDate, toDate, employee.getDailyWorkHours()));
return totalHours.setScale(2, RoundingMode.HALF_UP);
}
use of com.axelor.apps.hr.db.Employee in project axelor-open-suite by axelor.
the class TimesheetReportServiceImpl method getTotalWorksHours.
private BigDecimal getTotalWorksHours(User user, LocalDate date, boolean isPublicHoliday, BigDecimal dailyWorkingHours) throws AxelorException {
Employee employee = user.getEmployee();
BigDecimal worksHour = employeeService.getDaysWorksInPeriod(employee, date, date).multiply(employee.getDailyWorkHours()).setScale(2, RoundingMode.HALF_UP);
if (isPublicHoliday) {
worksHour = worksHour.add(dailyWorkingHours);
}
double extraHours = extraHoursLineRepository.all().filter("self.user = ? AND self.date = ? AND (self.extraHours.statusSelect = ? OR self.extraHours.statusSelect = ?)", user, date, ExtraHoursRepository.STATUS_VALIDATED, ExtraHoursRepository.STATUS_CONFIRMED).fetchStream().mapToDouble(ehl -> Double.parseDouble(ehl.getQty().toString())).sum();
worksHour = worksHour.add(new BigDecimal(extraHours));
return worksHour.setScale(2, RoundingMode.HALF_UP);
}
Aggregations