Search in sources :

Example 6 with TimesheetLine

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

the class TimesheetServiceImpl method setProjectTaskTotalRealHrs.

@Override
@Transactional
public void setProjectTaskTotalRealHrs(List<TimesheetLine> timesheetLines, boolean isAdd) {
    for (TimesheetLine timesheetLine : timesheetLines) {
        ProjectTask projectTask = timesheetLine.getProjectTask();
        if (projectTask != null) {
            projectTask = projectTaskRepo.find(projectTask.getId());
            BigDecimal totalrealhrs = isAdd ? projectTask.getTotalRealHrs().add(timesheetLine.getHoursDuration()) : projectTask.getTotalRealHrs().subtract(timesheetLine.getHoursDuration());
            projectTask.setTotalRealHrs(totalrealhrs);
            projectTaskRepo.save(projectTask);
        }
    }
}
Also used : TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) ProjectTask(com.axelor.apps.project.db.ProjectTask) BigDecimal(java.math.BigDecimal) Transactional(com.google.inject.persist.Transactional)

Example 7 with TimesheetLine

use of com.axelor.apps.hr.db.TimesheetLine 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 8 with TimesheetLine

use of com.axelor.apps.hr.db.TimesheetLine 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)

Example 9 with TimesheetLine

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

the class TimesheetLineController method setDuration.

/**
 * Called from timesheet editor Get the timesheet corresponding to timesheetline and call {@link
 * TimesheetLineService#computeHoursDuration(Timesheet, BigDecimal, boolean)}
 *
 * @param request
 * @param response
 */
public void setDuration(ActionRequest request, ActionResponse response) {
    try {
        TimesheetLine timesheetLine = request.getContext().asType(TimesheetLine.class);
        Timesheet timesheet;
        Context parent = request.getContext().getParent();
        if (parent != null && parent.getContextClass().equals(Timesheet.class)) {
            timesheet = parent.asType(Timesheet.class);
        } else {
            timesheet = timesheetLine.getTimesheet();
        }
        BigDecimal duration = Beans.get(TimesheetLineService.class).computeHoursDuration(timesheet, timesheetLine.getHoursDuration(), false);
        response.setValue(DURATION_FIELD, duration);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Timesheet(com.axelor.apps.hr.db.Timesheet) TimesheetLineService(com.axelor.apps.hr.service.timesheet.TimesheetLineService) BigDecimal(java.math.BigDecimal)

Example 10 with TimesheetLine

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

the class TimesheetLineController method setStoredDuration.

/**
 * Called from timesheet line editable grid or form. Get the timesheet corresponding to
 * timesheetline and call {@link TimesheetLineService#computeHoursDuration(Timesheet, BigDecimal,
 * boolean)}
 *
 * @param request
 * @param response
 */
public void setStoredDuration(ActionRequest request, ActionResponse response) {
    try {
        TimesheetLine timesheetLine = request.getContext().asType(TimesheetLine.class);
        Timesheet timesheet;
        Context parent = request.getContext().getParent();
        if (parent != null && parent.getContextClass().equals(Timesheet.class)) {
            timesheet = parent.asType(Timesheet.class);
        } else {
            timesheet = timesheetLine.getTimesheet();
        }
        BigDecimal hoursDuration = Beans.get(TimesheetLineService.class).computeHoursDuration(timesheet, timesheetLine.getDuration(), true);
        response.setValue(HOURS_DURATION_FIELD, hoursDuration);
    } catch (Exception e) {
        TraceBackService.trace(response, e);
    }
}
Also used : Context(com.axelor.rpc.Context) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) Timesheet(com.axelor.apps.hr.db.Timesheet) TimesheetLineService(com.axelor.apps.hr.service.timesheet.TimesheetLineService) BigDecimal(java.math.BigDecimal)

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