@RequestMapping( value = "/viewBal", method = {RequestMethod.POST, RequestMethod.GET}) public ModelAndView viewBalance(HttpServletRequest request, HttpSession session) { ModelAndView model = new ModelAndView(); LoginHandler handler = new LoginHandler(); String userName = ""; userName = (String) session.getAttribute("USERNAME"); String role = (String) session.getAttribute("Role"); try { if (role != null && !role.isEmpty() && (role.equalsIgnoreCase("USER") || role.equalsIgnoreCase("MERCHANT"))) { ResultSet rs = handler.requestBalance(userName); List<AccountDetails> acntdetails = new ArrayList<AccountDetails>(); try { while (rs.next()) { AccountDetails details = new AccountDetails(); details.setAccountNumber(rs.getString("accountnumber")); details.setAccountType(rs.getString("accounttype")); details.setBalance(rs.getDouble("balance")); acntdetails.add(details); } model.addObject("accountDetails", acntdetails); rs.close(); } catch (SQLException e) { model.addObject("accountDetails", ""); try { if (!userName.isEmpty() || !userName.equalsIgnoreCase(null)) { handler.updateLoggedInFlag(userName, 0); } } catch (Exception e1) { session.invalidate(); model.setViewName("index"); } session.invalidate(); model.setViewName("index"); e.printStackTrace(); } model.setViewName("viewBalance"); } else { if (!userName.isEmpty() || !userName.equalsIgnoreCase(null)) { handler.updateLoggedInFlag(userName, 0); } session.invalidate(); model.setViewName("index"); } } catch (Exception e) { session.invalidate(); model.setViewName("index"); } return model; }
@RequestMapping( value = "/debitAndCredit", method = {RequestMethod.POST, RequestMethod.GET}) public ModelAndView creditAndDebit(HttpServletRequest request, HttpSession session) { ModelAndView model = new ModelAndView(); String userName = ""; LoginHandler handler = new LoginHandler(); userName = (String) session.getAttribute("USERNAME"); String role = (String) session.getAttribute("Role"); try { if (role != null && !role.isEmpty() && (role.equalsIgnoreCase("USER") || role.equalsIgnoreCase("MERCHANT"))) { getAccountNumbers(model, userName, session); model.setViewName("creditAndDebit"); } else { if (!userName.isEmpty() || !userName.equalsIgnoreCase(null)) { handler.updateLoggedInFlag(userName, 0); } session.invalidate(); model.setViewName("index"); } } catch (Exception e) { session.invalidate(); model.setViewName("index"); } return model; }
private void getAccountNumbers(ModelAndView model, String userName, HttpSession session) { LoginHandler handler = new LoginHandler(); ResultSet rs = handler.requestBalance(userName); List<String> accountNumbers = new ArrayList<String>(); try { while (rs.next()) { accountNumbers.add(rs.getString("accountnumber")); } model.addObject("accountNumbers", accountNumbers); rs.close(); } catch (SQLException e) { try { if (!userName.isEmpty() || !userName.equalsIgnoreCase(null)) { handler.updateLoggedInFlag(userName, 0); } } catch (Exception e1) { session.invalidate(); model.setViewName("index"); } session.invalidate(); model.setViewName("index"); e.printStackTrace(); } }
@RequestMapping( value = "**/creditAndDebitFull**", method = {RequestMethod.POST, RequestMethod.GET}) public ModelAndView editCreditAndDebit(HttpServletRequest request, HttpSession session) { ModelAndView model = null; model = new ModelAndView(); String userName = ""; userName = (String) session.getAttribute("USERNAME"); if (request.getParameter("submit") != null) { String option = request.getParameter("transaction"); String accountNum = request.getParameter("transactions"); String amount = request.getParameter("amount"); try { double am = Double.parseDouble(amount); if (am > 0) { LoginHandler handler = new LoginHandler(); ResultSet rs = handler.requestBalance(userName); double balance = 0; try { while (rs.next()) { if (rs.getString("accountNumber").equals(accountNum)) { balance = rs.getDouble("balance"); } } double finalBalance = balance; if (option.equalsIgnoreCase("debit") && (Double.parseDouble(amount) > finalBalance)) { model.addObject("insuffFunds", "The Account has insufficient funds"); getAccountNumbers(model, userName, session); model.setViewName("creditAndDebit"); } else { int random = (new Random()).nextInt(900000) + 100000; // Date date=new Date(); boolean flag1 = false; boolean flag2 = false; if (option.equalsIgnoreCase("debit")) { logger.error( "Insereting the requested debit transacation for the user " + userName + " for amount:" + amount); flag1 = handler.insertTransactionDetails( userName, random, amount, accountNum, "", TimeUtility.generateSysDateMethod(), option, "pendingapproval"); logger.error( "Succesfully inserted the requested debit transacation for the user " + userName + " for amount:" + amount); balance = balance - Double.parseDouble(amount); flag2 = handler.updateBalance(accountNum, balance, userName); logger.error("Successfully updated the balance of the user:"******"credit")) { logger.error( "Insereting the requested debit transacation for the user " + userName + " for amount:" + amount); flag1 = handler.insertTransactionDetails( userName, random, amount, "", accountNum, TimeUtility.generateSysDateMethod(), option, "pendingapproval"); logger.error( "Succesfully inserted the requested debit transacation for the user " + userName + " for amount:" + amount); balance = balance + Double.parseDouble(amount); // flag2=handler.updateBalance(accountNum,balance,userName); logger.error("Successfully updated the balance of the user:"******"Transaction is Sucess"); model.setViewName("customerhome"); } else { logger.error("Transaction is failed"); model.setViewName("customerhome"); } } rs.close(); } catch (SQLException e) { try { if (!userName.isEmpty() || !userName.equalsIgnoreCase(null)) { handler.updateLoggedInFlag(userName, 0); } } catch (Exception e1) { session.invalidate(); model.setViewName("index"); } session.invalidate(); model.setViewName("index"); e.printStackTrace(); } } else { model.addObject("emptyFields", "Amount Field has invalid input"); getAccountNumbers(model, userName, session); model.setViewName("creditAndDebit"); } } catch (NumberFormatException nfe) { model.addObject("emptyFields", "Amount Field has invalid input"); getAccountNumbers(model, userName, session); model.setViewName("creditAndDebit"); } } return model; }