diff --git a/.gitignore b/.gitignore index d510687..248fbda 100644 --- a/.gitignore +++ b/.gitignore @@ -3,4 +3,6 @@ firsttime.txt cred.dat links.txt tempCodeRunnerFile.py -start program.bat \ No newline at end of file +start program.bat +README.md +.vscode/ \ No newline at end of file diff --git a/README.md b/README.md index 2ced7b5..ff9ab29 100644 --- a/README.md +++ b/README.md @@ -1,35 +1,42 @@ -# Bank Management System: -First of all, whole code is written by me and nothing has been copy pasted fron anywhere. - -The project has Dependencies which are all open sourced (modules such as pickle, csv, mysql-connector) - -# Requirements: -1. Python 3 -2. MySQL workbench 8.0 - -because I've tested the code using these versions only... - -# Setup: -Run the file named "main.py" and follow the instructions of the program... - -# How to reset: -Open the file named "firsttime.txt" and change the value from False to True (case sensitive) - -# Troubleshooting: -1.I suspect that the people who haven't set a password for SQL may encounter an error. (will fix it later) - -I strongly suggest users to have a password set in MySQL. - -2.Check if the terminal shows the message "Connection established successfully" - -That means you entered your credentials properly - -3.Any other exception will pop up in the terminal... - -# About: -This project aims to create a bridge between Python and SQL and use it in real world problems/applications... - -This project is currently under development... - -# Done by: -Om J Shah +# OLD NOTICE: +See [this pull request](https://github.com/OJASisLive/Bank-Management-System-Python-SQL/pull/6) for details about merger of ["shorten-the-code"](https://github.com/OJASisLive/Bank-Management-System-Python-SQL/tree/shorten-the-code) branch into the main branch. + + +# Bank Management System: +First of all, whole code is written by me and nothing has been copy pasted fron anywhere. + +The project has Dependencies which are all open sourced (modules such as pickle, csv, mysql-connector) + +# Requirements: +1. Python 3 +2. MySQL workbench 8.0 + +because I've tested the code using these versions only... + +# Setup: +Run the file named "main.py" and follow the instructions of the program... + +# How to reset: +Open the file named "firsttime.txt" and change the value from False to True (case sensitive) + +# Troubleshooting: +1. I suspect that the people who haven't set a password for SQL may encounter an error. (will fix it later) + + I strongly suggest users to have a password set in MySQL. + +2. Check if the terminal shows the message "Connection established successfully" + + That means you entered your credentials properly + +3. Any other exception will pop up in the terminal... + +# More information/Structure/Wiki +[Wiki](https://github.com/OJASisLive/Bank-Management-System-Python-SQL/wiki) + +# About: +This project aims to create a bridge between Python and SQL and use it in real world problems/applications... + +This project is currently under development... + +# Done by: +Om J Shah diff --git a/check.py b/check.py deleted file mode 100644 index d0aee5d..0000000 --- a/check.py +++ /dev/null @@ -1,6 +0,0 @@ -def check(): - with open("firsttime.txt","r") as a: - if a.read().strip()=="True": - return True - else: - return False \ No newline at end of file diff --git a/editemployee.py b/editemployee.py deleted file mode 100644 index 86feffe..0000000 --- a/editemployee.py +++ /dev/null @@ -1,276 +0,0 @@ -import mysql.connector -import pickle -from datetime import date - -def age(birthdate): - today = date.today() - age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day)) - return age - -cur=None -conn=None -emp_no=0 -hire_date=None -birth_date=None -def ap3(): - global cur - global conn - cred = open("cred.dat","rb") - dat=pickle.load(cred) - cred.close() - Passwo=dat[0] - Databa=dat[1] - conn=mysql.connector.connect(host="localhost",user="root",password=Passwo,database=Databa) - cur=conn.cursor() - - global emp_no - global birth_date - global hire_date - print("---------Edit employee process----------\n") - while True: - emp_no=input(("Enter emp_no of the employee to edit the details: ")) - if len(emp_no) <= 5: - try: - emp_no=int(emp_no) - print("Checking...") - except ValueError: - print("emp_no should be an integer!!") - else: - break - else: - print("Maximum length is 5!") - cur.execute("select * from employees where emp_no={}".format(emp_no)) - results=cur.fetchall() - if results == []: - print(results) - print("That employee number does not exist.") - else: - results1=results[0] - print("1.emp_no:",results1[0]) - print("2.birth_date:",results1[1]) - print("3.first_name:",results1[2]) - print("4.last-name:",results1[3]) - print("5.gender:",results1[4]) - print("6.hire_date:",results1[5]) - birth_date=results1[1] - hire_date=results1[5] - f2() - -def f2(): - global cur - global conn - global emp_no - global birth_date - global hire_date - print("0 to quit.") - a=input("What would you like to change from the above:") - if a == '1': - while True: - en=input("Enter emp_no (max 5 int): ") - if len(en) <= 5: - try: - en=int(en) - print("Done OK") - except ValueError: - print("emp_no should be an integer!!") - else: - try: - cur.execute("update employees set emp_no={} where emp_no={}".format(en,emp_no)) - conn.commit() - except mysql.connector.Error as err: - print(err.msg) - print("-----------Value addition was unsuccessful!!!!-------------") - else: - print("Updated employee number...") - break - else: - print("Maximum length is 5!") - if a == '2': - while True: - while True: - year=input("Enter birth year (4 int): ") - if len(year) == 4: - try: - year=int(year) - print("Done OK") - except ValueError: - print("year should be an integer!!") - else: - break - else: - print("Year consists of 4 integers!!") - - while True: - month=input("Enter birth month (2 int) (01 to 12): ") - if len(month) == 2: - try: - month=int(month) - print("Done OK") - except ValueError: - print("month should be an integer!!") - else: - break - else: - print("Month consists of 2 integers!!") - - while True: - day=input("Enter birth day (2 int) : ") - if len(day) == 2: - try: - day=int(day) - print("Done OK") - except ValueError: - print("Date should be an integer!!") - else: - break - else: - print("Date consists of 2 integers!!") - - try: - birth_date=date(year,month,day) - except ValueError: - import traceback - traceback.print_exc() - else: - if age(birth_date)>=20 and age(birth_date)<=60: - if age(birth_date)-age(hire_date)>=20: - try: - cur.execute("update employees set birth_date='{}' where emp_no={}".format(birth_date,emp_no)) - conn.commit() - except mysql.connector.Error as err: - print(err.msg) - print("-----------Value addition was unsuccessful!!!!-------------") - break - else: - print("Updated birth date...") - break - else: - print("Employee must be atleast 20 years of age when hired!!") - print(birth_date,": birth_date") - print(hire_date,":hire date you entered") - else: - if age(birth_date)<20: - print("Employee must be atleast 20 years of age!!") - else: - print("Maximum age is 60 years!!!") - print("\nwrong input\n") - if a == '3': - while True: - first_name=input("Enter first name (max 15 char): ") - if len(first_name)<= 15: - try: - cur.execute("update employees set first_name={} where emp_no={}".format(first_name,emp_no)) - conn.commit() - except mysql.connector.Error as err: - print(err.msg) - print("-----------Value addition was unsuccessful!!!!-------------") - break - else: - print("Updated first name...") - break - else: - print("Max 15 characters") - - if a == '4': - while True: - last_name=input("Enter last name (max 15 char): ") - if len(last_name)<= 15: - try: - cur.execute("update employees set last_name={} where emp_no={}".format(last_name,emp_no)) - conn.commit() - except mysql.connector.Error as err: - print(err.msg) - print("-----------Value addition was unsuccessful!!!!-------------") - break - else: - print("Updated last name...") - break - else: - print("Max 15 characters") - if a == '5': - while True: - print("1.Male") - print("2.Female") - a=input("Enter choice (1 or 2):") - if a== '1': - try: - cur.execute("update employees set gender='M' where emp_no={}".format(emp_no)) - conn.commit() - except mysql.connector.Error as err: - print(err.msg) - print("-----------Value addition was unsuccessful!!!!-------------") - break - else: - print("Updated first name...") - break - - elif a=='2': - gender='F' - try: - cur.execute("update employees set gender='F' where emp_no={}".format(emp_no)) - conn.commit() - except mysql.connector.Error as err: - print(err.msg) - print("-----------Value addition was unsuccessful!!!!-------------") - break - else: - print("Updated first name...") - break - - else: - print("Wrong input!!") - - if a == '6': - while True: - while True: - hyear=input("Enter hire year (4 int): ") - if len(hyear) == 4: - try: - hyear=int(hyear) - print("Done OK") - except ValueError: - print("year should be an integer!!") - else: - break - else: - print("Year consists of 4 integers!!") - - while True: - hmonth=input("Enter hire month (2 int) (01 to 12): ") - if len(hmonth) == 2: - try: - hmonth=int(hmonth) - print("Done OK") - except ValueError: - print("month should be an integer!!") - else: - break - else: - print("Month consists of 2 integers!!") - - while True: - hday=input("Enter hire day (2 int) (01 to 31): ") - if len(hday) == 2: - try: - hday=int(hday) - print("Done OK") - except ValueError: - print("Date should be an integer!!") - else: - break - else: - print("Date consists of 2 integers!!") - - try: - hire_date=date(hyear,hmonth,hday) - except ValueError: - import traceback - traceback.print_exc() - else: - if age(birth_date)-age(hire_date)>=20: - break - else: - print("Employee must atleast be 20 years of age when hired!!") - - cur.close() - conn.close() \ No newline at end of file diff --git a/firsttime.txt b/firsttime.txt deleted file mode 100644 index c1f22fb..0000000 --- a/firsttime.txt +++ /dev/null @@ -1 +0,0 @@ -False \ No newline at end of file diff --git a/hireemployee.py b/hireemployee.py deleted file mode 100644 index a386fdb..0000000 --- a/hireemployee.py +++ /dev/null @@ -1,185 +0,0 @@ -from datetime import date -import pickle -import mysql.connector - -def age(birthdate): - today = date.today() - age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day)) - return age - -def ap1(): - cred = open("cred.dat","rb") - dat=pickle.load(cred) - cred.close() - Passwo=dat[0] - Databa=dat[1] - query=mysql.connector.connect(host="localhost",user="root",password=Passwo,database=Databa) - cur=query.cursor() - print("-------------Hire Employee Process-------------") - -#Employee number - while True: - emp_no=input("Enter emp_no (max 5 int): ") - if len(emp_no) <= 5: - try: - emp_no=int(emp_no) - print("Done OK") - except ValueError: - print("emp_no should be an integer!!") - else: - break - else: - print("Maximum length is 5!") -#Employee Birth date - while True: - while True: - year=input("Enter birth year (4 int): ") - if len(year) == 4: - try: - year=int(year) - print("Done OK") - except ValueError: - print("year should be an integer!!") - else: - break - else: - print("Year consists of 4 integers!!") - - while True: - month=input("Enter birth month (2 int) (01 to 12): ") - if len(month) == 2: - try: - month=int(month) - print("Done OK") - except ValueError: - print("month should be an integer!!") - else: - break - else: - print("Month consists of 2 integers!!") - - while True: - day=input("Enter birth day (2 int) : ") - if len(day) == 2: - try: - day=int(day) - print("Done OK") - except ValueError: - print("Date should be an integer!!") - else: - break - else: - print("Date consists of 2 integers!!") - - try: - birth_date=date(year,month,day) - except ValueError: - import traceback - traceback.print_exc() - else: - if age(birth_date)>=20 and age(birth_date)<=60: - break - else: - if age(birth_date)<20: - print("Employee must be atleast 20 years of age!!") - else: - print("Maximum age is 60 years!!!") - print("\nwrong input\n") -#Employee name - while True: - first_name=input("Enter first name (max 15 char): ") - if len(first_name)<= 15: - break - else: - print("Max 15 characters") - - while True: - last_name=input("Enter last name (max 15 char): ") - if len(last_name)<= 15: - break - else: - print("Max 15 characters") -#Employee Gender - while True: - print("1.Male") - print("2.Female") - a=input("Enter choice (1 or 2):") - if a== '1': - gender='M' - break - elif a=='2': - gender='F' - break - else: - print("Wrong input!!") -#Employee hire date - while True: - while True: - hyear=input("Enter hire year (4 int): ") - if len(hyear) == 4: - try: - hyear=int(hyear) - print("Done OK") - except ValueError: - print("year should be an integer!!") - else: - break - else: - print("Year consists of 4 integers!!") - - while True: - hmonth=input("Enter hire month (2 int) (01 to 12): ") - if len(hmonth) == 2: - try: - hmonth=int(hmonth) - print("Done OK") - except ValueError: - print("month should be an integer!!") - else: - break - else: - print("Month consists of 2 integers!!") - - while True: - hday=input("Enter hire day (2 int) (01 to 31): ") - if len(hday) == 2: - try: - hday=int(hday) - print("Done OK") - except ValueError: - print("Date should be an integer!!") - else: - break - else: - print("Date consists of 2 integers!!") - - try: - hire_date=date(hyear,hmonth,hday) - except ValueError: - import traceback - traceback.print_exc() - else: - if age(hire_date)>60: - print("Employee must be below 60 years of age!!") - elif age(birth_date)-age(hire_date)>=20: - break - else: - print("Employee must atleast be 20 years of age!!") - - - print("=========== Final Data ===========") - print(emp_no,birth_date,first_name,last_name,gender,hire_date) - add_employee=("INSERT INTO employees " - "(emp_no,birth_date,first_name,last_name,gender,hire_date) " - "VALUES (%s,%s,%s,%s,%s,%s)") - data_employee=(emp_no,birth_date,first_name,last_name,gender,hire_date) - try: - cur.execute(add_employee, data_employee) - query.commit() - except mysql.connector.Error as err: - print(err.msg) - print("-----------Value addition was unsuccessful!!!!-------------") - else: - print("Values added successfully!!") - cur.close() - query.close() \ No newline at end of file diff --git a/main.py b/main.py deleted file mode 100644 index ca62589..0000000 --- a/main.py +++ /dev/null @@ -1,6 +0,0 @@ -import setup -from check import check -import accounttype -conn=setup.setup() -if not check: - accounttype.acctype() \ No newline at end of file diff --git a/photos/Clients.png b/photos/Clients.png new file mode 100644 index 0000000..e4c127e Binary files /dev/null and b/photos/Clients.png differ diff --git a/photos/Current.png b/photos/Current.png new file mode 100644 index 0000000..faef729 Binary files /dev/null and b/photos/Current.png differ diff --git a/photos/Structure.png b/photos/Structure.png new file mode 100644 index 0000000..bd09944 Binary files /dev/null and b/photos/Structure.png differ diff --git a/photos/cash_in_hand.png b/photos/cash_in_hand.png new file mode 100644 index 0000000..4135927 Binary files /dev/null and b/photos/cash_in_hand.png differ diff --git a/photos/empass.png b/photos/empass.png new file mode 100644 index 0000000..c93e4ab Binary files /dev/null and b/photos/empass.png differ diff --git a/photos/employees.png b/photos/employees.png new file mode 100644 index 0000000..17a02d9 Binary files /dev/null and b/photos/employees.png differ diff --git a/photos/loan.png b/photos/loan.png new file mode 100644 index 0000000..163d94b Binary files /dev/null and b/photos/loan.png differ diff --git a/photos/overdraft.png b/photos/overdraft.png new file mode 100644 index 0000000..62df398 Binary files /dev/null and b/photos/overdraft.png differ diff --git a/photos/savings.png b/photos/savings.png new file mode 100644 index 0000000..b6eefd8 Binary files /dev/null and b/photos/savings.png differ diff --git a/showemployee.py b/showemployee.py deleted file mode 100644 index 3d49304..0000000 --- a/showemployee.py +++ /dev/null @@ -1,20 +0,0 @@ -import mysql.connector -import pickle -def ap4(): - cred = open("cred.dat","rb") - dat=pickle.load(cred) - cred.close() - Passwo=dat[0] - Databa=dat[1] - conn=mysql.connector.connect(host="localhost",user="root",password=Passwo,database=Databa) - cur=conn.cursor() - cur.execute("select * from employees") - results=cur.fetchall() - print("---------------------------------------------------------------------------------------") - print("|","%7s"%"EMP_NO","|","%11s"%"BIRTH_DATE","|","%16s"%"FIRST_NAME","|","%16s"%"LAST_NAME","|","%7s"%"GENDER","|","%11s"%"HIRE_DATE","|") - for row in results: - print("---------------------------------------------------------------------------------------") - print("|","%7s"%row[0],"|","%11s"%row[1],"|","%16s"%row[2],"|","%16s"%row[3],"|","%7s"%row[4],"|","%11s"%row[5],"|") - cur.close() - conn.close() - print("---------------------------------------------------------------------------------------") \ No newline at end of file diff --git a/src/main/OmJShah/admin/editemployee.py b/src/main/OmJShah/admin/editemployee.py new file mode 100644 index 0000000..0c0bb94 --- /dev/null +++ b/src/main/OmJShah/admin/editemployee.py @@ -0,0 +1,133 @@ +from datetime import date +from tools import dataentering + +def age(birthdate): + today = date.today() + age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day)) + return age +emp_no=None +hire_date=None +birth_date=None + +def ap3(conn,cur): + global emp_no,birth_date,hire_date + print("---------Edit employee process----------\n") + while True: + print("input ~ to quit") + emp_no=input(("Enter emp_no of the employee to edit the details: ")) + if emp_no=="~": break + if len(emp_no) <= 5: + try: + emp_no=int(emp_no) + print("Checking...") + except ValueError: + print("emp_no should be an integer!!") + else: + next(conn,cur) + break + else: + print("Maximum length is 5!") + +def next(conn,cur): + cur.execute("select * from employees where emp_no={}".format(emp_no)) + results=cur.fetchall() + if len(results)==0: + print("That employee number does not exist.") + else: + results1=results[0] + print("1.emp_no:",results1[0]) + print("2.birth_date:",results1[1]) + print("3.first_name:",results1[2]) + print("4.last-name:",results1[3]) + print("5.gender:",results1[4]) + print("6.hire_date:",results1[5]) + print("7.password") + birth_date=results1[1] + hire_date=results1[5] + f2(conn,cur) + +def f2(conn,cur): + global emp_no,birth_date,hire_date + print("0 to quit.") + a=input("What would you like to change from the above:") + if a == '1': + en=dataentering.primary_key_no("emp_no") + query="update employees set emp_no=%s where emp_no=%s" + query2="update empass set emp_no=%s where emp_no=%s" + data=(en,emp_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + done=dataentering.tableupdate(conn,cur,query2,data) + if done: + print("Updated employee number...") + + if a == '2': + birth_date=dataentering.birthdate("employee",20,60) + if age(birth_date)-age(hire_date)>=20: + query="update employees set birth_date=%s where emp_no=%s" + data=(birth_date,emp_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + print("Updated birth date") + else: + print("Employee must be atleast 20 years of age when hired!!") + print(birth_date,": birth_date") + print(hire_date,":hire date you entered") + + if a == '3': + first_name=dataentering.fname() + query="update employees set first_name=%s where emp_no=%s" + data=(first_name,emp_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + print("Updated first name...") + + if a == '4': + last_name=dataentering.lname() + query="update employees set last_name=%s where emp_no=%s" + data=(last_name,emp_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + print("Updated last name...") + + if a == '5': + gender=dataentering.gender() + query="update employees set gender=%s where emp_no=%s" + data=(gender,emp_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + print("Updated gender...") + + if a == '6': + hire_date=dataentering.date2("employee",birth_date,"hire",20,60) + query="update employees set hire_date=%s where emp_no=%s" + data=(hire_date,emp_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + print("Updated hire date...") + + if a=='7': + print("1.Show the password") + print("2.Change the password") + ans=input("Enter your choice (1,2):") + if ans=='1': + cur.execute("SELECT pass from empass where emp_no={}".format(emp_no)) + result=cur.fetchall() + print(result[0][0], "is the password.") + elif ans=='2': + while True: + password=input("Enter employee login password(max 8 characters, min 4): ") + lp=len(password) + if lp>8: + print("Max 8 characters only.") + elif lp<4: + print("Minimum 4 characters to be entered.") + else: + query="UPDATE empass set pass=LPAD(%s,%s,'0') where emp_no=%s" + data=(password,lp,emp_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + print("Password changed successfully!!!") + break + else: + break \ No newline at end of file diff --git a/fireemployee.py b/src/main/OmJShah/admin/fireemployee.py similarity index 75% rename from fireemployee.py rename to src/main/OmJShah/admin/fireemployee.py index 0881743..7f5a360 100644 --- a/fireemployee.py +++ b/src/main/OmJShah/admin/fireemployee.py @@ -1,13 +1,5 @@ import mysql.connector -import pickle -def ap2(): - cred = open("cred.dat","rb") - dat=pickle.load(cred) - cred.close() - Passwo=dat[0] - Databa=dat[1] - conn=mysql.connector.connect(host="localhost",user="root",password=Passwo,database=Databa) - cur=conn.cursor() +def ap2(conn,cur): print("---------Fire employee process----------\n") while True: emp_no=input(("Enter emp_no of the employee to fire them: ")) @@ -23,22 +15,23 @@ def ap2(): print("Maximum length is 5!") query="delete from employees where emp_no = {}".format(emp_no) + query2="delete from empass where emp_no = {}".format(emp_no) cur.execute("select emp_no from employees") record=cur.fetchall() changed=False for r in record: if r[0]==emp_no: try: + cur.execute(query2) + conn.commit() cur.execute(query) conn.commit() changed=True except mysql.connector.Error as err: print(err.msg) - print("-----------Value addition was unsuccessful!!!!-------------\n") + print("-----------Value deletion was unsuccessful!!!!-------------\n") else: print("Employee fired successfully...\n") if not changed: print("The employee number does not exist.") - print("------------Could not fire employee-----------\n") - cur.close() - conn.close() \ No newline at end of file + print("------------Could not fire employee-----------\n") \ No newline at end of file diff --git a/src/main/OmJShah/admin/hireemployee.py b/src/main/OmJShah/admin/hireemployee.py new file mode 100644 index 0000000..fed7e35 --- /dev/null +++ b/src/main/OmJShah/admin/hireemployee.py @@ -0,0 +1,49 @@ +import mysql.connector +from tools import dataentering + +def ap1(query,cur): + print("-------------Hire Employee Process-------------") + +#Employee number + emp_no=dataentering.primary_key_no("emp_no") +#Employee Birth date + birth_date=dataentering.birthdate("employee",20,60) +#Employee name + first_name,last_name=dataentering.fname(),dataentering.lname() +#Employee Gender + gender=dataentering.gender() +#Employee hire date + hire_date=dataentering.date2("Employee",birth_date,"hire",20,60) + + + print("=========== Final Data ===========") + print(emp_no,birth_date,first_name,last_name,gender,hire_date) + add_employee=("INSERT INTO employees " + "(emp_no,birth_date,first_name,last_name,gender,hire_date) " + "VALUES (%s,%s,%s,%s,%s,%s)") + data_employee=(emp_no,birth_date,first_name,last_name,gender,hire_date) + try: + cur.execute(add_employee, data_employee) + query.commit() + except mysql.connector.Error as err: + print(err.msg) + print("-----------Value addition was unsuccessful!!!!-------------") + else: + print("Values added successfully!!") + while True: + password=input("Enter employee login password(max 8 characters, min 4): ") + lp=len(password) + if lp>8: + print("Max 8 characters only.") + elif lp<4: + print("Minimum 4 characters to be entered.") + else: + try: + cur.execute("INSERT INTO empass values({},LPAD({},{},'0'))".format(emp_no,password,lp)) + query.commit() + except mysql.connector.Error as err: + print(err.msg) + print("-----------Password addition was unsuccessful!!!!-------------") + else: + print("Password added successfully!!!") + break diff --git a/src/main/OmJShah/admin/showemployee.py b/src/main/OmJShah/admin/showemployee.py new file mode 100644 index 0000000..fa89c0d --- /dev/null +++ b/src/main/OmJShah/admin/showemployee.py @@ -0,0 +1,9 @@ +def ap4(cur): + cur.execute("select * from employees") + results=cur.fetchall() + print("+---------+-------------+------------------+------------------+---------+-------------+") + print("|","%7s"%"EMP_NO","|","%11s"%"BIRTH_DATE","|","%16s"%"FIRST_NAME","|","%16s"%"LAST_NAME","|","%7s"%"GENDER","|","%11s"%"HIRE_DATE","|") + for row in results: + print("+---------+-------------+------------------+------------------+---------+-------------+") + print("|","%7s"%row[0],"|","%11s"%row[1],"|","%16s"%row[2],"|","%16s"%row[3],"|","%7s"%row[4],"|","%11s"%row[5],"|") + print("+---------+-------------+------------------+------------------+---------+-------------+") \ No newline at end of file diff --git a/src/main/OmJShah/client/depositmoney.py b/src/main/OmJShah/client/depositmoney.py new file mode 100644 index 0000000..0ddf3d7 --- /dev/null +++ b/src/main/OmJShah/client/depositmoney.py @@ -0,0 +1,27 @@ +from tools import dataentering +def cp2(conn,cur,acc_type,acc_no): + cash_in_hand=dataentering.handcash(conn,cur,acc_no) + + deposit_amt=dataentering.amounts("deposit",cash_in_hand,acc_type) + deposit_amt=deposit_amt[0] + if deposit_amt: + query2="update {} set balance = balance+%s where acc_no = %s".format(acc_type) + data2=(deposit_amt,acc_no) + done2=dataentering.tableupdate(conn,cur,query2,data2) + if done2: + query3="update cash_in_hand set cash_in_hand = cash_in_hand-%s where acc_no = %s" + data3=(cash_in_hand,acc_no) + done3=dataentering.tableupdate(conn,cur,query3,data3) + if done3: + print("Deposit of {} currency successful".format(deposit_amt)) + print() + else: + query2="update {} set balance = balance-%s where acc_no = %s".format(acc_type) + data2=(deposit_amt,acc_no) + done2=dataentering.tableupdate(conn,cur,query2,data2) + if done2: + print("Unable to subtract amount from cash_in_hand\n") + else: + print("Error while trying to add amount to balance.\n") + else: + pass \ No newline at end of file diff --git a/src/main/OmJShah/client/loan_od.py b/src/main/OmJShah/client/loan_od.py new file mode 100644 index 0000000..60ea87f --- /dev/null +++ b/src/main/OmJShah/client/loan_od.py @@ -0,0 +1,76 @@ +from tools import dataentering +def cp5(cur,acc_type,acc_no): + loan_or_od=None + if acc_type=="current": + loan_or_od="overdraft" + else: + loan_or_od="loan" + cur.execute("select {} from {} where acc_no={}".format(loan_or_od,acc_type,acc_no)) + a=cur.fetchall() + if a[0][0]=="NO" and acc_type=="savings": + loan_process() + elif a[0][0]=="NO" and acc_type=="current": + #TODO:Check status of pending overdraft request if any + print("Congratulations! You don't have any overdraft to repay.") + elif a[0][0]=="YES" and acc_type=="current": + cur.execute("select {}_amt from {} where acc_no={}".format(loan_or_od,loan_or_od,acc_no)) + od=cur.fetchall() + od=od[0][0] + print("Your remaining od amount is {}") + else: + print("You already have a loan pending to repay...") + cur.execute("select {}_amt,{}_type from {} where acc_no={}".format(loan_or_od,loan_or_od,loan_or_od,acc_no)) + loan=cur.fetchall() + loan_type=loan[0][1] + if loan_type=='PL':loan_type='Personal Loan' + if loan_type=='HL':loan_type='Health Loan' + if loan_type=='EL':loan_type='Education Loan' + if loan_type=='TL':loan_type='Term Loan' + else:loan_type='Business Loan' + loan_amt=loan[0][0] + print("Your remaining od amount is {} of loan type {}".format(loan_amt,loan_type)) + + +def loan_process(): + while True: + loan_amt=input("Enter loan amount: ") + try: + loan_amt=int(loan_amt) + except ValueError: + print("Loan amount should be an integer") + else: + print("Done OK") + break + + while True: + print() + print("1.Personal Loan") + print("2.Home Loan") + print("3.Education Loan") + print("4.Term Loan") + print("5.Business Loan") + print(" Input ~ to quit\n") + loan_type=input("Enter choice: ") + if loan_type=="1": + loan_type='PL' + break + elif loan_type=="2": + loan_type='HL' + break + elif loan_type=="3": + loan_type='EL' + break + elif loan_type=="4": + loan_type='TL' + break + elif loan_type=="5": + loan_type='BL' + break + elif loan_type=="~": + break + else: + print("Wrong Input!!") + + if loan_type!="~": + return loan_amt,loan_type + #TODO: Add a method to store requests in dat file or csv file... diff --git a/src/main/OmJShah/client/redeemcode.py b/src/main/OmJShah/client/redeemcode.py new file mode 100644 index 0000000..1b39543 --- /dev/null +++ b/src/main/OmJShah/client/redeemcode.py @@ -0,0 +1,13 @@ +from tools import dataentering +def cp4(conn,cur,acc_type,acc_no): + rc=input("Enter redeem code: ") + if rc=="TESTREDEEMCODE": + query="update {} set balance = balance+%s where acc_no = %s".format(acc_type) + data=(5000,acc_no) + done = dataentering.tableupdate(conn,cur,query,data) + if done: + print("Added 5000 currency to your account!!") + else: + print("There was a problem while processing the request") + else: + print("Sorry! This redeem code doesn't work") \ No newline at end of file diff --git a/src/main/OmJShah/client/transfermoney.py b/src/main/OmJShah/client/transfermoney.py new file mode 100644 index 0000000..c9cec87 --- /dev/null +++ b/src/main/OmJShah/client/transfermoney.py @@ -0,0 +1,49 @@ +from tools import dataentering +def cp6(conn,cur,acc_type,acc_no,balance): + acc_to_transfer=dataentering.primary_key_no("acc_no of receiver") + cur.execute("select * from clients where acc_no={}".format(acc_to_transfer)) + result=cur.fetchall() + if result==[]: + print("That account number doesn't exist\n") + elif acc_to_transfer==acc_no: + print("You can't transfer to yourself\n") + else: + acc_type_receiver=result[0][1] + if acc_type_receiver == 'S': acc_type_receiver="savings" + if acc_type_receiver == 'C': acc_type_receiver="current" + fname,lname=result[0][2],result[0][3] + transfer_amt,overdraft=dataentering.amounts("transfer",balance,acc_type) + print(" Y - Yes") + print(" N - No") + ch=input("Do you want transfer {} currency to {} {}'s account: ".format(transfer_amt,fname,lname)) + if ch == "Y" : + + if transfer_amt: + if acc_type=="current": + if overdraft!=None: + print('''You will be notified about the overdraft status when an employee + sanctions your overdraft...''') + #TODO:some more stuff + else: + query="update {} set balance=balance-%s where acc_no = %s".format(acc_type) + data=(transfer_amt,acc_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + query2="update {} set balance=balance+%s where acc_no=%s".format(acc_type_receiver) + data2=(transfer_amt,acc_to_transfer) + done2=dataentering.tableupdate(conn,cur,query2,data2) + if done2: + print("Successfully transferred {} currency\n".format(transfer_amt)) + else: + query="update {} set balance=balance+%s where acc_no = %s".format(acc_type) + data=(transfer_amt,acc_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + print("Couldn't update receiver's balance\n") + else: + print("Couldn't transfer money.") + else : + print("You do not have enough balance!!") + + else: + print("Cancelled transfer") \ No newline at end of file diff --git a/src/main/OmJShah/client/withdrawmoney.py b/src/main/OmJShah/client/withdrawmoney.py new file mode 100644 index 0000000..158b859 --- /dev/null +++ b/src/main/OmJShah/client/withdrawmoney.py @@ -0,0 +1,28 @@ +from tools import dataentering +def cp3(conn,cur,acc_type,acc_no): + cur.execute("select balance from {} where acc_no={}".format(acc_type,acc_no)) + balance=cur.fetchall() + balance=balance[0][0] + withdraw_amt=dataentering.amounts("withdraw",balance,acc_type) + withdraw_amt=withdraw_amt[0] + if withdraw_amt: + query="update {} set balance = balance-%s where acc_no=%s".format(acc_type) + data=(withdraw_amt,acc_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + query2="update cash_in_hand set cash_in_hand=cash_in_hand+%s where acc_no=%s" + data2=(withdraw_amt,acc_no) + done2=dataentering.tableupdate(conn,cur,query2,data2) + if done2: + print("Successfully withdrawn {} currency".format(withdraw_amt)) + print() + else: + query="update {} set balance = balance+%s where acc_no=%s".format(acc_type) + data=(withdraw_amt,acc_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + print("Couldn't remove money from cash_in_hand\n") + else: + print("couldn't update balance\n") + else: + print("Couldn't withdraw amount\n") \ No newline at end of file diff --git a/src/main/OmJShah/employee/createaccount.py b/src/main/OmJShah/employee/createaccount.py new file mode 100644 index 0000000..fb37626 --- /dev/null +++ b/src/main/OmJShah/employee/createaccount.py @@ -0,0 +1,75 @@ +from tools import dataentering + +def ep1(query,cur): + print("-------------Create account Process-------------") + +#client number + acc_no=dataentering.primary_key_no("acc_no") +#client Birth date + birth_date=dataentering.birthdate("Client",10,100) +#client name + first_name,last_name=dataentering.fname(),dataentering.lname() +#client Gender + gender=dataentering.gender() +#client Account Type + while True: + print("1.Savings account") + print("2.Current account") + a=input("Enter choice (1 or 2):") + if a== '1': + acc_type='S' + break + elif a=='2': + acc_type='C' + break + else: + print("Wrong input!!") + +#Account creation date + acc_creation_date=dataentering.date2("client",birth_date,"account_creation",10,100) +#client password/pin + password,lp=dataentering.clientpassword() + +#mobile no + mobile_no,lmn=dataentering.mobileno() + +#email-id + email_id=dataentering.email() + + print("=========== Final Data ===========") + print(acc_no,acc_type,first_name,last_name,gender,birth_date,acc_creation_date,mobile_no,email_id,password) + add_client=("INSERT INTO clients " + "(acc_no,type,first_name,last_name,gender,birth_date,accd,mobile_no,email_id,pass) " + "VALUES (%s,%s,%s,%s,%s,%s,%s,LPAD(%s,%s,'0'),%s,LPAD(%s,%s,'0'))") + data_client=(acc_no,acc_type,first_name,last_name,gender,birth_date,acc_creation_date,mobile_no,lmn,email_id,password,lp) + + done=dataentering.tableupdate(query,cur,add_client,data_client) + if done: + if acc_type=='S': + bank_balance=dataentering.balance() + add_savings=("INSERT INTO SAVINGS VALUES(%s,%s,'NO')") + data_savings=(acc_no,bank_balance) + done2=dataentering.tableupdate(query,cur,add_savings,data_savings) + if done2: + pass + else: + print("Unable to add to savings table.") + print("Deleting from main table.......") + delete_client=("delete from clients where acc_no = %s") + data_delete_client=(acc_no) + done=dataentering.tableupdate(query,cur,delete_client,data_delete_client) + else: + bank_balance=dataentering.balance() + add_current=("INSERT INTO current VALUES(%s,%s,'NO')") + data_current=(acc_no,bank_balance) + done2=dataentering.tableupdate(query,cur,add_current,data_current) + if done2: + pass + else: + print("Unable to add to savings table.") + print("Deleting from main table.......") + delete_client=("delete from clients where acc_no = %s") + data_delete_client=(acc_no) + done=dataentering.tableupdate(query,cur,delete_client,data_delete_client) + + print("Values added successfully!!") \ No newline at end of file diff --git a/src/main/OmJShah/employee/deleteaccount.py b/src/main/OmJShah/employee/deleteaccount.py new file mode 100644 index 0000000..9f57fdb --- /dev/null +++ b/src/main/OmJShah/employee/deleteaccount.py @@ -0,0 +1,63 @@ +from tools import dataentering + +acc_no=None +def ep3(conn,cur): + global acc_no + while True: + print("\n----------------Account Deleteion Menu-----------------\n") + print("input ~ to quit") + acc_no=input("Enter acc_no (max 5 int) to DELETE THE ACCOUNT: ") + if acc_no=="~": break + elif len(acc_no) <= 5: + try: + acc_no=int(acc_no) + print("Done OK") + except ValueError: + print("acc_no should be an integer!!") + else: + print("Maximum length is 5!") + cur.execute("select * from clients where acc_no={}".format(acc_no)) + results=cur.fetchall() + if len(results)==0: + print("That account number does not exist.") + else : + results1=results[0] + acc_type=results1[1] + if acc_type == 'S': + loan_or_od="loan" + acc_type="savings" + if acc_type == 'C': + loan_or_od="overdraft" + acc_type="current" + cur.execute("select {} from {} where acc_no={}".format(loan_or_od,acc_type,acc_no)) + status=cur.fetchall() + status=status[0][0] + first_name=results1[2] + last_name=results1[3] + if status == "YES": + print("The Client {} {} has {} money to repay".format(first_name,last_name,loan_or_od)) + print("The account can't be deleted until {} is repayed".format(loan_or_od)) + break + else: + print(first_name,last_name,"found.") + print(" Y - Deletes the account") + print(" N - Cancel process") + print("It's case sensitive") + choice=input("Do you really wish to delete the account of {} {}: ".format(first_name,last_name)) + if choice == "Y": + query="delete from clients where acc_no = %s" + data=(acc_no,) + query2="delete from {} where acc_no = %s".format(acc_type) + data2=(acc_no,) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + done2=dataentering.tableupdate(conn,cur,query2,data2) + if done2: + print("Deleted {} {}'s account.".format(first_name,last_name)) + break + else: + print("Deletion from {} table was unsuccessful".format(acc_type)) + else: + print("Deletion was unsuccessful") + else: + break diff --git a/src/main/OmJShah/employee/editaccount.py b/src/main/OmJShah/employee/editaccount.py new file mode 100644 index 0000000..cf290ef --- /dev/null +++ b/src/main/OmJShah/employee/editaccount.py @@ -0,0 +1,154 @@ +from datetime import date +from tools import dataentering + +acc_no=None +first_name=None +last_name=None +gender=None +birth_date=None +acc_creation_date=None +mobile_no=None +email_id=None +password = None + +def age(birthdate): + today = date.today() + age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day)) + return age + +def ep2(conn,cur): + global acc_no,first_name,last_name,gender,birth_date,acc_creation_date,mobile_no,email_id,password + while True: + print("\ninput ~ to quit") + acc_no=input("Enter acc_no (max 5 int) to edit details: ") + if acc_no=="~": break + elif len(acc_no) <= 5: + try: + acc_no=int(acc_no) + print("Done OK") + except ValueError: + print("acc_no should be an integer!!") + else: + print("Maximum length is 5!") + cur.execute("select * from clients where acc_no={}".format(acc_no)) + results=cur.fetchall() + if len(results)==0: + print("That account number does not exist.") + else: + results1=results[0] + first_name=results1[2] + last_name=results1[3] + gender=results1[4] + birth_date=results1[5] + acc_creation_date=results1[6] + mobile_no=results1[7] + email_id=results1[8] + password=results1[9] + + print("1. first_name = ",first_name) + print("2. last_name = ",last_name) + print("3. gender = ",gender) + print("4. birth_date = ",birth_date) + print("5. account_creation_date = ",acc_creation_date) + print("6. mobile_no = ",mobile_no) + print("7. email_id = ",email_id) + print("8. password") + print("0 to quit") + ep2f2(conn,cur) + +def ep2f2(conn,cur): + global acc_no,first_name,last_name,gender,birth_date,acc_creation_date,mobile_no,email_id,password + choice=input("What would you like to change from here: ") +#First-name + if choice == "1": + first_name=dataentering.fname() + query="update clients set first_name=%s where acc_no=%s" + data=(first_name,acc_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + print("Updated first name") + +#Last-name + elif choice == "2": + last_name=dataentering.lname() + query="update clients set last_name=%s where acc_no=%s" + data=(last_name,acc_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + print("Updated last name") + +#Gender + elif choice == "3": + gender=dataentering.gender() + query="update clients set gender=%s where acc_no=%s" + data=(gender,acc_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + print("Updated gender") + +#Birth-date + elif choice == "4": + birth_date=dataentering.birthdate("Client",10,100) + if age(birth_date)-age(acc_creation_date)>=10: + query="update clients set birth_date=%s where acc_no=%s" + data=(birth_date,acc_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + print("Updated birth date") + else: + print("The client should atleast be 10 years of age.") + print("Birth date:",birth_date) + print("Account Creation Date:",acc_creation_date) + +#Account-creation-date(accd) + elif choice == "5": + acc_creation_date=dataentering.date2("client",birth_date,"account_creation",10,100) + query="update clients set accd=%s where acc_no=%s" + data=(acc_creation_date,acc_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + print("Updated account creation date") + +#Mobile No + elif choice == "6": + mobile_no,lmn=dataentering.mobileno() + query="update clients set mobile_no=LPAD(%s,%s,'0') where acc_no=%s" + data=(mobile_no,lmn,acc_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + print("Updated mobile number") + +#Email ID + elif choice == "7": + email_id=dataentering.email() + query="update clients set email=%s where acc_no=%s" + data=(mobile_no,acc_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + print("Updated mobile number") +#Password + elif choice == "8": + while True: + print("1.Show Password") + print("2.Change Password") + print("0 to quit") + choice=input("Enter choice: ") + if choice == "1": + print("\nThe password will be printed on the next line") + print(password) + print() + elif choice == "2": + password,lp=dataentering.clientpassword() + query="update clients set pass=LPAD(%s,%s,'0') where acc_no=%s" + data=(password,lp,acc_no) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + print("Updated password") + elif choice == "0": + break + else: + print("Wrong input!!") + elif choice == "0": + pass + else: + print("Wrong input!!") \ No newline at end of file diff --git a/src/main/OmJShah/employee/showaccounts.py b/src/main/OmJShah/employee/showaccounts.py new file mode 100644 index 0000000..97def00 --- /dev/null +++ b/src/main/OmJShah/employee/showaccounts.py @@ -0,0 +1,11 @@ +from tools import dataentering + +def ep4(cur): + cur.execute("select * from clients") + results=cur.fetchall() + print("+---------+-------+------------------+------------------+---------+-------------+-------------+------------------+---------------------------+") + print("|","%7s"%"ACC_NO","|","%5s"%"TYPE","|","%16s"%"FIRST_NAME","|","%16s"%"LAST_NAME","|","%7s"%"GENDER","|","%11s"%"BIRTH_DATE","|","%11s"%"ACCD","|","%16s"%"MOBILE_NO","|","%25s"%"EMAIL_ID","|") + for row in results: + print("+---------+-------+------------------+------------------+---------+-------------+-------------+------------------+---------------------------+") + print("|","%7s"%row[0],"|","%5s"%row[1],"|","%16s"%row[2],"|","%16s"%row[3],"|","%7s"%row[4],"|","%11s"%row[5],"|","%11s"%row[6],"|","%16s"%row[7],"|","%25s"%row[8],"|") + print("+---------+-------+------------------+------------------+---------+-------------+-------------+------------------+---------------------------+") diff --git a/src/main/OmJShah/initialization/check.py b/src/main/OmJShah/initialization/check.py new file mode 100644 index 0000000..69b4620 --- /dev/null +++ b/src/main/OmJShah/initialization/check.py @@ -0,0 +1,11 @@ +def check(): + try: + with open("files//firsttime.txt","r") as a: + if a.read().strip()=="True": + return True + else: + return False + except FileNotFoundError: + with open("files//firsttime.txt","w") as a: + a.write("True") + return True \ No newline at end of file diff --git a/setup.py b/src/main/OmJShah/initialization/setup.py similarity index 77% rename from setup.py rename to src/main/OmJShah/initialization/setup.py index 8c04424..ba40e73 100644 --- a/setup.py +++ b/src/main/OmJShah/initialization/setup.py @@ -1,10 +1,14 @@ -import check +from initialization import check import pickle import mysql.connector from mysql.connector import errorcode existing=0 + +conn=None +cursor=None + TABLES = {} TABLES['employees'] = ( "CREATE TABLE `employees` (" @@ -19,25 +23,34 @@ TABLES['clients'] = ( "CREATE TABLE `clients` (" - " `acc_no` int(5) NOT NULL PRIMARY KEY," - " `acc_type` enum('S','C') NOT NULL," + " `acc_no` int NOT NULL PRIMARY KEY," + " `type` enum('S','C') NOT NULL," " `first_name` varchar(15) NOT NULL," " `last_name` varchar(15) NOT NULL," " `gender` enum('M','F') NOT NULL," " `birth_date` date NOT NULL," - " `acc_creation_date` date NOT NULL," - " `mobile_no` int(10) NOT NULL," - " `email_id` varchar(25) NOT NULL" + " `accd` date NOT NULL," + " `mobile_no` varchar(20) NOT NULL," + " `email_id` varchar(25) NOT NULL," + " `pass` varchar(8) NOT NULL" ") " ) +TABLES['empass'] = ( + "CREATE TABLE `empass` (" + " `emp_no` int(5) NOT NULL," + " `pass` varchar(8) NOT NULL," + " PRIMARY KEY (`emp_no`)" + ") " +) + + TABLES['savings'] = ( "CREATE TABLE `savings` (" " `acc_no` int(5) NOT NULL," " `balance` int NOT NULL," " `loan` enum('YES','NO') NOT NULL," - " PRIMARY KEY (`acc_no`)," - " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" + " PRIMARY KEY (`acc_no`)" ") " ) @@ -45,9 +58,8 @@ "CREATE TABLE `current` (" " `acc_no` int(5) NOT NULL," " `balance` int NOT NULL," - " `overdraft` int NOT NULL," - " PRIMARY KEY (`acc_no`)," - " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" + " `overdraft` enum('YES','NO') NOT NULL," + " PRIMARY KEY (`acc_no`)" ") " ) @@ -60,8 +72,7 @@ " `iterest_perc_per_annum` int(1) NOT NULL," " `amt-per-month` int NOT NULL," " `remaining_amt` int NOT NULL," - " PRIMARY KEY (`acc_no`)," - " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" + " PRIMARY KEY (`acc_no`)" ") " ) @@ -70,8 +81,15 @@ " `acc_no` int(5) NOT NULL," " `overdraft_amt` int NOT NULL," " `od_with_interest_remaining` int NOT NULL," - " PRIMARY KEY (`acc_no`)," - " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" + " PRIMARY KEY (`acc_no`)" + ") " +) + +TABLES['cash_in_hand']=( + "CREATE TABLE `cash_in_hand` (" + " `acc_no` int(5) NOT NULL," + " `cash_in_hand` int NOT NULL," + " PRIMARY KEY (`acc_no`)" ") " ) @@ -82,7 +100,7 @@ Database="" def sqlpwd(): global Password - cred = open("cred.dat","rb") + cred = open("files//cred.dat","rb") dat=pickle.load(cred) cred.close() Password=dat[0] @@ -90,7 +108,7 @@ def sqlpwd(): def sqldb(): global Database - cred = open("cred.dat","rb") + cred = open("files//cred.dat","rb") dat=pickle.load(cred) cred.close() Database=dat[1] @@ -108,6 +126,8 @@ def connectionquery(): return query def querycheck(): + global conn + global cursor global existing conn=connectionquery() ans=False @@ -122,17 +142,19 @@ def querycheck(): try: print("Creating table {}: ".format(table_name), end='') cursor.execute(table_description) + existing+=1 except mysql.connector.Error as err: if err.errno == errorcode.ER_TABLE_EXISTS_ERROR: print("already exists.") existing+=1 else: - print(err.msg()) + print(err.msg) else: print("OK") - with open("firsttime.txt","w") as f: - f.write("False") - ans=True + if existing==8: + with open("files//firsttime.txt","w") as f: + f.write("False") + ans=True if not ans: print("There was a problem in connection") @@ -145,13 +167,15 @@ def mysqlsetup(): print("Create a database in your MYSQL Workbench.\n") Database=input("Enter database name: ") Password=input("Enter sql password (enter '' if nothing):") - cred2= open("cred.dat","wb") + cred2= open("files//cred.dat","wb") data=[Password,Database] pickle.dump(data,cred2) cred2.close() querycheck() def setup(): + global cursor + global conn global existing while check.check(): print("\n\n-----------------Welcome to the Project!!!-------------------") @@ -163,16 +187,14 @@ def setup(): ans2=input("How do you want to store the data? (1/2): ") if ans2 == "0": break - if ans2=="1": + elif ans2=="1": mysqlsetup() - if existing==6: - with open("firsttime.txt","w") as f: - f.write("False") + if existing==7: continue - if ans2=="2": + elif ans2=="2": print("\nThis is under development :). Please use mysql till then...") - elif ans2 != "1" or ans2 != "2": + else: print("\nWrong input, (1/2).........") else: if querycheck(): - connectionquery() + return True \ No newline at end of file diff --git a/src/main/OmJShah/main.py b/src/main/OmJShah/main.py new file mode 100644 index 0000000..40fdd60 --- /dev/null +++ b/src/main/OmJShah/main.py @@ -0,0 +1,20 @@ +from initialization import setup +from initialization import check +from panels import accounttype +from tools import connection +while True: + print("1.Continue") + print("2.Quit") + a=input("Enter your choice(1,2): ") + if a == "1": + if not check.check(): + query,cur=connection.cc() + accounttype.acctype(query,cur) + break + else: + setup.setup() + elif a == "2": + print("Shutting down the program") + break + else: + print("Wrong input.") \ No newline at end of file diff --git a/accounttype.py b/src/main/OmJShah/panels/accounttype.py similarity index 70% rename from accounttype.py rename to src/main/OmJShah/panels/accounttype.py index ea63a0a..bdcae35 100644 --- a/accounttype.py +++ b/src/main/OmJShah/panels/accounttype.py @@ -1,31 +1,33 @@ -import adminpanel -def acctype(): +from panels import adminpanel +from panels import employeepanel +from panels import clientpanel +def acctype(query,cur): while True: print("--------------Account Selector Menu--------------") print("1.Admin.") print("2.Employee.") print("3.Client.") - print("Enter 0 to end process.") + print("Enter ~ to end process.") a=input("\nEnter your account type:") if a=='1': b=input("\nEnter admin password:") if b=="admin123": - adminpanel.ap() + adminpanel.ap(query,cur) else: print("\nWrong password!\n") elif a=='2': b=input("\nEnter employee password:") if b=="emp123": - return 2 + employeepanel.ep(query,cur) else: print("\nWrong password!\n") elif a=='3': - return 3 + clientpanel.cp(query,cur) - elif a=='0': + elif a=='~': print("\nShutting down the program.") break diff --git a/adminpanel.py b/src/main/OmJShah/panels/adminpanel.py similarity index 64% rename from adminpanel.py rename to src/main/OmJShah/panels/adminpanel.py index 6650314..612eb24 100644 --- a/adminpanel.py +++ b/src/main/OmJShah/panels/adminpanel.py @@ -1,9 +1,8 @@ -import hireemployee -import fireemployee -import editemployee -import showemployee - -def ap(): +from admin import hireemployee +from admin import fireemployee +from admin import editemployee +from admin import showemployee +def ap(query,conn): print("\nWelcome Admin!!") while True: @@ -15,13 +14,13 @@ def ap(): print("\nInput 0 to quit.") a=input("Enter choice:") if a=='1': - hireemployee.ap1() + hireemployee.ap1(query,conn) elif a=='2': - fireemployee.ap2() + fireemployee.ap2(query,conn) elif a=='3': - editemployee.ap3() + editemployee.ap3(query,conn) elif a=='4': - showemployee.ap4() + showemployee.ap4(conn) elif a=='0': print("Quit Admin Panel.") break diff --git a/src/main/OmJShah/panels/clientpanel.py b/src/main/OmJShah/panels/clientpanel.py new file mode 100644 index 0000000..597ad57 --- /dev/null +++ b/src/main/OmJShah/panels/clientpanel.py @@ -0,0 +1,65 @@ +from tools import dataentering +from client import redeemcode +from client import depositmoney +from client import withdrawmoney +from client import loan_od +from client import transfermoney +def cp(conn,cur): + print("\n------------------Client Panel------------------") + print("Welcome client!!") + acc_no=dataentering.primary_key_no("acc_no") + cur.execute("select first_name,last_name,pass,type from clients where acc_no = {}".format(acc_no)) + result=cur.fetchall() + if result == []: + print("No account holder with this account number.") + else: + acc_type=result[0][3] + if acc_type == 'S': acc_type="savings" + if acc_type == 'C': acc_type="current" + while True: + print("\nInput ~ to quit") + passwd=input("Enter password to continue: ") + if passwd == "~": + break + elif passwd == result[0][2]: + print("\n--------------------Welcome {} {}-------------------".format(result[0][0],result[0][1])) + cmenu(conn,cur,acc_no,acc_type) + else: + print("Wrong password") + +def cmenu(conn,cur,acc_no,acc_type): + cash_in_hand=dataentering.handcash(conn,cur,acc_no) + print("\n Your Cash_In_Hand is {} currency".format(cash_in_hand)) + print() + print("1.Show Balance") + print("2.Deposit money") + print("3.Withdraw money") + print("4.Redeem Code") + if acc_type=='savings': + print("5.Ask for loan / Check loan status") + else: + print("5.Check overdraft status") + print("6.Transfer money to other account") + print("~ to quit") + choice=input("Enter your choice: ") + if choice=="~": pass + elif choice=="1": + cur.execute("select balance from {} where acc_no={}".format(acc_type,acc_no)) + balance=cur.fetchall() + print("Your balance is: ",balance[0][0]) + print() + elif choice=="2": + depositmoney.cp2(conn,cur,acc_type,acc_no) + elif choice=="3": + withdrawmoney.cp3(conn,cur,acc_type,acc_no) + elif choice=="4": + redeemcode.cp4(conn,cur,acc_type,acc_no) + elif choice=="5": + loan_od.cp5(cur,acc_type,acc_no) + elif choice=="6": + cur.execute("select balance from {} where acc_no={}".format(acc_type,acc_no)) + balance=cur.fetchall() + balance=balance[0][0] + transfermoney.cp6(conn,cur,acc_type,acc_no,balance) + else: + print("Wrong input!!!!\n") diff --git a/src/main/OmJShah/panels/employeepanel.py b/src/main/OmJShah/panels/employeepanel.py new file mode 100644 index 0000000..91cba8b --- /dev/null +++ b/src/main/OmJShah/panels/employeepanel.py @@ -0,0 +1,74 @@ +from employee import createaccount +from employee import editaccount +from employee import deleteaccount +from employee import showaccounts + +def ep(conn,cur): + print("\nWelcome employee!!") + print("Please log in with your creds (emp_id and password):") + print("---------------------Employee Panel--------------------") + print("1.Employee login.") + print("2.Quit.") + ch = input("Enter your choice:") + logged_in= bool(False) + if ch == "1": + print("------------login panel-------------") + logged_in=bool(True) + elif ch == "2": + pass + else: + print("Wrong input!!!(1 or 2 only)") + if logged_in: + while True: + emp_no=input("Enter emp_no (max 5 int): ") + if len(emp_no) <= 5: + try: + emp_no=int(emp_no) + print("Done OK") + except ValueError: + print("emp_no should be an integer!!") + else: + break + else: + print("Maximum length is 5!") + + cur.execute("select * from empass where emp_no = {}".format(emp_no)) + record=cur.fetchall() + if record == []: + print("This emp_no doesn't exist!!!") + else: + while True: + password=record[0][1] + print("\nInput ~ to quit.") + a=input("Enter your password to continue:") + print() + if a==password: + choice=menu(emp_no,cur) + if choice=="1": + createaccount.ep1(conn,cur) + elif choice=="2": + editaccount.ep2(conn,cur) + elif choice=="3": + deleteaccount.ep3(conn,cur) + elif choice=="4": + showaccounts.ep4(cur) + elif choice=="0": + break + else: + print("Wrong input!") + elif a == "~" : break + else: + print("Wrong password!!") + break + +def menu(x,cur): + cur.execute("select first_name,last_name from employees where emp_no = {}".format(x)) + record=cur.fetchone() + print("---------------Welcome {} {} ----------------".format(record[0],record[1])) + print("1.Create client account") + print("2.Change client details") + print("3.Close client account") + print("4.Show client table") + print("Enter 0 to quit.") + choice=input("Enter your choice: ") + return choice \ No newline at end of file diff --git a/src/main/OmJShah/tests.py b/src/main/OmJShah/tests.py new file mode 100644 index 0000000..163a11a --- /dev/null +++ b/src/main/OmJShah/tests.py @@ -0,0 +1,6 @@ +file=open("files//config.txt","r") +x=file.read() +print(x) +#alter table current modify column overdraft enum('YES','NO'); +#alter table current drop foreign key current_ibfk_1; +#alter table savings drop foreign key savings_ibfk_1; \ No newline at end of file diff --git a/src/main/OmJShah/tools/connection.py b/src/main/OmJShah/tools/connection.py new file mode 100644 index 0000000..4e5d229 --- /dev/null +++ b/src/main/OmJShah/tools/connection.py @@ -0,0 +1,17 @@ +from initialization import check +import mysql.connector +import pickle +def cc(): + global cur + global conn + if not check.check(): + cred = open("files//cred.dat","rb") + dat=pickle.load(cred) + cred.close() + Passwo=dat[0] + Databa=dat[1] + conn=mysql.connector.connect(host="localhost",user="root",password=Passwo,database=Databa) + cur=conn.cursor() + return conn,cur + else: + return 0,0 \ No newline at end of file diff --git a/src/main/OmJShah/tools/dataentering.py b/src/main/OmJShah/tools/dataentering.py new file mode 100644 index 0000000..0f89da1 --- /dev/null +++ b/src/main/OmJShah/tools/dataentering.py @@ -0,0 +1,285 @@ +from datetime import date +import mysql.connector + +def age(birthdate): + today = date.today() + age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day)) + return age + + +def primary_key_no(x): +#Employee number and client number + while True: + emp_no=input("Enter {} (max 5 int): ".format(x)) + if len(emp_no) <= 5: + try: + emp_no=int(emp_no) + print("Done OK") + except ValueError: + print("{} should be an integer!!".format(x)) + else: + return emp_no + else: + print("Maximum length is 5!") + +def birthdate(person,minage,maxage): +#Employee Birth date and client birth date + while True: + while True: + year=input("Enter birth year (4 int): ") + if len(year) == 4: + try: + year=int(year) + print("Done OK") + except ValueError: + print("year should be an integer!!") + else: + break + else: + print("Year consists of 4 integers!!") + + while True: + month=input("Enter birth month (2 int) (01 to 12): ") + if len(month) == 2: + try: + month=int(month) + print("Done OK") + except ValueError: + print("month should be an integer!!") + else: + break + else: + print("Month consists of 2 integers!!") + + while True: + day=input("Enter birth day (2 int) : ") + if len(day) == 2: + try: + day=int(day) + print("Done OK") + except ValueError: + print("Date should be an integer!!") + else: + break + else: + print("Date consists of 2 integers!!") + + try: + birth_date=date(year,month,day) + except ValueError: + import traceback + traceback.print_exc() + else: + if age(birth_date)>=minage and age(birth_date)<=maxage: + return birth_date + else: + if age(birth_date)<minage: + print("{} must be atleast {} years of age!!".format(person,minage)) + else: + print("Maximum age is {} years!!!".format(maxage)) + print("\nwrong input\n") + +def fname(): +#Employee name and client name + while True: + first_name=input("Enter first name (max 15 char): ") + if len(first_name)<= 15: + break + else: + print("Max 15 characters") + return first_name + +def lname(): + while True: + last_name=input("Enter last name (max 15 char): ") + if len(last_name)<= 15: + break + else: + print("Max 15 characters") + + return last_name + +def gender(): +#Employee Gender and client gender + while True: + print("1.Male") + print("2.Female") + a=input("Enter choice (1 or 2):") + if a== '1': + gender='M' + break + elif a=='2': + gender='F' + break + else: + print("Wrong input!!") + return gender + +def date2(person,birth_date,hire_or_creation,minage,maxage): +#Employee hire date and account creation date + while True: + while True: + hyear=input("Enter {} year (4 int): ".format(hire_or_creation)) + if len(hyear) == 4: + try: + hyear=int(hyear) + print("Done OK") + except ValueError: + print("year should be an integer!!") + else: + break + else: + print("Year consists of 4 integers!!") + + while True: + hmonth=input("Enter {} month (2 int) (01 to 12): ".format(hire_or_creation)) + if len(hmonth) == 2: + try: + hmonth=int(hmonth) + print("Done OK") + except ValueError: + print("month should be an integer!!") + else: + break + else: + print("Month consists of 2 integers!!") + + while True: + hday=input("Enter {} day (2 int) (01 to 31): ".format(hire_or_creation)) + if len(hday) == 2: + try: + hday=int(hday) + print("Done OK") + except ValueError: + print("Date should be an integer!!") + else: + break + else: + print("Date consists of 2 integers!!") + + try: + hire_date=date(hyear,hmonth,hday) + except ValueError: + import traceback + traceback.print_exc() + else: + if age(hire_date)>maxage: + print("{} must be below {} years of age!!".format(person,maxage)) + elif age(birth_date)-age(hire_date)>=minage: + break + else: + print("{} must atleast be {} years of age!!".format(person,minage)) + return hire_date + +def mobileno(): + while True: + mobile_no_str=input("Enter mobile no. (7 to 15 int): ") + mobile_no=mobile_no_str + #Thanks to the international phone numbering plan (ITU-T E. 164), + #phone numbers cannot contain more than 15 digits. The shortest + #international phone numbers in use contain seven digits. + try: + mobile_no=int(mobile_no) + except ValueError: + print("mobile_no should be an integer!!") + else: + if len(mobile_no_str)>6 and len(mobile_no_str)<16: + mobile_no=mobile_no_str + lmn=len(mobile_no) + break + else: + print("Mobile number can have min 7 digits and max 15!!") + return mobile_no,lmn + +def email(): + while True: + email_id=input("Enter client Email ID (max 25 char): ") + if len(email_id)<26: + break + else: + print("Maximum 25 characters") + return email_id + +def clientpassword(): + while True: + password=input("Enter client login password(max 8 characters, min 4): ") + lp=len(password) + if lp>8: + print("Max 8 characters only.") + elif lp<4: + print("Minimum 4 characters to be entered.") + else: + break + return password,lp + +def tableupdate(conn,cur,query,data): + try: + cur.execute(query,data) + conn.commit() + except mysql.connector.Error as err: + print(err.msg) + print("-----------Value addition/deletion was unsuccessful!!!!-------------") + else: + return bool(True) + +#bank balance +def balance(): + while True: + bank_balance=input("Enter starting balance (min 1000 currency): ") + if len(bank_balance) >= 3: + try: + bank_balance=int(bank_balance) + print("Done OK") + except ValueError: + print("Balance should be an integer!!") + else: + if bank_balance>=1000: + return bank_balance + else: + print("Minimum balance is 1000 currency") + +#Withdraw amount and Deposit amount +def amounts(deposit_or_withdraw_or_transfer,cash_in_hand_or_balance,acc_type): + while True: + print() + print("--------------------{} screen-------------------".format(deposit_or_withdraw_or_transfer)) + amt=input("Enter amount to {}: ".format(deposit_or_withdraw_or_transfer)) + try: + amt=int(amt) + print("Done OK") + except ValueError: + print("{} amount should be an integer!!".format(deposit_or_withdraw_or_transfer)) + else: + if amt<=cash_in_hand_or_balance: + return amt,None + else: + if deposit_or_withdraw_or_transfer=="transfer": + if acc_type=="current": + overdraft=amt-cash_in_hand_or_balance + if (overdraft) <= 50000: + return amt,overdraft + else: + return bool(False),None + else: + print("You do not have enough balance\n") + else: + if deposit_or_withdraw_or_transfer=="deposit": + print("You do not have sufficient cash_in_hand\n") + else: + print("You do not have enough balance\n") + return bool(False),None + +def handcash(conn,cur,acc_no): + cur.execute("select cash_in_hand from cash_in_hand where acc_no={}".format(acc_no)) + cash_in_hand=cur.fetchall() + if cash_in_hand==[]: + query="insert into cash_in_hand values(%s,0)" + data=(acc_no,) + done=tableupdate(conn,cur,query,data) + if done: + cash_in_hand=0 + else: + print("Unable to figure out your cash in hand values.") + else: + cash_in_hand=cash_in_hand[0][0] + return cash_in_hand \ No newline at end of file