Example #1
0
  @Override
  public void withdrawl(int C_ID, String accNum, int amount, String description) {
    try {
      TransactionDAO dao = new RDBTransactionsDAO(connection);
      Transactions trans = new Transactions(accNum, amount, description);
      dao.deposit(trans);

    } catch (Exception e) {
      System.out.println("Could not make a withdrawl.");
      e.printStackTrace();
    }
  }
Example #2
0
  @Override
  public List viewAllTransactions(String accNum) {
    ArrayList transList = new ArrayList();
    try {
      TransactionDAO dao = new RDBTransactionsDAO(connection);
      // Transactions trans = new Transactions(accNum);
      dao.viewAllTransactions(accNum);
      return transList;

    } catch (Exception e) {
      System.out.println("Could not make a withdrawl.");
      e.printStackTrace();
      return transList;
    }
  }
  public ChangesStatus transferMoney(
      int account_id_from, int account_id_to, int customer_id_by, int amount)
      throws BelowMinimumBalanceException {

    Connection connection = DBConnectionHelper.getConnection();
    try {
      Account account_1 = new Account();
      account_1 = accountDAO.getObject(connection, account_id_from);

      double newAmount_1 = account_1.getAmount() - amount;
      if (newAmount_1 < BusinessRules.SAVING_ACCOUNT_MIN_BALANCE_AMOUNT) {
        throw new BelowMinimumBalanceException("Below Minimum balance exceed");
      }
      account_1.setAmount(newAmount_1);
      accountDAO.save(connection, account_1);

      Account account_2 = new Account();
      account_2 = accountDAO.getObject(connection, account_id_to);

      double newAmount_2 = account_2.getAmount() + amount;
      account_2.setAmount(newAmount_2);
      accountDAO.save(connection, account_2);

      Transaction transaction = new Transaction();
      transaction.setCustomer_id_by(customer_id_by);
      transaction.setAccount_id(account_id_from);
      transaction.setAccount_id_to(account_id_to);
      transaction.setTransaction_amount(amount);
      transaction.setTransaction_type(3);

      Date date = new Date();
      transaction.setTransaction_time(new Timestamp(date.getTime()));
      transactionDAO.create(connection, transaction);
      // If exception found roll back in catch block
      connection.commit();

      return new ChangesStatus(true, "Successfully Transfered " + amount);

    } catch (NotFoundException e) {
      e.printStackTrace();

    } catch (SQLException e) {
      try {
        e.printStackTrace();
        connection.rollback();
        return new ChangesStatus(false, "Rolledbacked. Transaction Unsuccessful.");
      } catch (SQLException e1) {
        e1.printStackTrace();
        return new ChangesStatus(false, "Unsuccessful Rolledback.");
      }
    } finally {
      try {
        connection.close();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
    return null;
  }
Example #4
0
  public String perform(HttpServletRequest request) {
    HttpSession session = request.getSession();
    List<String> errors = new ArrayList<String>();
    // authority judge
    if ((EmployeeBean) session.getAttribute("employee") == null) {
      return "employeelogin.do";
    }

    request.setAttribute("errors", errors);
    EmployeeBean employee = (EmployeeBean) session.getAttribute("employee");
    if (employee == null) {
      return "employeelogin.do";
    }

    /*
     * Check the deposit form.
     */
    DepositCheckForm depositcheckform = new DepositCheckForm(request);
    request.setAttribute("depositcheckform", depositcheckform);
    if (!depositcheckform.isPresent()) {
      return "employee_deposit_check.jsp";
    }
    errors.addAll(depositcheckform.getValidationErrors());
    if (errors.size() != 0) {
      return "employee_deposit_check.jsp";
    }

    CustomerBean customer = (CustomerBean) session.getAttribute("modifyCustomer");
    int id = customer.getCustomerId();
    try {
      customer = customerDAO.read(id);
    } catch (RollbackException e1) {
      // TODO Auto-generated catch block
      e1.printStackTrace();
    }

    double amount = depositcheckform.getAmount();

    //////////////////////
    // Transaction START //
    //////////////////////
    try {
      Transaction.begin();
      TransactionBean transaction = new TransactionBean();
      // what kind of transaction
      transaction.setTransactionType(TransactionType.DEPOSIT.toString());
      // who request the deposit
      transaction.setCustomerId(customer.getCustomerId());
      // how much money(in long)
      transaction.writeAmount(amount);
      // Create transaction
      transactionDAO.create(transaction);

      // update balance&available immediately.
      customer.writeCashBalance(amount);
      customerDAO.update(customer);

      Transaction.commit();
    } catch (RollbackException e) {
      e.printStackTrace();
    }
    ////////////////////
    // Transaction END//
    ////////////////////

    session.setAttribute("modifyCustomer", customer);
    // session.setAttribute("customer", customer);

    session.setAttribute(
        "message", "Thank you! You have successfully sent your deposit check request!");
    return "success_employee.jsp";
  }
  public ChangesStatus withdrawMoney(int account_id, int customer_id_by, int amount, int pin)
      throws BelowMinimumBalanceException {

    Connection connection = DBConnectionHelper.getConnection();

    try {
      Account account = accountDAO.getObject(connection, account_id);

      // Checking Security Pin
      if (!(account.getPin() == pin)) {
        return new ChangesStatus(false, "Security Pin do not match! Transaction Canceled.");
      }

      // Checking Permission
      if (!(PermissionHelper.isThisAccountOwnByThisCustomer(account_id, customer_id_by))) {
        return new ChangesStatus(false, "You do not own this account. Transaction Canceled.");
      }

      double newAmount = account.getAmount() - amount;

      if (newAmount < BusinessRules.SAVING_ACCOUNT_MIN_BALANCE_AMOUNT) {
        throw new BelowMinimumBalanceException("Below Minimum Balance to be left");
      }

      account.setAmount(newAmount);

      accountDAO.save(connection, account);

      Transaction transaction = new Transaction();
      transaction.setCustomer_id_by(customer_id_by);
      transaction.setAccount_id(account_id);
      transaction.setTransaction_amount(amount);
      transaction.setTransaction_type(2);

      Date date = new Date();
      transaction.setTransaction_time(new Timestamp(date.getTime()));
      transactionDAO.create(connection, transaction);
      // If exception found roll back in catch block
      connection.commit();

      return new ChangesStatus(true, "Successfully Withdrawed" + amount);

    } catch (NotFoundException e) {
      e.printStackTrace();
    } catch (SQLException e) {
      try {
        connection.rollback();
        e.printStackTrace();
        return new ChangesStatus(false, "Transaction Rolledbacked. Unsuccessful.");
      } catch (SQLException e1) {
        e1.printStackTrace();
        return new ChangesStatus(false, "Unsuccessful Rolledback.");
      }
    } finally {
      try {
        connection.close();
      } catch (SQLException e) {
        e.printStackTrace();
      }
    }
    return null;
  }