Search in sources :

Example 21 with User

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

the class ExpenseController method showSubordinateExpenses.

public void showSubordinateExpenses(ActionRequest request, ActionResponse response) {
    User user = AuthUtils.getUser();
    Company activeCompany = user.getActiveCompany();
    ActionViewBuilder actionView = ActionView.define(I18n.get("Expenses to be Validated by your subordinates")).model(Expense.class.getName()).add("grid", "expense-grid").add("form", "expense-form").param("search-filters", "expense-filters");
    String domain = "self.user.employee.managerUser.employee.managerUser = :_user AND self.company = :_activeCompany AND self.statusSelect = 2";
    long nbExpenses = Query.of(Expense.class).filter(domain).bind("_user", user).bind("_activeCompany", activeCompany).count();
    if (nbExpenses == 0) {
        response.setNotify(I18n.get("No expense to be validated by your subordinates"));
    } else {
        response.setView(actionView.domain(domain).context("_user", user).context("_activeCompany", activeCompany).map());
    }
}
Also used : Company(com.axelor.apps.base.db.Company) User(com.axelor.auth.db.User) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)

Example 22 with User

use of com.axelor.auth.db.User 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);
}
Also used : IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) LeaveRequestRepository(com.axelor.apps.hr.db.repo.LeaveRequestRepository) Employee(com.axelor.apps.hr.db.Employee) Inject(com.google.inject.Inject) TimesheetReportRepository(com.axelor.apps.hr.db.repo.TimesheetReportRepository) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) LeaveReasonRepository(com.axelor.apps.hr.db.repo.LeaveReasonRepository) TimesheetReminder(com.axelor.apps.hr.db.TimesheetReminder) Duration(java.time.Duration) Map(java.util.Map) EmployeeService(com.axelor.apps.hr.service.employee.EmployeeService) RoundingMode(java.math.RoundingMode) PublicHolidayService(com.axelor.apps.base.service.publicHoliday.PublicHolidayService) Set(java.util.Set) Message(com.axelor.apps.message.db.Message) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Collectors(java.util.stream.Collectors) MessageService(com.axelor.apps.message.service.MessageService) List(java.util.List) Stream(java.util.stream.Stream) TimesheetRepository(com.axelor.apps.hr.db.repo.TimesheetRepository) LocalDate(java.time.LocalDate) TemporalAdjusters(java.time.temporal.TemporalAdjusters) Optional(java.util.Optional) LeaveService(com.axelor.apps.hr.service.leave.LeaveService) ExtraHoursRepository(com.axelor.apps.hr.db.repo.ExtraHoursRepository) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) TimesheetReminderLine(com.axelor.apps.hr.db.TimesheetReminderLine) ExtraHoursLineRepository(com.axelor.apps.hr.db.repo.ExtraHoursLineRepository) AppHumanResourceService(com.axelor.apps.hr.service.app.AppHumanResourceService) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TimesheetLineRepository(com.axelor.apps.hr.db.repo.TimesheetLineRepository) TimesheetReport(com.axelor.apps.hr.db.TimesheetReport) AxelorException(com.axelor.exception.AxelorException) I18n(com.axelor.i18n.I18n) DateTool(com.axelor.apps.tool.date.DateTool) WeekFields(java.time.temporal.WeekFields) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) QueryBuilder(com.axelor.apps.tool.QueryBuilder) TraceBackService(com.axelor.exception.service.TraceBackService) TimesheetReminderRepository(com.axelor.apps.hr.db.repo.TimesheetReminderRepository) Template(com.axelor.apps.message.db.Template) DayPlanning(com.axelor.apps.base.db.DayPlanning) Beans(com.axelor.inject.Beans) WeeklyPlanningService(com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService) DayOfWeek(java.time.DayOfWeek) TemplateMessageService(com.axelor.apps.message.service.TemplateMessageService) User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) BigDecimal(java.math.BigDecimal)

Example 23 with User

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

the class TimesheetReportServiceImpl method getTotalWeekWorksHours.

private BigDecimal getTotalWeekWorksHours(User user, LocalDate fromDate, LocalDate toDate, BigDecimal publicHolidays) throws AxelorException {
    Employee employee = user.getEmployee();
    BigDecimal worksHour = employeeService.getDaysWorksInPeriod(employee, fromDate, toDate).multiply(employee.getDailyWorkHours()).setScale(2, RoundingMode.HALF_UP);
    worksHour = worksHour.add(publicHolidays.multiply(employee.getDailyWorkHours()));
    double extraHours = extraHoursLineRepository.all().filter("self.user = ? AND (self.date BETWEEN ? AND ?) AND (self.extraHours.statusSelect = ? OR self.extraHours.statusSelect = ?)", user, fromDate, toDate, 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);
}
Also used : IExceptionMessage(com.axelor.apps.hr.exception.IExceptionMessage) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) LeaveRequestRepository(com.axelor.apps.hr.db.repo.LeaveRequestRepository) Employee(com.axelor.apps.hr.db.Employee) Inject(com.google.inject.Inject) TimesheetReportRepository(com.axelor.apps.hr.db.repo.TimesheetReportRepository) Transactional(com.google.inject.persist.Transactional) BigDecimal(java.math.BigDecimal) LeaveReasonRepository(com.axelor.apps.hr.db.repo.LeaveReasonRepository) TimesheetReminder(com.axelor.apps.hr.db.TimesheetReminder) Duration(java.time.Duration) Map(java.util.Map) EmployeeService(com.axelor.apps.hr.service.employee.EmployeeService) RoundingMode(java.math.RoundingMode) PublicHolidayService(com.axelor.apps.base.service.publicHoliday.PublicHolidayService) Set(java.util.Set) Message(com.axelor.apps.message.db.Message) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Collectors(java.util.stream.Collectors) MessageService(com.axelor.apps.message.service.MessageService) List(java.util.List) Stream(java.util.stream.Stream) TimesheetRepository(com.axelor.apps.hr.db.repo.TimesheetRepository) LocalDate(java.time.LocalDate) TemporalAdjusters(java.time.temporal.TemporalAdjusters) Optional(java.util.Optional) LeaveService(com.axelor.apps.hr.service.leave.LeaveService) ExtraHoursRepository(com.axelor.apps.hr.db.repo.ExtraHoursRepository) LocalDateTime(java.time.LocalDateTime) HashMap(java.util.HashMap) TimesheetReminderLine(com.axelor.apps.hr.db.TimesheetReminderLine) ExtraHoursLineRepository(com.axelor.apps.hr.db.repo.ExtraHoursLineRepository) AppHumanResourceService(com.axelor.apps.hr.service.app.AppHumanResourceService) CollectionUtils(org.apache.commons.collections4.CollectionUtils) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) TimesheetLineRepository(com.axelor.apps.hr.db.repo.TimesheetLineRepository) TimesheetReport(com.axelor.apps.hr.db.TimesheetReport) AxelorException(com.axelor.exception.AxelorException) I18n(com.axelor.i18n.I18n) DateTool(com.axelor.apps.tool.date.DateTool) WeekFields(java.time.temporal.WeekFields) TraceBackRepository(com.axelor.exception.db.repo.TraceBackRepository) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) QueryBuilder(com.axelor.apps.tool.QueryBuilder) TraceBackService(com.axelor.exception.service.TraceBackService) TimesheetReminderRepository(com.axelor.apps.hr.db.repo.TimesheetReminderRepository) Template(com.axelor.apps.message.db.Template) DayPlanning(com.axelor.apps.base.db.DayPlanning) Beans(com.axelor.inject.Beans) WeeklyPlanningService(com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService) DayOfWeek(java.time.DayOfWeek) TemplateMessageService(com.axelor.apps.message.service.TemplateMessageService) User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) BigDecimal(java.math.BigDecimal)

Example 24 with User

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

the class TimesheetController method validateTimesheet.

public void validateTimesheet(ActionRequest request, ActionResponse response) {
    User user = AuthUtils.getUser();
    Employee employee = user.getEmployee();
    ActionViewBuilder actionView = ActionView.define(I18n.get("Timesheets to Validate")).model(Timesheet.class.getName()).add("grid", "timesheet-validate-grid").add("form", "timesheet-form").param("search-filters", "timesheet-filters").context("todayDate", Beans.get(AppBaseService.class).getTodayDate(user.getActiveCompany()));
    Beans.get(HRMenuValidateService.class).createValidateDomain(user, employee, actionView);
    response.setView(actionView.map());
}
Also used : User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) HRMenuValidateService(com.axelor.apps.hr.service.HRMenuValidateService) Timesheet(com.axelor.apps.hr.db.Timesheet) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)

Example 25 with User

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

the class TimesheetController method allTimesheet.

public void allTimesheet(ActionRequest request, ActionResponse response) {
    User user = AuthUtils.getUser();
    Employee employee = user.getEmployee();
    ActionViewBuilder actionView = ActionView.define(I18n.get("Timesheets")).model(Timesheet.class.getName()).add("grid", "all-timesheet-grid").add("form", "timesheet-form").param("search-filters", "timesheet-filters");
    if (employee == null || !employee.getHrManager()) {
        if (employee == null || employee.getManagerUser() == null) {
            actionView.domain("self.user = :_user OR self.user.employee.managerUser = :_user").context("_user", user);
        } else {
            actionView.domain("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)

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