Skip to content

Commit 2b517ca

Browse files
committed
Added Creation of client accounts
1 parent a908f01 commit 2b517ca

File tree

4 files changed

+324
-2
lines changed

4 files changed

+324
-2
lines changed

accounttype.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import adminpanel
2+
import employeepanel
23
def acctype():
34
while True:
45
print("--------------Account Selector Menu--------------")
@@ -18,7 +19,7 @@ def acctype():
1819
elif a=='2':
1920
b=input("\nEnter employee password:")
2021
if b=="emp123":
21-
return 2
22+
employeepanel.ep()
2223
else:
2324
print("\nWrong password!\n")
2425

createaccount.py

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
import pickle
2+
from datetime import date
3+
4+
import mysql.connector
5+
6+
7+
def age(birthdate):
8+
today = date.today()
9+
age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day))
10+
return age
11+
12+
def ap1():
13+
cred = open("cred.dat","rb")
14+
dat=pickle.load(cred)
15+
cred.close()
16+
Passwo=dat[0]
17+
Databa=dat[1]
18+
query=mysql.connector.connect(host="localhost",user="root",password=Passwo,database=Databa)
19+
cur=query.cursor()
20+
print("-------------Create account Process-------------")
21+
22+
#client number
23+
while True:
24+
acc_no=input("Enter acc_no (max 5 int): ")
25+
if len(acc_no) <= 5:
26+
try:
27+
acc_no=int(acc_no)
28+
print("Done OK")
29+
except ValueError:
30+
print("acc_no should be an integer!!")
31+
else:
32+
break
33+
else:
34+
print("Maximum length is 5!")
35+
#client Birth date
36+
while True:
37+
while True:
38+
year=input("Enter birth year (4 int): ")
39+
if len(year) == 4:
40+
try:
41+
year=int(year)
42+
print("Done OK")
43+
except ValueError:
44+
print("year should be an integer!!")
45+
else:
46+
break
47+
else:
48+
print("Year consists of 4 integers!!")
49+
50+
while True:
51+
month=input("Enter birth month (2 int) (01 to 12): ")
52+
if len(month) == 2:
53+
try:
54+
month=int(month)
55+
print("Done OK")
56+
except ValueError:
57+
print("month should be an integer!!")
58+
else:
59+
break
60+
else:
61+
print("Month consists of 2 integers!!")
62+
63+
while True:
64+
day=input("Enter birth day (2 int) : ")
65+
if len(day) == 2:
66+
try:
67+
day=int(day)
68+
print("Done OK")
69+
except ValueError:
70+
print("Date should be an integer!!")
71+
else:
72+
break
73+
else:
74+
print("Date consists of 2 integers!!")
75+
76+
try:
77+
birth_date=date(year,month,day)
78+
except ValueError:
79+
import traceback
80+
traceback.print_exc()
81+
else:
82+
if age(birth_date)>=10:
83+
break
84+
else:
85+
print("Account holder must be atleast 10 years of age!!")
86+
#client name
87+
while True:
88+
first_name=input("Enter first name (max 15 char): ")
89+
if len(first_name)<= 15:
90+
break
91+
else:
92+
print("Max 15 characters")
93+
94+
while True:
95+
last_name=input("Enter last name (max 15 char): ")
96+
if len(last_name)<= 15:
97+
break
98+
else:
99+
print("Max 15 characters")
100+
#client Gender
101+
while True:
102+
print("1.Male")
103+
print("2.Female")
104+
a=input("Enter choice (1 or 2):")
105+
if a== '1':
106+
gender='M'
107+
break
108+
elif a=='2':
109+
gender='F'
110+
break
111+
else:
112+
print("Wrong input!!")
113+
114+
#client Account Type
115+
while True:
116+
print("1.Savings account")
117+
print("2.Current account")
118+
a=input("Enter choice (1 or 2):")
119+
if a== '1':
120+
acc_type='S'
121+
break
122+
elif a=='2':
123+
acc_type='C'
124+
break
125+
else:
126+
print("Wrong input!!")
127+
128+
#Account creation date
129+
while True:
130+
while True:
131+
hyear=input("Enter account_creation year (4 int): ")
132+
if len(hyear) == 4:
133+
try:
134+
hyear=int(hyear)
135+
print("Done OK")
136+
except ValueError:
137+
print("year should be an integer!!")
138+
else:
139+
break
140+
else:
141+
print("Year consists of 4 integers!!")
142+
143+
while True:
144+
hmonth=input("Enter account_creation month (2 int) (01 to 12): ")
145+
if len(hmonth) == 2:
146+
try:
147+
hmonth=int(hmonth)
148+
print("Done OK")
149+
except ValueError:
150+
print("month should be an integer!!")
151+
else:
152+
break
153+
else:
154+
print("Month consists of 2 integers!!")
155+
156+
while True:
157+
hday=input("Enter account_creation day (2 int) (01 to 31): ")
158+
if len(hday) == 2:
159+
try:
160+
hday=int(hday)
161+
print("Done OK")
162+
except ValueError:
163+
print("Date should be an integer!!")
164+
else:
165+
break
166+
else:
167+
print("Date consists of 2 integers!!")
168+
169+
try:
170+
acc_creation_date=date(hyear,hmonth,hday)
171+
except ValueError:
172+
import traceback
173+
traceback.print_exc()
174+
else:
175+
if age(birth_date)-age(acc_creation_date)>=10:
176+
break
177+
else:
178+
print("client must atleast be 10 years of age!!")
179+
#client password/pin
180+
while True:
181+
password=input("Enter client login password(max 8 characters, min 4): ")
182+
lp=len(password)
183+
if lp>8:
184+
print("Max 8 characters only.")
185+
elif lp<4:
186+
print("Minimum 4 characters to be entered.")
187+
else:
188+
break
189+
190+
#mobile no
191+
while True:
192+
mobile_no_str=input("Enter mobile no. (7 to 15 int)")
193+
mobile_no=mobile_no_str
194+
#Thanks to the international phone numbering plan (ITU-T E. 164),
195+
#phone numbers cannot contain more than 15 digits. The shortest
196+
#international phone numbers in use contain seven digits.
197+
try:
198+
mobile_no=int(mobile_no)
199+
except ValueError:
200+
print("acc_no should be an integer!!")
201+
else:
202+
if len(mobile_no_str)>6 and len(mobile_no_str)<16:
203+
mobile_no=mobile_no_str
204+
lmn=len(mobile_no)
205+
break
206+
else:
207+
print("Mobile number can have min 7 digits and max 15!!")
208+
209+
#email-id
210+
while True:
211+
email_id=input("Enter client Email ID (max 25 char):")
212+
if len(email_id)<26:
213+
break
214+
else:
215+
print("Maximum 25 characters")
216+
217+
218+
219+
print("=========== Final Data ===========")
220+
print(acc_no,acc_type,first_name,last_name,gender,birth_date,acc_creation_date,mobile_no,email_id,password)
221+
add_client=("INSERT INTO clients "
222+
"(acc_no,acc_type,first_name,last_name,gender,birth_date,acc_creation_date,mobile_no,email_id,pass) "
223+
"VALUES (%s,%s,%s,%s,%s,%s,%s,LPAD(%s,%s,'0'),%s,LPAD(%s,%s,'0'))")
224+
data_client=(acc_no,acc_type,first_name,last_name,gender,birth_date,acc_creation_date,mobile_no,lmn,email_id,password,lp)
225+
try:
226+
cur.execute(add_client, data_client)
227+
query.commit()
228+
except mysql.connector.Error as err:
229+
print(err.msg)
230+
print("-----------Value addition was unsuccessful!!!!-------------")
231+
else:
232+
print("Values added successfully!!")
233+
cur.close()
234+
query.close()

employeepanel.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import pickle
2+
import mysql.connector
3+
import createaccount
4+
5+
conn=None
6+
cur=None
7+
def ep():
8+
global conn
9+
global cur
10+
print("\nWelcome employee!!")
11+
print("Please log in with your creds (emp_id and password):")
12+
13+
cred = open("cred.dat","rb")
14+
dat=pickle.load(cred)
15+
cred.close()
16+
Passwo=dat[0]
17+
Databa=dat[1]
18+
conn=mysql.connector.connect(host="localhost",user="root",password=Passwo,database=Databa)
19+
cur=conn.cursor()
20+
21+
while True:
22+
print("---------------------Employee Panel--------------------")
23+
print("1.Employee login.")
24+
print("2.Quit.")
25+
ch = input("Enter your choice:")
26+
if ch == "1":
27+
print("------------login panel-------------")
28+
elif ch == "2":
29+
cur.close()
30+
conn.close()
31+
break
32+
else:
33+
print("Wrong input!!!(1 or 2 only)")
34+
while True:
35+
emp_no=input("Enter emp_no (max 5 int): ")
36+
if len(emp_no) <= 5:
37+
try:
38+
emp_no=int(emp_no)
39+
print("Done OK")
40+
except ValueError:
41+
print("emp_no should be an integer!!")
42+
else:
43+
break
44+
else:
45+
print("Maximum length is 5!")
46+
47+
cur.execute("select * from empass where emp_no = {}".format(emp_no))
48+
record=cur.fetchall()
49+
if record == []:
50+
print("This emp_no doesn't exist!!!")
51+
else:
52+
while True:
53+
password=record[0][1]
54+
a=input("Enter your password:")
55+
if a==password:
56+
choice=menu(emp_no)
57+
if choice=="1":
58+
createaccount.ep1()
59+
elif choice=="2":
60+
break
61+
elif choice=="3":
62+
break
63+
elif choice=="4":
64+
break
65+
elif choice=="0":
66+
cur.close()
67+
conn.close()
68+
break
69+
else:
70+
print("Wrong input!")
71+
else:
72+
print("Wrong password!!")
73+
break
74+
75+
def menu(x):
76+
global conn
77+
global cur
78+
cur.execute("select first_name,last_name from employees where emp_no = {}".format(x))
79+
record=cur.fetchone()
80+
print("---------------Welcome {} {} ----------------".format(record[0],record[1]))
81+
print("1.Create client account")
82+
print("2.Change client pin")
83+
print("3.Close client account")
84+
print("4.Show client table")
85+
print("Enter 0 to quit.")
86+
choice=input("Enter your choice: ")
87+
return choice

setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
" `gender` enum('M','F') NOT NULL,"
3131
" `birth_date` date NOT NULL,"
3232
" `acc_creation_date` date NOT NULL,"
33-
" `mobile_no` int(10) NOT NULL,"
33+
" `mobile_no` varchar(20) NOT NULL,"
3434
" `email_id` varchar(25) NOT NULL,"
3535
" `pass` varchar(8) NOT NULL"
3636
") "

0 commit comments

Comments
 (0)