public List<DifferentOrder> getSellingOrder(Person user) {
    List<DifferentOrder> sellingOrders = new ArrayList<DifferentOrder>();
    List<DifferentOrder> orderList = new ArrayList<DifferentOrder>();

    Query q = getSession().createQuery("from DifferentOrder where orderPersonId =:userID");
    q.setParameter("userID", user.getPersonId());
    orderList = q.list();
    for (int i = 0; i < orderList.size(); i++) {
      DifferentOrder ord = orderList.get(i);
      if (ord.getOrderType().equalsIgnoreCase("Seller Old")) {
        sellingOrders.add(ord);
      }
    }

    return sellingOrders;
  }
 // updates the order status
 public Boolean updateOrderStatus(int orderId, String status) {
   Boolean flag = false;
   try {
     Session session1 = HibernateUtil.getSessionFactory().openSession();
     Transaction tx1 = session1.beginTransaction();
     DifferentOrder order = (DifferentOrder) session1.get(DifferentOrder.class, orderId);
     order.setOrderStatus(status);
     session1.update(order);
     flag = true;
     tx1.commit();
     session1.close();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return flag;
 }
 // get the list of order items by a particular order id
 public Set<OrderItem> getOrderitemList(int orderId) {
   Set<OrderItem> orderitemList = new HashSet<OrderItem>();
   try {
     Session session = HibernateUtil.getSessionFactory().openSession();
     Criteria cr = session.createCriteria(DifferentOrder.class);
     cr.add(Restrictions.eq("orderId", orderId));
     Object result = cr.uniqueResult();
     if (result != null) {
       DifferentOrder order = (DifferentOrder) result;
       orderitemList = (Set<OrderItem>) order.getOrderitemList();
     }
     close();
   } catch (Exception e) {
     e.printStackTrace();
   }
   return orderitemList;
 }
  // confirm a selling order by the customer
  public boolean confirmSellingOrder(List<OrderItem> list, Person person) {
    boolean flag = false;

    try {

      if (list.size() > 0) {
        DifferentOrder order1 = new DifferentOrder();
        order1.setOrderDate(new Date());
        order1.setOrderStatus("Order to be reviewed");
        order1.setOrderType("Seller Old");
        order1.setPerson(person);

        for (int i = 0; i < list.size(); i++) {
          OrderItem oi = new OrderItem();
          oi = list.get(i);
          // oi.setOrder(order);
        }

        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        session.save(order1);
        tx.commit();
        session.close();

        for (int i = 0; i < list.size(); i++) {
          OrderItem oi = new OrderItem();
          oi = list.get(i);
          oi.setOrderNo(order1);
          Session session1 = HibernateUtil.getSessionFactory().openSession();
          Transaction tx1 = session1.beginTransaction();
          session1.save(oi);
          tx1.commit();
          session1.close();
        }
        flag = true;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }

    return flag;
  }
  // updates the order item cost for the books to be sold by the customer
  public Boolean updateOrderitemCost(int orderitemId, Float cost) {
    Boolean flag = false;
    try {
      Session session1 = HibernateUtil.getSessionFactory().openSession();
      Transaction tx1 = session1.beginTransaction();
      OrderItem orderitem = (OrderItem) session1.get(OrderItem.class, orderitemId);
      Book book = orderitem.getBook();
      book.setProductCost(cost);
      orderitem.setBook(book);
      DifferentOrder order = orderitem.getOrderNo();
      order.setOrderAmount(orderitem.getQuantity() * orderitem.getBook().getProductCost());
      orderitem.setOrderNo(order);
      session1.update(order);
      session1.update(orderitem);
      flag = true;
      tx1.commit();
      session1.close();

    } catch (Exception e) {
      e.printStackTrace();
    }
    return flag;
  }
  // confirm and place the order in the database
  public Boolean confirmOrder(
      List<OrderItem> list, List<OrderItem> newlist, Address address, Card card, Person person) {

    Boolean flag = false;
    float total = 0;
    try {

      if (list.size() > 0) {
        DifferentOrder order1 = new DifferentOrder();
        order1.setOrderDate(new Date());
        order1.setOrderStatus("Order to be reviewed");
        order1.setOrderType("Buyer Old");
        order1.setPerson(person);

        for (int i = 0; i < list.size(); i++) {
          OrderItem oi = new OrderItem();
          oi = list.get(i);
          // oi.setOrder(order);
          total = oi.getQuantity() * oi.getBook().getProductCost();
        }

        order1.setOrderAmount(total);
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        session.save(order1);
        tx.commit();
        session.close();

        for (int i = 0; i < list.size(); i++) {
          OrderItem oi = new OrderItem();
          oi = list.get(i);
          oi.setOrderNo(order1);
          Session session1 = HibernateUtil.getSessionFactory().openSession();
          Transaction tx1 = session1.beginTransaction();
          session1.save(oi);
          tx1.commit();
          session1.close();
        }
        flag = true;
      }

      if (newlist.size() > 0) {
        DifferentOrder order1 = new DifferentOrder();
        order1.setOrderDate(new Date());
        order1.setOrderStatus("Order to be reviewed");
        order1.setOrderType("Buyer New");
        order1.setPerson(person);

        for (int i = 0; i < newlist.size(); i++) {
          OrderItem oi = new OrderItem();
          oi = newlist.get(i);
          // total= oi.getQuantity() * oi.getBook().getProductCost();
        }

        // order.setOrderAmount(total);
        Session session = HibernateUtil.getSessionFactory().openSession();
        Transaction tx = session.beginTransaction();
        session.save(order1);
        tx.commit();
        session.close();

        for (int i = 0; i < newlist.size(); i++) {
          OrderItem oi = new OrderItem();
          oi = newlist.get(i);
          oi.setOrderNo(order1);
          Session session1 = HibernateUtil.getSessionFactory().openSession();
          Transaction tx1 = session1.beginTransaction();
          session1.save(oi);
          tx1.commit();
          session1.close();
        }
        flag = true;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return flag;
  }