@RequestMapping(
      value = "/buy/{stockname}/{id}/{sellprice}/{buyeruserid}",
      method = RequestMethod.POST)
  public String sellShares(
      @PathVariable("stockname") String stockname,
      @PathVariable("id") int sellingtableuniqueid,
      @PathVariable("sellprice") String sellprice,
      @PathVariable("buyeruserid") String buyeruserid,
      HttpServletRequest request,
      ModelMap model,
      @ModelAttribute("Transaction") Transaction transaction,
      BindingResult result) {

    List<SellStocks> x = sellingTableInterfaceService.listsellshs(sellingtableuniqueid);

    SellStocks u_r = x.get(0);
    users u = u_r.getUser();

    users us = (users) request.getSession().getAttribute("Users");
    Integer amount = Integer.valueOf(sellprice);

    transaction.setAmountpaid(amount);
    transaction.setBuyTableID(sellingtableuniqueid);
    transaction.setStockname(stockname);
    DateFormat dateFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
    transaction.setDateoftransaction(new Date());
    transaction.setUse(us);
    transaction.setUser(u);

    int results = transactionServiceInterface.addTransaction(transaction);

    // sellingTableInterfaceService.

    // listsellshs
    List<SellStocks> xyu = sellingTableInterfaceService.listsellshs(sellingtableuniqueid);

    SellStocks ui = xyu.get(0);

    sellingTableInterfaceService.updatesellShares(sellingtableuniqueid);
    users loggeduser = (users) request.getSession().getAttribute("Users");

    confirmationpage cp = new confirmationpage();
    cp.setAmount(amount);
    cp.setNumberofshares(ui.getNoofshares());
    cp.setStockname(stockname);
    cp.setTransactionnumber(results);
    cp.setUsername(us.getUSER_ID());

    model.addAttribute("Confirmation", cp);
    String amounts = String.valueOf(cp.getAmount());
    model.addAttribute("amounts", amounts);

    // ..updatesellShares(int id)

    return "confirmationpage";
  }
  @RequestMapping(
      value = "/sell/{stockname}/{stockid}/{numberofshares}",
      method = RequestMethod.POST)
  public String sellShares(
      @PathVariable("numberofshares") int numberofshares,
      @PathVariable("stockid") int stockid,
      @PathVariable("stockname") String stockname,
      HttpServletRequest request,
      ModelMap model,
      @ModelAttribute("sellStocks") SellStocks sellStocks,
      BindingResult result) {

    users user = (users) request.getSession().getAttribute("Users");
    sellStocks.setUser(user);
    sellStocks.setStockname(stockname);
    sellStocks.setStatus("N");
    // sellStocks.setNoofshares(noofshares)
    int y = sellStocks.getNoofshares();
    int x = numberofshares - y;
    System.out.println(String.valueOf(x));

    int xy = sellingTableInterfaceService.addSellShareDetails(sellStocks);
    stockPortfolioIInterfaceService.updateStockPortfolio(x, stockid);

    return "redirect:/Client/viewmyaccount";
  }
  @RequestMapping(value = "/GenerateReports", method = RequestMethod.POST)
  public String prWelc(ModelMap model, HttpServletRequest request) throws Exception {

    int user_id = (Integer) request.getSession().getAttribute("UserID");

    List<stockportfolio> myportfolio = stockPortfolioIInterfaceService.liststock(user_id);

    model.addAttribute("myportfolio", myportfolio);

    model.addAttribute("sellStocks", new SellStocks());

    List<SellStocks> sellstocks = sellingTableInterfaceService.listsellshares(user_id);
    model.addAttribute("sellstocks", sellstocks);

    ArrayList<String> as = new ArrayList<String>();

    for (stockportfolio s : myportfolio) {
      as.add(s.getStockname());
      System.out.println(s.getStockname());
    }

    ArrayList<String> gh = new ArrayList<String>();
    gh.add("nb");
    //
    OrderPDF of = new OrderPDF(as, String.valueOf(user_id), "Automatcic Portfolio Mangement");
    model.addAttribute("pdf", "PDF File Generated");

    stockportfolio sp = new stockportfolio();
    model.addAttribute("stockportfolio", sp);

    return "clientPortfolio";
  }
  @RequestMapping(value = "/buy", method = RequestMethod.GET)
  public String pri(ModelMap model, HttpServletRequest request) {

    List<SellStocks> x = sellingTableInterfaceService.liststock();
    model.addAttribute("BuyShares", x);

    model.addAttribute("Transaction", new Transaction());
    return "buyShares";
  }
  @RequestMapping(value = "/viewmyaccount", method = RequestMethod.GET)
  public String printWelc(ModelMap model, HttpServletRequest request) {

    int user_id = (Integer) request.getSession().getAttribute("UserID");
    // int user_id=(Integer) request.getAttribute("UserID");

    List<stockportfolio> myportfolio = stockPortfolioIInterfaceService.liststock(user_id);
    model.addAttribute("myportfolio", myportfolio);

    model.addAttribute("sellStocks", new SellStocks());

    List<SellStocks> sellstocks = sellingTableInterfaceService.listsellshares(user_id);
    model.addAttribute("sellstocks", sellstocks);

    System.out.println("controller" + String.valueOf(sellstocks.size()));

    stockportfolio sp = new stockportfolio();
    model.addAttribute("stockportfolio", sp);

    return "clientPortfolio";
  }
  @RequestMapping(value = "/AddStock", method = RequestMethod.POST)
  public String printWelco(
      @Valid stockportfolio stockportfolio,
      BindingResult result,
      HttpServletRequest request,
      ModelMap model) {

    /*	if(result.hasErrors())
    {




    	 stocksearchhelper ssh=new stocksearchhelper();
    		model.addAttribute("StockSearchHelper",ssh);
    	    List<stock> x=stockServiceInterface.liststock("NASDAQ");
    		List<stock> y=stockServiceInterface.liststock("NASDAQCOMPOSITE");
    		List<stock> z=stockServiceInterface.liststock("DOWJONES");
    		List<stock> a=stockServiceInterface.liststock("GOLD");
    		List<stock> b=stockServiceInterface.liststock("SANDP");
    		List<stock> c=stockServiceInterface.liststock("OIL");
    		model.addAttribute("NASDAQ",x.get(0).getPrice());
    		model.addAttribute("NASDAQCOMPOSITE",y.get(0).getPrice());
    		model.addAttribute("DOWJONES",z.get(0).getPrice());
    		model.addAttribute("GOLD",a.get(0).getPrice());
    		model.addAttribute("SANDP",b.get(0).getPrice());
    		model.addAttribute("OIL",c.get(0).getPrice());
    		model.addAttribute("stockerror", "Please enter all the values");
    		System.out.println("sajkasja");






    		//** Main Page **/

    /*	int user_id=(Integer) request.getSession().getAttribute("UserID");
    		//int user_id=(Integer) request.getAttribute("UserID");


    		List<stockportfolio> myportfolio=stockPortfolioIInterfaceService.liststock(user_id);
    		model.addAttribute("myportfolio",myportfolio);

    		model.addAttribute("sellStocks",new SellStocks());



    		List<SellStocks> sellstocks=sellingTableInterfaceService.listsellshares(user_id);
    		model.addAttribute("sellstocks",sellstocks);


    		System.out.println("controller"+String.valueOf(sellstocks.size()));

    			stockportfolio sp=new stockportfolio();
    			model.addAttribute("stockportfolio", sp);

    			return "clientPortfolio";











    	//return "redirect:/Client/viewmyaccount";

    //	}

    //else
    //{ */

    int user_id = (Integer) request.getSession().getAttribute("UserID");
    users user = (users) request.getSession().getAttribute("Users");

    stockportfolio.setUser(user);

    int res = stockPortfolioIInterfaceService.addStockPortfolio(stockportfolio);

    stocksearchhelper ssh = new stocksearchhelper();
    model.addAttribute("StockSearchHelper", ssh);
    List<stock> x = stockServiceInterface.liststock("NASDAQ");
    List<stock> y = stockServiceInterface.liststock("NASDAQCOMPOSITE");
    List<stock> z = stockServiceInterface.liststock("DOWJONES");
    List<stock> a = stockServiceInterface.liststock("GOLD");
    List<stock> b = stockServiceInterface.liststock("SANDP");
    List<stock> c = stockServiceInterface.liststock("OIL");
    model.addAttribute("NASDAQ", x.get(0).getPrice());
    model.addAttribute("NASDAQCOMPOSITE", y.get(0).getPrice());
    model.addAttribute("DOWJONES", z.get(0).getPrice());
    model.addAttribute("GOLD", a.get(0).getPrice());
    model.addAttribute("SANDP", b.get(0).getPrice());
    model.addAttribute("OIL", c.get(0).getPrice());

    List<SellStocks> sellstocks = sellingTableInterfaceService.listsellshares(user_id);
    // model.addAttribute("sellstocks",sellstocks);

    return "redirect:/Client/viewmyaccount";

    // }

  }