List of usage examples for org.hibernate Criteria setProjection
public Criteria setProjection(Projection projection);
From source file:com.fich.wafproject.dao.UserHistoryDaoImpl.java
@SuppressWarnings("unchecked") public List<UsersHistory> findAll(int pageNumber) { int pageSize = 6; Criteria crit = createEntityCriteria(); crit.setProjection(Projections.distinct(Projections.property("id"))); crit.setFirstResult((pageNumber - 1) * pageSize); crit.setMaxResults(pageSize);//from w w w . java2s. c o m List<UsersHistory> events = new ArrayList<UsersHistory>(); for (Object idUsersHistory : crit.list()) { // System.out.println(idUsersHistory); events.add(this.findById((Long) idUsersHistory)); } return events; }
From source file:com.fich.wafproject.dao.UserHistoryDaoImpl.java
public List<UsersHistory> filter(String[] values, String[] names, String[] targets, int pageNumber, String role) {//from w w w .ja v a2 s .c o m int pageSize = 6; int count = 0; boolean filterByUserProperty = false, filterByUserName = false; Criteria crit = this.createEntityCriteria();//.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); crit.setProjection(Projections.distinct(Projections.property("id"))); String dateFrom = "", dateTo = "", targetDate = ""; if (names != null) { for (String alias : names) { crit.createAlias(alias, alias); if (alias.equals("user")) filterByUserProperty = true; } } if (!filterByUserProperty && !role.equals("")) crit.createAlias("user", "user"); if (values != null) { for (String value : values) { if (!value.equals("") && value != null) { if (targets[count].contains("date")) { if (dateFrom != "") { dateTo = value; } else { dateFrom = value; targetDate = targets[count]; } } else { if (targets[count].contains("userName")) filterByUserName = true; crit.add(Restrictions.like(targets[count], "%" + value + "%")); } } count++; } if (targetDate != "") { if (dateFrom != "" && dateTo == "") { dateTo = dateFrom; } DateFormat format = new SimpleDateFormat("yyyy-MM-dd", Locale.ENGLISH); try { Date dateF = format.parse(dateFrom); Date dateT = format.parse(dateTo); crit.add(Restrictions.between(targetDate, dateF, dateT)); } catch (ParseException ex) { Logger.getLogger(UserHistoryDaoImpl.class.getName()).log(Level.SEVERE, null, ex); } } } if (!filterByUserName && !role.equals("")) crit.add(Restrictions.like("user.userName", role)); crit.setFirstResult((pageNumber - 1) * pageSize); crit.setMaxResults(pageSize); List<UsersHistory> events = new ArrayList<UsersHistory>(); for (Object idEvent : crit.list()) { events.add(this.findById((Long) idEvent)); } return (List<UsersHistory>) events; }
From source file:com.floreantpos.model.dao.KitchenTicketDAO.java
License:Open Source License
public List<Ticket> findNextKitchenTickets(PaginatedTableModel tableModel) { Session session = null;/* w w w . j a v a 2 s.c o m*/ Criteria criteria = null; try { int nextIndex = tableModel.getNextRowIndex(); session = createNewSession(); criteria = session.createCriteria(getReferenceClass()); criteria.setFirstResult(nextIndex); criteria.setMaxResults(tableModel.getPageSize()); List kitchenTicketList = criteria.list(); criteria.setProjection(Projections.rowCount()); Integer rowCount = (Integer) criteria.uniqueResult(); if (rowCount != null) { tableModel.setNumRows(rowCount); } tableModel.setCurrentRowIndex(nextIndex); return kitchenTicketList; } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.KitchenTicketDAO.java
License:Open Source License
public List<Ticket> findPreviousKitchenTickets(PaginatedTableModel tableModel) { Session session = null;//from w ww .j av a 2 s . c o m Criteria criteria = null; try { int previousIndex = tableModel.getPreviousRowIndex(); session = createNewSession(); criteria = session.createCriteria(getReferenceClass()); criteria.setFirstResult(previousIndex); criteria.setMaxResults(tableModel.getPageSize()); List kitchenTicketList = criteria.list(); criteria.setProjection(Projections.rowCount()); Integer rowCount = (Integer) criteria.uniqueResult(); if (rowCount != null) { tableModel.setNumRows(rowCount); } tableModel.setCurrentRowIndex(previousIndex); return kitchenTicketList; } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.MenuGroupDAO.java
License:Open Source License
@SuppressWarnings("unchecked") public boolean hasChildren(Terminal terminal, MenuGroup group, OrderType orderType) throws PosException { Session session = null;//w w w . j av a 2 s . c o m try { session = getSession(); Criteria criteria = session.createCriteria(MenuItem.class); criteria.add(Restrictions.eq(MenuItem.PROP_PARENT, group)); criteria.add(Restrictions.eq(MenuItem.PROP_VISIBLE, Boolean.TRUE)); // if(terminal!=null) { // criteria.add(Restrictions.eq(MenuItem., criteria)) // } criteria.setProjection(Projections.rowCount()); criteria.createAlias("orderTypeList", "type", CriteriaSpecification.LEFT_JOIN); criteria.add(Restrictions.or(Restrictions.isEmpty("orderTypeList"), Restrictions.eq("type.id", orderType.getId()))); int uniqueResult = (Integer) criteria.uniqueResult(); return uniqueResult > 0; } catch (Exception e) { e.printStackTrace(); throw new PosException(Messages.getString("MenuItemDAO.0")); //$NON-NLS-1$ } finally { if (session != null) { session.close(); } } }
From source file:com.floreantpos.model.dao.PackagingUnitDAO.java
License:Open Source License
public boolean nameExists(String name) { Session session = null;/* w w w .j a v a 2 s. co m*/ try { session = getSession(); Criteria criteria = session.createCriteria(getReferenceClass()); criteria.add(Restrictions.eq(PackagingUnit.PROP_NAME, name).ignoreCase()); criteria.setProjection(Projections.rowCount()); Integer rowCount = (Integer) criteria.uniqueResult(); if (rowCount == null) return false; return (rowCount > 0) ? true : false; } finally { if (session != null) { closeSession(session); } } }
From source file:com.floreantpos.model.dao.PosTransactionDAO.java
License:Open Source License
public TransactionSummary getTransactionSummary(Terminal terminal, Class transactionClass, Date from, Date to) { Session session = null;/*from w w w . j a va 2 s . com*/ TransactionSummary summary = new TransactionSummary(); try { session = getSession(); Criteria criteria = session.createCriteria(transactionClass); criteria.add(Restrictions.eq(PosTransaction.PROP_DRAWER_RESETTED, Boolean.FALSE)); if (terminal != null) { criteria.add(Restrictions.eq(PosTransaction.PROP_TERMINAL, terminal)); } if (from != null && to != null) { criteria.add(Restrictions.ge(PosTransaction.PROP_TRANSACTION_TIME, from)); criteria.add(Restrictions.le(PosTransaction.PROP_TRANSACTION_TIME, to)); } ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.count(PosTransaction.PROP_ID)); projectionList.add(Projections.sum(PosTransaction.PROP_AMOUNT)); projectionList.add(Projections.sum(PosTransaction.PROP_TIPS_AMOUNT)); criteria.setProjection(projectionList); List list = criteria.list(); if (list == null || list.size() == 0) return summary; Object[] o = (Object[]) list.get(0); int index = 0; summary.setCount(HibernateProjectionsUtil.getInt(o, index++)); summary.setAmount(HibernateProjectionsUtil.getDouble(o, index++)); summary.setTipsAmount(HibernateProjectionsUtil.getDouble(o, index++)); return summary; } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.RefundTransactionDAO.java
License:Open Source License
public RefundSummary getTotalRefundForTerminal(Terminal terminal) { Session session = null;/* w w w. ja v a 2s . c o m*/ RefundSummary refundSummary = new RefundSummary(); try { session = getSession(); Criteria criteria = session.createCriteria(getReferenceClass()); ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.rowCount()); projectionList.add(Projections.sum(RefundTransaction.PROP_AMOUNT)); criteria.setProjection(projectionList); criteria.add(Restrictions.eq(RefundTransaction.PROP_TERMINAL, terminal)); criteria.add(Restrictions.eq(RefundTransaction.PROP_DRAWER_RESETTED, Boolean.FALSE)); List list = criteria.list(); if (list.size() > 0) { Object[] objects = (Object[]) list.get(0); if (objects.length > 0 && objects[0] != null) { refundSummary.setCount(((Number) objects[0]).intValue()); } if (objects.length > 1 && objects[1] != null) { refundSummary.setAmount(((Number) objects[1]).doubleValue()); } } return refundSummary; } finally { closeSession(session); } }
From source file:com.floreantpos.model.dao.SalesSummaryDAO.java
License:Open Source License
public List<SalesAnalysisData> findSalesAnalysis(Date start, Date end, UserType userType, Terminal terminal) { Session session = null;/*from w w w . j a v a2 s. co m*/ try { ArrayList<SalesAnalysisData> list = new ArrayList<SalesAnalysisData>(); session = getSession(); Criteria criteria = session.createCriteria(Shift.class); List<Shift> shifts = criteria.list(); criteria = session.createCriteria(MenuCategory.class); List<MenuCategory> categories = criteria.list(); MenuCategory miscCategory = new MenuCategory(); miscCategory.setName(Messages.getString("SalesSummaryDAO.0")); //$NON-NLS-1$ categories.add(miscCategory); //find food sales criteria = session.createCriteria(TicketItem.class, "item"); //$NON-NLS-1$ criteria.createCriteria("ticket", "t"); //$NON-NLS-1$ //$NON-NLS-2$ criteria.createCriteria("t.owner", "u"); //$NON-NLS-1$ //$NON-NLS-2$ ProjectionList projectionList = Projections.projectionList(); projectionList.add(Projections.sum(TicketItem.PROP_ITEM_COUNT)); projectionList.add(Projections.sum(TicketItem.PROP_SUBTOTAL_AMOUNT)); projectionList.add(Projections.sum(TicketItem.PROP_DISCOUNT_AMOUNT)); criteria.setProjection(projectionList); criteria.add(Restrictions.eq("item." + TicketItem.PROP_BEVERAGE, Boolean.FALSE)); //$NON-NLS-1$ criteria.add(Restrictions.ge("t." + Ticket.PROP_ACTIVE_DATE, start)); //$NON-NLS-1$ criteria.add(Restrictions.le("t." + Ticket.PROP_ACTIVE_DATE, end)); //$NON-NLS-1$ if (userType != null) { criteria.add(Restrictions.eq("u." + User.PROP_TYPE, userType)); //$NON-NLS-1$ } if (terminal != null) { criteria.add(Restrictions.eq("t." + Ticket.PROP_TERMINAL, terminal)); //$NON-NLS-1$ } List datas = criteria.list(); if (datas.size() > 0) { Object[] objects = (Object[]) datas.get(0); SalesAnalysisData data = new SalesAnalysisData(); data.setShiftName(""); //$NON-NLS-1$ data.setCategoryName(Messages.getString("SalesSummaryDAO.1")); //$NON-NLS-1$ if (objects.length > 0 && objects[0] != null) data.setCount(((Number) objects[0]).intValue()); if (objects.length > 1 && objects[1] != null) data.setGross(((Number) objects[1]).doubleValue()); if (objects.length > 2 && objects[2] != null) data.setDiscount(((Number) objects[2]).doubleValue()); data.calculate(); list.add(data); } //find non food sales criteria = session.createCriteria(TicketItem.class, "item"); //$NON-NLS-1$ criteria.createCriteria("ticket", "t"); //$NON-NLS-1$ //$NON-NLS-2$ criteria.createCriteria("t.owner", "u"); //$NON-NLS-1$ //$NON-NLS-2$ projectionList = Projections.projectionList(); projectionList.add(Projections.sum(TicketItem.PROP_ITEM_COUNT)); projectionList.add(Projections.sum(TicketItem.PROP_SUBTOTAL_AMOUNT)); projectionList.add(Projections.sum(TicketItem.PROP_DISCOUNT_AMOUNT)); criteria.setProjection(projectionList); criteria.add(Restrictions.eq("item." + TicketItem.PROP_BEVERAGE, Boolean.TRUE)); //$NON-NLS-1$ criteria.add(Restrictions.ge("t." + Ticket.PROP_ACTIVE_DATE, start)); //$NON-NLS-1$ criteria.add(Restrictions.le("t." + Ticket.PROP_ACTIVE_DATE, end)); //$NON-NLS-1$ if (userType != null) { criteria.add(Restrictions.eq("u." + User.PROP_TYPE, userType)); //$NON-NLS-1$ } if (terminal != null) { criteria.add(Restrictions.eq("t." + Ticket.PROP_TERMINAL, terminal)); //$NON-NLS-1$ } datas = criteria.list(); if (datas.size() > 0) { Object[] objects = (Object[]) datas.get(0); SalesAnalysisData data = new SalesAnalysisData(); data.setShiftName(""); //$NON-NLS-1$ data.setCategoryName(Messages.getString("SalesSummaryDAO.2")); //$NON-NLS-1$ if (objects.length > 0 && objects[0] != null) data.setCount(((Number) objects[0]).intValue()); if (objects.length > 1 && objects[1] != null) data.setGross(((Number) objects[1]).doubleValue()); if (objects.length > 2 && objects[2] != null) data.setDiscount(((Number) objects[2]).doubleValue()); data.calculate(); list.add(data); } //find shift wise salse for (Shift shift : shifts) { for (MenuCategory category : categories) { criteria = session.createCriteria(TicketItem.class, "item"); //$NON-NLS-1$ criteria.createCriteria("ticket", "t"); //$NON-NLS-1$ //$NON-NLS-2$ criteria.createCriteria("t.owner", "u"); //$NON-NLS-1$ //$NON-NLS-2$ projectionList = Projections.projectionList(); projectionList.add(Projections.sum(TicketItem.PROP_ITEM_COUNT)); projectionList.add(Projections.sum(TicketItem.PROP_SUBTOTAL_AMOUNT)); projectionList.add(Projections.sum(TicketItem.PROP_DISCOUNT_AMOUNT)); criteria.setProjection(projectionList); criteria.add(Restrictions.eq("item." + TicketItem.PROP_CATEGORY_NAME, category.getName())); //$NON-NLS-1$ criteria.add(Restrictions.eq("t." + Ticket.PROP_SHIFT, shift)); //$NON-NLS-1$ criteria.add(Restrictions.ge("t." + Ticket.PROP_ACTIVE_DATE, start)); //$NON-NLS-1$ criteria.add(Restrictions.le("t." + Ticket.PROP_ACTIVE_DATE, end)); //$NON-NLS-1$ if (userType != null) { criteria.add(Restrictions.eq("u." + User.PROP_TYPE, userType)); //$NON-NLS-1$ } if (terminal != null) { criteria.add(Restrictions.eq("t." + Ticket.PROP_TERMINAL, terminal)); //$NON-NLS-1$ } datas = criteria.list(); if (datas.size() > 0) { Object[] objects = (Object[]) datas.get(0); SalesAnalysisData data = new SalesAnalysisData(); data.setShiftName(shift.getName()); data.setCategoryName(category.getName()); if (objects.length > 0 && objects[0] != null) data.setCount(((Number) objects[0]).intValue()); if (objects.length > 1 && objects[1] != null) data.setGross(((Number) objects[1]).doubleValue()); if (objects.length > 2 && objects[2] != null) data.setDiscount(((Number) objects[2]).doubleValue()); data.calculate(); list.add(data); } } } //find all sales for (MenuCategory category : categories) { criteria = session.createCriteria(TicketItem.class, "item"); //$NON-NLS-1$ criteria.createCriteria("ticket", "t"); //$NON-NLS-1$ //$NON-NLS-2$ criteria.createCriteria("t.owner", "u"); //$NON-NLS-1$ //$NON-NLS-2$ projectionList = Projections.projectionList(); projectionList.add(Projections.sum(TicketItem.PROP_ITEM_COUNT)); projectionList.add(Projections.sum(TicketItem.PROP_SUBTOTAL_AMOUNT)); projectionList.add(Projections.sum(TicketItem.PROP_DISCOUNT_AMOUNT)); criteria.setProjection(projectionList); criteria.add(Restrictions.eq("item." + TicketItem.PROP_CATEGORY_NAME, category.getName())); //$NON-NLS-1$ criteria.add(Restrictions.ge("t." + Ticket.PROP_ACTIVE_DATE, start)); //$NON-NLS-1$ criteria.add(Restrictions.le("t." + Ticket.PROP_ACTIVE_DATE, end)); //$NON-NLS-1$ if (userType != null) { criteria.add(Restrictions.eq("u." + User.PROP_TYPE, userType)); //$NON-NLS-1$ } if (terminal != null) { criteria.add(Restrictions.eq("t." + Ticket.PROP_TERMINAL, terminal)); //$NON-NLS-1$ } datas = criteria.list(); if (datas.size() > 0) { Object[] objects = (Object[]) datas.get(0); SalesAnalysisData data = new SalesAnalysisData(); data.setShiftName("ALL DAY"); //$NON-NLS-1$ data.setCategoryName(category.getName()); if (objects.length > 0 && objects[0] != null) data.setCount(((Number) objects[0]).intValue()); if (objects.length > 1 && objects[1] != null) data.setGross(((Number) objects[1]).doubleValue()); if (objects.length > 2 && objects[2] != null) data.setDiscount(((Number) objects[2]).doubleValue()); data.calculate(); list.add(data); } } return list; } finally { if (session != null) { closeSession(session); } } }
From source file:com.floreantpos.model.dao.SalesSummaryDAO.java
License:Open Source License
public SalesStatistics findKeyStatistics(Date start, Date end, UserType userType, Terminal terminal) { Session session = null;/* w w w. j a v a 2s. c o m*/ try { SalesStatistics salesSummary = new SalesStatistics(); session = getSession(); //retrieve restaurant information and set it to sales summary Restaurant restaurant = (Restaurant) get(Restaurant.class, new Integer(1), session); if (restaurant != null) { salesSummary .setCapacity(restaurant.getCapacity() != null ? restaurant.getCapacity().intValue() : 0); salesSummary.setTables(restaurant.getTables() != null ? restaurant.getTables().intValue() : 0); } { //find gross sale, discount and tax. this excludes void tickets //net sale = gross_sale - discount 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_SUBTOTAL_AMOUNT)); projectionList.add(Projections.sum(Ticket.PROP_DISCOUNT_AMOUNT)); projectionList.add(Projections.sum(Ticket.PROP_TAX_AMOUNT)); criteria.setProjection(projectionList); criteria.add(Restrictions.ge(Ticket.PROP_CREATE_DATE, start)); criteria.add(Restrictions.le(Ticket.PROP_CREATE_DATE, end)); //do not take into account void tickets criteria.add(Restrictions.eq(Ticket.PROP_VOIDED, Boolean.FALSE)); criteria.add(Restrictions.eq(Ticket.PROP_REFUNDED, Boolean.FALSE)); if (userType != null) { criteria.add(Restrictions.eq("u." + User.PROP_TYPE, userType)); //$NON-NLS-1$ } if (terminal != null) { criteria.add(Restrictions.eq(Ticket.PROP_TERMINAL, terminal)); } List list = criteria.list(); if (list.size() > 0) { Object[] objects = (Object[]) list.get(0); if (objects.length > 1 && objects[1] != null) { salesSummary.setGrossSale(((Number) objects[1]).doubleValue()); } if (objects.length > 2 && objects[2] != null) { salesSummary.setDiscount(((Number) objects[2]).intValue()); } if (objects.length > 3 && objects[3] != null) { salesSummary.setTax(((Number) objects[3]).intValue()); } } } { //determine number of guests within the specified time. this includes void tickets, 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)); criteria.setProjection(projectionList); criteria.add(Restrictions.ge(Ticket.PROP_CREATE_DATE, start)); criteria.add(Restrictions.le(Ticket.PROP_CREATE_DATE, end)); if (userType != null) { criteria.add(Restrictions.eq("u." + User.PROP_TYPE, userType)); //$NON-NLS-1$ } if (terminal != null) { criteria.add(Restrictions.eq(Ticket.PROP_TERMINAL, terminal)); } List list = criteria.list(); if (list.size() > 0) { Object[] objects = (Object[]) list.get(0); salesSummary.setCheckCount(((Number) objects[0]).intValue()); if (objects.length > 1 && objects[1] != null) { salesSummary.setGuestCount(((Number) objects[1]).intValue()); } } } { //find number of open tickets and its total amount 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_TOTAL_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_CLOSED, Boolean.FALSE)); if (userType != null) { criteria.add(Restrictions.eq("u." + User.PROP_TYPE, userType)); //$NON-NLS-1$ } if (terminal != null) { criteria.add(Restrictions.eq(Ticket.PROP_TERMINAL, terminal)); } List list = criteria.list(); if (list.size() > 0) { Object[] objects = (Object[]) list.get(0); salesSummary.setOpenChecks(((Number) objects[0]).intValue()); if (objects.length > 1 && objects[1] != null) { salesSummary.setOpenAmount(((Number) objects[1]).doubleValue()); } } } { //find number of void tickets and its total amount 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_TOTAL_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_CLOSED, Boolean.TRUE)); criteria.add(Restrictions.eq(Ticket.PROP_VOIDED, Boolean.TRUE)); if (userType != null) { criteria.add(Restrictions.eq("u." + User.PROP_TYPE, userType)); //$NON-NLS-1$ } if (terminal != null) { criteria.add(Restrictions.eq(Ticket.PROP_TERMINAL, terminal)); } List list = criteria.list(); if (list.size() > 0) { Object[] objects = (Object[]) list.get(0); salesSummary.setVoidChecks(((Number) objects[0]).intValue()); if (objects.length > 1 && objects[1] != null) { salesSummary.setVoidAmount(((Number) objects[1]).doubleValue()); } } } { //find non taxable sales 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_TOTAL_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_VOIDED, Boolean.FALSE)); criteria.add(Restrictions.eq(Ticket.PROP_REFUNDED, Boolean.FALSE)); criteria.add(Restrictions.eq(Ticket.PROP_TAX_EXEMPT, Boolean.TRUE)); if (userType != null) { criteria.add(Restrictions.eq("u." + User.PROP_TYPE, userType)); //$NON-NLS-1$ } if (terminal != null) { criteria.add(Restrictions.eq(Ticket.PROP_TERMINAL, terminal)); } List list = criteria.list(); if (list.size() > 0) { Object[] objects = (Object[]) list.get(0); salesSummary.setNtaxChecks(((Number) objects[0]).intValue()); if (objects.length > 1 && objects[1] != null) { salesSummary.setNtaxAmount(((Number) objects[1]).doubleValue()); } } } { //find reopen statistics 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_TOTAL_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_RE_OPENED, Boolean.TRUE)); if (userType != null) { criteria.add(Restrictions.eq("u." + User.PROP_TYPE, userType)); //$NON-NLS-1$ } if (terminal != null) { criteria.add(Restrictions.eq(Ticket.PROP_TERMINAL, terminal)); } List list = criteria.list(); if (list.size() > 0) { Object[] objects = (Object[]) list.get(0); salesSummary.setRopnChecks(((Number) objects[0]).intValue()); if (objects.length > 1 && objects[1] != null) { salesSummary.setRopnAmount(((Number) objects[1]).doubleValue()); } } } { //calculate totalLaborHours in the specified period Criteria criteria = session.createCriteria(AttendenceHistory.class, "history"); //$NON-NLS-1$ criteria.createCriteria(AttendenceHistory.PROP_USER, "u"); //$NON-NLS-1$ criteria.add(Restrictions.ge(AttendenceHistory.PROP_CLOCK_IN_TIME, start)); criteria.add(Restrictions.le(AttendenceHistory.PROP_CLOCK_IN_TIME, end)); if (userType != null) { criteria.add(Restrictions.eq("u." + User.PROP_TYPE, userType)); //$NON-NLS-1$ } if (terminal != null) { criteria.add(Restrictions.eq(AttendenceHistory.PROP_TERMINAL, terminal)); } List list = criteria.list(); double laborHours = 0; double laborCost = 0; for (Object object : list) { AttendenceHistory attendenceHistory = (AttendenceHistory) object; double laborHourInMillisecond = 0; if (!attendenceHistory.isClockedOut() || attendenceHistory.getClockOutTime() == null) { Shift attendenceShift = attendenceHistory.getShift(); laborHourInMillisecond = Math .abs(end.getTime() - attendenceHistory.getClockInTime().getTime()); if (laborHourInMillisecond > attendenceShift.getShiftLength()) { laborHourInMillisecond = attendenceShift.getShiftLength(); } } else { laborHourInMillisecond = Math.abs(attendenceHistory.getClockInTime().getTime() - attendenceHistory.getClockInTime().getTime()); } double hour = (laborHourInMillisecond * (2.77777778 * Math.pow(10, -7))); laborHours += hour; laborCost += hour * (attendenceHistory.getUser().getCostPerHour() == null ? 0 : attendenceHistory.getUser().getCostPerHour()); } salesSummary.setLaborHour(laborHours); salesSummary.setLaborCost(laborCost); } { //find summary by shift Criteria criteria = session.createCriteria(Shift.class); List shifts = criteria.list(); for (Object object : shifts) { Shift shift = (Shift) object; List<OrderType> values = Application.getInstance().getOrderTypes(); //change enum for (OrderType ticketType : values) { findRecordByProfitCenter(start, end, userType, terminal, session, salesSummary, shift, ticketType); } } } salesSummary.calculateOthers(); return salesSummary; } finally { if (session != null) { closeSession(session); } } }