Example usage for org.hibernate Criteria setProjection

List of usage examples for org.hibernate Criteria setProjection

Introduction

In this page you can find the example usage for org.hibernate Criteria setProjection.

Prototype

public Criteria setProjection(Projection projection);

Source Link

Document

Used to specify that the query results will be a projection (scalar in nature).

Usage

From source file:com.floreantpos.report.service.ReportService.java

License:Open Source License

private double calculateCashPayout(Session session, Date fromDate, Date toDate, User user) {
    Criteria criteria = session.createCriteria(PayOutTransaction.class);
    criteria.add(Restrictions.ge(PayOutTransaction.PROP_TRANSACTION_TIME, fromDate));
    criteria.add(Restrictions.le(PayOutTransaction.PROP_TRANSACTION_TIME, toDate));

    if (user != null) {
        criteria.add(Restrictions.eq(PayOutTransaction.PROP_USER, user));
    }/*w w w . j  a  v  a2 s . c  o m*/

    criteria.setProjection(Projections.sum(PayOutTransaction.PROP_AMOUNT));

    return getDoubleAmount(criteria.uniqueResult());
}

From source file:com.floreantpos.report.service.ReportService.java

License:Open Source License

private double calculateTipsPaid(Session session, Date fromDate, Date toDate, User user) {
    Criteria criteria = session.createCriteria(Ticket.class);
    criteria.createAlias(Ticket.PROP_GRATUITY, "gratuity"); //$NON-NLS-1$
    criteria.add(Restrictions.ge(Ticket.PROP_CREATE_DATE, fromDate));
    criteria.add(Restrictions.le(Ticket.PROP_CREATE_DATE, toDate));

    criteria.add(Restrictions.eq("gratuity." + Gratuity.PROP_PAID, Boolean.TRUE)); //$NON-NLS-1$

    if (user != null) {
        criteria.add(Restrictions.eq(Ticket.PROP_OWNER, user));
    }/*from  w  w  w.ja  v  a 2  s . c  o  m*/

    criteria.setProjection(Projections.sum("gratuity." + Gratuity.PROP_AMOUNT)); //$NON-NLS-1$

    return getDoubleAmount(criteria.uniqueResult());
}

From source file:com.floreantpos.report.service.ReportService.java

License:Open Source License

private double calculateCreditReceipt(Session session, Class transactionClass, Date fromDate, Date toDate,
        User user) {/* w w w.  j  a  va2s . c o m*/
    //cash receipt
    Criteria criteria = session.createCriteria(transactionClass);
    criteria.add(Restrictions.ge(PosTransaction.PROP_TRANSACTION_TIME, fromDate));
    criteria.add(Restrictions.le(PosTransaction.PROP_TRANSACTION_TIME, toDate));
    criteria.add(Restrictions.eq(PosTransaction.PROP_TRANSACTION_TYPE, TransactionType.CREDIT.name()));

    if (user != null) {
        criteria.add(Restrictions.eq(PosTransaction.PROP_USER, user));
    }

    criteria.setProjection(Projections.sum(CashTransaction.PROP_AMOUNT));

    return getDoubleAmount(criteria.uniqueResult());
}

From source file:com.floreantpos.report.service.ReportService.java

License:Open Source License

private double calculateCashReceipt(Session session, Date fromDate, Date toDate) {
    //cash receipt
    Criteria criteria = session.createCriteria(CashTransaction.class);
    criteria.add(Restrictions.ge(CashTransaction.PROP_TRANSACTION_TIME, fromDate));
    criteria.add(Restrictions.le(CashTransaction.PROP_TRANSACTION_TIME, toDate));
    criteria.add(Restrictions.eq(CashTransaction.PROP_TRANSACTION_TYPE, TransactionType.CREDIT.name()));

    criteria.setProjection(Projections.sum(CashTransaction.PROP_AMOUNT));

    return getDoubleAmount(criteria.uniqueResult());
}

From source file:com.floreantpos.report.service.ReportService.java

License:Open Source License

private double calculateCreditCardReceipt(Session session, Date fromDate, Date toDate) {
    //cash receipt
    Criteria criteria = session.createCriteria(CashTransaction.class);
    criteria.add(Restrictions.ge(CreditCardTransaction.PROP_TRANSACTION_TIME, fromDate));
    criteria.add(Restrictions.le(CreditCardTransaction.PROP_TRANSACTION_TIME, toDate));
    criteria.add(Restrictions.eq(CreditCardTransaction.PROP_TRANSACTION_TYPE, TransactionType.CREDIT.name()));

    criteria.setProjection(Projections.sum(CashTransaction.PROP_AMOUNT));

    return getDoubleAmount(criteria.uniqueResult());
}

From source file:com.floreantpos.report.service.ReportService.java

License:Open Source License

private double calculateGiftCertSoldAmount(Session session, Date fromDate, Date toDate) {
    //cash receipt
    Criteria criteria = session.createCriteria(GiftCertificateTransaction.class);
    criteria.add(Restrictions.ge(GiftCertificateTransaction.PROP_TRANSACTION_TIME, fromDate));
    criteria.add(Restrictions.le(GiftCertificateTransaction.PROP_TRANSACTION_TIME, toDate));
    criteria.add(//from  www .j a va 2 s .co m
            Restrictions.eq(GiftCertificateTransaction.PROP_TRANSACTION_TYPE, TransactionType.CREDIT.name()));

    criteria.setProjection(Projections.sum(GiftCertificateTransaction.PROP_GIFT_CERT_FACE_VALUE));

    return getDoubleAmount(criteria.uniqueResult());
}

From source file:com.floreantpos.report.service.ReportService.java

License:Open Source License

private double calculateTips(Session session, Date fromDate, Date toDate, User user) {
    //tips/*  www  .j  av a2s  . co m*/
    Criteria criteria = session.createCriteria(Ticket.class);
    criteria.createAlias(Ticket.PROP_GRATUITY, "g"); //$NON-NLS-1$
    criteria.add(Restrictions.ge(Ticket.PROP_CREATE_DATE, fromDate));
    criteria.add(Restrictions.le(Ticket.PROP_CREATE_DATE, toDate));

    if (user != null) {
        criteria.add(Restrictions.eq(Ticket.PROP_OWNER, user));
    }
    //FIXME: HOW ABOUT TIPS ON VOID OR REFUNDED TICKET?

    //criteria.add(Restrictions.eq(Ticket.PROP_VOIDED, Boolean.FALSE));
    //criteria.add(Restrictions.eq(Ticket.PROP_REFUNDED, Boolean.FALSE));

    criteria.setProjection(Projections.sum("g." + Gratuity.PROP_AMOUNT)); //$NON-NLS-1$

    return getDoubleAmount(criteria.uniqueResult());
}

From source file:com.floreantpos.report.service.ReportService.java

License:Open Source License

private double calculateDiscount(Session session, Date fromDate, Date toDate, User user) {
    //discounts/*from ww  w.  j  av a 2s  .  c  o  m*/
    Criteria criteria = session.createCriteria(Ticket.class);
    criteria.add(Restrictions.ge(Ticket.PROP_CREATE_DATE, fromDate));
    criteria.add(Restrictions.le(Ticket.PROP_CREATE_DATE, toDate));
    criteria.add(Restrictions.eq(Ticket.PROP_VOIDED, Boolean.FALSE));
    criteria.add(Restrictions.eq(Ticket.PROP_REFUNDED, Boolean.FALSE));

    if (user != null) {
        criteria.add(Restrictions.eq(Ticket.PROP_OWNER, user));
    }

    criteria.setProjection(Projections.sum(Ticket.PROP_DISCOUNT_AMOUNT));

    return getDoubleAmount(criteria.uniqueResult());
}

From source file:com.floreantpos.report.service.ReportService.java

License:Open Source License

private double calculateTax(Session session, Date fromDate, Date toDate, User user) {
    //discounts// ww  w  .j  a  v  a2s  .c o m
    Criteria criteria = session.createCriteria(Ticket.class);
    criteria.add(Restrictions.ge(Ticket.PROP_CREATE_DATE, fromDate));
    criteria.add(Restrictions.le(Ticket.PROP_CREATE_DATE, toDate));
    criteria.add(Restrictions.eq(Ticket.PROP_VOIDED, Boolean.FALSE));
    criteria.add(Restrictions.eq(Ticket.PROP_REFUNDED, Boolean.FALSE));

    if (user != null) {
        criteria.add(Restrictions.eq(Ticket.PROP_OWNER, user));
    }

    criteria.setProjection(Projections.sum(Ticket.PROP_TAX_AMOUNT));

    return getDoubleAmount(criteria.uniqueResult());
}

From source file:com.floreantpos.report.service.ReportService.java

License:Open Source License

private double calculateGrossSales(Session session, Date fromDate, Date toDate, User user,
        boolean taxableSales) {
    Criteria criteria = session.createCriteria(Ticket.class);
    criteria.add(Restrictions.ge(Ticket.PROP_CREATE_DATE, fromDate));
    criteria.add(Restrictions.le(Ticket.PROP_CREATE_DATE, toDate));
    criteria.add(Restrictions.eq(Ticket.PROP_VOIDED, Boolean.FALSE));
    criteria.add(Restrictions.eq(Ticket.PROP_REFUNDED, Boolean.FALSE));

    if (user != null) {
        criteria.add(Restrictions.eq(Ticket.PROP_OWNER, user));
    }//from ww w  . ja va2 s  .  c o m

    criteria.add(Restrictions.eq(Ticket.PROP_TAX_EXEMPT, Boolean.valueOf(!taxableSales)));

    criteria.setProjection(Projections.sum(Ticket.PROP_SUBTOTAL_AMOUNT));

    return getDoubleAmount(criteria.uniqueResult());
}