Search in sources :

Example 91 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class ExtraHoursController method historicExtraHours.

public void historicExtraHours(ActionRequest request, ActionResponse response) {
    User user = AuthUtils.getUser();
    Employee employee = user.getEmployee();
    ActionViewBuilder actionView = ActionView.define(I18n.get("Historic colleague extra hours")).model(ExtraHours.class.getName()).add("grid", "extra-hours-grid").add("form", "extra-hours-form").param("search-filters", "extra-hours-filters");
    actionView.domain("self.company = :_activeCompany AND (self.statusSelect = 3 OR self.statusSelect = 4)").context("_activeCompany", user.getActiveCompany());
    if (employee == null || !employee.getHrManager()) {
        actionView.domain(actionView.get().getDomain() + " AND self.user.employee.managerUser = :_user").context("_user", user);
    }
    response.setView(actionView.map());
}
Also used : User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)

Example 92 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class LeaveController method editLeave.

public void editLeave(ActionRequest request, ActionResponse response) {
    try {
        User user = AuthUtils.getUser();
        List<LeaveRequest> leaveList = Beans.get(LeaveRequestRepository.class).all().filter("self.user = ?1 AND self.company = ?2 AND self.statusSelect = 1", user, user.getActiveCompany()).fetch();
        if (leaveList.isEmpty()) {
            response.setView(ActionView.define(I18n.get("LeaveRequest")).model(LeaveRequest.class.getName()).add("form", "leave-request-form").map());
        } else if (leaveList.size() == 1) {
            response.setView(ActionView.define(I18n.get("LeaveRequest")).model(LeaveRequest.class.getName()).add("form", "leave-request-form").param("forceEdit", "true").context("_showRecord", String.valueOf(leaveList.get(0).getId())).map());
        } else {
            response.setView(ActionView.define(I18n.get("LeaveRequest")).model(Wizard.class.getName()).add("form", "popup-leave-request-form").param("forceEdit", "true").param("popup", "true").param("show-toolbar", "false").param("show-confirm", "false").param("forceEdit", "true").param("popup-save", "false").map());
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : User(com.axelor.auth.db.User) LeaveRequestRepository(com.axelor.apps.hr.db.repo.LeaveRequestRepository) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) Wizard(com.axelor.apps.base.db.Wizard) AxelorException(com.axelor.exception.AxelorException)

Example 93 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class LeaveController method validateLeave.

public void validateLeave(ActionRequest request, ActionResponse response) {
    try {
        User user = AuthUtils.getUser();
        Employee employee = user.getEmployee();
        ActionViewBuilder actionView = ActionView.define(I18n.get("Leave Requests to Validate")).model(LeaveRequest.class.getName()).add("grid", "leave-request-validate-grid").add("form", "leave-request-form").param("search-filters", "leave-request-filters");
        Beans.get(HRMenuValidateService.class).createValidateDomain(user, employee, actionView);
        response.setView(actionView.map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) HRMenuValidateService(com.axelor.apps.hr.service.HRMenuValidateService) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException)

Example 94 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class UserController method changePfpValidator.

@SuppressWarnings("unchecked")
public void changePfpValidator(ActionRequest request, ActionResponse response) {
    Integer pfpValidatorUserId = (Integer) request.getContext().get("_userId");
    LinkedHashMap<String, Object> newPfpValidatorUserMap = (LinkedHashMap<String, Object>) request.getContext().get("newPfpValidatorUser");
    if (newPfpValidatorUserMap == null) {
        return;
    }
    UserRepository userRepository = Beans.get(UserRepository.class);
    User newPfpValidatorUser = userRepository.find(((Integer) newPfpValidatorUserMap.get("id")).longValue());
    User pfpValidatorUser = userRepository.find(pfpValidatorUserId.longValue());
    int updateCount = Beans.get(UserServiceAccountImpl.class).changePfpValidator(pfpValidatorUser, newPfpValidatorUser);
    if (updateCount >= 1) {
        response.setFlash(I18n.get(IExceptionMessage.USER_PFP_VALIDATOR_UPDATED));
        response.setCanClose(true);
    } else if (updateCount == 0) {
        response.setAlert(String.format(I18n.get(IExceptionMessage.USER_PFP_VALIDATOR_NO_RELATED_ACCOUNTING_SITUATION), pfpValidatorUser.getName()));
    }
}
Also used : UserRepository(com.axelor.auth.db.repo.UserRepository) User(com.axelor.auth.db.User) UserServiceAccountImpl(com.axelor.apps.account.service.UserServiceAccountImpl) LinkedHashMap(java.util.LinkedHashMap)

Example 95 with User

use of com.axelor.auth.db.User in project axelor-open-suite by axelor.

the class WkfEmailServiceImpl method sendEmail.

@Override
public void sendEmail(WkfTaskConfig wkfTaskConfig, DelegateExecution execution) throws ClassNotFoundException, MessagingException, AxelorException, InstantiationException, IllegalAccessException, IOException {
    String title = wkfTaskConfig.getTaskEmailTitle();
    if (title == null) {
        return;
    }
    FullContext wkfContext = wkfUserActionService.getModelCtx(wkfTaskConfig, execution);
    if (wkfContext == null) {
        return;
    }
    String model = null;
    String tag = null;
    Long id = null;
    title = wkfUserActionService.processTitle(title, wkfContext);
    model = wkfContext.getTarget().getClass().getName();
    if (wkfContext.getTarget().getClass().equals(MetaJsonRecord.class)) {
        tag = (String) wkfContext.get("jsonModel");
        model = tag;
    } else {
        tag = wkfContext.getTarget().getClass().getSimpleName();
    }
    id = (Long) wkfContext.get("id");
    String url = createUrl(wkfContext, wkfTaskConfig.getDefaultForm());
    String activeNode = execution.getCurrentActivityName();
    Template template = Beans.get(TemplateRepository.class).findByName(wkfTaskConfig.getTemplateName());
    Message message = null;
    if (template != null) {
        url = "<a href=\"" + url + "\" >" + url + "</a>";
        message = Beans.get(TemplateMessageService.class).generateMessage(id, model, tag, template);
        message.setSubject(message.getSubject().replace("{{activeNode}}", activeNode));
        message.setContent(message.getContent().replace("{{activeNode}}", activeNode));
        message.setSubject(message.getSubject().replace("{{recordUrl}}", url));
        message.setContent(message.getContent().replace("{{recordUrl}}", url));
    } else {
        User user = null;
        if (wkfTaskConfig.getUserPath() != null) {
            user = wkfUserActionService.getUser(wkfTaskConfig.getUserPath(), wkfContext);
        }
        if (user == null || user.getEmail() == null) {
            return;
        }
        String content = String.format(EMAIL_CONTENT, user.getName(), activeNode, url, url);
        List<EmailAddress> toEmailAddressList = new ArrayList<EmailAddress>();
        EmailAddress emailAddress = Beans.get(EmailAddressRepository.class).findByAddress(user.getEmail());
        if (emailAddress == null) {
            emailAddress = new EmailAddress(user.getEmail());
        }
        toEmailAddressList.add(emailAddress);
        message = messageService.createMessage(model, id, title, content, null, null, toEmailAddressList, null, null, null, null, MessageRepository.MEDIA_TYPE_EMAIL, null, null);
    }
    messageService.sendByEmail(message);
}
Also used : TemplateRepository(com.axelor.apps.message.db.repo.TemplateRepository) User(com.axelor.auth.db.User) Message(com.axelor.apps.message.db.Message) EmailAddressRepository(com.axelor.apps.message.db.repo.EmailAddressRepository) FullContext(com.axelor.apps.tool.context.FullContext) ArrayList(java.util.ArrayList) EmailAddress(com.axelor.apps.message.db.EmailAddress) Template(com.axelor.apps.message.db.Template)

Aggregations

User (com.axelor.auth.db.User)157 AxelorException (com.axelor.exception.AxelorException)35 Employee (com.axelor.apps.hr.db.Employee)28 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)25 Transactional (com.google.inject.persist.Transactional)24 LocalDate (java.time.LocalDate)23 Filter (com.axelor.rpc.filter.Filter)22 BigDecimal (java.math.BigDecimal)22 ClientViewService (com.axelor.apps.portal.service.ClientViewService)20 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)17 List (java.util.List)17 Map (java.util.Map)16 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)12 LocalDateTime (java.time.LocalDateTime)12 Company (com.axelor.apps.base.db.Company)11 Partner (com.axelor.apps.base.db.Partner)11 Beans (com.axelor.inject.Beans)11 Inject (com.google.inject.Inject)11 Product (com.axelor.apps.base.db.Product)9