Search in sources :

Example 16 with TimesheetLine

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

the class TimesheetLineController method updateOperationOrder.

/**
 * Called from timesheet line form view, on save. <br>
 * Call {@link OperationOrderTimesheetService#updateOperationOrders(Timesheet)}.
 *
 * @param request
 * @param response
 */
public void updateOperationOrder(ActionRequest request, ActionResponse response) {
    try {
        TimesheetLine timesheetLine = request.getContext().asType(TimesheetLine.class);
        Timesheet timesheet = timesheetLine.getTimesheet();
        if (timesheet == null && request.getContext().getParent() != null) {
            timesheet = request.getContext().getParent().asType(Timesheet.class);
        }
        if (timesheet != null) {
            Beans.get(OperationOrderTimesheetService.class).updateOperationOrders(timesheet);
        }
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : OperationOrderTimesheetService(com.axelor.apps.businessproduction.service.OperationOrderTimesheetService) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Timesheet(com.axelor.apps.hr.db.Timesheet)

Example 17 with TimesheetLine

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

the class TimesheetServiceImpl method computeTimeSpent.

@Override
public BigDecimal computeTimeSpent(Project project) {
    BigDecimal sum = BigDecimal.ZERO;
    List<TimesheetLine> timesheetLineList = timesheetlineRepo.all().filter("self.project = ?1 AND self.timesheet.statusSelect = ?2", project, TimesheetRepository.STATUS_VALIDATED).fetch();
    for (TimesheetLine timesheetLine : timesheetLineList) {
        sum = sum.add(timesheetLine.getHoursDuration());
    }
    return sum;
}
Also used : TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) BigDecimal(java.math.BigDecimal)

Example 18 with TimesheetLine

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

the class TimesheetServiceImpl method generateLines.

@Override
public Timesheet generateLines(Timesheet timesheet, LocalDate fromGenerationDate, LocalDate toGenerationDate, BigDecimal logTime, Project project, Product product) throws AxelorException {
    User user = timesheet.getUser();
    Employee employee = user.getEmployee();
    if (fromGenerationDate == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_FROM_DATE));
    }
    if (toGenerationDate == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_TO_DATE));
    }
    if (product == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_MISSING_FIELD, I18n.get(IExceptionMessage.TIMESHEET_PRODUCT));
    }
    if (employee == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.LEAVE_USER_EMPLOYEE), user.getName());
    }
    WeeklyPlanning planning = employee.getWeeklyPlanning();
    if (planning == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_DAY_PLANNING), user.getName());
    }
    List<DayPlanning> dayPlanningList = planning.getWeekDays();
    Map<Integer, String> correspMap = getCorresMap();
    LocalDate fromDate = fromGenerationDate;
    LocalDate toDate = toGenerationDate;
    if (employee.getPublicHolidayEventsPlanning() == null) {
        throw new AxelorException(timesheet, TraceBackRepository.CATEGORY_CONFIGURATION_ERROR, I18n.get(IExceptionMessage.TIMESHEET_EMPLOYEE_PUBLIC_HOLIDAY_EVENTS_PLANNING), user.getName());
    }
    LeaveService leaveService = Beans.get(LeaveService.class);
    PublicHolidayHrService publicHolidayHrService = Beans.get(PublicHolidayHrService.class);
    while (!fromDate.isAfter(toDate)) {
        if (isWorkedDay(fromDate, correspMap, dayPlanningList) && !leaveService.isLeaveDay(user, fromDate) && !publicHolidayHrService.checkPublicHolidayDay(fromDate, employee)) {
            TimesheetLine timesheetLine = timesheetLineService.createTimesheetLine(project, product, user, fromDate, timesheet, timesheetLineService.computeHoursDuration(timesheet, logTime, true), "");
            timesheetLine.setDuration(logTime);
        }
        fromDate = fromDate.plusDays(1);
    }
    return timesheet;
}
Also used : AxelorException(com.axelor.exception.AxelorException) User(com.axelor.auth.db.User) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) WeeklyPlanning(com.axelor.apps.base.db.WeeklyPlanning) DayPlanning(com.axelor.apps.base.db.DayPlanning) LocalDate(java.time.LocalDate) Employee(com.axelor.apps.hr.db.Employee) PublicHolidayHrService(com.axelor.apps.hr.service.publicHoliday.PublicHolidayHrService) LeaveService(com.axelor.apps.hr.service.leave.LeaveService)

Example 19 with TimesheetLine

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

the class TimesheetServiceImpl method updateTimeLoggingPreference.

@Override
public void updateTimeLoggingPreference(Timesheet timesheet) throws AxelorException {
    String timeLoggingPref;
    if (timesheet.getUser() == null || timesheet.getUser().getEmployee() == null) {
        timeLoggingPref = EmployeeRepository.TIME_PREFERENCE_HOURS;
    } else {
        Employee employee = timesheet.getUser().getEmployee();
        timeLoggingPref = employee.getTimeLoggingPreferenceSelect();
    }
    timesheet.setTimeLoggingPreferenceSelect(timeLoggingPref);
    if (timesheet.getTimesheetLineList() != null) {
        for (TimesheetLine timesheetLine : timesheet.getTimesheetLineList()) {
            timesheetLine.setDuration(Beans.get(TimesheetLineService.class).computeHoursDuration(timesheet, timesheetLine.getHoursDuration(), false));
        }
    }
}
Also used : Employee(com.axelor.apps.hr.db.Employee) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine)

Example 20 with TimesheetLine

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

the class TimesheetServiceImpl method computeTimeSpent.

@Override
@Transactional
public void computeTimeSpent(Timesheet timesheet) {
    List<TimesheetLine> timesheetLineList = timesheet.getTimesheetLineList();
    if (timesheetLineList != null) {
        Map<Project, BigDecimal> projectTimeSpentMap = timesheetLineService.getProjectTimeSpentMap(timesheetLineList);
        Iterator<Project> projectIterator = projectTimeSpentMap.keySet().iterator();
        while (projectIterator.hasNext()) {
            Project project = projectIterator.next();
            getEntityManager().flush();
            executor.submit(() -> {
                final Long startTime = System.currentTimeMillis();
                boolean done = false;
                PersistenceException persistenceException = null;
                do {
                    try {
                        inTransaction(() -> {
                            final Project updateProject = findProject(project.getId());
                            getEntityManager().lock(updateProject, LockModeType.PESSIMISTIC_WRITE);
                            BigDecimal timeSpent = projectTimeSpentMap.get(updateProject).add(this.computeSubTimeSpent(updateProject));
                            updateProject.setTimeSpent(timeSpent);
                            projectRepo.save(updateProject);
                            this.computeParentTimeSpent(updateProject);
                        });
                        done = true;
                    } catch (PersistenceException e) {
                        persistenceException = e;
                        sleep();
                    }
                } while (!done && System.currentTimeMillis() - startTime < ENTITY_FIND_TIMEOUT);
                if (!done) {
                    throw persistenceException;
                }
                return true;
            });
        }
    }
    this.setProjectTaskTotalRealHrs(timesheet.getTimesheetLineList(), true);
}
Also used : Project(com.axelor.apps.project.db.Project) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) PersistenceException(javax.persistence.PersistenceException) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Aggregations

TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)32 BigDecimal (java.math.BigDecimal)15 Transactional (com.google.inject.persist.Transactional)9 LocalDate (java.time.LocalDate)8 User (com.axelor.auth.db.User)7 ArrayList (java.util.ArrayList)7 Timesheet (com.axelor.apps.hr.db.Timesheet)6 Project (com.axelor.apps.project.db.Project)6 AxelorException (com.axelor.exception.AxelorException)6 HashMap (java.util.HashMap)6 TimesheetLineService (com.axelor.apps.hr.service.timesheet.TimesheetLineService)5 Product (com.axelor.apps.base.db.Product)4 Employee (com.axelor.apps.hr.db.Employee)4 InvoiceLine (com.axelor.apps.account.db.InvoiceLine)3 TimesheetLineRepository (com.axelor.apps.hr.db.repo.TimesheetLineRepository)3 ProjectTask (com.axelor.apps.project.db.ProjectTask)3 DayPlanning (com.axelor.apps.base.db.DayPlanning)2 PriceList (com.axelor.apps.base.db.PriceList)2 WeeklyPlanning (com.axelor.apps.base.db.WeeklyPlanning)2 ExpenseLine (com.axelor.apps.hr.db.ExpenseLine)2