use of com.axelor.apps.project.db.ProjectPlanningTime in project axelor-open-suite by axelor.
the class ProjectPlanningTimeServiceImpl method removeProjectPlanningLines.
@Override
@Transactional
public void removeProjectPlanningLines(List<Map<String, Object>> projectPlanningLines) {
for (Map<String, Object> line : projectPlanningLines) {
ProjectPlanningTime projectPlanningTime = planningTimeRepo.find(Long.parseLong(line.get("id").toString()));
planningTimeRepo.remove(projectPlanningTime);
}
}
use of com.axelor.apps.project.db.ProjectPlanningTime in project axelor-open-suite by axelor.
the class ProjectPlanningTimeController method updateIsIncludeInTuronverForecast.
/**
* Invert value of 'isIncludeInTuronverForecast' field and save the record.
*
* @param request
* @param response
* @throws AxelorException
*/
@Transactional
public void updateIsIncludeInTuronverForecast(ActionRequest request, ActionResponse response) {
try {
ProjectPlanningTime projectPlanningTime = request.getContext().asType(ProjectPlanningTime.class);
projectPlanningTime = Beans.get(ProjectPlanningTimeRepository.class).find(projectPlanningTime.getId());
projectPlanningTime.setIsIncludeInTurnoverForecast(!projectPlanningTime.getIsIncludeInTurnoverForecast());
Beans.get(ProjectPlanningTimeRepository.class).save(projectPlanningTime);
response.setValue("isIncludeInTurnoverForecast", projectPlanningTime.getIsIncludeInTurnoverForecast());
} catch (Exception e) {
TraceBackService.trace(response, e);
}
}
use of com.axelor.apps.project.db.ProjectPlanningTime 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.project.db.ProjectPlanningTime 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;
}
use of com.axelor.apps.project.db.ProjectPlanningTime in project axelor-open-suite by axelor.
the class ProjectPlanningTimeServiceImpl method addMultipleProjectPlanningTime.
@Override
@Transactional(rollbackOn = { Exception.class })
public void addMultipleProjectPlanningTime(Map<String, Object> datas) throws AxelorException {
if (datas.get("project") == null || datas.get("user") == null || datas.get("fromDate") == null || datas.get("toDate") == null) {
return;
}
DateTimeFormatter formatter = DateTimeFormatter.ISO_DATE_TIME;
LocalDateTime fromDate = LocalDateTime.parse(datas.get("fromDate").toString(), formatter);
LocalDateTime toDate = LocalDateTime.parse(datas.get("toDate").toString(), formatter);
ProjectTask projectTask = null;
Map<String, Object> objMap = (Map) datas.get("project");
Project project = projectRepo.find(Long.parseLong(objMap.get("id").toString()));
Integer timePercent = 0;
if (datas.get("timepercent") != null) {
timePercent = Integer.parseInt(datas.get("timepercent").toString());
}
objMap = (Map) datas.get("user");
User user = userRepo.find(Long.parseLong(objMap.get("id").toString()));
if (user.getEmployee() == null) {
return;
}
if (datas.get("task") != null) {
objMap = (Map) datas.get("task");
projectTask = projectTaskRepo.find(Long.valueOf(objMap.get("id").toString()));
}
Product activity = null;
if (datas.get("product") != null) {
objMap = (Map) datas.get("product");
activity = productRepo.find(Long.valueOf(objMap.get("id").toString()));
}
Employee employee = user.getEmployee();
BigDecimal dailyWorkHrs = employee.getDailyWorkHours();
while (fromDate.isBefore(toDate)) {
LocalDate date = fromDate.toLocalDate();
LOG.debug("Create Planning for the date: {}", date);
double dayHrs = 0;
if (employee.getWeeklyPlanning() != null) {
dayHrs = weeklyPlanningService.getWorkingDayValueInDays(employee.getWeeklyPlanning(), date);
}
if (dayHrs > 0 && !holidayService.checkPublicHolidayDay(date, employee)) {
ProjectPlanningTime planningTime = new ProjectPlanningTime();
planningTime.setProjectTask(projectTask);
planningTime.setProduct(activity);
planningTime.setTimepercent(timePercent);
planningTime.setUser(user);
planningTime.setDate(date);
planningTime.setProject(project);
planningTime.setIsIncludeInTurnoverForecast((Boolean) datas.get("isIncludeInTurnoverForecast"));
BigDecimal totalHours = BigDecimal.ZERO;
if (timePercent > 0) {
totalHours = dailyWorkHrs.multiply(new BigDecimal(timePercent)).divide(new BigDecimal(100));
}
planningTime.setPlannedHours(totalHours);
planningTimeRepo.save(planningTime);
}
fromDate = fromDate.plusDays(1);
}
}
Aggregations