use of com.axelor.rpc.Context 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.rpc.Context 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.rpc.Context in project axelor-open-suite by axelor.
the class ProjectPlanningTimeController method showPlanning.
public void showPlanning(ActionRequest request, ActionResponse response) {
Context context = request.getContext();
Collection<Map<String, Object>> users = (Collection<Map<String, Object>>) context.get("userSet");
Map<String, Object> project = (Map<String, Object>) context.get("_project");
String userIds = "";
if (users != null) {
for (Map<String, Object> user : users) {
if (userIds.isEmpty()) {
userIds = user.get("id").toString();
} else {
userIds += "," + user.get("id").toString();
}
}
}
String projectId = "";
if (project != null && project.get("id") != null) {
projectId = project.get("id").toString();
}
ActionViewBuilder builder = ActionView.define(I18n.get("Project Planning time")).model(ProjectPlanningTime.class.getName());
String url = "project/planning";
if (!userIds.isEmpty() && !projectId.isEmpty()) {
url += "?userIds=" + userIds + "&projectIds=" + projectId;
} else if (!userIds.isEmpty()) {
url += "?userIds=" + userIds;
} else if (!projectId.isEmpty()) {
url += "?projectIds=" + projectId;
}
builder.add("html", url);
response.setView(builder.map());
response.setCanClose(true);
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class TimesheetLineController method setDuration.
/**
* Called from timesheet editor Get the timesheet corresponding to timesheetline and call {@link
* TimesheetLineService#computeHoursDuration(Timesheet, BigDecimal, boolean)}
*
* @param request
* @param response
*/
public void setDuration(ActionRequest request, ActionResponse response) {
try {
TimesheetLine timesheetLine = request.getContext().asType(TimesheetLine.class);
Timesheet timesheet;
Context parent = request.getContext().getParent();
if (parent != null && parent.getContextClass().equals(Timesheet.class)) {
timesheet = parent.asType(Timesheet.class);
} else {
timesheet = timesheetLine.getTimesheet();
}
BigDecimal duration = Beans.get(TimesheetLineService.class).computeHoursDuration(timesheet, timesheetLine.getHoursDuration(), false);
response.setValue(DURATION_FIELD, duration);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.rpc.Context in project axelor-open-suite by axelor.
the class TimesheetLineController method setStoredDuration.
/**
* Called from timesheet line editable grid or form. Get the timesheet corresponding to
* timesheetline and call {@link TimesheetLineService#computeHoursDuration(Timesheet, BigDecimal,
* boolean)}
*
* @param request
* @param response
*/
public void setStoredDuration(ActionRequest request, ActionResponse response) {
try {
TimesheetLine timesheetLine = request.getContext().asType(TimesheetLine.class);
Timesheet timesheet;
Context parent = request.getContext().getParent();
if (parent != null && parent.getContextClass().equals(Timesheet.class)) {
timesheet = parent.asType(Timesheet.class);
} else {
timesheet = timesheetLine.getTimesheet();
}
BigDecimal hoursDuration = Beans.get(TimesheetLineService.class).computeHoursDuration(timesheet, timesheetLine.getDuration(), true);
response.setValue(HOURS_DURATION_FIELD, hoursDuration);
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
Aggregations