Search in sources :

Example 1 with TimesheetReport

use of com.axelor.apps.hr.db.TimesheetReport in project axelor-open-suite by axelor.

the class TimesheetReportController method fillTimesheetReportReminderUsers.

public void fillTimesheetReportReminderUsers(ActionRequest request, ActionResponse response) {
    TimesheetReport timesheetReport = request.getContext().asType(TimesheetReport.class);
    Set<User> reminderUserSet = Beans.get(TimesheetReportService.class).getUserToBeReminded(timesheetReport);
    if (!ObjectUtils.isEmpty(reminderUserSet)) {
        response.setValue("reminderUserSet", reminderUserSet);
    } else {
        response.setValue("reminderUserSet", null);
        response.setNotify(I18n.get(ITranslation.TS_REPORT_FILL_NO_USER));
    }
}
Also used : User(com.axelor.auth.db.User) TimesheetReport(com.axelor.apps.hr.db.TimesheetReport) TimesheetReportService(com.axelor.apps.hr.service.timesheet.TimesheetReportService)

Example 2 with TimesheetReport

use of com.axelor.apps.hr.db.TimesheetReport 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 3 with TimesheetReport

use of com.axelor.apps.hr.db.TimesheetReport 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 4 with TimesheetReport

use of com.axelor.apps.hr.db.TimesheetReport in project axelor-open-suite by axelor.

the class TimesheetReportController method printEmployeeTimesheetReport.

public void printEmployeeTimesheetReport(ActionRequest request, ActionResponse response) throws AxelorException {
    TimesheetReport timesheetReport = request.getContext().asType(TimesheetReport.class);
    String name = I18n.get(ITranslation.TS_REPORT_TITLE);
    String fileLink = ReportFactory.createReport(IReport.EMPLOYEE_TIMESHEET, name).addParam("TimesheetReportId", timesheetReport.getId().toString()).addParam("Timezone", null).addParam("Locale", ReportSettings.getPrintingLocale(null)).addParam("FromDate", timesheetReport.getFromDate().format(DateTimeFormatter.ofPattern("dd-MM-yyy"))).addParam("ToDate", timesheetReport.getToDate().format(DateTimeFormatter.ofPattern("dd-MM-yyy"))).toAttach(timesheetReport).generate().getFileLink();
    logger.debug("Printing {}", name);
    response.setView(ActionView.define(name).add("html", fileLink).map());
}
Also used : TimesheetReport(com.axelor.apps.hr.db.TimesheetReport)

Example 5 with TimesheetReport

use of com.axelor.apps.hr.db.TimesheetReport in project axelor-open-suite by axelor.

the class TimesheetReportController method sendTimesheetReminder.

public void sendTimesheetReminder(ActionRequest request, ActionResponse response) throws AxelorException {
    TimesheetReport timesheetReport = request.getContext().asType(TimesheetReport.class);
    if (ObjectUtils.isEmpty(timesheetReport.getReminderUserSet())) {
        return;
    }
    List<Message> messages = Beans.get(TimesheetReportService.class).sendReminders(timesheetReport);
    List<Long> messageIds = new ArrayList<Long>();
    messageIds.add(0L);
    for (Message message : messages) {
        messageIds.add(message.getId());
    }
    response.setView(ActionView.define(I18n.get("Messages")).model(Message.class.getName()).add("grid", "message-timesheet-reminder-grid").add("form", "message-form").domain("self.id in (:messageIds)").context("messageIds", messageIds).map());
}
Also used : Message(com.axelor.apps.message.db.Message) TimesheetReport(com.axelor.apps.hr.db.TimesheetReport) TimesheetReportService(com.axelor.apps.hr.service.timesheet.TimesheetReportService) ArrayList(java.util.ArrayList)

Aggregations

TimesheetReport (com.axelor.apps.hr.db.TimesheetReport)5 User (com.axelor.auth.db.User)3 ArrayList (java.util.ArrayList)3 DayPlanning (com.axelor.apps.base.db.DayPlanning)2 WeeklyPlanning (com.axelor.apps.base.db.WeeklyPlanning)2 Employee (com.axelor.apps.hr.db.Employee)2 TimesheetReportService (com.axelor.apps.hr.service.timesheet.TimesheetReportService)2 Message (com.axelor.apps.message.db.Message)2 AxelorException (com.axelor.exception.AxelorException)2 BigDecimal (java.math.BigDecimal)2 LocalDate (java.time.LocalDate)2 WeekFields (java.time.temporal.WeekFields)2 HashMap (java.util.HashMap)2 Map (java.util.Map)2 PublicHolidayService (com.axelor.apps.base.service.publicHoliday.PublicHolidayService)1 WeeklyPlanningService (com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService)1 LeaveRequest (com.axelor.apps.hr.db.LeaveRequest)1 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)1 TimesheetReminder (com.axelor.apps.hr.db.TimesheetReminder)1 TimesheetReminderLine (com.axelor.apps.hr.db.TimesheetReminderLine)1