-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbank.py
More file actions
90 lines (83 loc) · 3.94 KB
/
bank.py
File metadata and controls
90 lines (83 loc) · 3.94 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
# Bank Services
from database import *
import datetime
class Bank:
def __init__(self, username, account_number):
self.__username = username
self.__account_number = account_number
def create_transaction_table(self):
db_query(f"CREATE TABLE IF NOT EXISTS {self.__username}_transaction "
f"( timedate VARCHAR(30),"
f"account_number INTEGER,"
f"remarks VARCHAR(30),"
f"amount INTEGER )")
def balanceequiry(self):
temp = db_query(
f"SELECT balance FROM customers WHERE username = '{self.__username}';")
print(f"{self.__username} Balance is {temp[0][0]}")
def deposit(self, amount):
temp = db_query(
f"SELECT balance FROM customers WHERE username = '{self.__username}';")
test = amount + temp[0][0]
db_query(
f"UPDATE customers SET balance = '{test}' WHERE username = '{self.__username}'; ")
self.balanceequiry()
db_query(f"INSERT INTO {self.__username}_transaction VALUES ("
f"'{datetime.datetime.now()}',"
f"'{self.__account_number}',"
f"'Amount Deposit',"
f"'{amount}'"
f")")
print(f"{self.__username} Amount is Sucessfully Depositted into Your Account {self.__account_number}")
def withdraw(self, amount):
temp = db_query(
f"SELECT balance FROM customers WHERE username = '{self.__username}';")
if amount > temp[0][0]:
print("Insufficient Balance Please Deposit Money")
else:
test = temp[0][0] - amount
db_query(
f"UPDATE customers SET balance = '{test}' WHERE username = '{self.__username}'; ")
self.balanceequiry()
db_query(f"INSERT INTO {self.__username}_transaction VALUES ("
f"'{datetime.datetime.now()}',"
f"'{self.__account_number}',"
f"'Amount Withdraw',"
f"'{amount}'"
f")")
print(
f"{self.__username} Amount is Sucessfully Withdraw from Your Account {self.__account_number}")
def fundtransfer(self, receive, amount):
temp = db_query(
f"SELECT balance FROM customers WHERE username = '{self.__username}';")
if amount > temp[0][0]:
print("Insufficient Balance Please Deposit Money")
else:
temp2 = db_query(
f"SELECT balance FROM customers WHERE account_number = '{receive}';")
if temp2 == []:
print("Account Number Does not Exists")
else:
test1 = temp[0][0] - amount
test2 = amount + temp2[0][0]
db_query(
f"UPDATE customers SET balance = '{test1}' WHERE username = '{self.__username}'; ")
db_query(
f"UPDATE customers SET balance = '{test2}' WHERE account_number = '{receive}'; ")
receiver_username = db_query(
f"SELECT username FROM customers where account_number = '{receive}';")
self.balanceequiry()
db_query(f"INSERT INTO {receiver_username[0][0]}_transaction VALUES ("
f"'{datetime.datetime.now()}',"
f"'{self.__account_number}',"
f"'Fund Transfer From {self.__account_number}',"
f"'{amount}'"
f")")
db_query(f"INSERT INTO {self.__username}_transaction VALUES ("
f"'{datetime.datetime.now()}',"
f"'{self.__account_number}',"
f"'Fund Transfer -> {receive}',"
f"'{amount}'"
f")")
print(
f"{self.__username} Amount is Sucessfully Transaction from Your Account {self.__account_number}")