use of com.axelor.apps.project.db.Project in project axelor-open-suite by axelor.
the class TimesheetServiceImpl method computeSubTimeSpent.
@Override
public BigDecimal computeSubTimeSpent(Project project) {
BigDecimal sum = BigDecimal.ZERO;
List<Project> subProjectList = projectRepo.all().filter("self.parentProject = ?1", project).fetch();
if (subProjectList == null || subProjectList.isEmpty()) {
return this.computeTimeSpent(project);
}
for (Project projectIt : subProjectList) {
sum = sum.add(this.computeSubTimeSpent(projectIt));
}
return sum;
}
use of com.axelor.apps.project.db.Project 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.project.db.Project in project axelor-open-suite by axelor.
the class TimesheetHRRepository method remove.
@Override
public void remove(Timesheet entity) {
if (entity.getStatusSelect() == TimesheetRepository.STATUS_VALIDATED && entity.getTimesheetLineList() != null) {
timesheetService.setProjectTaskTotalRealHrs(entity.getTimesheetLineList(), false);
Map<Project, BigDecimal> projectTimeSpentMap = timesheetLineService.getProjectTimeSpentMap(entity.getTimesheetLineList());
Iterator<Project> projectIterator = projectTimeSpentMap.keySet().iterator();
while (projectIterator.hasNext()) {
Project project = projectIterator.next();
project.setTimeSpent(project.getTimeSpent().subtract(projectTimeSpentMap.get(project)));
projectRepository.save(project);
}
}
super.remove(entity);
}
use of com.axelor.apps.project.db.Project in project axelor-open-suite by axelor.
the class HumanResourceMobileController method insertOrUpdateTSLine.
/*
* This method is used in mobile application.
* It was in TimesheetServiceImpl
* @param request
* @param response
*
* POST /open-suite-webapp/ws/action/com.axelor.apps.hr.mobile.HumanResourceMobileController:insertOrUpdateTSLine
* Content-Type: application/json
*
* URL: com.axelor.apps.hr.mobile.HumanResourceMobileController:insertOrUpdateTSLine
* fields: (id,) project, activity, date, duration, comments
*
* payload:
* { "data": {
* "action": "com.axelor.apps.hr.mobile.HumanResourceMobileController:insertOrUpdateTSLine",
* "id": 1,
* "project": 1,
* "activity": 2,
* "date": "2018-02-22",
* "duration": 10,
* "comments": "no"
* } }
*/
@Transactional
public void insertOrUpdateTSLine(ActionRequest request, ActionResponse response) {
// insert TimesheetLine
try {
Map<String, Object> requestData = request.getData();
User user = AuthUtils.getUser();
Project project = Beans.get(ProjectRepository.class).find(new Long(request.getData().get("project").toString()));
Product product = Beans.get(ProductRepository.class).find(new Long(request.getData().get("activity").toString()));
LocalDate date = LocalDate.parse(request.getData().get("date").toString(), DateTimeFormatter.ISO_DATE);
TimesheetRepository timesheetRepository = Beans.get(TimesheetRepository.class);
TimesheetService timesheetService = Beans.get(TimesheetService.class);
TimesheetLineService timesheetLineService = Beans.get(TimesheetLineService.class);
if (user != null) {
Timesheet timesheet = timesheetRepository.all().filter("self.statusSelect = 1 AND self.user.id = ?1", user.getId()).order("-id").fetchOne();
if (timesheet == null) {
timesheet = timesheetService.createTimesheet(user, date, date);
}
BigDecimal hours = new BigDecimal(request.getData().get("duration").toString());
TimesheetLine line;
Object idO = requestData.get("id");
if (idO != null) {
line = timesheetLineService.updateTimesheetLine(Beans.get(TimesheetLineRepository.class).find(Long.valueOf(idO.toString())), project, product, user, date, timesheet, hours, request.getData().get("comments").toString());
} else {
line = timesheetLineService.createTimesheetLine(project, product, user, date, timesheet, hours, request.getData().get("comments").toString());
}
// convert hours to what is defined in timeLoggingPreferenceSelect
BigDecimal duration = timesheetLineService.computeHoursDuration(timesheet, hours, false);
line.setDuration(duration);
timesheet.addTimesheetLineListItem(line);
timesheetRepository.save(timesheet);
response.setTotal(1);
HashMap<String, Object> data = new HashMap<>();
data.put("id", line.getId());
response.setData(data);
}
} catch (Exception e) {
TraceBackService.trace(e);
}
}
use of com.axelor.apps.project.db.Project in project axelor-open-suite by axelor.
the class ProjectHRRepository method save.
@Override
public Project save(Project project) {
project = super.save(project);
if (!Beans.get(AppHumanResourceService.class).isApp("employee")) {
return project;
}
List<ProjectPlanningTime> projectPlanningTimeList = planningTimeRepo.all().filter("self.project = ?1 OR self.project.parentProject = ?1", project).fetch();
project.setTotalPlannedHrs(projectPlanningTimeService.getProjectPlannedHrs(project));
Project parentProject = project.getParentProject();
if (parentProject != null) {
parentProject.setTotalPlannedHrs(projectPlanningTimeService.getProjectPlannedHrs(parentProject));
}
if (projectPlanningTimeList != null) {
for (ProjectPlanningTime planningTime : projectPlanningTimeList) {
ProjectTask task = planningTime.getProjectTask();
if (task != null) {
task.setTotalPlannedHrs(projectPlanningTimeService.getTaskPlannedHrs(task));
}
}
}
return project;
}
Aggregations