-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBankacc.py
301 lines (301 loc) · 9.18 KB
/
Bankacc.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
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
import mysql.connector as sq
import datetime
import sys
import random
from prettytable import PrettyTable
bank=sq.connect(user='root',password='',host='localhost',database='bank',charset='utf8')
mycursor=bank.cursor()
def menu ():
print('BANK ACCOUNT SOFTWARE'.center(120))
print('-*-'*44)
print('WELCOME'.center(120))
print('''MAIN MENU
1.Open Account
2. Display Account
3. Modify Account
4. Withdraw Money
5. Deposit Money
6. Display Passbook
7. Close Account
8. Exit''')
choice=int(input('Enter your choice'))
while True:
if choice==1:
create()
elif choice==2:
display()
elif choice==3:
Modify()
elif choice==7:
close()
elif choice==8:
print('Exiting...')
bank.close()
sys.exit()
elif choice==4:
withdraw()
elif choice==5:
deposit()
elif choice==6:
dis_pass()
else:
print('Wrong Choice!')
menu()
def create():
try:
cmd='''create table bankacc (AcNo varchar(15) primary key,Name varchar(20),Address varchar(20),Email varchar(20),Mobile varchar(10),Amount varchar(131),Type char(20))'''
mycursor.execute(cmd)
cmd='''create table passbook (AcNo varchar(15) ,Date date ,Debit integer,Credit integer,Balance integer,Particular char(20))'''
mycursor.execute(cmd)
open()
except:
Open()
def Open():
while True:
acc=random.randint(11111111,99999999)
Name=str(input('Enter Name'))
add=input('Enter Address')
email=input('Enter Your Email')
mob=int(input('Enter Your Mobile No.'))
amt=amount()
typea=typ()
rec=(acc,Name,add,email,mob,amt,typea)
cmd='insert into bankacc values(%s,%s,%s,%s,%s,%s,%s)'
c=bank.cursor()
c.execute(cmd,rec)
bank.commit()
print('Your Account no. is --->',acc)
ch=input('Do you want to enter more records (y/n)')
if ch=='n' or ch=='N':
break
menu()
def amount():
a=int(input('Enter opening Amount'))
s=0
if a>=5000:
s+=a
else:
print('Minimum opening amount is 5000 Rs.')
s=amount()
return s
def typ():
print('''Enter from the given choice which type of Account you want to open
1. FD
2. Saving
3. Current''')
typ1=int(input('Enter(1/2/3)'))
a=''
if typ1==1:
a+='FD'
elif typ1==2:
a+='Saving'
elif typ1==3:
a+='Current'
else:
print('wrong choice')
typ()
return a
def display():
mycursor.execute('select*from bankacc')
d=mycursor.fetchall()
ac=str(input('enter your account no.'))
for i in d:
if i[0]==ac:
print('Account no.-->',i[0])
print('Name-->',i[1])
print('Address-->',i[2])
print('Email-->',i[3])
print('Mobile-->',i[4])
print('Amount-->','₹',i[5])
print('Type-->',i[6])
break
else:
print('Account no. not found')
menu()
def Modify():
mycursor.execute('select*from bankacc')
d=mycursor.fetchall()
ac=str(input('enter your account no.'))
f=False
for i in d:
if i[0]==ac:
f=True
while True:
print('''what you want to modify
Press 1.To Change Name
2. To change address
3.To Change Mobile no
4.To Change email
5. To Change Type of account''')
c=int(input('enter your choice'))
if c==1:
Name=str(input('enter new name'))
cmd='update bankacc set name=%s where acno=%s'
rec=(Name,i[0])
mycursor.execute(cmd,rec)
bank.commit()
print('Name updated!')
elif c==2:
ad=str(input('enter new address'))
cmd='update bankacc set address=%s where acno=%s'
rec=(ad,ac)
mycursor.execute(cmd,rec)
bank.commit()
print('Address updated!')
elif c==3:
mob=int(input('enter new mobile no.'))
cmd='update bankacc set mobile=%s where acno=%s'
rec=(mob,ac)
mycursor.execute(cmd,rec)
bank.commit()
print('mobile no. updated!')
elif c==4:
em=str(input('enter new email'))
cmd='update bankacc set email=%s where acno=%s'
rec=(em,ac)
mycursor.execute(cmd,rec)
bank.commit()
print('email updated!')
elif c==5:
ty=typ()
cmd='update bankacc set type=%s where acno=%s'
rec=(ty,ac)
mycursor.execute(cmd,rec)
bank.commit()
print('Account type updated!')
else:
print('Please select right choice')
continue
w=str(input('want to update more records(y/n)'))
if w=='n' or w=='N':
break
if f==True:
menu()
else:
print('Wrong Account No.!')
menu()
def close():
mycursor.execute('select*from bankacc')
d=mycursor.fetchall()
ac=str(input('enter Your account no. to be Close'))
for i in d:
if i[0]==ac:
cmd='delete from bankacc where acno=%s'
rec=(i[0],)
mycursor.execute(cmd,rec)
bank.commit()
print('Account deleted!')
break
else:
print('Account no. not matched!!')
menu()
def money():
a=''
print('''select your choice
1.By Cash
2.By cheque
3.NEFT''')
c=int(input('Enter(1/2/3)'))
if c==1:
a+='Cash'
elif c==2:
a+='Cheque'
elif c==3:
a+='NEFT'
else:
print('Wrong choice')
print('Enter again!')
money()
return a
def withdraw():
mycursor.execute('select*from bankacc')
d=mycursor.fetchall()
ac=str(input('enter your account no.'))
found=True
s=True
t=True
for i in d:
if i[0]==ac:
q=int(i[5])
wi=int(input('enter money you want to withdraw'))
if (int(i[5])-wi)>=5000:
found=False
cmd='update bankacc set amount=amount-%s where acno=%s'
rec=(wi,i[0])
mycursor.execute(cmd,rec)
bank.commit()
d=sam()
u=q-wi
re=(d,wi,i[0],u)
cm='Insert into passbook (date,debit,acno,balance) values (%s,%s,%s,%s)'
mycursor.execute(cm,re)
bank.commit()
elif int(i[5])<wi:
t=False
else:
s=False
if found==False:
print('₹',wi,'withdraw successfully')
elif s==False:
print('Your bank balance should have minimum of ₹5000')
elif t==False:
print('Your account balance is only',q)
else:
print("Wrong account no.")
menu()
def sam():
mycursor.execute('select curdate()')
da=mycursor.fetchone()
dat=da[0]
return dat
def deposit():
mycursor.execute('select*from bankacc')
d=mycursor.fetchall()
ac=str(input('enter your account no.'))
my=money()
f=False
for i in d:
if i[0]==ac:
f=True
wi=int(input('enter money you want to deposit'))
cmd='update bankacc set amount=amount+%s where acno=%s'
rec=(wi,i[0])
mycursor.execute(cmd,rec)
bank.commit()
de=sam()
s=wi+int(i[5])
re=(de,wi,i[0],my,s)
cm='Insert into passbook (date,credit,acno,Particular,balance) values (%s,%s,%s,%s,%s)'
mycursor.execute(cm,re)
bank.commit()
if f==False:
print('Account no. not matched')
else:
print('₹',wi,'Credited successfully','by',my)
menu()
def dis_pass():
c=str(input('enter your account no.'))
mycursor.execute('Select*from bankacc')
d=mycursor.fetchall()
mycursor.execute('Select*from passbook')
e=mycursor.fetchall()
f=False
s=False
for j in d:
if j[0]==c:
s=True
l=PrettyTable(['Date', 'Debit', 'Credit', 'Mode', 'Balance'])
for i in e:
if i[0]==c:
f=True
l.add_row([i[1], i[2], i[3], i[5], i[4]])
#print('Date -->',i[1],'Debit--> ₹',i[2],'Credit--> ₹',i[3],'Mode-->',i[5],'Balance--> ₹',i[4])
print(l)
if s==False:
print('Wrong Account no.')
elif f==False:
print('No Transaction')
else:
menu()
menu()
menu()