Search in sources :

Example 26 with User

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());
    }
}
Also used : Company(com.axelor.apps.base.db.Company) User(com.axelor.auth.db.User) ActionViewBuilder(com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)

Example 27 with User

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));
            }
        }
    }
}
Also used : User(com.axelor.auth.db.User) EventsPlanning(com.axelor.apps.base.db.EventsPlanning) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) LeaveRequest(com.axelor.apps.hr.db.LeaveRequest) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AppTimesheet(com.axelor.apps.base.db.AppTimesheet) Employee(com.axelor.apps.hr.db.Employee) HRConfig(com.axelor.apps.hr.db.HRConfig) LeaveService(com.axelor.apps.hr.service.leave.LeaveService) WeeklyPlanningService(com.axelor.apps.base.service.weeklyplanning.WeeklyPlanningService) List(java.util.List) PriceList(com.axelor.apps.base.db.PriceList) ArrayList(java.util.ArrayList) PublicHolidayService(com.axelor.apps.base.service.publicHoliday.PublicHolidayService)

Example 28 with User

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;
}
Also used : User(com.axelor.auth.db.User) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) PartnerPriceListService(com.axelor.apps.base.service.PartnerPriceListService) InvoiceLine(com.axelor.apps.account.db.InvoiceLine) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) DateFormat(java.text.DateFormat) SimpleDateFormat(java.text.SimpleDateFormat) SimpleDateFormat(java.text.SimpleDateFormat) PriceList(com.axelor.apps.base.db.PriceList)

Example 29 with User

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;
}
Also used : Project(com.axelor.apps.project.db.Project) User(com.axelor.auth.db.User) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) ArrayList(java.util.ArrayList) Product(com.axelor.apps.base.db.Product) Map(java.util.Map) HashMap(java.util.HashMap) BigDecimal(java.math.BigDecimal)

Example 30 with User

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);
    }
}
Also used : User(com.axelor.auth.db.User) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) ProjectPlanningTime(com.axelor.apps.project.db.ProjectPlanningTime) Transactional(com.google.inject.persist.Transactional)

Aggregations

User (com.axelor.auth.db.User)157 AxelorException (com.axelor.exception.AxelorException)35 Employee (com.axelor.apps.hr.db.Employee)28 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)25 Transactional (com.google.inject.persist.Transactional)24 LocalDate (java.time.LocalDate)23 Filter (com.axelor.rpc.filter.Filter)22 BigDecimal (java.math.BigDecimal)22 ClientViewService (com.axelor.apps.portal.service.ClientViewService)20 ActionViewBuilder (com.axelor.meta.schema.actions.ActionView.ActionViewBuilder)17 List (java.util.List)17 Map (java.util.Map)16 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)12 LocalDateTime (java.time.LocalDateTime)12 Company (com.axelor.apps.base.db.Company)11 Partner (com.axelor.apps.base.db.Partner)11 Beans (com.axelor.inject.Beans)11 Inject (com.google.inject.Inject)11 Product (com.axelor.apps.base.db.Product)9