Search in sources :

Example 1 with TimesheetReminderLine

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

the class TimesheetReportServiceImpl method createTimesheetReminderLine.

private TimesheetReminderLine createTimesheetReminderLine(LocalDate fromDate, LocalDate toDate, BigDecimal worksHour, BigDecimal missingHour, BigDecimal extraHour) {
    TimesheetReminderLine line = new TimesheetReminderLine();
    line.setFromDate(fromDate);
    line.setToDate(toDate);
    line.setRequiredHours(worksHour);
    line.setExtraHours(extraHour);
    line.setMissingHours(missingHour);
    line.setWorkHour(worksHour.subtract(missingHour).add(extraHour));
    return line;
}
Also used : TimesheetReminderLine(com.axelor.apps.hr.db.TimesheetReminderLine)

Example 2 with TimesheetReminderLine

use of com.axelor.apps.hr.db.TimesheetReminderLine 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)

Aggregations

TimesheetReminderLine (com.axelor.apps.hr.db.TimesheetReminderLine)2 DayPlanning (com.axelor.apps.base.db.DayPlanning)1 WeeklyPlanning (com.axelor.apps.base.db.WeeklyPlanning)1 PublicHolidayService (com.axelor.apps.base.service.publicHoliday.PublicHolidayService)1 WeeklyPlanningService (com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService)1 Employee (com.axelor.apps.hr.db.Employee)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 TimesheetReport (com.axelor.apps.hr.db.TimesheetReport)1 ExtraHoursLineRepository (com.axelor.apps.hr.db.repo.ExtraHoursLineRepository)1 ExtraHoursRepository (com.axelor.apps.hr.db.repo.ExtraHoursRepository)1 LeaveReasonRepository (com.axelor.apps.hr.db.repo.LeaveReasonRepository)1 LeaveRequestRepository (com.axelor.apps.hr.db.repo.LeaveRequestRepository)1 TimesheetLineRepository (com.axelor.apps.hr.db.repo.TimesheetLineRepository)1 TimesheetReminderRepository (com.axelor.apps.hr.db.repo.TimesheetReminderRepository)1 TimesheetReportRepository (com.axelor.apps.hr.db.repo.TimesheetReportRepository)1 TimesheetRepository (com.axelor.apps.hr.db.repo.TimesheetRepository)1 IExceptionMessage (com.axelor.apps.hr.exception.IExceptionMessage)1 AppHumanResourceService (com.axelor.apps.hr.service.app.AppHumanResourceService)1