Search in sources :

Example 1 with Project

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

Example 2 with Project

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;
}
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 3 with Project

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

Example 4 with Project

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);
    }
}
Also used : User(com.axelor.auth.db.User) ProjectRepository(com.axelor.apps.project.db.repo.ProjectRepository) TimesheetLine(com.axelor.apps.hr.db.TimesheetLine) HashMap(java.util.HashMap) ProductRepository(com.axelor.apps.base.db.repo.ProductRepository) Timesheet(com.axelor.apps.hr.db.Timesheet) Product(com.axelor.apps.base.db.Product) TimesheetService(com.axelor.apps.hr.service.timesheet.TimesheetService) LocalDate(java.time.LocalDate) BigDecimal(java.math.BigDecimal) AxelorException(com.axelor.exception.AxelorException) Project(com.axelor.apps.project.db.Project) TimesheetLineRepository(com.axelor.apps.hr.db.repo.TimesheetLineRepository) TimesheetRepository(com.axelor.apps.hr.db.repo.TimesheetRepository) TimesheetLineService(com.axelor.apps.hr.service.timesheet.TimesheetLineService) Transactional(com.google.inject.persist.Transactional)

Example 5 with Project

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

Aggregations

Project (com.axelor.apps.project.db.Project)64 AxelorException (com.axelor.exception.AxelorException)15 InvoicingProject (com.axelor.apps.businessproject.db.InvoicingProject)12 Transactional (com.google.inject.persist.Transactional)12 BigDecimal (java.math.BigDecimal)11 ArrayList (java.util.ArrayList)9 Product (com.axelor.apps.base.db.Product)8 User (com.axelor.auth.db.User)8 HashMap (java.util.HashMap)7 TimesheetLine (com.axelor.apps.hr.db.TimesheetLine)6 ProjectTask (com.axelor.apps.project.db.ProjectTask)6 Map (java.util.Map)6 Partner (com.axelor.apps.base.db.Partner)5 AppProject (com.axelor.apps.base.db.AppProject)4 ProjectRepository (com.axelor.apps.project.db.repo.ProjectRepository)4 Invoice (com.axelor.apps.account.db.Invoice)3 File (java.io.File)3 LocalDate (java.time.LocalDate)3 Company (com.axelor.apps.base.db.Company)2 PriceList (com.axelor.apps.base.db.PriceList)2