Transfer option completed.

master
Matt Theissen 4 years ago
parent 7e42705dc5
commit 5b1f1ea7d9

@ -71,6 +71,7 @@ list_balance() {
echo "1) List all users balances."
echo "2) Exact User Search"
echo "3) User Search"
echo ""
echo "0) Go back."
echo ""
read -n1 -p "*Balance Menu: Select from the above: " ii
@ -132,6 +133,18 @@ do
depo_new_amt=$($db_conn "select balance + '$depo_amt' from balance where id = '$depo_user_id';" | awk 'FNR ==3')
# Updates the database with the new amount.
$db_conn "update balance set balance = '$depo_new_amt' where id = '$depo_user_id';" ;;
3 ) read -p "Transfer from user: " tran_user1
read -p "Transer to user: " tran_user2
read -p "Amount to transfer: " tran_amt
# Grabs user IDs.
tran_user1_id=$($db_conn "select id,username,balance from account join balance using (id) where username='$tran_user1';" | awk 'FNR == 3' | awk -F\| '{print $1}')
tran_user2_id=$($db_conn "select id,username,balance from account join balance using (id) where username='$tran_user2';" | awk 'FNR == 3' | awk -F\| '{print $1}')
# Does the math to complete the transfer.
tran1_new_amt=$($db_conn "select balance - '$tran_amt' from balance where id = '$tran_user1_id';" | awk 'FNR ==3')
tran2_new_amt=$($db_conn "select balance + '$tran_amt' from balance where id = '$tran_user2_id';" | awk 'FNR ==3')
# Updates the database with the new amounts.
$db_conn "update balance set balance = '$tran1_new_amt' where id = '$tran_user1_id';"
$db_conn "update balance set balance = '$tran2_new_amt' where id = '$tran_user2_id';" ;;
4 ) $db_conn "select id,username,balance from account join balance using (id) where username='$LAST_USER';" ;;
@ -151,7 +164,8 @@ do
echo "1) Create new user account."
echo "2) List user accounts."
echo "3) List user(s) balance."
echo "4) Banking (Deposit, withdraw, transfer)"
echo "4) Banking Menu (Deposit, withdraw, transfer)"
echo ""
echo "9) Clear contents of screen"
echo "0) Exit"
echo ""