@RequestMapping(value = "/vendorReturnSearch", method = RequestMethod.GET)
  @Scope("request")
  public ModelAndView searchVendorReturn(
      @ModelAttribute("vendorReturnCommand") VendorReturn vendorReturnSearch,
      BindingResult bindingResult,
      HttpServletRequest request,
      HttpServletResponse response) {
    response.setCharacterEncoding("UTF-8");
    List<VendorReturn> vrlist = new ArrayList<VendorReturn>();
    List<Object> list = null;
    List<Object> lob = null;
    try {

      String dbField = vendorReturnSearch.getXmlLabel();
      String operation = vendorReturnSearch.getOperations();
      String basicSearchId = vendorReturnSearch.getBasicSearchId();

      if (operation.equals("_%")) {
        operation = " like ";
        basicSearchId = basicSearchId + "%";

      } else if (operation.equals("%_")) {
        operation = " like ";
        basicSearchId = "%" + basicSearchId;

      } else if (operation.equals("%_%")) {
        operation = " like ";
        basicSearchId = "%" + basicSearchId + "%";
      }
      if (basicSearchId == "") {

        lob = vrService.searchVendorReturn();

        Iterator<Object> iterator = lob.iterator();

        while (iterator.hasNext()) {
          VendorReturn vr = (VendorReturn) iterator.next();
          vr.setVendorReturnId(vr.getVendorReturnId());
          vr.setVendorReturnNo(vr.getVendorReturnNo());
          vr.setVendorReturnDate(
              dateService.dateFormat(dateService.dateParse(vr.getVendorReturnDate(), "se"), "se"));
          vr.setReference(vr.getReference());
          vr.setDescription(vr.getDescription());
          vr.setBatchNo(vr.getBatchNo());

          vrlist.add(vr);
        }

      } else {

        list = vrService.basicSearchVendorReturn(dbField, operation, basicSearchId);
        Iterator<Object> iter = list.iterator();

        while (iter.hasNext()) {
          VendorReturn vr = (VendorReturn) iter.next();
          vr.setVendorReturnId(vr.getVendorReturnId());
          vr.setVendorReturnNo(vr.getVendorReturnNo());
          vr.setVendorReturnDate(
              dateService.dateFormat(dateService.dateParse(vr.getVendorReturnDate(), "se"), "se"));
          vr.setReference(vr.getReference());
          vr.setDescription(vr.getDescription());
          vr.setBatchNo(vr.getBatchNo());
          vrlist.add(vr);
        }
      }

    } catch (Exception e) {
      e.printStackTrace();
    }
    request.setAttribute("vendorReturnSearch", vrlist);
    ModelAndView modelAndView = new ModelAndView();
    modelAndView.setViewName("vendorReturnHome");
    modelAndView.addObject("vendorReturnCommand");

    return modelAndView;
  }
  /* ================================Add Method========================== */
  @RequestMapping(value = "/vendorReturn", method = RequestMethod.GET)
  public String addVendorReturn(
      @ModelAttribute("vendorReturnCommand") VendorReturn vendorReturnAdd,
      HttpServletRequest request,
      HttpServletResponse response,
      Model model) {

    response.setCharacterEncoding("UTF-8");
    List<String> list = new ArrayList<String>();
    VendorReturnLine vrLine = null;
    List<VendorReturnLine> vrLines = null;
    String vrAddSus = null;
    String msg = null;

    String checkVrNo = vendorReturnAdd.getVendorReturnNo();
    int list1 = vrService.checkDuplicate(checkVrNo);
    if (list1 == 0) {

      try {

        vrLines = new ArrayList<VendorReturnLine>();

        String material = vendorReturnAdd.getmId();
        String[] bNo = vendorReturnAdd.getBatchNo();
        List<String> mlist = Arrays.asList(material.split(","));
        Object[] materialiid = mlist.toArray();

        Integer[] quantity = vendorReturnAdd.getQuantity();
        String unit = vendorReturnAdd.getUomm();
        List<String> uomlist = Arrays.asList(unit.split(","));
        Object[] uomid = uomlist.toArray();

        float[] price = vendorReturnAdd.getPrice();

        String rfr = vendorReturnAdd.getRfrId();
        List<String> rfrlist = Arrays.asList(rfr.split(","));
        Object[] rfrid = rfrlist.toArray();

        String storage = vendorReturnAdd.getStLId();
        List<String> storagelist = Arrays.asList(storage.split(","));
        Object[] storageid = storagelist.toArray();

        for (int i = 0; i < quantity.length; i++) {
          vrLine = new VendorReturnLine();
          vrLine.setMaterial_Id(materialiid[i].toString());
          vrLine.setQuantity(quantity[i]);
          vrLine.setUom_Id(uomid[i].toString());
          vrLine.setPrice(price[i]);
          vrLine.setReasonForRejectionId(rfrid[i].toString());
          vrLine.setStorageLocationId(storageid[i].toString());
          vrLine.setBatchNo(bNo[i]);
          vrLines.add(vrLine);

          float enteredQty = vrLine.getQuantity();
          int materialid = Integer.parseInt(vrLine.getMaterial_Id());
          float materialStock;
          materialStock = materialService.materialStockGet(materialid);
          float updatedStock = 0;
          updatedStock = materialStock - enteredQty;
          // msg =
          // materialService.materialStockUpdate(materialid,updatedStock);
          // Update Goods Receipt Line Returns Qty
          vrService.updateGRLQtyReturns(
              Integer.parseInt(vendorReturnAdd.getGoodsReceiptId()),
              materialiid[i].toString(),
              String.valueOf(bNo[i]),
              quantity[i].floatValue());
        }
        vendorReturnAdd.setVendorReturnDate(
            dateService.dateFormat(
                dateService.dateParse(vendorReturnAdd.getVendorReturnDate(), "au"), "au"));
        vendorReturnAdd.setVendorReturnLine(vrLines);
        msg = vrService.addVendorReturn(vendorReturnAdd);
        request.setAttribute("addVendorReturn", "Vendor Return Details Successfully Saved");
      } catch (Exception e) {
        e.printStackTrace();
      }

      if (msg.equals("S")) {
        session = request.getSession(false);
        Date dates = new Date();
        String modifiedDate = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(dates);
        auditLogService.setAuditLogSave(
            session.getAttribute("userId").toString(),
            "A",
            "Vendor Returns",
            "ROW",
            String.valueOf(vendorReturnAdd.getVendorReturnId()),
            "1",
            modifiedDate,
            session.getAttribute("userName").toString());
        vrAddSus = "Vendor Return Details Successfully Saved";
        list.add("2");
      }
      model.addAttribute("vendorReturnCommand", new VendorReturn());

      return "redirect:VendorReturn.mnt?Addsuccess=" + vrAddSus + "";

    } else {
      vendorReturnAdd.setAid(1);

      request.setAttribute(
          "addVendorReturnDuplicate", "Vendor Return No Already Exists Choose Another One");
      return "redirect:VendorReturn.mnt?AddFail=" + vrAddSus + "";
    }
  }