Search in sources :

Example 81 with User

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

the class ProjectPlanningTimeServiceImpl method addMultipleProjectPlanningTime.

@Override
@Transactional(rollbackOn = { Exception.class })
public void addMultipleProjectPlanningTime(Map<String, Object> datas) throws AxelorException {
    if (datas.get("project") == null || datas.get("user") == null || datas.get("fromDate") == null || datas.get("toDate") == null) {
        return;
    }
    DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
    LocalDateTime fromDate = LocalDateTime.parse(datas.get("fromDate").toString(), formatter);
    LocalDateTime toDate = LocalDateTime.parse(datas.get("toDate").toString(), formatter);
    ProjectTask projectTask = null;
    Map<String, Object> objMap = (Map) datas.get("project");
    Project project = projectRepo.find(Long.parseLong(objMap.get("id").toString()));
    Integer timePercent = 0;
    if (datas.get("timepercent") != null) {
        timePercent = Integer.parseInt(datas.get("timepercent").toString());
    }
    objMap = (Map) datas.get("user");
    User user = userRepo.find(Long.parseLong(objMap.get("id").toString()));
    if (user.getEmployee() == null) {
        return;
    }
    if (datas.get("task") != null) {
        objMap = (Map) datas.get("task");
        projectTask = projectTaskRepo.find(Long.valueOf(objMap.get("id").toString()));
    }
    Product activity = null;
    if (datas.get("product") != null) {
        objMap = (Map) datas.get("product");
        activity = productRepo.find(Long.valueOf(objMap.get("id").toString()));
    }
    Employee employee = user.getEmployee();
    BigDecimal dailyWorkHrs = employee.getDailyWorkHours();
    while (fromDate.isBefore(toDate)) {
        LocalDate date = fromDate.toLocalDate();
        LOG.debug("Create Planning for the date: {}", date);
        double dayHrs = 0;
        if (employee.getWeeklyPlanning() != null) {
            dayHrs = weeklyPlanningService.getWorkingDayValueInDays(employee.getWeeklyPlanning(), date);
        }
        if (dayHrs > 0 && !holidayService.checkPublicHolidayDay(date, employee)) {
            ProjectPlanningTime planningTime = new ProjectPlanningTime();
            planningTime.setProjectTask(projectTask);
            planningTime.setProduct(activity);
            planningTime.setTimepercent(timePercent);
            planningTime.setUser(user);
            planningTime.setDate(date);
            planningTime.setProject(project);
            planningTime.setIsIncludeInTurnoverForecast((Boolean) datas.get("isIncludeInTurnoverForecast"));
            BigDecimal totalHours = BigDecimal.ZERO;
            if (timePercent > 0) {
                totalHours = dailyWorkHrs.multiply(new BigDecimal(timePercent)).divide(new BigDecimal(100));
            }
            planningTime.setPlannedHours(totalHours);
            planningTimeRepo.save(planningTime);
        }
        fromDate = fromDate.plusDays(1);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) User(com.axelor.auth.db.User) Product(com.axelor.apps.base.db.Product) ProjectPlanningTime(com.axelor.apps.project.db.ProjectPlanningTime) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Project(com.axelor.apps.project.db.Project) Employee(com.axelor.apps.hr.db.Employee) ProjectTask(com.axelor.apps.project.db.ProjectTask) DateTimeFormatter(java.time.format.DateTimeFormatter) Map(java.util.Map) Transactional(com.google.inject.persist.Transactional)

Example 82 with User

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

the class TimesheetLineServiceImpl method computeHoursDuration.

@Override
public BigDecimal computeHoursDuration(Timesheet timesheet, BigDecimal duration, boolean toHours) throws AxelorException {
    if (duration == null) {
        return null;
    }
    AppBaseService appBaseService = Beans.get(AppBaseService.class);
    BigDecimal dailyWorkHrs;
    String timePref;
    log.debug("Get user duration for duration: {}, timesheet: {}", duration, timesheet == null ? "null" : timesheet.getFullName());
    if (timesheet != null) {
        User user = timesheet.getUser();
        timePref = timesheet.getTimeLoggingPreferenceSelect();
        if (user.getEmployee() != null) {
            Employee employee = employeeRepository.find(user.getEmployee().getId());
            log.debug("Employee: {}", employee);
            dailyWorkHrs = employee.getDailyWorkHours();
            if (timePref == null) {
                timePref = employee.getTimeLoggingPreferenceSelect();
            }
        } else {
            dailyWorkHrs = appBaseService.getAppBase().getDailyWorkHours();
        }
    } else {
        timePref = appBaseService.getAppBase().getTimeLoggingPreferenceSelect();
        dailyWorkHrs = appBaseService.getAppBase().getDailyWorkHours();
    }
    return computeHoursDuration(timePref, duration, dailyWorkHrs, toHours);
}
Also used : User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) BigDecimal(java.math.BigDecimal)

Example 83 with User

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

the class TimesheetReportServiceImpl method getTimesheetReportList.

public List<Map<String, Object>> getTimesheetReportList(String timesheetReportId) {
    List<Map<String, Object>> list = new ArrayList<>();
    WeekFields weekFields = WeekFields.of(DayOfWeek.MONDAY, 5);
    TimesheetReport timesheetReport = timesheetReportRepository.find(Long.parseLong(timesheetReportId.toString()));
    int numOfDays = timesheetReport.getFromDate().until(timesheetReport.getToDate()).getDays();
    List<LocalDate> daysRange = Stream.iterate(timesheetReport.getFromDate(), date -> date.plusDays(1)).limit(numOfDays + 1).collect(Collectors.toList());
    List<User> users = getUsers(timesheetReport);
    for (User user : users) {
        Employee employee = user.getEmployee();
        BigDecimal dailyWorkingHours = employee.getDailyWorkHours();
        WeeklyPlanning weeklyPlanning = employee.getWeeklyPlanning();
        Integer weekNumber = 1;
        int lastDayIndex = -1;
        int daysInWeek = 0;
        try {
            for (LocalDate date : daysRange) {
                DayPlanning dayPlanning = weeklyPlanningService.findDayPlanning(weeklyPlanning, date);
                if (dayPlanning == null) {
                    continue;
                }
                int dayIndex = date.get(weekFields.dayOfWeek()) - 1;
                if (lastDayIndex < dayIndex) {
                    lastDayIndex = dayIndex;
                    if (weeklyPlanningService.getWorkingDayValueInDays(weeklyPlanning, date) != 0) {
                        daysInWeek++;
                    }
                } else {
                    lastDayIndex = -1;
                    daysInWeek = 1;
                    weekNumber++;
                }
                BigDecimal weeklyWorkHours = daysInWeek <= 5 ? employee.getWeeklyWorkHours().multiply(BigDecimal.valueOf(daysInWeek / 5.00)).setScale(2, RoundingMode.HALF_UP) : employee.getWeeklyWorkHours();
                Map<String, Object> map = getTimesheetMap(user, date, dailyWorkingHours);
                map.put("weeklyWorkHours", weeklyWorkHours);
                map.put("weekNumber", weekNumber.toString());
                list.add(map);
            }
        } catch (Exception e) {
            System.out.println(e);
        }
    }
    return list;
}
Also used : User(com.axelor.auth.db.User) TimesheetReport(com.axelor.apps.hr.db.TimesheetReport) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) ArrayList(java.util.ArrayList) DayPlanning(com.axelor.apps.base.db.DayPlanning) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) Employee(com.axelor.apps.hr.db.Employee) WeekFields(java.time.temporal.WeekFields) Map(java.util.Map) HashMap(java.util.HashMap)

Example 84 with User

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

the class LeaveController method leaveCalendar.

public void leaveCalendar(ActionRequest request, ActionResponse response) {
    try {
        User user = AuthUtils.getUser();
        Employee employee = user.getEmployee();
        ActionViewBuilder actionView = ActionView.define(I18n.get("Leaves calendar")).model(ICalendarEvent.class.getName()).add("calendar", "calendar-event-leave-request").add("grid", "calendar-event-grid").add("form", "calendar-event-form");
        actionView.domain("self.typeSelect = 4 AND self.id IN (SELECT leaveRequest.icalendarEvent FROM LeaveRequest leaveRequest WHERE leaveRequest.statusSelect = 3");
        if (employee == null || !employee.getHrManager()) {
            actionView.domain(actionView.get().getDomain() + " AND leaveRequest.user.employee.managerUser = :_user").context("_user", user);
        }
        actionView.domain(actionView.get().getDomain() + ")");
        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) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder) AxelorException(com.axelor.exception.AxelorException)

Example 85 with User

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

the class LunchVoucherAdvanceController method print.

public void print(ActionRequest request, ActionResponse response) {
    LunchVoucherAdvance lunchVoucherAdvance = request.getContext().asType(LunchVoucherAdvance.class);
    String name = lunchVoucherAdvance.getEmployee().getName() + "-" + Beans.get(AppBaseService.class).getTodayDate(Optional.ofNullable(lunchVoucherAdvance.getEmployee()).map(Employee::getUser).map(User::getActiveCompany).orElse(Optional.ofNullable(AuthUtils.getUser()).map(User::getActiveCompany).orElse(null))).format(DateTimeFormatter.ISO_DATE);
    try {
        String fileLink = ReportFactory.createReport(IReport.LUNCH_VOUCHER_ADVANCE, name).addParam("lunchVoucherAdvId", lunchVoucherAdvance.getId()).addParam("Timezone", getTimezone(lunchVoucherAdvance)).addFormat(ReportSettings.FORMAT_PDF).generate().getFileLink();
        response.setView(ActionView.define(name).add("html", fileLink).map());
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : LunchVoucherAdvance(com.axelor.apps.hr.db.LunchVoucherAdvance) User(com.axelor.auth.db.User) AppBaseService(com.axelor.apps.base.service.app.AppBaseService) AxelorException(com.axelor.exception.AxelorException)

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