-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbank.py
269 lines (210 loc) · 10.4 KB
/
bank.py
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
from random import randint
from colorama import Fore, Back, Style
import sqlite3
import datetime
import os
import os.path
import time
from colorama import init
init()
BASE_DIR = os.path.dirname(os.path.abspath(__file__))
db_path = os.path.join(BASE_DIR, "bank.db")
db = sqlite3.connect(db_path)
cursor = db.cursor()
asw = ""
totalAmount = 0
transactionAmount = 0
transactionNum = 0
newAmount = 0
now = datetime.datetime.now()
class Bank():
def newAccount(self):
print("+{:-<100}+".format(""))
print('\x1b[6;30;47m' + "|{:^100}|".format("REGISTER ACOUNT FORM")+'\x1b[0m')
print("+{:-<100}+".format(""))
accNumber = input("Insert new account number: ")
email = input("Insert new email: ")
bankCode = input("Insert bank code: ")
totalAmount = int(input("Insert first ammount: "))
newAcc = '''INSERT INTO USER(accNumber,email,bankCode,totalAmount)
VALUES ('%s', '%s', '%s', '%s') ''' % (accNumber, email, bankCode, totalAmount)
cursor.execute(newAcc)
db.commit()
db.close()
print("+{:-<100}+".format(""))
print("|{:^100}|".format("NEW USER"))
print("+{:-<100}+".format(""))
print('\x1b[6;30;42m' + "|{:^100}|".format("SUCCESS")+'\x1b[0m')
print("+{:-<22}+{:-<31}+{:-<22}+{:-<22}+".format("", "", "", ""))
print("|{:^22}|{:^31}|{:^22}|{:^22}|".format(
"Account Number", "Email", "Bank Code", "Total Amount"))
print("+{:-<22}+{:-<31}+{:-<22}+{:-<22}+".format("", "", "", ""))
print("|{:^22}|{:^31}|{:^22}|{:^22}|".format(
accNumber, email, bankCode, totalAmount))
print("+{:-<22}+{:-<31}+{:-<22}+{:-<22}+".format("", "", "", ""))
def deposit(self):
print("+{:-<100}+".format(""))
print('\x1b[6;30;47m' + "|{:^100}|".format("DEPOSIT FORM")+'\x1b[0m')
print("+{:-<100}+".format(""))
accNumber = input("Insert account number to login: ")
findAcc = ("SELECT * FROM USER WHERE accNumber = ?")
cursor.execute(findAcc, [(accNumber)])
results = cursor.fetchall()
if results:
for i in results:
print("+{:-<100}+".format(""))
print("|{:^100}|".format('Welcome: ' + i[1]))
print("+{:-<100}+".format(""))
transactionType = "Deposit"
transactionDate = now.strftime('%Y-%m-%d')
print("Date: " + str(transactionDate))
print("+{:-<100}+".format(""))
transactionNum = randint(100000, 999999)
print("Your transacion number is: " + str(transactionNum))
print("+{:-<100}+".format(""))
transactionAmount = int(input("Insert deposit amount: "))
print("+{:-<100}+".format(""))
newTran = '''INSERT INTO MONEY(accNumber, transactionNum, transactionType, transactionDate, transactionAmount)
VALUES ('%s', '%s', '%s', '%s', '%s') ''' % (accNumber, transactionNum, transactionType, transactionDate, transactionAmount)
cursor.execute(newTran)
db.commit()
accountAmount = (
"SELECT totalAmount FROM USER WHERE accNumber = ?")
cursor.execute(accountAmount, [(accNumber)])
currentAmount = cursor.fetchone()
oldAmount = currentAmount[0]
newAmount = oldAmount + transactionAmount
updateAmount = (
"UPDATE USER SET totalAmount =? WHERE accNumber = ?")
cursor.execute(updateAmount, [(newAmount), (accNumber)])
db.commit()
print('\x1b[6;30;42m' +
"|{:^100}|".format("SUCCESS")+'\x1b[0m')
print("+{:-<100}+".format(""))
print("|{:^100}|".format("You have now: " + str(newAmount)))
print("+{:-<100}+".format(""))
else:
print("+{:-<100}+".format(""))
print('\x1b[0;37;41m' +
"|{:^100}|".format("Account doesn't exist")+'\x1b[0m')
print("+{:-<100}+".format(""))
again = input("Do you want to try again? (Y/N): ").upper()
if again != "N":
Bank.deposit(self)
else:
print("+{:-<100}+".format(""))
print("|{:^100}|".format("GOOD BYE"))
print("+{:-<100}+".format(""))
def withdraw(self):
print("+{:-<100}+".format(""))
print('\x1b[6;30;47m' + "|{:^100}|".format("WITHDRAW FORM")+'\x1b[0m')
print("+{:-<100}+".format(""))
accNumber = input("Insert account number to login: ")
findAcc = ("SELECT * FROM USER WHERE accNumber = ?")
cursor.execute(findAcc, [(accNumber)])
results = cursor.fetchall()
if results:
for i in results:
print("+{:-<100}+".format(""))
print("|{:^100}|".format('Welcome: ' + i[1]))
print("+{:-<100}+".format(""))
transactionType = "Withdraw"
transactionDate = now.strftime('%Y-%m-%d')
print("Date: " + str(transactionDate))
print("+{:-<100}+".format(""))
transactionNum = randint(100000, 999999)
print("Your transacion number is: " + str(transactionNum))
print("+{:-<100}+".format(""))
transactionAmount = int(input("Insert withdraw amount: "))
print("+{:-<100}+".format(""))
accountAmount = (
"SELECT totalAmount FROM USER WHERE accNumber = ?")
cursor.execute(accountAmount, [(accNumber)])
currentAmount = cursor.fetchone()
oldAmount = currentAmount[0]
if oldAmount > transactionAmount:
newAmount = oldAmount - transactionAmount
newTran = '''INSERT INTO MONEY(accNumber, transactionNum, transactionType ,transactionDate, transactionAmount)
VALUES ('%s', '%s', '%s', '%s', '%s') ''' % (accNumber, transactionNum, transactionType, transactionDate, transactionAmount)
cursor.execute(newTran)
db.commit()
updateAmount = (
"UPDATE USER SET totalAmount =? WHERE accNumber = ?")
cursor.execute(updateAmount, [(newAmount), (accNumber)])
db.commit()
print('\x1b[6;30;42m' +
"|{:^100}|".format("SUCCESS")+'\x1b[0m')
print("+{:-<100}+".format(""))
print("|{:^100}|".format(
"You have now: " + str(newAmount)))
print("+{:-<100}+".format(""))
else:
print("+{:-<100}+".format(""))
print('\x1b[0;37;41m' +
"|{:^100}|".format("You don't have enough money to do that")+'\x1b[0m')
print("+{:-<100}+".format(""))
again = input("Do you want to try again? (Y/N): ").upper()
if again != "N":
Bank.withdraw(self)
else:
print("+{:-<100}+".format(""))
print("|{:^100}|".format("GOOD BYE"))
print("+{:-<100}+".format(""))
else:
print("+{:-<100}+".format(""))
print('\x1b[0;37;41m' +
"|{:^100}|".format("Account doesn't exist")+'\x1b[0m')
print("+{:-<100}+".format(""))
again = input("Do you want to try again? (Y/N): ").upper()
if again != "N":
Bank.withdraw(self)
else:
print("+{:-<100}+".format(""))
print("|{:^100}|".format("GOOD BYE"))
print("+{:-<100}+".format(""))
def checkMovements(self):
print("+{:-<100}+".format(""))
print('\x1b[6;30;47m' + "|{:^100}|".format("BANK MOVEMENTS")+'\x1b[0m')
print("+{:-<100}+".format(""))
accNumber = input("Insert account number to check: ")
findAcc = ("SELECT * FROM USER WHERE accNumber = ?")
cursor.execute(findAcc, [(accNumber)])
results = cursor.fetchall()
accountAmount = ("SELECT totalAmount FROM USER WHERE accNumber = ?")
cursor.execute(accountAmount, [(accNumber)])
currentAmount = cursor.fetchone()
allAmount = currentAmount[0]
if results:
for i in results:
print("+{:-<100}+".format(""))
print("|{:^100}|".format('Welcome: ' + i[1]))
print("+{:-<100}+".format(""))
accountMovement = (
"SELECT transactionNum, transactionType, transactionDate, transactionAmount FROM MONEY WHERE accNumber = ? ORDER BY transactionDate DESC")
cursor.execute(accountMovement, [(accNumber)])
movements = cursor.fetchall()
print('\x1b[6;30;42m' +
"|{:^100}|".format("SUCCESS")+'\x1b[0m')
print("+{:-<100}+".format(""))
print("|{:^100}|".format("LIFE SAVINGS: " + str(allAmount)))
print("+{:-<24}+{:-<24}+{:-<25}+{:-<24}+".format("", "", "", ""))
print("|{:^24}|{:^24}|{:^25}|{:^24}|".format(
"Transaction Number", "Transaction Type", "Transaction Date", "Transaction Amount"))
print("+{:-<24}+{:-<24}+{:-<25}+{:-<24}+".format("", "", "", ""))
for transactionNum, transactionType, transactionDate, transactionAmount in movements:
print("|{:^24}|{:^24}|{:^25}|{:^24}|".format(
transactionNum, transactionType, transactionDate, transactionAmount))
print(
"+{:-<24}+{:-<24}+{:-<25}+{:-<24}+".format("", "", "", ""))
else:
print("+{:-<100}+".format(""))
print('\x1b[0;37;41m' +
"|{:^100}|".format("Account doesn't exist")+'\x1b[0m')
print("+{:-<100}+".format(""))
again = input("Do you want to try again? (Y/N): ").upper()
if again != "N":
Bank.checkMovements(self)
else:
print("+{:-<100}+".format(""))
print("|{:^100}|".format("GOOD BYE"))
print("+{:-<100}+".format(""))