@RequestMapping(value = "/download", method = RequestMethod.GET)
  public void downloadStatement(HttpSession session, HttpServletResponse response, Model model)
      throws IOException {
    String uniqId = session.getAttribute("uniqueid").toString();
    StatementGenerator.statementbyuniqid(uniqId, session);
    ExternalUser extUser = databaseConnector.getExternalUserByUniqId(uniqId);
    TempTransactions transactionObj = new TempTransactions();
    transactionObj.setBalance(extUser.getBalance());
    logger.info("Current Balance" + transactionObj.getBalance());
    float amount = transactionObj.getTransactionAmount();
    float currentBalance = transactionObj.getBalance();
    logger.info("balance :", currentBalance);
    logger.info("account number ", transactionObj.getAccountno());
    // credit amount from current account balance

    transactionObj.setUniqId(uniqId);
    transactionObj.setDescription("transferred amount: " + amount);
    transactionObj.setTransactionType("tranfer");
    transactionObj.setBalance(currentBalance - amount);

    extUser.setBalance(currentBalance - amount);

    Transactions temp = new Transactions();
    temp.setBalance(transactionObj.getBalance());
    model.addAttribute("debitOp", temp);
    model.addAttribute("creditOp", temp);
    model.addAttribute("checkAccBal", temp.getBalance());
    model.addAttribute("transferOp", transactionObj);
    model.addAttribute("paymerchantOp", transactionObj);
    List<Transactions> obj = displaytransaction(session);
    model.addAttribute("transactionOp", obj);
    // get absolute path of the application
    ServletContext context = session.getServletContext();

    String realContextPath = context.getRealPath("/");
    String fullpath = realContextPath + "/statement/" + uniqId + "_statement.pdf";
    //  System.out.println("aPath = " +realContextPath);
    // String filePath="Statement.pdf";
    // construct the complete absolute path of the file
    //  String fullPath = realContextPath+filePath;
    System.out.println(fullpath);

    File downloadFile = new File(fullpath);
    FileInputStream inputStream = new FileInputStream(downloadFile);

    // get MIME type of the file
    String mimeType = context.getMimeType(fullpath);
    if (mimeType == null) {
      // set to binary type if MIME mapping not found
      mimeType = "application/pdf";
    }
    System.out.println("MIME type: " + mimeType);

    // set content attributes for the response
    response.setContentType(mimeType);
    response.setContentLength((int) downloadFile.length());

    // set headers for the response
    String headerKey = "Content-Disposition";
    String headerValue = String.format("attachment; filename=\"%s\"", downloadFile.getName());
    response.setHeader(headerKey, headerValue);

    OutputStream outStream = response.getOutputStream();

    byte[] buffer = new byte[4096];
    int bytesRead = -1;

    // write bytes read from the input stream into the output stream
    while ((bytesRead = inputStream.read(buffer)) != -1) {
      outStream.write(buffer, 0, bytesRead);
    }

    inputStream.close();
    outStream.close();

    //
    //					//ServletOutputStream out = response.getOutputStream();
    //					FileOutputStream fos = new FileOutputStream(downloadFile);
    //						System.out.println("Adding " + downloadFile.getName());
    //
    //						// Get the file
    //						FileInputStream fis = null;
    //						try {
    //							fis = new FileInputStream(downloadFile);
    //
    //						} catch (FileNotFoundException fnfe) {
    //							// If the file does not exists, write an error entry instead of
    //							// file
    //							// contents
    //							fos.write(("ERROR could not find file " + downloadFile.getName())
    //									.getBytes());
    //							fos.close();
    //							System.out.println("Couldfind file "
    //									+ downloadFile.getAbsolutePath());
    //						}
    //
    //						BufferedInputStream fif = new BufferedInputStream(fis);
    //
    //						// Write the contents of the file
    //						int data = 0;
    //						while ((data = fif.read()) != -1) {
    //							fos.write(data);
    //						}
    //						fif.close();
    //
    //						fos.close();
    System.out.println("Finished Downloading file " + downloadFile.getName());
    return;
    // return "redirect:extUserHomePage";
  }
  @RequestMapping(value = "/credit_money", method = RequestMethod.POST)
  public String creditmoneyPageAction(
      @ModelAttribute("creditOp") Transactions transactionObj, Model model, HttpSession session) {
    logger.info("Inside credit money op POST");
    logger.info("Current Balance" + transactionObj.getBalance());
    /** To display user profile */
    UserInfo UI = new UserInfo();
    DatabaseConnectors dbcon = new DatabaseConnectors();
    UI = dbcon.getUserInfoByUniqId((String) session.getAttribute("uniqueid"));

    String utype = null;
    String str1 = (String) session.getAttribute("uniqueid");

    System.out.println(str1);
    String str2 = str1.substring(0, 2);

    if (str2.equals("ei")) {
      utype = "Single User";
    } else if (str2.equals("em")) {
      utype = "Merchant";
    } else if (str2.equals("ir")) {
      utype = "Internal User";
    } else if (str2.equals("im")) {
      utype = "Manager";
    } else if (str2.equals("admin")) {
      utype = "Administrator";
    }

    model.addAttribute("firstName", UI.getFirstName());
    model.addAttribute("lastName", UI.getLastName());
    model.addAttribute("Username", UI.getUsername());
    model.addAttribute("email", UI.getEmailId());

    model.addAttribute("streetAddress", UI.getAddress());
    model.addAttribute("city", UI.getCity());
    model.addAttribute("state", UI.getState());
    model.addAttribute("country", UI.getCountry());
    model.addAttribute("zip", UI.getZipcode());
    model.addAttribute("contactNo", UI.getContactNo());
    model.addAttribute("userType", utype);

    String uniqueID = (String) session.getAttribute("uniqueid");
    // String uniqueID ="EM123";
    ExternalUser extUser = databaseConnector.getExternalUserByUniqId(uniqueID);

    model.addAttribute("accountno", extUser.getAccountno());

    transactionObj.setBalance(extUser.getBalance());
    float amount = transactionObj.getTransactionAmount();
    float currentBalance = transactionObj.getBalance();
    logger.info("balance :", currentBalance);
    // credit amount from current account balance
    transactionObj.setUniqId(uniqueID);
    transactionObj.setDescription("credited amount: " + amount);
    transactionObj.setTransactionType("credit");
    transactionObj.setBalance(currentBalance + amount);
    transactionObj.setStatus("Pending");
    extUser.setBalance(currentBalance + amount);
    databaseConnector.updateExternalUser(extUser);
    databaseConnector.saveTransaction(transactionObj);

    TempTransactions temp = new TempTransactions();
    temp.setBalance(transactionObj.getBalance());

    model.addAttribute("debitOp", transactionObj);
    model.addAttribute("creditOp", transactionObj);
    model.addAttribute("checkAccBal", transactionObj.getBalance());
    model.addAttribute("transferOp", temp);
    model.addAttribute("paymerchantOp", temp);
    model.addAttribute("UpdateProfile", new UserInfo());
    List<Transactions> obj = displaytransaction(session);
    if (obj == null) {
      model.addAttribute("transactionOp", null);
    } else {
      model.addAttribute("transactionOp", obj);
    }

    logger.info("Leaving credit money POST");
    return "extUserHomePage";
  }