@SuppressWarnings("unchecked") @Override public List<Sales> getPendingSalesBetween(Date startDate, Date endDate) throws Exception { Session session = HibernateUtil.startSession(); Criteria criteria = session.createCriteria(Sales.class); criteria.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY); List<Sales> sales = new ArrayList<Sales>(); try { Date lowerBound = DateTool.getTomorrowDate(DateTool.getDateWithoutTime(startDate)); Date upperBound = DateTool.getDateWithoutTime(endDate); sales = criteria .add(Restrictions.ge("date", lowerBound)) .add(Restrictions.lt("date", upperBound)) .add(Restrictions.eq("valid", true)) .add(Restrictions.isNull("inventorySheetData")) .addOrder(Order.desc("date")) .list(); } catch (HibernateException ex) { ex.printStackTrace(); } finally { session.close(); } return sales; }
@Override public List<Date> getDatesOfPendingSales() throws Exception { List<Sales> sales = getPendingSales(); List<Date> dates = new ArrayList<Date>(); for (Sales sale : sales) { Date date = DateTool.getDateWithoutTime(sale.getDate()); boolean found = false; for (Date d : dates) { if (d.compareTo(date) == 0) { found = true; } } if (!found) { dates.add(date); } } return dates; }