Example usage for org.hibernate.criterion Projections sum

List of usage examples for org.hibernate.criterion Projections sum

Introduction

In this page you can find the example usage for org.hibernate.criterion Projections sum.

Prototype

public static AggregateProjection sum(String propertyName) 

Source Link

Document

A property value sum projection

Usage

From source file:es.sm2.openppm.core.dao.ExpensesheetDAO.java

License:Open Source License

public double getCostResource(Integer idEmployee, Integer id, Date since, Date until, String minStatus,
        String maxStatus, Employee user) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setProjection(Projections.sum(Expensesheet.COST))
            .add(Restrictions.or(Restrictions.eq(Expensesheet.STATUS, minStatus),
                    Restrictions.eq(Expensesheet.STATUS, maxStatus)))
            .add(Restrictions.between(Expensesheet.EXPENSEDATE, since, until));

    Criteria employeeCrit = crit.createCriteria(Expensesheet.EMPLOYEE).add(Restrictions.idEq(idEmployee));

    if (Constants.EXPENSE_STATUS_APP1.equals(minStatus)) {
        crit.add(Restrictions.eq(Expensesheet.PROJECT, new Project(id)));
    } else if (Constants.EXPENSE_STATUS_APP2.equals(minStatus)) {

        employeeCrit.add(Restrictions.eq(Employee.PERFORMINGORG, user.getPerformingorg()));
    }//from   w w w .j a v  a 2s . c o m
    double cost = (Double) (crit.uniqueResult() == null ? 0D : crit.uniqueResult());

    return cost;
}

From source file:es.sm2.openppm.core.dao.ExpensesheetDAO.java

License:Open Source License

public double getSumExpenseSheet(Expenses expense) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setProjection(Projections.sum(Expensesheet.COST))
            .add(Restrictions.eq(Expensesheet.STATUS, Constants.EXPENSE_STATUS_APP3))
            .add(Restrictions.eq(Expensesheet.EXPENSES, expense));

    double cost = (Double) (crit.uniqueResult() == null ? 0D : crit.uniqueResult());

    return cost;/*from  w  ww .j a v  a  2  s .c o  m*/
}

From source file:es.sm2.openppm.core.dao.ProcurementpaymentsDAO.java

License:Open Source License

/**
 * Get Procurement Budgets from Project//from   w  w  w. j a  va 2s . c  o m
 * 
 * @param proj
 * @param joins
 * @return
 */
public List<ProcurementBudget> consProcurementBudgetsByProject(Project proj, List<String> joins) {
    Criteria crit = getSession().createCriteria(getPersistentClass());

    for (String join : joins) {
        crit.setFetchMode(join, FetchMode.JOIN);
    }

    crit.addOrder(Order.asc(Procurementpayments.SELLER))
            .setProjection(Projections.projectionList().add(Projections.sum(Procurementpayments.PLANNEDPAYMENT))
                    .add(Projections.sum(Procurementpayments.ACTUALPAYMENT)).add(Projections.rowCount())
                    .add(Projections.groupProperty(Procurementpayments.SELLER)))
            .add(Restrictions.eq(Procurementpayments.PROJECT, proj));

    List<ProcurementBudget> lista = new ArrayList<ProcurementBudget>();
    List<String> purchase = null;

    for (int i = 0; i < crit.list().size(); i++) {
        ProcurementBudget budget = new ProcurementBudget();
        Object[] row = (Object[]) crit.list().get(i);
        budget.setPlannedPayment((Double) row[0]);
        budget.setActualPayment((Double) row[1]);
        budget.setnPayments((Integer) row[2]);

        Seller seller = (Seller) row[3];
        budget.setSeller(seller.getName());

        purchase = consPruchaseOrder(seller, proj);
        String order = "";
        if (purchase != null) {
            for (String s : purchase) {
                if (!order.equals("")) {
                    order += ", ";
                }
                order += s;
            }
        }
        budget.setPurchaseOrder(order);

        lista.add(budget);
    }

    return lista;
}

From source file:es.sm2.openppm.core.dao.ProjectActivityDAO.java

License:Open Source License

/**
 * Sum EV//  w  w  w  . j  a va2s  .com
 * 
 * @param proj
 * @return
 */
public double sumEV(Project proj) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setProjection(Projections.sum(Projectactivity.EV))
            .add(Restrictions.eq(Projectactivity.PROJECT, proj));

    crit.createCriteria(Projectactivity.WBSNODE).add(Restrictions.eq(Wbsnode.ISCONTROLACCOUNT, true));

    Double value = (Double) crit.uniqueResult();

    return (value == null ? 0 : value);
}

From source file:es.sm2.openppm.core.dao.ProjectActivityDAO.java

License:Open Source License

public double clacPocBySum(Project project) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .add(Restrictions.eq(Projectactivity.PROJECT, project)).setProjection(Projections.projectionList()
                    .add(Projections.sum(Projectactivity.POC)).add(Projections.rowCount()));

    Criteria critWBSNode = crit.createCriteria(Projectactivity.WBSNODE)
            .add(Restrictions.eq(Wbsnode.ISCONTROLACCOUNT, true));

    Object[] value = (Object[]) crit.uniqueResult();

    double poc = 0;

    if (value != null && value.length == 2) {
        double sumPoc = (Double) value[0] == null ? 0 : (Double) value[0];
        int rows = (Integer) value[1];

        if (rows > 0) {
            poc = sumPoc / new Double(rows);
        }// w  ww  .j  a v  a  2  s . co m
    }

    return poc;
}

From source file:es.sm2.openppm.core.dao.ProjectDAO.java

License:Open Source License

/**
 * //  ww w .j  a v a 2 s  . c  om
 * @param program
 * @return
 */
public Double getBudgetBottomUp(Program program, boolean projectsDisabled) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setProjection(Projections.sum(Project.TCV)).add(Restrictions.eq(Project.PROGRAM, program));

    // Projects disabled
    if (projectsDisabled) {

        crit.add(Restrictions.disjunction().add(Restrictions.ne(Project.DISABLE, Constants.SELECTED))
                .add(Restrictions.isNull(Project.DISABLE)));
    }

    Double budget = (Double) crit.uniqueResult();

    return (budget == null ? 0 : budget);
}

From source file:es.sm2.openppm.core.dao.ProjectDAO.java

License:Open Source License

/**
 * Sum priority by program//from www.  j  a v  a 2 s  .c o  m
 * @param program
 * @return
 */
public Integer sumPriorityByProgram(Program program, boolean projectsDisabled) {

    Criteria crit = getSession().createCriteria(getPersistentClass())
            .setProjection(Projections.sum(Project.PRIORITY)).add(Restrictions.eq(Project.PROGRAM, program))
            .add(Restrictions.disjunction()
                    .add(Restrictions.eq(Project.INVESTMENTSTATUS, Constants.INVESTMENT_APPROVED))
                    .add(Restrictions.eq(Project.INVESTMENTSTATUS, Constants.INVESTMENT_IN_PROCESS)));

    // Projects not disabled
    if (projectsDisabled) {

        crit.add(Restrictions.disjunction().add(Restrictions.ne(Project.DISABLE, Constants.SELECTED))
                .add(Restrictions.isNull(Project.DISABLE)));
    }

    Integer priority = (Integer) crit.uniqueResult();

    return (priority == null ? 0 : priority);
}

From source file:es.sm2.openppm.core.dao.TimesheetDAO.java

License:Open Source License

/**
 * Get Hours resource/*from  w ww  .j av  a2 s. co m*/
 * @param idEmployee
 * @param id
 * @param initDate
 * @param endDate
 * @param minStatus
 * @param maxStatus
 * @return
 */
public double getHoursResource(Integer idEmployee, Integer id, Date initDate, Date endDate, String minStatus,
        Employee filterUser) {

    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.sum(Timesheet.HOURSDAY1));
    proList.add(Projections.sum(Timesheet.HOURSDAY2));
    proList.add(Projections.sum(Timesheet.HOURSDAY3));
    proList.add(Projections.sum(Timesheet.HOURSDAY4));
    proList.add(Projections.sum(Timesheet.HOURSDAY5));
    proList.add(Projections.sum(Timesheet.HOURSDAY6));
    proList.add(Projections.sum(Timesheet.HOURSDAY7));

    Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(proList)
            .add(Restrictions.disjunction().add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP1))
                    .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP2))
                    .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)))
            .add(Restrictions.eq(Timesheet.INITDATE, initDate)).add(Restrictions.eq(Timesheet.ENDDATE, endDate))
            .add(Restrictions.eq(Timesheet.EMPLOYEE, new Employee(idEmployee)));

    if (Constants.TIMESTATUS_APP1.equals(minStatus)) {
        crit.createCriteria(Timesheet.PROJECTACTIVITY)
                .add(Restrictions.eq(Projectactivity.PROJECT, new Project(id)));
    } else if (Constants.TIMESTATUS_APP2.equals(minStatus)) {

        // Filter by User. Settings by company for last approval.

        Criteria critFilter = crit.createCriteria(Timesheet.PROJECTACTIVITY)
                .createCriteria(Projectactivity.PROJECT);

        Resourceprofiles profile = filterUser.getResourceprofiles();

        if (profile.getIdProfile() == Constants.ROLE_FM) {

            critFilter.add(Restrictions.eq(Project.EMPLOYEEBYFUNCTIONALMANAGER, filterUser));
        } else if (profile.getIdProfile() == Constants.ROLE_PMO) {

            critFilter.add(Restrictions.eq(Project.PERFORMINGORG, filterUser.getPerformingorg()));
        }
    }
    Object[] hoursList = (Object[]) crit.uniqueResult();

    double hours = 0;

    if (hoursList != null) {
        hours += (hoursList[0] == null ? 0 : (Double) hoursList[0]);
        hours += (hoursList[1] == null ? 0 : (Double) hoursList[1]);
        hours += (hoursList[2] == null ? 0 : (Double) hoursList[2]);
        hours += (hoursList[3] == null ? 0 : (Double) hoursList[3]);
        hours += (hoursList[4] == null ? 0 : (Double) hoursList[4]);
        hours += (hoursList[5] == null ? 0 : (Double) hoursList[5]);
        hours += (hoursList[6] == null ? 0 : (Double) hoursList[6]);
    }

    return hours;
}

From source file:es.sm2.openppm.core.dao.TimesheetDAO.java

License:Open Source License

/**
 * Get Hours resource by operation//from  w ww .j a va 2 s  .c  o m
 * @param idEmployee
 * @param initDate
 * @param endDate
 * @return
 */
public double getHoursResourceOpeartion(Integer idEmployee, Date initDate, Date endDate) {

    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.sum(Timesheet.HOURSDAY1));
    proList.add(Projections.sum(Timesheet.HOURSDAY2));
    proList.add(Projections.sum(Timesheet.HOURSDAY3));
    proList.add(Projections.sum(Timesheet.HOURSDAY4));
    proList.add(Projections.sum(Timesheet.HOURSDAY5));
    proList.add(Projections.sum(Timesheet.HOURSDAY6));
    proList.add(Projections.sum(Timesheet.HOURSDAY7));

    Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(proList)
            .add(Restrictions.disjunction().add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP1))
                    .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP2))
                    .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3)))
            .add(Restrictions.eq(Timesheet.INITDATE, initDate)).add(Restrictions.eq(Timesheet.ENDDATE, endDate))
            .add(Restrictions.eq(Timesheet.EMPLOYEE, new Employee(idEmployee)))
            .add(Restrictions.isNotNull(Timesheet.OPERATION));

    Object[] hoursList = (Object[]) crit.uniqueResult();

    double hours = 0;

    if (hoursList != null) {
        hours += (hoursList[0] == null ? 0 : (Double) hoursList[0]);
        hours += (hoursList[1] == null ? 0 : (Double) hoursList[1]);
        hours += (hoursList[2] == null ? 0 : (Double) hoursList[2]);
        hours += (hoursList[3] == null ? 0 : (Double) hoursList[3]);
        hours += (hoursList[4] == null ? 0 : (Double) hoursList[4]);
        hours += (hoursList[5] == null ? 0 : (Double) hoursList[5]);
        hours += (hoursList[6] == null ? 0 : (Double) hoursList[6]);
    }

    return hours;
}

From source file:es.sm2.openppm.core.dao.TimesheetDAO.java

License:Open Source License

/**
 * Calculate Fte for inputed hours in project
 * /*from w w  w .j  a  va  2s .c om*/
 * @param project
 * @param member
 * @param firstWeekDay
 * @param lastWeekDay
 * @return
 */
public double getHoursResource(Project project, Employee member, Date firstWeekDay, Date lastWeekDay) {

    ProjectionList proList = Projections.projectionList();
    proList.add(Projections.sum(Timesheet.HOURSDAY1));
    proList.add(Projections.sum(Timesheet.HOURSDAY2));
    proList.add(Projections.sum(Timesheet.HOURSDAY3));
    proList.add(Projections.sum(Timesheet.HOURSDAY4));
    proList.add(Projections.sum(Timesheet.HOURSDAY5));
    proList.add(Projections.sum(Timesheet.HOURSDAY6));
    proList.add(Projections.sum(Timesheet.HOURSDAY7));

    Criteria crit = getSession().createCriteria(getPersistentClass()).setProjection(proList)
            .add(Restrictions.eq(Timesheet.STATUS, Constants.TIMESTATUS_APP3))
            .add(Restrictions.eq(Timesheet.EMPLOYEE, member));

    if (firstWeekDay != null && lastWeekDay != null) {

        crit.add(Restrictions.eq(Timesheet.INITDATE, firstWeekDay))
                .add(Restrictions.eq(Timesheet.ENDDATE, lastWeekDay));
    }

    // Aliases 
    //
    crit.createAlias(Timesheet.PROJECTACTIVITY, "pa", CriteriaSpecification.LEFT_JOIN);

    // Projects or operations
    crit.add(Restrictions.disjunction().add(Restrictions.isNotNull(Timesheet.OPERATION))
            .add(Restrictions.eq("pa." + Projectactivity.PROJECT, project)));

    Object[] hoursList = (Object[]) crit.uniqueResult();

    double hours = 0;

    if (hoursList != null) {
        hours += (hoursList[0] == null ? 0 : (Double) hoursList[0]);
        hours += (hoursList[1] == null ? 0 : (Double) hoursList[1]);
        hours += (hoursList[2] == null ? 0 : (Double) hoursList[2]);
        hours += (hoursList[3] == null ? 0 : (Double) hoursList[3]);
        hours += (hoursList[4] == null ? 0 : (Double) hoursList[4]);
        hours += (hoursList[5] == null ? 0 : (Double) hoursList[5]);
        hours += (hoursList[6] == null ? 0 : (Double) hoursList[6]);
    }

    return hours;
}