/**
   * ========================================Duplicate Checking for edit===========================
   */
  @RequestMapping(value = "/vendorReturnDuplicateEditCheck", method = RequestMethod.POST)
  public @ResponseBody String checknameEdit(
      HttpServletRequest request, HttpServletResponse response, VendorReturn vend) {
    response.setCharacterEncoding("UTF-8");
    String msg = null;
    int pname = 0;

    try {

      String beforeedit = request.getParameter("vendorReturnNo");
      int iid = Integer.parseInt(request.getParameter("vid"));
      pname = vrService.checkEditDuplicate(beforeedit, iid);

      if (pname != 0) {
        vend.setVendorReturnIdEditt(1);
        request.setAttribute(
            "updateVendorReturnDuplicate", "Vendor Return No Already Exists Choose Another One");
        vend.setVendorReturnNoEditt("");

        msg = "Vendor Return No Already Exists Choose Another One";
      }
      if (pname == 0) {
        vend.setVendorReturnIdEditt(1);
        request.setAttribute(
            "updateQuotDuplicate", "Vendor Return No Already Exists Choose Another One");
        vend.setVendorReturnNoEditt("");

        msg = "";
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    return msg;
  }
  /*
   * =====================================Edit
   * Method==============================
   */
  @RequestMapping(value = "/vendorReturnIdEdit1", method = RequestMethod.GET)
  @Scope("request")
  public String vendorReturnEdit(
      @ModelAttribute VendorReturn vendorReturnIdEdit1,
      BindingResult result,
      HttpServletRequest request,
      HttpServletResponse response,
      Model model) {
    response.setCharacterEncoding("UTF-8");
    List<Float> qtyList = new ArrayList<Float>();
    List<Object> list = null;
    List<VendorReturn> vrEditList = new ArrayList<VendorReturn>();
    List<VendorReturnLine> vrLineEditList = new ArrayList<VendorReturnLine>();
    int vrid = vendorReturnIdEdit1.getVendorReturnId();

    try {

      list = vrService.editVendorReturnWithId(vrid);

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

      if (iterator.hasNext()) {
        Object vrObj = iterator.next();
        VendorReturn vr = (VendorReturn) vrObj;

        vendorReturnIdEdit1.setVendorReturnIdEditt(vr.getVendorReturnId());
        vendorReturnIdEdit1.setVendorReturnNoEditt(vr.getVendorReturnNo());
        vendorReturnIdEdit1.setVendorReturnDateEditt(
            dateService.dateFormat(dateService.dateParse(vr.getVendorReturnDate(), "se"), "se"));
        vendorReturnIdEdit1.setReferenceEditt(vr.getReference());
        vendorReturnIdEdit1.setDescriptionEditt(vr.getDescription());
        vendorReturnIdEdit1.setPurchaseOrderIdEditt(vr.getPurchaseOrderId());
        vendorReturnIdEdit1.setGoodsReceiptIdEdit(vr.getGoodsReceiptId());

        List<VendorReturnLine> listEdit = vr.getVendorReturnLine();

        Iterator<VendorReturnLine> iterator1 = listEdit.iterator();
        while (iterator1.hasNext()) {
          Object vrLineObj = iterator1.next();
          VendorReturnLine vrLine = (VendorReturnLine) vrLineObj;
          VendorReturnLine vrMultiple = new VendorReturnLine();
          vrMultiple.setVendorReturnLineId(vrLine.getVendorReturnLineId());

          int materialId = Integer.parseInt(vrLine.getMaterial_Id());

          int previousUpdatedStock;
          previousUpdatedStock = materialService.materialStockGet(materialId);

          int materialQtyInEditField = (int) (vrLine.getQuantity());
          int stockEdit = previousUpdatedStock + materialQtyInEditField;

          vrMultiple.setStockEdit(stockEdit);

          Material material = vrLine.getMaterialDetails();
          Uom uom = vrLine.getUomDetails();
          ReasonForRejection rfr = vrLine.getRfrDetails();
          StorageLocation storage = vrLine.getStorageDetails();

          vrMultiple.setMaterial_IdEditt((vrLine.getMaterial_Id()));
          vrMultiple.setMaterialName(material.getMaterialName());
          vrMultiple.setQuantityEditt((vrLine.getQuantity()));

          vrMultiple.setBatchNoEdit(vrLine.getBatchNo());
          vrMultiple.setUom_IdEditt(vrLine.getUom_Id());
          vrMultiple.setUomName(uom.getUom());
          vrMultiple.setPriceEditt(vrLine.getPrice());
          vrMultiple.setReasonForRejectionIdEditt(vrLine.getReasonForRejectionId());
          vrMultiple.setRfrName(rfr.getReasonForRejection());
          vrMultiple.setStorageLocationIdEditt(vrLine.getStorageLocationId());
          vrMultiple.setStorageName(storage.getStorageLocation());
          vrLineEditList.add(vrMultiple);
          qtyList.add((float) vrLine.getQuantity());
        }
        vrEditList.add(vendorReturnIdEdit1);
      }

      model.addAttribute("vendorReturnCommand", vendorReturnIdEdit1);
      session = request.getSession(false);
      session.setAttribute("qtyList", qtyList);
      request.setAttribute("vrEditList", vrEditList);
      request.setAttribute("vrLineEditList", vrLineEditList);

    } catch (Exception e) {
      e.printStackTrace();
    }
    return "vendorReturnHome";
  }