List of usage examples for org.hibernate Criteria setProjection
public Criteria setProjection(Projection projection);
From source file:com.floreantpos.model.dao.SalesSummaryDAO.java
License:Open Source License
private void findRecordByProfitCenter(Date start, Date end, UserType userType, Terminal terminal, Session session, SalesStatistics salesSummary, Shift shift, OrderType ticketType) { Criteria criteria; criteria = session.createCriteria(Ticket.class, "ticket"); //$NON-NLS-1$ criteria.createCriteria(Ticket.PROP_OWNER, "u"); //$NON-NLS-1$ ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.rowCount()); projectionList.add(Projections.sum(Ticket.PROP_NUMBER_OF_GUESTS)); projectionList.add(Projections.sum(Ticket.PROP_SUBTOTAL_AMOUNT)); criteria.setProjection(projectionList); criteria.add(Restrictions.ge(Ticket.PROP_CREATE_DATE, start)); criteria.add(Restrictions.le(Ticket.PROP_CREATE_DATE, end)); criteria.add(Restrictions.eq(Ticket.PROP_SHIFT, shift)); criteria.add(Restrictions.eq(Ticket.PROP_TICKET_TYPE, ticketType.name())); if (userType != null) { criteria.add(Restrictions.eq("u." + User.PROP_TYPE, userType)); //$NON-NLS-1$ }/*from w w w.j a v a 2 s .co m*/ if (terminal != null) { criteria.add(Restrictions.eq(Ticket.PROP_TERMINAL, terminal)); } List list = criteria.list(); if (list.size() > 0) { ShiftwiseSalesTableData data = new ShiftwiseSalesTableData(); data.setProfitCenter(ticketType.toString()); Object[] objects = (Object[]) list.get(0); data.setShiftName(shift.getName()); data.setCheckCount(((Number) objects[0]).intValue()); if (objects.length > 1 && objects[1] != null) { data.setGuestCount(((Number) objects[1]).intValue()); } if (objects.length > 2 && objects[2] != null) { data.setTotalSales(((Number) objects[2]).doubleValue()); } data.setPercentage(data.getTotalSales() * 100 / salesSummary.getGrossSale()); data.calculateOthers(); salesSummary.addSalesTableData(data); } }
From source file:com.floreantpos.model.dao.ShopTableDAO.java
License:Open Source License
public int getNextTableNumber() { Session session = null;/*from w w w .j a va2 s. c o m*/ try { session = createNewSession(); Criteria criteria = session.createCriteria(getReferenceClass()); criteria.setProjection(Projections.rowCount()); return (Integer) criteria.uniqueResult(); } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.TicketDAO.java
License:Open Source License
public double getPaidGratuityAmount(Terminal terminal) { Session session = null;/*from w w w. j a va 2s. com*/ try { session = getSession(); Criteria criteria = session.createCriteria(getReferenceClass(), "t"); //$NON-NLS-1$ criteria = criteria.createAlias(Ticket.PROP_GRATUITY, "gratuity"); //$NON-NLS-1$ criteria.add(Restrictions.eq(Ticket.PROP_DRAWER_RESETTED, Boolean.FALSE)); criteria.add(Restrictions.eq(Ticket.PROP_TERMINAL, terminal)); criteria.add(Restrictions.eq("gratuity.paid", Boolean.TRUE)); //$NON-NLS-1$ criteria.setProjection(Projections.sum("gratuity.amount")); //$NON-NLS-1$ List list = criteria.list(); if (list.size() > 0 && list.get(0) instanceof Number) { return ((Number) list.get(0)).doubleValue(); } return 0; } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.TicketDAO.java
License:Open Source License
public List<Ticket> findTickets(PaginatedTableModel tableModel) { Session session = null;//from ww w. j av a2s . c om Criteria criteria = null; try { session = createNewSession(); criteria = session.createCriteria(getReferenceClass()); updateCriteriaFilters(criteria); criteria.setFirstResult(0); criteria.setMaxResults(tableModel.getPageSize()); List ticketList = criteria.list(); criteria.setProjection(Projections.rowCount()); Integer rowCount = (Integer) criteria.uniqueResult(); if (rowCount != null) { tableModel.setNumRows(rowCount); } tableModel.setCurrentRowIndex(0); return ticketList; } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.TicketDAO.java
License:Open Source License
public List<Ticket> findNextTickets(PaginatedTableModel tableModel) { Session session = null;//from w ww.j av a 2 s. co m Criteria criteria = null; try { int nextIndex = tableModel.getNextRowIndex(); session = createNewSession(); criteria = session.createCriteria(getReferenceClass()); updateCriteriaFilters(criteria); criteria.setFirstResult(nextIndex); criteria.setMaxResults(tableModel.getPageSize()); List ticketList = criteria.list(); criteria.setProjection(Projections.rowCount()); Integer rowCount = (Integer) criteria.uniqueResult(); if (rowCount != null) { tableModel.setNumRows(rowCount); } tableModel.setCurrentRowIndex(nextIndex); return ticketList; } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.TicketDAO.java
License:Open Source License
public List<Ticket> findPreviousTickets(PaginatedTableModel tableModel) { Session session = null;/* www. j a v a2 s .c o m*/ Criteria criteria = null; try { int previousIndex = tableModel.getPreviousRowIndex(); session = createNewSession(); criteria = session.createCriteria(getReferenceClass()); updateCriteriaFilters(criteria); criteria.setFirstResult(previousIndex); criteria.setMaxResults(tableModel.getPageSize()); List ticketList = criteria.list(); criteria.setProjection(Projections.rowCount()); Integer rowCount = (Integer) criteria.uniqueResult(); if (rowCount != null) { tableModel.setNumRows(rowCount); } tableModel.setCurrentRowIndex(previousIndex); return ticketList; } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.TicketDAO.java
License:Open Source License
public List<Ticket> findCustomerTickets(Integer customerId, PaginatedTableModel tableModel) { Session session = null;/*from w w w . j a v a2 s. c o m*/ Criteria criteria = null; try { session = createNewSession(); criteria = session.createCriteria(getReferenceClass()); criteria.add(Restrictions.eq(Ticket.PROP_CUSTOMER_ID, customerId)); /*if (filter.equals(PaymentStatusFilter.OPEN.toString())) { criteria.add(Restrictions.eq(Ticket.PROP_PAID, Boolean.FALSE)); criteria.add(Restrictions.eq(Ticket.PROP_CLOSED, Boolean.FALSE)); }*/ criteria.setFirstResult(0); criteria.setMaxResults(tableModel.getPageSize()); List ticketList = criteria.list(); criteria.setProjection(Projections.rowCount()); Integer rowCount = (Integer) criteria.uniqueResult(); if (rowCount != null) { tableModel.setNumRows(rowCount); } tableModel.setCurrentRowIndex(0); return ticketList; } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.TicketDAO.java
License:Open Source License
public List<Ticket> findNextCustomerTickets(Integer customerId, PaginatedTableModel tableModel, String filter) { Session session = null;/*from w w w .j av a2s . c o m*/ Criteria criteria = null; try { int nextIndex = tableModel.getNextRowIndex(); session = createNewSession(); criteria = session.createCriteria(getReferenceClass()); criteria.add(Restrictions.eq(Ticket.PROP_CUSTOMER_ID, customerId)); if (filter.equals(PaymentStatusFilter.OPEN)) { criteria.add(Restrictions.eq(Ticket.PROP_PAID, Boolean.FALSE)); criteria.add(Restrictions.eq(Ticket.PROP_CLOSED, Boolean.FALSE)); } criteria.setFirstResult(nextIndex); criteria.setMaxResults(tableModel.getPageSize()); List ticketList = criteria.list(); criteria.setProjection(Projections.rowCount()); Integer rowCount = (Integer) criteria.uniqueResult(); if (rowCount != null) { tableModel.setNumRows(rowCount); } tableModel.setCurrentRowIndex(nextIndex); return ticketList; } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.TicketDAO.java
License:Open Source License
public List<Ticket> findPreviousCustomerTickets(Integer customerId, PaginatedTableModel tableModel, String filter) {//www . j a v a 2 s . c o m Session session = null; Criteria criteria = null; try { int previousIndex = tableModel.getPreviousRowIndex(); session = createNewSession(); criteria = session.createCriteria(getReferenceClass()); criteria.add(Restrictions.eq(Ticket.PROP_CUSTOMER_ID, customerId)); if (filter.equals(PaymentStatusFilter.OPEN)) { criteria.add(Restrictions.eq(Ticket.PROP_PAID, Boolean.FALSE)); criteria.add(Restrictions.eq(Ticket.PROP_CLOSED, Boolean.FALSE)); } criteria.setFirstResult(previousIndex); criteria.setMaxResults(tableModel.getPageSize()); List ticketList = criteria.list(); criteria.setProjection(Projections.rowCount()); Integer rowCount = (Integer) criteria.uniqueResult(); if (rowCount != null) { tableModel.setNumRows(rowCount); } tableModel.setCurrentRowIndex(previousIndex); return ticketList; } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.TicketDAO.java
License:Open Source License
public TicketSummary getOpenTicketSummary() { Session session = null;/* w w w . jav a 2s .c o m*/ TicketSummary ticketSummary = new TicketSummary(); try { session = getSession(); Criteria criteria = session.createCriteria(Ticket.class); criteria.add(Restrictions.eq(Ticket.PROP_CLOSED, Boolean.FALSE)); criteria.add(Restrictions.eq(Ticket.PROP_VOIDED, Boolean.FALSE)); criteria.add(Restrictions.eq(Ticket.PROP_REFUNDED, Boolean.FALSE)); criteria.add(Restrictions.eq(Ticket.PROP_DRAWER_RESETTED, Boolean.FALSE)); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.count(Ticket.PROP_ID)); projectionList.add(Projections.sum(Ticket.PROP_TOTAL_AMOUNT)); criteria.setProjection(projectionList); List list = criteria.list(); if (list.size() > 0) { Object[] o = (Object[]) list.get(0); ticketSummary.setTotalTicket(((Integer) o[0]).intValue()); ticketSummary.setTotalPrice(o[1] == null ? 0 : ((Double) o[1]).doubleValue()); } return ticketSummary; } finally { closeSession(session); } }