Search in sources :

Example 1 with ActivitySearch

use of com.autentia.tnt.dao.search.ActivitySearch in project TNTConcept by autentia.

the class GlobalHoursReportBean method getAll.

public List<GlobalHourReport> getAll() {
    // Retrieve activities for every User during that period of time
    ActivitySearch search = new ActivitySearch();
    Calendar init = Calendar.getInstance();
    init.setTime(startDate);
    Calendar last = Calendar.getInstance();
    last.setTime(endDate);
    init.set(Calendar.HOUR_OF_DAY, init.getMinimum(Calendar.HOUR_OF_DAY));
    init.set(Calendar.MINUTE, init.getMinimum(Calendar.MINUTE));
    init.set(Calendar.SECOND, init.getMinimum(Calendar.SECOND));
    init.set(Calendar.MILLISECOND, init.getMinimum(Calendar.MILLISECOND));
    last.set(Calendar.HOUR_OF_DAY, last.getMaximum(Calendar.HOUR_OF_DAY));
    last.set(Calendar.MINUTE, last.getMaximum(Calendar.MINUTE));
    last.set(Calendar.SECOND, last.getMaximum(Calendar.SECOND));
    last.set(Calendar.MILLISECOND, last.getMaximum(Calendar.MILLISECOND));
    search.setStartStartDate(init.getTime());
    search.setEndStartDate(last.getTime());
    List<GlobalHourReport> listGlobal = new ArrayList<GlobalHourReport>();
    if (billable)
        search.setBillable(true);
    // Search activities during indicated dates
    List<Activity> activities = manager.getAllEntities(search, new SortCriteria("role.project.client.name"));
    for (Activity act : activities) {
        Project proj = act.getRole().getProject();
        GlobalHourReport unit = new GlobalHourReport();
        unit.setProject(proj);
        // an entry in the list represents a project
        if (!listGlobal.contains(unit))
            listGlobal.add(unit);
        // Retrieve the stored unit and save hours
        GlobalHourReport storedUnit = listGlobal.get(listGlobal.indexOf(unit));
        float horas = act.getDuration() / 60.0f;
        storedUnit.setUserHours(act.getUser(), horas);
        storedUnit.setIterator(usuarios.iterator());
    }
    return listGlobal;
}
Also used : SortCriteria(com.autentia.tnt.dao.SortCriteria) Project(com.autentia.tnt.businessobject.Project) GlobalHourReport(com.autentia.tnt.businessobject.GlobalHourReport) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Activity(com.autentia.tnt.businessobject.Activity) ActivitySearch(com.autentia.tnt.dao.search.ActivitySearch)

Example 2 with ActivitySearch

use of com.autentia.tnt.dao.search.ActivitySearch in project TNTConcept by autentia.

the class ActivityBean method getYearWorkHours.

private double getYearWorkHours() {
    ActivitySearch activitySearch = new ActivitySearch();
    Date startStartDate = new GregorianCalendar(getSelectedYear(), 0, 1).getTime();
    Date endStartDate = new GregorianCalendar(getSelectedYear(), 11, 31).getTime();
    activitySearch.setUser(authManager.getCurrentPrincipal().getUser());
    activitySearch.setStartStartDate(startStartDate);
    activitySearch.setEndStartDate(endStartDate);
    List<Activity> activities = manager.getAllEntities(activitySearch, null);
    return manager.workedTime(activities) / 60.0f;
}
Also used : GregorianCalendar(java.util.GregorianCalendar) Activity(com.autentia.tnt.businessobject.Activity) ExternalActivity(com.autentia.tnt.businessobject.ExternalActivity) ExternalActivitySearch(com.autentia.tnt.dao.search.ExternalActivitySearch) ActivitySearch(com.autentia.tnt.dao.search.ActivitySearch) Date(java.util.Date) LocalDate(java.time.LocalDate)

Example 3 with ActivitySearch

use of com.autentia.tnt.dao.search.ActivitySearch in project TNTConcept by autentia.

the class ActivityBean method create.

/**
 * Go to create page
 *
 * @return forward to CREATE page
 */
public String create() {
    activity = new Activity();
    externalActivity = new ExternalActivity();
    selectedOrganization = null;
    selectedProject = null;
    organizations.clear();
    projects.clear();
    cal.setTime(scheduleModel.getSelectedDate());
    if (scheduleModel.getMode() == ScheduleModel.MONTH || scheduleModel.getMode() == ScheduleModel.WEEK) {
        cal.set(Calendar.HOUR_OF_DAY, ((SettingBean) FacesUtils.getBean("settingBean")).getMySettings().getWorkingDayHourStarts());
    }
    activity.setStartDate(cal.getTime());
    activity.setDescription(FacesUtils.getMessage("activity.description"));
    activity.setUser(authManager.getCurrentPrincipal().getUser());
    externalActivity.setStartDate(cal.getTime());
    // it is going to end in the same day
    externalActivity.setEndDate(cal.getTime());
    externalActivity.setComments(FacesUtils.getMessage("offer.observations"));
    externalActivity.setOwnerId(authManager.getCurrentPrincipal().getUser().getId());
    externalActivity.setDepartmentId(authManager.getCurrentPrincipal().getUser().getDepartmentId());
    DocumentCategory padre = dcManager.getDocumentCategoryParent();
    // User category
    DocumentCategory extActDocCategory = new DocumentCategory();
    extActDocCategory.setName(externalActivity.getName());
    extActDocCategory.setDescription(externalActivity.getName());
    extActDocCategory.setPadre(padre);
    externalActivity.setDocumentCategory(extActDocCategory);
    // Preselect last selected options
    Setting val = settings.get(SettingPath.BITACORE_LAST_ROLEID, false);
    int projectRoleId = SettingManager.getInt(val, -1);
    Project pr = null;
    if (projectRoleId != -1) {
        ProjectRole projectRole;
        try {
            projectRole = projectRoleMgr.getEntityById(projectRoleId);
            if (!projectRole.getProject().isFinished()) {
                setRole(projectRole);
                setSelectedProject(projectRole.getProject());
                setSelectedOrganization(getSelectedProject().getClient());
                pr = projectRole.getProject();
            }
        } catch (ObjectNotFoundException onfex) {
        // Caso especial. Si no se localiza el anterior rol, continuamos con la
        // ejecucion.
        }
    }
    if (pr != null) {
        setBillable(pr.getBillable());
        setDefaultBillable(pr.getBillable());
    } else {
        val = settings.get(SettingPath.BITACORE_LAST_BILLABLE, false);
        setBillable(SettingManager.getBoolean(val, false));
    }
    if (scheduleModel.getMode() == ScheduleModel.MONTH || scheduleModel.getMode() == ScheduleModel.WEEK) {
        ActivitySearch searchToday = new ActivitySearch();
        ExternalActivitySearch extActivitySearchToday = new ExternalActivitySearch();
        Calendar initToday = Calendar.getInstance();
        initToday.setTime(DateUtils.minHourInDate(scheduleModel.getSelectedDate()));
        Calendar lastToday = Calendar.getInstance();
        lastToday.setTime(DateUtils.maxHourInDate(scheduleModel.getSelectedDate()));
        searchToday.setStartStartDate(initToday.getTime());
        searchToday.setEndStartDate(lastToday.getTime());
        extActivitySearchToday.setStartStartDate(initToday.getTime());
        extActivitySearchToday.setEndStartDate(lastToday.getTime());
        // Try to obtain the last hour in day.
        searchToday.setUser(authManager.getCurrentPrincipal().getUser());
        extActivitySearchToday.setOwner(authManager.getCurrentPrincipal().getUser());
        List<Activity> activities = manager.getAllEntities(searchToday, new SortCriteria(sortColumn, sortAscending));
        List<ExternalActivity> extActivities = externalActivityManager.getAllEntities(extActivitySearchToday, new SortCriteria(sortColumn, sortAscending));
        if (activities.size() > 0 && extActivities.size() <= 0) {
            // No externalActivities
            // sort is descendent
            Collections.sort(activities, new compareActivitiesByStartAndDuration());
            activity.setStartDate(activities.get(0).getEndDate());
            externalActivity.setStartDate(activities.get(0).getEndDate());
            externalActivity.setEndDate(activities.get(0).getEndDate());
        } else if (activities.size() <= 0 && extActivities.size() > 0) {
            // No activities
            Collections.sort(extActivities, new compareExternalActivitiesActivitiesByStartAndDuration());
            activity.setStartDate(extActivities.get(0).getEndDate());
            externalActivity.setStartDate(extActivities.get(0).getEndDate());
            externalActivity.setEndDate(extActivities.get(0).getEndDate());
        } else if (activities.size() > 0 && extActivities.size() > 0) {
            Collections.sort(activities, new compareActivitiesByStartAndDuration());
            Collections.sort(extActivities, new compareExternalActivitiesActivitiesByStartAndDuration());
            Date lastActivityEndDate = activities.get(0).getEndDate();
            Date lastExtActivityEndDate = extActivities.get(0).getEndDate();
            Date startDate = (lastActivityEndDate.compareTo(lastExtActivityEndDate) > 0) ? lastActivityEndDate : lastExtActivityEndDate;
            activity.setStartDate(startDate);
            externalActivity.setStartDate(startDate);
            externalActivity.setEndDate(startDate);
        }
    }
    tabsRendered = NO_EDIT_SELECTED;
    return NavigationResults.CREATE;
}
Also used : ExternalActivitySearch(com.autentia.tnt.dao.search.ExternalActivitySearch) Setting(com.autentia.tnt.businessobject.Setting) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) Activity(com.autentia.tnt.businessobject.Activity) ExternalActivity(com.autentia.tnt.businessobject.ExternalActivity) ProjectRole(com.autentia.tnt.businessobject.ProjectRole) DocumentCategory(com.autentia.tnt.businessobject.DocumentCategory) Date(java.util.Date) LocalDate(java.time.LocalDate) ExternalActivity(com.autentia.tnt.businessobject.ExternalActivity) SortCriteria(com.autentia.tnt.dao.SortCriteria) Project(com.autentia.tnt.businessobject.Project) ObjectNotFoundException(org.hibernate.ObjectNotFoundException) SettingBean(com.autentia.tnt.bean.admin.SettingBean) ExternalActivitySearch(com.autentia.tnt.dao.search.ExternalActivitySearch) ActivitySearch(com.autentia.tnt.dao.search.ActivitySearch)

Example 4 with ActivitySearch

use of com.autentia.tnt.dao.search.ActivitySearch in project TNTConcept by autentia.

the class BillManager method getAllBitacoreBreakDowns.

public List<BillBreakDown> getAllBitacoreBreakDowns(Date start, Date end, Project project) {
    final List<BillBreakDown> desgloses = new ArrayList<BillBreakDown>();
    ActivityDAO activityDAO = ActivityDAO.getDefault();
    ActivitySearch actSearch = new ActivitySearch();
    actSearch.setBillable(new Boolean(true));
    actSearch.setStartStartDate(start);
    actSearch.setEndStartDate(end);
    List<Activity> actividadesTotal = new ArrayList<Activity>();
    Hashtable user_roles = new Hashtable();
    ProjectRoleDAO projectRoleDAO = ProjectRoleDAO.getDefault();
    ProjectRoleSearch prjRolSearch = new ProjectRoleSearch();
    prjRolSearch.setProject(project);
    List<ProjectRole> roles = projectRoleDAO.search(prjRolSearch, new SortCriteria("id", false));
    for (ProjectRole proyRole : roles) {
        actSearch.setRole(proyRole);
        List<Activity> actividades = activityDAO.search(actSearch, new SortCriteria("startDate", false));
        actividadesTotal.addAll(actividades);
    }
    for (Activity act : actividadesTotal) {
        String key = act.getRole().getId().toString() + act.getUser().getId().toString();
        if (!user_roles.containsKey(key)) {
            Hashtable value = new Hashtable();
            value.put("ROLE", act.getRole());
            value.put("USER", act.getUser());
            user_roles.put(key, value);
        }
    }
    Enumeration en = user_roles.keys();
    while (en.hasMoreElements()) {
        String key = (String) en.nextElement();
        Hashtable pair = (Hashtable) user_roles.get(key);
        actSearch.setBillable(new Boolean(true));
        actSearch.setStartStartDate(start);
        actSearch.setEndStartDate(end);
        ProjectRole pR = (ProjectRole) pair.get("ROLE");
        User u = (User) pair.get("USER");
        actSearch.setRole(pR);
        actSearch.setUser(u);
        List<Activity> actividadesUsuarioRol = activityDAO.search(actSearch, new SortCriteria("startDate", false));
        BillBreakDown brd = new BillBreakDown();
        brd.setConcept("Imputaciones (usuario - rol): " + u.getName() + " - " + pR.getName());
        brd.setAmount(pR.getCostPerHour());
        IvaApplicator.applyIvaToTaxableObject(start, brd);
        BigDecimal unitsTotal = new BigDecimal(0);
        for (Activity act : actividadesUsuarioRol) {
            BigDecimal unitsActual = new BigDecimal(act.getDuration());
            unitsActual = unitsActual.divide(new BigDecimal(60), 2, RoundingMode.HALF_UP);
            unitsTotal = unitsTotal.add(unitsActual);
        }
        brd.setUnits(unitsTotal);
        brd.setSelected(true);
        desgloses.add(brd);
    }
    ProjectCostDAO prjCostDAO = ProjectCostDAO.getDefault();
    ProjectCostSearch prjCostSearch = new ProjectCostSearch();
    prjCostSearch.setProject(project);
    List<ProjectCost> costes = prjCostDAO.search(prjCostSearch, new SortCriteria("id", false));
    for (ProjectCost proyCost : costes) {
        BillBreakDown brd = new BillBreakDown();
        brd.setConcept("Coste: " + proyCost.getName());
        brd.setUnits(new BigDecimal(1));
        brd.setAmount(proyCost.getCost());
        IvaApplicator.applyIvaToTaxableObject(start, brd);
        brd.setSelected(true);
        desgloses.add(brd);
    }
    return desgloses;
}
Also used : ProjectRoleDAO(com.autentia.tnt.dao.hibernate.ProjectRoleDAO) Enumeration(java.util.Enumeration) User(com.autentia.tnt.businessobject.User) ProjectCostDAO(com.autentia.tnt.dao.hibernate.ProjectCostDAO) Hashtable(java.util.Hashtable) ArrayList(java.util.ArrayList) ProjectCostSearch(com.autentia.tnt.dao.search.ProjectCostSearch) Activity(com.autentia.tnt.businessobject.Activity) ProjectRole(com.autentia.tnt.businessobject.ProjectRole) BigDecimal(java.math.BigDecimal) SortCriteria(com.autentia.tnt.dao.SortCriteria) ProjectRoleSearch(com.autentia.tnt.dao.search.ProjectRoleSearch) ActivitySearch(com.autentia.tnt.dao.search.ActivitySearch) ProjectCost(com.autentia.tnt.businessobject.ProjectCost) BillBreakDown(com.autentia.tnt.businessobject.BillBreakDown) ActivityDAO(com.autentia.tnt.dao.hibernate.ActivityDAO)

Example 5 with ActivitySearch

use of com.autentia.tnt.dao.search.ActivitySearch in project TNTConcept by autentia.

the class ActivityBean method fillActivities.

private void fillActivities(SimpleScheduleModel model) {
    ActivitySearch searchMonth = new ActivitySearch();
    Calendar calMin = Calendar.getInstance();
    Calendar calMax = Calendar.getInstance();
    calMin = getMinimumSearchTime(selectedDate);
    calMax = getMaximumSearchTime(selectedDate);
    searchMonth.setStartStartDate(calMin.getTime());
    searchMonth.setEndStartDate(calMax.getTime());
    searchMonth.setUser(authManager.getCurrentPrincipal().getUser());
    /* search data in persistence layer */
    List<Activity> activities = manager.getAllEntities(searchMonth, new SortCriteria(sortColumn, sortAscending));
    List<Activity> activitiesWorkables = new ArrayList<>(activities.size());
    /* load data in component */
    for (Activity actualActivity : activities) {
        calMin.setTime(actualActivity.getStartDate());
        calMax.setTime(selectedDate);
        if (calMin.get(Calendar.MONTH) == calMax.get(Calendar.MONTH)) {
            activitiesWorkables.add(actualActivity);
        }
        ActivityScheduleEntry entry = new ActivityScheduleEntry(actualActivity);
        scheduleModel.addEntry(entry);
    }
    monthPerformedHours = manager.workedTime(activitiesWorkables) / 60.0f;
}
Also used : SortCriteria(com.autentia.tnt.dao.SortCriteria) GregorianCalendar(java.util.GregorianCalendar) Calendar(java.util.Calendar) ArrayList(java.util.ArrayList) Activity(com.autentia.tnt.businessobject.Activity) ExternalActivity(com.autentia.tnt.businessobject.ExternalActivity) ExternalActivitySearch(com.autentia.tnt.dao.search.ExternalActivitySearch) ActivitySearch(com.autentia.tnt.dao.search.ActivitySearch)

Aggregations

Activity (com.autentia.tnt.businessobject.Activity)8 ActivitySearch (com.autentia.tnt.dao.search.ActivitySearch)8 SortCriteria (com.autentia.tnt.dao.SortCriteria)6 Calendar (java.util.Calendar)5 ExternalActivity (com.autentia.tnt.businessobject.ExternalActivity)3 Project (com.autentia.tnt.businessobject.Project)3 ProjectRole (com.autentia.tnt.businessobject.ProjectRole)3 User (com.autentia.tnt.businessobject.User)3 ExternalActivitySearch (com.autentia.tnt.dao.search.ExternalActivitySearch)3 LocalDate (java.time.LocalDate)3 ArrayList (java.util.ArrayList)3 GregorianCalendar (java.util.GregorianCalendar)3 Date (java.util.Date)2 SettingBean (com.autentia.tnt.bean.admin.SettingBean)1 BillBreakDown (com.autentia.tnt.businessobject.BillBreakDown)1 DocumentCategory (com.autentia.tnt.businessobject.DocumentCategory)1 GlobalHourReport (com.autentia.tnt.businessobject.GlobalHourReport)1 ProjectCost (com.autentia.tnt.businessobject.ProjectCost)1 Setting (com.autentia.tnt.businessobject.Setting)1 ActivityDAO (com.autentia.tnt.dao.hibernate.ActivityDAO)1