Search in sources :

Example 16 with Context

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);
}
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 17 with Context

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);
    }
}
Also used : Context(com.axelor.rpc.Context) AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) AppHumanResourceService(com.axelor.apps.hr.service.app.AppHumanResourceService) Expense(com.axelor.apps.hr.db.Expense) ExpenseLine(com.axelor.apps.hr.db.ExpenseLine) KilometricService(com.axelor.apps.hr.service.KilometricService) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException)

Example 18 with Context

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);
}
Also used : Context(com.axelor.rpc.Context) Collection(java.util.Collection) ProjectPlanningTime(com.axelor.apps.project.db.ProjectPlanningTime) Map(java.util.Map) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)

Example 19 with Context

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);
    }
}
Also used : Context(com.axelor.rpc.Context) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Timesheet(com.axelor.apps.hr.db.Timesheet) TimesheetLineService(com.axelor.apps.hr.service.timesheet.TimesheetLineService) BigDecimal(java.math.BigDecimal)

Example 20 with Context

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);
    }
}
Also used : Context(com.axelor.rpc.Context) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Timesheet(com.axelor.apps.hr.db.Timesheet) TimesheetLineService(com.axelor.apps.hr.service.timesheet.TimesheetLineService) BigDecimal(java.math.BigDecimal)

Aggregations

Context (com.axelor.rpc.Context)149 AxelorException (com.axelor.exception.AxelorException)52 BigDecimal (java.math.BigDecimal)37 Map (java.util.Map)37 HashMap (java.util.HashMap)26 ArrayList (java.util.ArrayList)23 SaleOrder (com.axelor.apps.sale.db.SaleOrder)19 List (java.util.List)18 SaleOrderLine (com.axelor.apps.sale.db.SaleOrderLine)17 Invoice (com.axelor.apps.account.db.Invoice)16 LinkedHashMap (java.util.LinkedHashMap)15 Product (com.axelor.apps.base.db.Product)14 Model (com.axelor.db.Model)13 StockMove (com.axelor.apps.stock.db.StockMove)12 StockMoveLine (com.axelor.apps.stock.db.StockMoveLine)12 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)11 PurchaseOrder (com.axelor.apps.purchase.db.PurchaseOrder)11 LocalDate (java.time.LocalDate)11 Beans (com.axelor.inject.Beans)10 ActionRequest (com.axelor.rpc.ActionRequest)10