use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class TimesheetController method showSubordinateTimesheets.
public void showSubordinateTimesheets(ActionRequest request, ActionResponse response) {
User user = AuthUtils.getUser();
Company activeCompany = user.getActiveCompany();
ActionViewBuilder actionView = ActionView.define(I18n.get("Timesheets to be Validated by your subordinates")).model(Timesheet.class.getName()).add("grid", "timesheet-grid").add("form", "timesheet-form").param("search-filters", "timesheet-filters");
String domain = "self.user.employee.managerUser.employee.managerUser = :_user AND self.company = :_activeCompany AND self.statusSelect = 2";
long nbTimesheets = Query.of(Timesheet.class).filter(domain).bind("_user", user).bind("_activeCompany", activeCompany).count();
if (nbTimesheets == 0) {
response.setNotify(I18n.get("No timesheet to be validated by your subordinates"));
} else {
response.setView(actionView.domain(domain).context("_user", user).context("_activeCompany", activeCompany).map());
}
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method prefillLines.
@Override
public void prefillLines(Timesheet timesheet) throws AxelorException {
PublicHolidayService holidayService = Beans.get(PublicHolidayService.class);
LeaveService leaveService = Beans.get(LeaveService.class);
WeeklyPlanningService weeklyPlanningService = Beans.get(WeeklyPlanningService.class);
AppTimesheet appTimesheet = appHumanResourceService.getAppTimesheet();
LocalDate fromDate = timesheet.getFromDate();
LocalDate toDate = timesheet.getToDate();
User user = timesheet.getUser();
Employee employee = user.getEmployee();
HRConfig config = timesheet.getCompany().getHrConfig();
WeeklyPlanning weeklyPlanning = employee != null ? employee.getWeeklyPlanning() : config.getWeeklyPlanning();
EventsPlanning holidayPlanning = employee != null ? employee.getPublicHolidayEventsPlanning() : config.getPublicHolidayEventsPlanning();
for (LocalDate date = fromDate; !date.isAfter(toDate); date = date.plusDays(1)) {
BigDecimal dayValueInHours = weeklyPlanningService.getWorkingDayValueInHours(weeklyPlanning, date, LocalTime.MIN, LocalTime.MAX);
if (appTimesheet.getCreateLinesForHolidays() && holidayService.checkPublicHolidayDay(date, holidayPlanning)) {
timesheetLineService.createTimesheetLine(user, date, timesheet, dayValueInHours, I18n.get(IExceptionMessage.TIMESHEET_HOLIDAY));
} else if (appTimesheet.getCreateLinesForLeaves()) {
List<LeaveRequest> leaveList = leaveService.getLeaves(user, date);
BigDecimal totalLeaveHours = BigDecimal.ZERO;
if (ObjectUtils.notEmpty(leaveList)) {
for (LeaveRequest leave : leaveList) {
BigDecimal leaveHours = leaveService.computeDuration(leave, date, date);
if (leave.getLeaveReason().getUnitSelect() == LeaveReasonRepository.UNIT_SELECT_DAYS) {
leaveHours = leaveHours.multiply(dayValueInHours);
}
totalLeaveHours = totalLeaveHours.add(leaveHours);
}
timesheetLineService.createTimesheetLine(user, date, timesheet, totalLeaveHours, I18n.get(IExceptionMessage.TIMESHEET_DAY_LEAVE));
}
}
}
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method createInvoiceLines.
@Override
public List<InvoiceLine> createInvoiceLines(Invoice invoice, List<TimesheetLine> timesheetLineList, int priority) throws AxelorException {
List<InvoiceLine> invoiceLineList = new ArrayList<>();
int count = 0;
DateFormat ddmmFormat = new SimpleDateFormat("dd/MM");
HashMap<String, Object[]> timeSheetInformationsMap = new HashMap<>();
// Check if a consolidation by product and user must be done
boolean consolidate = appHumanResourceService.getAppTimesheet().getConsolidateTSLine();
for (TimesheetLine timesheetLine : timesheetLineList) {
Object[] tabInformations = new Object[5];
tabInformations[0] = timesheetLine.getProduct();
tabInformations[1] = timesheetLine.getUser();
// Start date
tabInformations[2] = timesheetLine.getDate();
// End date, useful only for consolidation
tabInformations[3] = timesheetLine.getDate();
tabInformations[4] = timesheetLine.getHoursDuration();
String key = null;
if (consolidate) {
key = timesheetLine.getProduct().getId() + "|" + timesheetLine.getUser().getId();
if (timeSheetInformationsMap.containsKey(key)) {
tabInformations = timeSheetInformationsMap.get(key);
// Update date
if (timesheetLine.getDate().compareTo((LocalDate) tabInformations[2]) < 0) {
// If date is lower than start date then replace start date by this one
tabInformations[2] = timesheetLine.getDate();
} else if (timesheetLine.getDate().compareTo((LocalDate) tabInformations[3]) > 0) {
// If date is upper than end date then replace end date by this one
tabInformations[3] = timesheetLine.getDate();
}
tabInformations[4] = ((BigDecimal) tabInformations[4]).add(timesheetLine.getHoursDuration());
} else {
timeSheetInformationsMap.put(key, tabInformations);
}
} else {
key = String.valueOf(timesheetLine.getId());
timeSheetInformationsMap.put(key, tabInformations);
}
timesheetLine.setInvoiced(true);
}
for (Object[] timesheetInformations : timeSheetInformationsMap.values()) {
String strDate = null;
Product product = (Product) timesheetInformations[0];
User user = (User) timesheetInformations[1];
LocalDate startDate = (LocalDate) timesheetInformations[2];
LocalDate endDate = (LocalDate) timesheetInformations[3];
BigDecimal hoursDuration = (BigDecimal) timesheetInformations[4];
PriceList priceList = Beans.get(PartnerPriceListService.class).getDefaultPriceList(invoice.getPartner(), PriceListRepository.TYPE_SALE);
if (consolidate) {
strDate = ddmmFormat.format(startDate) + " - " + ddmmFormat.format(endDate);
} else {
strDate = ddmmFormat.format(startDate);
}
invoiceLineList.addAll(this.createInvoiceLine(invoice, product, user, strDate, hoursDuration, priority * 100 + count, priceList));
count++;
}
return invoiceLineList;
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method createDefaultLines.
@Override
public List<Map<String, Object>> createDefaultLines(Timesheet timesheet) {
List<Map<String, Object>> lines = new ArrayList<>();
User user = timesheet.getUser();
if (user == null || timesheet.getFromDate() == null) {
return lines;
}
user = userRepo.find(user.getId());
Product product = userHrService.getTimesheetProduct(user);
if (product == null) {
return lines;
}
List<Project> projects = projectRepo.all().filter("self.membersUserSet.id = ?1 and " + "self.imputable = true " + "and self.statusSelect != 3", user.getId()).fetch();
for (Project project : projects) {
TimesheetLine line = timesheetLineService.createTimesheetLine(project, product, user, timesheet.getFromDate(), timesheet, new BigDecimal(0), null);
lines.add(Mapper.toMap(line));
}
return lines;
}
use of com.axelor.auth.db.User in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method generateLinesFromExpectedProjectPlanning.
@Transactional(rollbackOn = { Exception.class })
@Override
public void generateLinesFromExpectedProjectPlanning(Timesheet timesheet) throws AxelorException {
User user = timesheet.getUser();
List<ProjectPlanningTime> planningList = getExpectedProjectPlanningTimeList(timesheet);
for (ProjectPlanningTime projectPlanningTime : planningList) {
TimesheetLine timesheetLine = new TimesheetLine();
timesheetLine.setHoursDuration(projectPlanningTime.getPlannedHours());
timesheetLine.setDuration(timesheetLineService.computeHoursDuration(timesheet, projectPlanningTime.getPlannedHours(), false));
timesheetLine.setTimesheet(timesheet);
timesheetLine.setUser(user);
timesheetLine.setProduct(projectPlanningTime.getProduct());
timesheetLine.setProjectTask(projectPlanningTime.getProjectTask());
timesheetLine.setProject(projectPlanningTime.getProject());
timesheetLine.setDate(projectPlanningTime.getDate());
timesheetLine.setProjectPlanningTime(projectPlanningTime);
timesheet.addTimesheetLineListItem(timesheetLine);
}
}
Aggregations