Search in sources :

Example 76 with User

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

the class TimesheetReportServiceImpl method getUserToBeReminded.

@Override
public Set<User> getUserToBeReminded(TimesheetReport timesheetReport) {
    Set<User> userSet = new HashSet<>();
    BigDecimal worksHour = BigDecimal.ZERO, workedHour = BigDecimal.ZERO;
    List<User> users = getUsers(timesheetReport);
    LocalDate fromDate = timesheetReport.getFromDate();
    LocalDate toDate = timesheetReport.getToDate();
    for (User user : users) {
        Employee employee = user.getEmployee();
        try {
            worksHour = workedHour = BigDecimal.ZERO;
            BigDecimal publicHolidays = publicHolidayService.computePublicHolidayDays(fromDate, toDate, employee.getWeeklyPlanning(), employee.getPublicHolidayEventsPlanning());
            worksHour = getTotalWeekWorksHours(user, fromDate, toDate, publicHolidays);
            workedHour = getTotalWeekWorkedHours(user, fromDate, toDate, publicHolidays);
            if (worksHour.compareTo(workedHour) != 0) {
                userSet.add(user);
            }
        } catch (Exception e) {
            TraceBackService.trace(e);
        }
    }
    return userSet;
}
Also used : User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) HashSet(java.util.HashSet)

Example 77 with User

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

the class TimesheetReportServiceImpl method addTimesheetReminder.

private void addTimesheetReminder(TimesheetReport timesheetReport, List<User> users, List<TimesheetReminder> timesheetReminders) throws AxelorException {
    BigDecimal worksHour = BigDecimal.ZERO, workedHour = BigDecimal.ZERO, missingHour = BigDecimal.ZERO, extraHour = BigDecimal.ZERO;
    LocalDate fromDate = timesheetReport.getFromDate();
    LocalDate toDate = null;
    do {
        toDate = fromDate.with(TemporalAdjusters.nextOrSame(DayOfWeek.SUNDAY));
        if (toDate.until(timesheetReport.getToDate()).getDays() < 0) {
            toDate = timesheetReport.getToDate();
        }
        for (User user : users) {
            Employee employee = user.getEmployee();
            missingHour = BigDecimal.ZERO;
            extraHour = BigDecimal.ZERO;
            BigDecimal publicHolidays = publicHolidayService.computePublicHolidayDays(fromDate, toDate, employee.getWeeklyPlanning(), employee.getPublicHolidayEventsPlanning());
            worksHour = getTotalWeekWorksHours(user, fromDate, toDate, publicHolidays);
            workedHour = getTotalWeekWorkedHours(user, fromDate, toDate, publicHolidays);
            if (worksHour.compareTo(workedHour) == 1) {
                missingHour = worksHour.subtract(workedHour);
            } else if (worksHour.compareTo(workedHour) == -1) {
                extraHour = workedHour.subtract(worksHour);
            }
            if (missingHour.compareTo(BigDecimal.ZERO) == 0 && extraHour.compareTo(BigDecimal.ZERO) == 0) {
                continue;
            }
            Optional<TimesheetReminder> optReminder = timesheetReminders.stream().filter(reminder -> reminder.getEmployee().getId().compareTo(employee.getId()) == 0).findFirst();
            TimesheetReminder timesheetReminder = null;
            if (optReminder.isPresent()) {
                timesheetReminder = optReminder.get();
                timesheetReminder.addTimesheetReminderLineListItem(createTimesheetReminderLine(fromDate, toDate, worksHour, missingHour, extraHour));
            } else {
                List<TimesheetReminderLine> timesheetReminderLines = new ArrayList<>();
                timesheetReminder = new TimesheetReminder();
                timesheetReminder.setEmployee(employee);
                timesheetReminder.setTimesheetReminderLineList(timesheetReminderLines);
                timesheetReminder.addTimesheetReminderLineListItem(createTimesheetReminderLine(fromDate, toDate, worksHour, missingHour, extraHour));
                timesheetReminders.add(timesheetReminder);
            }
            timesheetReminderRepo.save(timesheetReminder);
        }
        fromDate = fromDate.with(TemporalAdjusters.next(DayOfWeek.MONDAY));
    } while (toDate.until(timesheetReport.getToDate()).getDays() > 0);
}
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) TimesheetReminderLine(com.axelor.apps.hr.db.TimesheetReminderLine) User(com.axelor.auth.db.User) Employee(com.axelor.apps.hr.db.Employee) TimesheetReminder(com.axelor.apps.hr.db.TimesheetReminder) ArrayList(java.util.ArrayList) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal)

Example 78 with User

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

the class TimesheetServiceImpl method generateLines.

@Override
public Timesheet generateLines(Timesheet timesheet, LocalDate fromGenerationDate, LocalDate toGenerationDate, BigDecimal logTime, Project project, Product product) throws AxelorException {
    User user = timesheet.getUser();
    Employee employee = user.getEmployee();
    if (fromGenerationDate == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_FROM_DATE));
    }
    if (toGenerationDate == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_TO_DATE));
    }
    if (product == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_PRODUCT));
    }
    if (employee == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), user.getName());
    }
    WeeklyPlanning planning = employee.getWeeklyPlanning();
    if (planning == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_DAY_PLANNING), user.getName());
    }
    List<DayPlanning> dayPlanningList = planning.getWeekDays();
    Map<Integer, String> correspMap = getCorresMap();
    LocalDate fromDate = fromGenerationDate;
    LocalDate toDate = toGenerationDate;
    if (employee.getPublicHolidayEventsPlanning() == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_PUBLIC_HOLIDAY_EVENTS_PLANNING), user.getName());
    }
    LeaveService leaveService = Beans.get(LeaveService.class);
    PublicHolidayHrService publicHolidayHrService = Beans.get(PublicHolidayHrService.class);
    while (!fromDate.isAfter(toDate)) {
        if (isWorkedDay(fromDate, correspMap, dayPlanningList) && !leaveService.isLeaveDay(user, fromDate) && !publicHolidayHrService.checkPublicHolidayDay(fromDate, employee)) {
            TimesheetLine timesheetLine = timesheetLineService.createTimesheetLine(project, product, user, fromDate, timesheet, timesheetLineService.computeHoursDuration(timesheet, logTime, true), "");
            timesheetLine.setDuration(logTime);
        }
        fromDate = fromDate.plusDays(1);
    }
    return timesheet;
}
Also used : AxelorException(com.axelor.exception.AxelorException) User(com.axelor.auth.db.User) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) DayPlanning(com.axelor.apps.base.db.DayPlanning) LocalDate(java.time.LocalDate) Employee(com.axelor.apps.hr.db.Employee) PublicHolidayHrService(com.axelor.apps.hr.service.publicHoliday.PublicHolidayHrService) LeaveService(com.axelor.apps.hr.service.leave.LeaveService)

Example 79 with User

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

the class TimesheetServiceImpl method checkEmptyPeriod.

public void checkEmptyPeriod(Timesheet timesheet) throws AxelorException {
    LeaveService leaveService = Beans.get(LeaveService.class);
    PublicHolidayHrService publicHolidayHrService = Beans.get(PublicHolidayHrService.class);
    User user = timesheet.getUser();
    Employee employee = user.getEmployee();
    if (employee == null) {
        return;
    }
    if (employee.getPublicHolidayEventsPlanning() == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_PUBLIC_HOLIDAY_EVENTS_PLANNING), user.getName());
    }
    WeeklyPlanning planning = employee.getWeeklyPlanning();
    if (planning == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_DAY_PLANNING), user.getName());
    }
    List<DayPlanning> dayPlanningList = planning.getWeekDays();
    Map<Integer, String> correspMap = getCorresMap();
    List<TimesheetLine> timesheetLines = timesheet.getTimesheetLineList();
    timesheetLines.sort(Comparator.comparing(TimesheetLine::getDate));
    for (int i = 0; i < timesheetLines.size(); i++) {
        if (i + 1 < timesheetLines.size()) {
            LocalDate date1 = timesheetLines.get(i).getDate();
            LocalDate date2 = timesheetLines.get(i + 1).getDate();
            LocalDate missingDay = date1.plusDays(1);
            while (ChronoUnit.DAYS.between(date1, date2) > 1) {
                if (isWorkedDay(missingDay, correspMap, dayPlanningList) && !leaveService.isLeaveDay(user, missingDay) && !publicHolidayHrService.checkPublicHolidayDay(missingDay, employee)) {
                    throw new AxelorException(TraceBackRepository.CATEGORY_MISSING_FIELD, "Line for %s is missing.", missingDay);
                }
                date1 = missingDay;
                missingDay = missingDay.plusDays(1);
            }
        }
    }
}
Also used : AxelorException(com.axelor.exception.AxelorException) User(com.axelor.auth.db.User) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) DayPlanning(com.axelor.apps.base.db.DayPlanning) LocalDate(java.time.LocalDate) Employee(com.axelor.apps.hr.db.Employee) PublicHolidayHrService(com.axelor.apps.hr.service.publicHoliday.PublicHolidayHrService) LeaveService(com.axelor.apps.hr.service.leave.LeaveService)

Example 80 with User

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

the class TimesheetServiceImpl method computeFullName.

@Override
public String computeFullName(Timesheet timesheet) {
    User timesheetUser = timesheet.getUser();
    LocalDateTime createdOn = timesheet.getCreatedOn();
    if (timesheetUser != null && createdOn != null) {
        return timesheetUser.getFullName() + " " + createdOn.getDayOfMonth() + "/" + createdOn.getMonthValue() + "/" + timesheet.getCreatedOn().getYear() + " " + createdOn.getHour() + ":" + createdOn.getMinute();
    } else if (timesheetUser != null) {
        return timesheetUser.getFullName() + " N°" + timesheet.getId();
    } else {
        return "N°" + timesheet.getId();
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) User(com.axelor.auth.db.User)

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