/** * Returns a list of all active and finished one-time orders going back n number of months, for * all direct immediate of the given parent user id. This is useful for determining usage across * all child users. * * @param parentUserId parent user id * @param itemId item id of order lines * @param months previous number of months to include (1 = 1 month period starting from today) * @return list of found one-time orders, empty list if none found */ @SuppressWarnings("unchecked") public List<OrderLineDTO> findOnetimeByParentUserItem( Integer parentUserId, Integer itemId, Integer months) { UserDTO parent = new UserBL(parentUserId).getEntity(); if (parent == null || parent.getCustomer() == null) { LOG.warn("Parent user " + parentUserId + " does not exist or is not a customer!"); return Collections.emptyList(); } final String hql = "select line " + " from OrderLineDTO line " + " where line.deleted = 0 " + " and line.item.id = :itemId " + " and line.purchaseOrder.baseUserByUserId.customer.parent.id = :parentId" + " and line.purchaseOrder.orderPeriod.id = :period " + " and (line.purchaseOrder.orderStatus.orderStatusFlag = :active_status" + " or line.purchaseOrder.orderStatus.orderStatusFlag = :finished_status)" + " and line.purchaseOrder.deleted = 0 " + " and line.purchaseOrder.createDate > :startdate "; Query query = getSession().createQuery(hql); query.setParameter("itemId", itemId); query.setParameter("parentId", parent.getCustomer().getId()); query.setParameter("period", Constants.ORDER_PERIOD_ONCE); query.setParameter("active_status", OrderStatusFlag.INVOICE.ordinal()); query.setParameter("finished_status", OrderStatusFlag.FINISHED); DateMidnight startdate = new DateMidnight().minusMonths(months); query.setParameter("startdate", startdate.toDate()); return query.list(); }
/** * Returns a list of all active and finished one time orders going back n number of months, * containing the given item id for the given user. * * @param userId user id of orders * @param itemId item id of order lines * @param months previous number of months to include (1 = this month plus the previous) * @return list of found one-time orders, empty list if none found */ @SuppressWarnings("unchecked") public List<OrderLineDTO> findOnetimeByUserItem(Integer userId, Integer itemId, Integer months) { final String hql = "select line " + " from OrderLineDTO line " + "where line.deleted = 0 " + " and line.item.id = :itemId " + " and line.purchaseOrder.baseUserByUserId.id = :userId " + " and line.purchaseOrder.orderPeriod.id = :period " + " and (line.purchaseOrder.orderStatus.orderStatusFlag = :active_status" + " or line.purchaseOrder.orderStatus.orderStatusFlag = :finished_status)" + " and line.purchaseOrder.deleted = 0 " + " and line.purchaseOrder.createDate > :startdate"; Query query = getSession().createQuery(hql); query.setParameter("itemId", itemId); query.setParameter("userId", userId); query.setParameter("period", Constants.ORDER_PERIOD_ONCE); query.setParameter("active_status", OrderStatusFlag.INVOICE.ordinal()); query.setParameter("finished_status", OrderStatusFlag.FINISHED.ordinal()); DateMidnight startdate = new DateMidnight().minusMonths(months); query.setParameter("startdate", startdate.toDate()); return query.list(); }