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