@RequestMapping(value = "/vendorReturnAdvanceSearchOperations", method = RequestMethod.POST)
  public String vendorReturnAdvanceSearchOperations(
      @ModelAttribute("vendorReturnCommand") VendorReturn vendorReturn,
      HttpServletRequest request,
      HttpServletResponse response,
      Model model) {

    vr1 = new ArrayList<VendorReturn>();
    String columns = vendorReturn.getFirstLabel();
    String operations = vendorReturn.getOperations1();
    String advanceSearchText = vendorReturn.getAdvanceSearchText();

    if (advanceSearchText.length() != 0) {
      objectsArray = vrService.getVendorReturnAdvance(columns, operations, advanceSearchText);
    } else {
      objectsArray = vrService.getVendorReturn("ALL");
    }
    iterator = objectsArray.iterator();
    while (iterator.hasNext()) {

      VendorReturn vr = (VendorReturn) iterator.next();
      vr.setVendorReturnId(vr.getVendorReturnId());
      vr.setVendorReturnNo(vr.getVendorReturnNo());
      vr.setVendorReturnDate(vr.getVendorReturnDate());
      vr.setReference(vr.getReference());
      vr.setDescription(vr.getDescription());
      vr1.add(vr);
    }

    request.setAttribute("vendorReturnSearch", vr1);
    model.addAttribute("vendorReturn", new VendorReturn());
    vendorReturn.setAdvanceSearchHidden(0);
    return "vendorReturnHome";
  }
  /* ===================================Update Method======================== */
  @RequestMapping(value = "/vendorReturnEdit", method = RequestMethod.GET)
  public String updateVendorReturn(
      @ModelAttribute("vendorReturnCommand") VendorReturn vrEdit,
      HttpServletRequest request,
      HttpServletResponse response,
      Model model) {
    response.setCharacterEncoding("UTF-8");
    VendorReturnLine vrLine = null;
    List<VendorReturnLine> vrLines = null;
    String vendorReturnUpdate = null;
    List<Object[]> ob = null;
    float rejQty = 0.0f, returnQty = 0.0f, qty = 0.0f, diffQty = 0.0f;
    List<String> list = new ArrayList<String>();
    String msg = null;

    String checkVrNo = vrEdit.getVendorReturnNoEditt();

    int id = vrEdit.getVendorReturnIdEditt();

    int list1 = vrService.checkEditDuplicate(checkVrNo, id);

    if (list1 == 0) {

      try {
        float stockEdit = vrEdit.getStockEdit();
        vrEdit.setVendorReturnId(id);
        vrEdit.setVendorReturnNo(vrEdit.getVendorReturnNoEditt());
        vrEdit.setVendorReturnDate(
            dateService.dateFormat(
                dateService.dateParse(vrEdit.getVendorReturnDateEditt(), "au"), "au"));
        vrEdit.setReference(vrEdit.getReferenceEditt());
        vrEdit.setDescription(vrEdit.getDescriptionEditt());
        vrEdit.setPurchaseOrderId(vrEdit.getPurchaseOrderIdEditt());
        vrEdit.setGoodsReceiptId(vrEdit.getGoodsReceiptIdEdit());
        vrLines = new ArrayList<VendorReturnLine>();
        List<Float> newQty = new ArrayList<Float>();

        int[] vrIdUpdate = vrEdit.getVendorReturnLineIdEditt();
        String[] bno = vrEdit.getBatchNoEdit();
        String materialedit = vrEdit.getmIdEditt();
        List<String> meditlist = Arrays.asList(materialedit.split(","));
        Object[] materialiidedit = meditlist.toArray();

        Integer[] quantity = vrEdit.getQuantityEditt();

        String unitedit = vrEdit.getUommEditt();
        List<String> uomeditlist = Arrays.asList(unitedit.split(","));
        Object[] uomidedit = uomeditlist.toArray();

        float[] price = vrEdit.getPriceEditt();

        String rfredit = vrEdit.getRfrIdEditt();
        List<String> rfreditlist = Arrays.asList(rfredit.split(","));
        Object[] rfridedit = rfreditlist.toArray();

        String storageedit = vrEdit.getUommEditt();
        List<String> storageeditlist = Arrays.asList(storageedit.split(","));
        Object[] storageidedit = storageeditlist.toArray();

        String idQL = null;

        if (quantity != null) {
          session = request.getSession(false);
          @SuppressWarnings("unchecked")
          List<Float> oldQty = (List<Float>) session.getAttribute("qtyList");
          for (int i = 0; i < quantity.length; i++) {
            int kk = vrIdUpdate[i];
            // get the Qtys
            ob =
                vrService.getRejQty(
                    Integer.parseInt(vrEdit.getPurchaseOrderId()),
                    Integer.parseInt(vrEdit.getGoodsReceiptId()),
                    materialiidedit[i].toString(),
                    bno[i]);

            if (kk == 0) {
              vrLine = new VendorReturnLine();
              vrLine.setBatchNo(bno[i]);
              vrLine.setMaterial_Id(materialiidedit[i].toString());
              vrLine.setQuantity(quantity[i]);

              /*
               * float afterEdit = vrLine.getQuantity(); int
               * materialId = Integer.parseInt(vrLine
               * .getMaterial_Id()); float finalStock = 0;
               * finalStock = stockEdit - afterEdit;
               *
               * materialService.materialStockUpdate(materialId,
               * finalStock);
               */
              vrLine.setUom_Id(uomidedit[i].toString());
              vrLine.setPrice(price[i]);
              vrLine.setReasonForRejectionId(rfridedit[i].toString());
              vrLine.setStorageLocationId(storageidedit[i].toString());
              vrLines.add(vrLine);
              // update qty returns in GRL
              if (ob != null) {
                Iterator<Object[]> itr = ob.iterator();
                while (itr.hasNext()) {
                  Object[] obj = (Object[]) itr.next();
                  if (obj[0] != null && obj[1] != null) {
                    rejQty = (Float) obj[0];
                    returnQty = (Float) obj[1];
                  } else if (obj[0] != null) {
                    rejQty = (Float) obj[0];
                  }
                }
                diffQty = returnQty + quantity[i].floatValue();
                // update qty returns in GRL
                vrService.updateGRLQtyReturns(
                    Integer.parseInt(vrEdit.getGoodsReceiptIdEdit()),
                    materialiidedit[i].toString(),
                    String.valueOf(bno[i]),
                    diffQty);
              }

            } else {

              vrLine = new VendorReturnLine();
              vrLine.setBatchNo(bno[i]);
              vrLine.setMaterial_Id(materialiidedit[i].toString());
              vrLine.setQuantity(quantity[i]);
              vrLine.setUom_Id(uomidedit[i].toString());
              vrLine.setPrice(price[i]);
              vrLine.setReasonForRejectionId(rfridedit[i].toString());
              vrLine.setStorageLocationId(storageidedit[i].toString());

              newQty.add((float) (quantity[i]));
              String ch = "1", ch1 = "0";
              idQL = request.getParameter(kk + "Check");
              if (ch.equals(idQL)) {
                vrService.deleteVendorReturnLine(kk);
              }
              if (ch1.equals(idQL) || idQL == null) {
                vrLines.add(vrLine);
              }

              if (oldQty.get(i) > (newQty.get(i))) {
                qty = oldQty.get(i) - newQty.get(i);
                if (ob != null) {
                  Iterator<Object[]> itr = ob.iterator();
                  while (itr.hasNext()) {
                    Object[] obj = (Object[]) itr.next();
                    if (obj[0] != null && obj[1] != null) {
                      rejQty = (Float) obj[0];
                      returnQty = (Float) obj[1];
                    } else if (obj[0] != null) {
                      rejQty = (Float) obj[0];
                    }
                  }
                  diffQty = returnQty - qty;
                  // update qty returns in GRL
                  vrService.updateGRLQtyReturns(
                      Integer.parseInt(vrEdit.getGoodsReceiptIdEdit()),
                      materialiidedit[i].toString(),
                      String.valueOf(bno[i]),
                      diffQty);
                }
              } else if (oldQty.get(i) < (newQty.get(i))) {
                qty = newQty.get(i) - oldQty.get(i);
                if (ob != null) {
                  Iterator<Object[]> itr = ob.iterator();
                  while (itr.hasNext()) {
                    Object[] obj = (Object[]) itr.next();
                    if (obj[0] != null && obj[1] != null) {
                      rejQty = (Float) obj[0];
                      returnQty = (Float) obj[1];
                    } else if (obj[0] != null) {
                      rejQty = (Float) obj[0];
                    }
                  }

                  diffQty = returnQty + qty;
                  // update qty returns in GRL
                  vrService.updateGRLQtyReturns(
                      Integer.parseInt(vrEdit.getGoodsReceiptIdEdit()),
                      materialiidedit[i].toString(),
                      String.valueOf(bno[i]),
                      diffQty);
                }

              } else { // Two Quantitys are Equal No update... }

              }
            }
          }
        }
        vrEdit.setVendorReturnLine(vrLines);
        msg = vrService.updateVendorReturn(vrEdit);

        request.setAttribute("updateVendorReturn", "Vendor Return Details Updated Successfully");
      } catch (Exception e) {
        e.printStackTrace();
      }
      if (msg.equals("Vendor Return Details Updated Successfully")) {
        vendorReturnUpdate = "Vendor Return Details Updated Successfully";
        list.add("2");
      } else {
        return "redirect:VendorReturn.mnt?updateFail=" + vendorReturnUpdate + "";
      }

      model.addAttribute("vendorReturnCommand", new VendorReturn());

      return "redirect:VendorReturn.mnt?updateSuccess=" + vendorReturnUpdate + "";
    } else {

      request.setAttribute("vrEditList", "vrEditList");
      return "redirect:VendorReturn.mnt?updateFail=" + vendorReturnUpdate + "";
    }
  }
  @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;
  }