Search in sources :

Example 1 with ProjectPlanningTime

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);
    }
}
Also used : ProjectPlanningTime(com.axelor.apps.project.db.ProjectPlanningTime) Transactional(com.google.inject.persist.Transactional)

Example 2 with 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);
    }
}
Also used : ProjectPlanningTime(com.axelor.apps.project.db.ProjectPlanningTime) ProjectPlanningTimeRepository(com.axelor.apps.project.db.repo.ProjectPlanningTimeRepository) AxelorException(com.axelor.exception.AxelorException) Transactional(com.google.inject.persist.Transactional)

Example 3 with ProjectPlanningTime

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);
    }
}
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 4 with ProjectPlanningTime

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;
}
Also used : Project(com.axelor.apps.project.db.Project) ProjectPlanningTime(com.axelor.apps.project.db.ProjectPlanningTime) ProjectTask(com.axelor.apps.project.db.ProjectTask)

Example 5 with ProjectPlanningTime

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);
    }
}
Also used : LocalDateTime(java.time.LocalDateTime) User(com.axelor.auth.db.User) Product(com.axelor.apps.base.db.Product) ProjectPlanningTime(com.axelor.apps.project.db.ProjectPlanningTime) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) Project(com.axelor.apps.project.db.Project) Employee(com.axelor.apps.hr.db.Employee) ProjectTask(com.axelor.apps.project.db.ProjectTask) DateTimeFormatter(java.time.format.DateTimeFormatter) Map(java.util.Map) Transactional(com.google.inject.persist.Transactional)

Aggregations

ProjectPlanningTime (com.axelor.apps.project.db.ProjectPlanningTime)5 Transactional (com.google.inject.persist.Transactional)4 Project (com.axelor.apps.project.db.Project)2 ProjectTask (com.axelor.apps.project.db.ProjectTask)2 User (com.axelor.auth.db.User)2 Product (com.axelor.apps.base.db.Product)1 Employee (com.axelor.apps.hr.db.Employee)1 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)1 ProjectPlanningTimeRepository (com.axelor.apps.project.db.repo.ProjectPlanningTimeRepository)1 AxelorException (com.axelor.exception.AxelorException)1 BigDecimal (java.math.BigDecimal)1 LocalDate (java.time.LocalDate)1 LocalDateTime (java.time.LocalDateTime)1 DateTimeFormatter (java.time.format.DateTimeFormatter)1 Map (java.util.Map)1