2014-11-02 12:46:54 -08:00
|
|
|
Posting Date: October 29
|
2014-10-28 22:40:56 -07:00
|
|
|
Team Name: Team F8LException
|
|
|
|
|
Project Title: Online Banking System
|
2014-11-02 12:46:54 -08:00
|
|
|
Link to Github: https://github.com/dhurng/cs157AOnlineBanking/edit/master/proj.txt
|
2014-10-25 14:06:33 -07:00
|
|
|
|
|
|
|
|
Database Schema
|
2014-11-11 20:20:05 -08:00
|
|
|
1. User {userId, username, password, loanId, accountId1, accountId2}
|
|
|
|
|
int userId: autogenerated user id number.
|
|
|
|
|
String username: Customer's username.
|
|
|
|
|
String password: Customer's password.
|
|
|
|
|
int loanId: loan number, if user has a loan.
|
|
|
|
|
int accountId1: account number for first account
|
|
|
|
|
int accountId2: account number for second account
|
2014-10-25 19:06:37 -07:00
|
|
|
|
2014-11-11 20:20:05 -08:00
|
|
|
2. Transfer {id1, id2, amount}
|
|
|
|
|
int id1: sender account.
|
|
|
|
|
int id2: recipient account.
|
2014-10-25 19:06:37 -07:00
|
|
|
double amount: amount to transfer.
|
|
|
|
|
|
2014-11-11 20:20:05 -08:00
|
|
|
3. Loan {loanId, userId, amount, paymentDueDate, paymentDate balance}
|
|
|
|
|
int loanId: loan number.
|
|
|
|
|
int userId: user who owns this loan.
|
2014-10-25 19:06:37 -07:00
|
|
|
double amount: amount to pay.
|
2014-11-11 20:20:05 -08:00
|
|
|
Date paymentDueDate: date payment is due
|
|
|
|
|
Date paymentDate: date most recent payment was made
|
2014-10-25 19:06:37 -07:00
|
|
|
double balance: remaining balance.
|
|
|
|
|
|
2014-11-11 20:20:05 -08:00
|
|
|
4. Account {accountId, userId, balance, interestRate, accountType}
|
|
|
|
|
int accountId: account number.
|
|
|
|
|
int userId: user who owns this account.
|
|
|
|
|
double balance: account balance.
|
|
|
|
|
double interestRate: interest rate to add to balance.
|
|
|
|
|
String accountType: account type - savings, checking
|
|
|
|
|
|
|
|
|
|
5. Transaction {userId, accountId, accountType, date, amount, transactionType, toId}
|
|
|
|
|
int userId: customer id
|
|
|
|
|
int accountId: account number or loan number
|
|
|
|
|
String accountType: checking, savings, loan
|
|
|
|
|
Date date: date of transaction
|
|
|
|
|
double amount: transaction amount
|
|
|
|
|
String transactionType: transaction type - deposit, withdraw, interest, payment
|
|
|
|
|
int toId: to customer id, for transfers
|
2014-10-25 19:06:37 -07:00
|
|
|
|
2014-10-25 18:43:46 -07:00
|
|
|
Functional Requirements
|
2014-11-11 20:20:05 -08:00
|
|
|
1. Customer can register to create a new user.
|
|
|
|
|
2. Customer can open a new account.
|
|
|
|
|
3. Customer can close their account.
|
|
|
|
|
4. Customer can log into their account.
|
2014-10-25 18:43:46 -07:00
|
|
|
5. Customer can change password.
|
|
|
|
|
6. Customer can reset their password.
|
2014-11-11 20:20:05 -08:00
|
|
|
7. Customer can check their checking or savings account balance.
|
|
|
|
|
8. Customer can check their loan balance.
|
|
|
|
|
9. Customer can withdraw from their checking or savings accounts.
|
|
|
|
|
10. Customer can deposit to their checking or savings accounts.
|
2014-10-25 18:43:46 -07:00
|
|
|
11. Customer can view their statements from each account (Checking and Savings).
|
2014-11-11 20:20:05 -08:00
|
|
|
12. Customer can pay their loan payment.
|
2014-10-25 18:43:46 -07:00
|
|
|
13. Administrator can reset non-Admin password.
|
|
|
|
|
14. Administrator can view customers who have a zero balance in their checking and/or savings account.
|
2014-11-11 20:20:05 -08:00
|
|
|
15. Administrator can view who is a late paying their loan payment.
|
2014-11-02 12:21:02 -08:00
|
|
|
|
|
|
|
|
Requirements Functionalities
|
|
|
|
|
//Send Query to Database
|
|
|
|
|
function queryMysql($query){
|
|
|
|
|
global $conection;
|
|
|
|
|
$result = $conection->query($query);
|
|
|
|
|
if (!$result) die ($conection->error);
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-11 20:20:05 -08:00
|
|
|
// 1. Customer Registers to Create new User
|
|
|
|
|
function registerUser ($username, $password){
|
|
|
|
|
$result = queryMysql("INSERT INTO User(username, password)
|
|
|
|
|
VALUES ('$username', '$password'", $link) or die ("Database Error");
|
2014-11-02 12:21:02 -08:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 20:20:05 -08:00
|
|
|
//2. Customer opens a New Account
|
|
|
|
|
function registerAccount ($userid, $initialAmount, $accountType){
|
|
|
|
|
$result = queryMysql("INSERT INTO Account(userId, balance, accountType)
|
|
|
|
|
VALUES ('$userId', '$initialAmount', '$accountType'", $link) or die ("Database Error");
|
|
|
|
|
$result = queryMysql("INSERT INTO Transaction(userId, accountId, accountType, amount, date)
|
|
|
|
|
VALUES ('$userId', 'accountId', '$accountType', '$initialAmount', '$today'", $link) or die ("Database Error");
|
|
|
|
|
|
|
|
|
|
// 3. Customer Closes Account
|
|
|
|
|
function cancelAccount ($userId, $accountId){
|
|
|
|
|
$result = queryMysql("DELETE FROM Account WHERE userId='$userId' and accountId='$accountId'", $link)
|
|
|
|
|
or die ("Database Error");
|
2014-11-02 12:21:02 -08:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 20:20:05 -08:00
|
|
|
// 4. Customer Logs In
|
2014-11-02 12:21:02 -08:00
|
|
|
function userLogIn ($username, $password){
|
2014-11-11 20:20:05 -08:00
|
|
|
$result = queryMysql("SELECT * FROM User WHERE username='$username' and password='$password'", $link) or die ("Database Error");
|
2014-11-02 12:21:02 -08:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 20:20:05 -08:00
|
|
|
// 5. Customer Changes Password
|
2014-11-02 12:21:02 -08:00
|
|
|
function checkPassword($username, $oldPass, $newPass){
|
2014-11-11 20:20:05 -08:00
|
|
|
$result = queryMysql("UPDATE User SET password = '$newPass'
|
|
|
|
|
WHERE username='$username' and password='$oldPass'", $link) or die ("Database Error");
|
2014-11-02 12:21:02 -08:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 20:20:05 -08:00
|
|
|
// 6. Reset Customer Password
|
|
|
|
|
function resetPassword ($username, $userId) {
|
2014-11-02 12:21:02 -08:00
|
|
|
$salt1 = "qm&h";
|
|
|
|
|
$token = hash('f8luser', "$salt1'somePassword'");
|
2014-11-11 20:20:05 -08:00
|
|
|
$result = queryMysql("UPDATE User SET password='$token'
|
|
|
|
|
WHERE username='$username' and userId='$userId'", $link) or die ("Database Error");
|
2014-11-02 12:21:02 -08:00
|
|
|
return $token;
|
2014-11-02 12:46:54 -08:00
|
|
|
}
|
2014-11-02 15:02:37 -08:00
|
|
|
|
2014-11-11 20:20:05 -08:00
|
|
|
// 7. Check Checking Account Balance
|
|
|
|
|
function get_CheckingBalance ($username, $accountId) {
|
|
|
|
|
include 'db_connect.php';
|
|
|
|
|
$result=mysql_query("SELECT balance FROM account
|
|
|
|
|
WHERE accountType='checking' and username='$username' and accountId='$accountId'", $link)
|
|
|
|
|
or die ("Database Error");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 8. Check Savings Account Balance
|
|
|
|
|
function check_SavingBalance ($username, $accountId) {
|
2014-11-02 15:02:37 -08:00
|
|
|
include 'db_connect.php';
|
2014-11-11 20:20:05 -08:00
|
|
|
$result=mysql_query("SELECT balance FROM account
|
|
|
|
|
WHERE accountType='savings' and username='$username' and accountId='$accountId'", $link)
|
|
|
|
|
or die ("Database Error");
|
2014-11-02 15:02:37 -08:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 20:20:05 -08:00
|
|
|
// 9. Customer can withdraw from their accounts.
|
|
|
|
|
function accountWithdraw($userId, $accountId, $accountType, $amount) {
|
2014-11-02 15:02:37 -08:00
|
|
|
include 'db_connect.php';
|
2014-11-11 20:20:05 -08:00
|
|
|
$result=mysql_query("UPDATE Account SET balance=balance-'$amount'
|
|
|
|
|
WHERE userId='$userId' and accountId='$accountId'", $link) or die ("Database Error");
|
|
|
|
|
$result = queryMysql("INSERT INTO Transaction(userId, accountId, accountType, amount, date)
|
|
|
|
|
VALUES ('$userId', 'accountId', '$accountType', '$amount', '$today'", $link)
|
|
|
|
|
or die ("Database Error");
|
2014-11-02 15:02:37 -08:00
|
|
|
}
|
|
|
|
|
|
2014-11-11 20:20:05 -08:00
|
|
|
// 10. Customer can deposit to their accounts.
|
|
|
|
|
function accountDeposit($userId, $accountId, $accountType, $amount) {
|
|
|
|
|
include 'db_connect.php';
|
|
|
|
|
$result=mysql_query("UPDATE Account SET balance=balance+'$amount'
|
|
|
|
|
WHERE userId='$userId' and accountId='$accountId'", $link) or die ("Database Error");
|
|
|
|
|
$result = queryMysql("INSERT INTO Transaction(userId, accountId, accountType, amount, date)
|
|
|
|
|
VALUES ('$userId', 'accountId', '$accountType', '$amount', '$today'", $link)
|
|
|
|
|
or die ("Database Error");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 11. Customer can view their statements from each account (Checking and Savings).
|
|
|
|
|
function viewStatement($userId) {
|
|
|
|
|
include 'db_connect.php';
|
|
|
|
|
$result=mysql_query("SELECT accountType, date, transactionType, amount
|
|
|
|
|
FROM Transaction GROUP BY accountType
|
|
|
|
|
HAVING userId='$userId' ORDER BY date", $link) or die ("Database Error");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 12. Customer can pay their loan payment.
|
|
|
|
|
function loanPayment($userId, $loanId, $amount) {
|
|
|
|
|
include 'db_connect.php';
|
|
|
|
|
$result=mysql_query("UPDATE Loan SET balance=balance-'$amount', paymentDate='$today'
|
|
|
|
|
WHERE userId='$userId' and loanId='$loanId'", $link) or die ("Database Error");
|
|
|
|
|
$result = queryMysql("INSERT INTO Transaction(userId, loanId, accountType, amount)
|
|
|
|
|
VALUES ('$userId', 'loanId', 'loan', '$amount'", $link) or die ("Database Error");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 13. Administrator can reset non-Admin password.
|
|
|
|
|
function adminResetUserPassword ($userId, $newPassword) {
|
|
|
|
|
include 'db_connect.php';
|
|
|
|
|
$result = queryMysql("UPDATE User SET password='$newPassword' WHERE userId='$userId'", $link)
|
|
|
|
|
or die ("Database Error");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 14. Administrator can view customers who have a zero balance in their checking and/or savings account.
|
|
|
|
|
function adminGetPoorUsers() {
|
|
|
|
|
include 'db_connect.php';
|
|
|
|
|
$result = queryMysql("SELECT userId FROM User WHERE balance<=0", $link)
|
|
|
|
|
or die ("Database Error");
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 15. Administrator can view who is late paying their loan payment.
|
|
|
|
|
function adminGetUsersOfOverdueLoans() {
|
|
|
|
|
include 'db_connect.php';
|
|
|
|
|
$result=mysql_query("SELECT userId FROM User
|
|
|
|
|
WHERE userId IN (SELECT userId FROM Loan
|
|
|
|
|
WHERE paymentDueDate<paymentDate", $link) or die ("Database Error");
|