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));
}
}
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);
}
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;
}
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());
}
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());
}
Aggregations