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