// calculate amount
  public Reconciliation calculateamt(String logstr, ReconciliationDto tobemerged) throws Exception {
    // TODO Auto-generated method stub
    int qty;
    double fprice, amt = 0;
    Date date = new Date();
    // if (tobemerged.getOrderid() == null)
    //		throw new ReconcileException("Order item list is empty");

    // Finding all order to the perticular user
    List<OrderItem> orderRecords =
        orderItemRepository.findByUidAndOid(tobemerged.getUserid(), tobemerged.getOrderid());
    if (orderRecords == null) {
      logger.debug(logstr + "Reconciliation record does not exist according to oid and uid");
      throw new Exception();
    }

    for (OrderItem orderItem : orderRecords) {
      FoodItem foodItem = foodItemRepository.findOne(orderItem.getItem_id());
      amt = amt + orderItem.getQty() * foodItem.getPrice();
    }

    // Create Reconcile entity
    Reconciliation reconciliation = new Reconciliation();

    logger.debug(logstr + "create reconciliation entry" + reconciliation.fetchLogDetails());
    // reconciliation.setDate(getDate);
    reconciliation.setOrderid(tobemerged.getOrderid());
    reconciliation.setOrdercost(amt);
    reconciliation.setAmountpaid(tobemerged.getAmtpaid());
    reconciliation.setUserid(tobemerged.getUserid());
    reconciliation.setStatus("processed");
    reconciliation.setDate(date);

    // new update for another update by same user
    Reconciliation recRecords =
        reconciliationRepository.findByUseridAndOrderid(
            tobemerged.getUserid(), tobemerged.getOrderid());
    if (recRecords != null) {
      reconciliation.setId(recRecords.getId());
      reconciliation.setAmountpaid(tobemerged.getAmtpaid() + recRecords.getAmountpaid());
      update(logstr, reconciliation);
    } else {
      reconciliation = reconciliationRepository.save(reconciliation);
    }
    logger.debug(logstr + "created reconciliation entry " + reconciliation.fetchLogDetails());
    return reconciliation;
  }
  // Get all records by orderid
  public List<ReconciliationDto> getRecordsByOid(String logstr, String ordername) throws Exception {
    // TODO Auto-generated method stub
    logger.debug(logstr + "get all order records");
    // fetch last record of reconciliation
    List<Reconciliation> recRecords = reconciliationRepository.fetchLast();
    if (recRecords.size() == 0) return null;
    Foodorder foodorder = orderRepository.findOne(recRecords.get(0).getOrderid());

    List<Foodorder> foodorderrecords = orderRepository.fetchByDate(foodorder.getOrderdate());
    Long orderid = null;
    // find the orderid by the ordername
    for (Foodorder food : foodorderrecords) {
      if (ordername.equals(food.getName())) {
        orderid = food.getId();
      }
    }
    if (orderid == null) return null;
    List<Reconciliation> reconciliationrecords = reconciliationRepository.findByOrderid(orderid);
    List<ReconciliationDto> reconciliationDtoRecords = new ArrayList<ReconciliationDto>();
    try {

      for (Reconciliation reconciliation : reconciliationrecords) {
        ReconciliationDto reconciliationDto = new ReconciliationDto();
        reconciliationDto.setOrderid(orderid);
        reconciliationDto.setAmtpaid(reconciliation.getAmountpaid());
        reconciliationDto.setCost(reconciliation.getOrdercost());
        reconciliationDto.setUserid(reconciliation.getUserid());
        User user = userRepository.findOne(reconciliation.getUserid());
        reconciliationDto.setUsername(user.getName());
        reconciliationDto.setStatus(reconciliation.getStatus());
        // reconciliationDto.setUserid(reconciliation.getUserid());

        reconciliationDtoRecords.add(reconciliationDto);
      }
      logger.debug(logstr + "Records retrived by orderid");
    } catch (Exception e) {
      throw new Exception();
    }
    return reconciliationDtoRecords;
  }