From 1df5a9918caa438b162af793390424f27c7ad3e5 Mon Sep 17 00:00:00 2001 From: Om Date: Sun, 4 Dec 2022 14:17:01 +0530 Subject: [PATCH 01/18] Tried to shorten code by shortening connection --- adminpanel.py | 13 ++++++------- connection.py | 13 +++++++++++++ editemployee.py | 25 ++++--------------------- employeepanel.py | 2 +- fireemployee.py | 14 ++------------ hireemployee.py | 24 +++++++++++++++--------- showemployee.py | 13 ++----------- 7 files changed, 43 insertions(+), 61 deletions(-) create mode 100644 connection.py diff --git a/adminpanel.py b/adminpanel.py index 6650314..a46431d 100644 --- a/adminpanel.py +++ b/adminpanel.py @@ -1,7 +1,4 @@ import hireemployee -import fireemployee -import editemployee -import showemployee def ap(): print("\nWelcome Admin!!") @@ -17,13 +14,15 @@ def ap(): if a=='1': hireemployee.ap1() elif a=='2': - fireemployee.ap2() + hireemployee.ap2() elif a=='3': - editemployee.ap3() + hireemployee.ap3() elif a=='4': - showemployee.ap4() + hireemployee.ap4() elif a=='0': print("Quit Admin Panel.") break else: - print("Wrong input!(1,2,3)") \ No newline at end of file + print("Wrong input!(1,2,3)") + +ap() \ No newline at end of file diff --git a/connection.py b/connection.py new file mode 100644 index 0000000..3fc55f4 --- /dev/null +++ b/connection.py @@ -0,0 +1,13 @@ +import mysql.connector +import pickle +def cc(): + 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() + return conn,cur \ No newline at end of file diff --git a/editemployee.py b/editemployee.py index 6c7381d..db3dc9b 100644 --- a/editemployee.py +++ b/editemployee.py @@ -6,23 +6,10 @@ 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() - +def ap3(conn,cur): global emp_no global birth_date global hire_date @@ -55,11 +42,9 @@ def ap3(): print("7.password") birth_date=results1[1] hire_date=results1[5] - f2() + f2(conn,cur) -def f2(): - global cur - global conn +def f2(conn,cur): global emp_no global birth_date global hire_date @@ -306,6 +291,4 @@ def f2(): print("-----------Password change was unsuccessful!!!!-------------") else: print("Password changed successfully!!!") - break - cur.close() - conn.close() \ No newline at end of file + break \ No newline at end of file diff --git a/employeepanel.py b/employeepanel.py index 22c5ead..d09ae8f 100644 --- a/employeepanel.py +++ b/employeepanel.py @@ -79,7 +79,7 @@ def menu(x): record=cur.fetchone() print("---------------Welcome {} {} ----------------".format(record[0],record[1])) print("1.Create client account") - print("2.Change client pin") + print("2.Change client details") print("3.Close client account") print("4.Show client table") print("Enter 0 to quit.") diff --git a/fireemployee.py b/fireemployee.py index 01f76cd..7f5a360 100644 --- a/fireemployee.py +++ b/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: ")) @@ -42,6 +34,4 @@ def ap2(): 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/hireemployee.py b/hireemployee.py index 9af8f14..b83a5ea 100644 --- a/hireemployee.py +++ b/hireemployee.py @@ -1,20 +1,16 @@ from datetime import date import pickle import mysql.connector +import connection def age(birthdate): today = date.today() age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day)) return age +query,cur=connection.cc() 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() + global query,cur print("-------------Hire Employee Process-------------") #Employee number @@ -198,5 +194,15 @@ def ap1(): else: print("Password added successfully!!!") break - cur.close() - query.close() \ No newline at end of file + +import editemployee +def ap3(): + editemployee.ap3(query,cur) + +import fireemployee +def ap2(): + fireemployee.ap2(query,cur) + +import showemployee +def ap4(): + showemployee.ap4(cur) \ No newline at end of file diff --git a/showemployee.py b/showemployee.py index d9b2016..eb26833 100644 --- a/showemployee.py +++ b/showemployee.py @@ -1,13 +1,6 @@ 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() + +def ap4(cur): cur.execute("select * from employees") results=cur.fetchall() print("+---------+-------------+------------------+------------------+---------+-------------+") @@ -15,6 +8,4 @@ def ap4(): 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 From c209b0ddc0a04756c59acb61a57dbe66041f506b Mon Sep 17 00:00:00 2001 From: Om Date: Sun, 4 Dec 2022 16:25:36 +0530 Subject: [PATCH 02/18] Shortened the code,more --- accounttype.py | 6 +- adminpanel.py | 18 ++--- createaccount.py | 10 +-- dataentering.py | 171 +++++++++++++++++++++++++++++++++++++++++++++ editaccount.py | 25 +++++++ editemployee.py | 178 +++++++++-------------------------------------- employeepanel.py | 23 ++---- hireemployee.py | 174 +++------------------------------------------ main.py | 4 +- 9 files changed, 257 insertions(+), 352 deletions(-) create mode 100644 dataentering.py create mode 100644 editaccount.py diff --git a/accounttype.py b/accounttype.py index 9973f60..052630b 100644 --- a/accounttype.py +++ b/accounttype.py @@ -1,6 +1,6 @@ import adminpanel import employeepanel -def acctype(): +def acctype(query,cur): while True: print("--------------Account Selector Menu--------------") print("1.Admin.") @@ -12,14 +12,14 @@ def acctype(): 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": - employeepanel.ep() + employeepanel.ep(query,cur) else: print("\nWrong password!\n") diff --git a/adminpanel.py b/adminpanel.py index a46431d..11221ed 100644 --- a/adminpanel.py +++ b/adminpanel.py @@ -1,6 +1,8 @@ import hireemployee - -def ap(): +import fireemployee +import editemployee +import showemployee +def ap(query,conn): print("\nWelcome Admin!!") while True: @@ -12,17 +14,15 @@ def ap(): print("\nInput 0 to quit.") a=input("Enter choice:") if a=='1': - hireemployee.ap1() + hireemployee.ap1(query,conn) elif a=='2': - hireemployee.ap2() + fireemployee.ap2(query,conn) elif a=='3': - hireemployee.ap3() + editemployee.ap3(query,conn) elif a=='4': - hireemployee.ap4() + showemployee.ap4(conn) elif a=='0': print("Quit Admin Panel.") break else: - print("Wrong input!(1,2,3)") - -ap() \ No newline at end of file + print("Wrong input!(1,2,3)") \ No newline at end of file diff --git a/createaccount.py b/createaccount.py index a502d69..7438c8e 100644 --- a/createaccount.py +++ b/createaccount.py @@ -1,4 +1,3 @@ -import pickle from datetime import date import mysql.connector @@ -9,14 +8,7 @@ def age(birthdate): age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day)) return age -def ep1(): - 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() +def ep1(query,cur): print("-------------Create account Process-------------") #client number diff --git a/dataentering.py b/dataentering.py new file mode 100644 index 0000000..50ab857 --- /dev/null +++ b/dataentering.py @@ -0,0 +1,171 @@ +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 + + +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 + break + 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 + break + else: + if age(birth_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,maxage)) + return hire_date \ No newline at end of file diff --git a/editaccount.py b/editaccount.py new file mode 100644 index 0000000..d4ce64c --- /dev/null +++ b/editaccount.py @@ -0,0 +1,25 @@ +import pickle +import mysql.connector + +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 +acc_no=0 +acc_creation_date=None +birth_date=None +def ep2(conn,cur): + while True: + acc_no=input("Enter acc_no (max 5 int) to edit details: ") + if len(acc_no) <= 5: + try: + acc_no=int(acc_no) + print("Done OK") + except ValueError: + print("acc_no should be an integer!!") + else: + break + else: + print("Maximum length is 5!") \ No newline at end of file diff --git a/editemployee.py b/editemployee.py index db3dc9b..bb215e9 100644 --- a/editemployee.py +++ b/editemployee.py @@ -1,6 +1,6 @@ import mysql.connector -import pickle from datetime import date +import dataentering def age(birthdate): today = date.today() @@ -51,95 +51,32 @@ def f2(conn,cur): 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!!") + en=dataentering.primary_key_no("emp_no") + 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...") + if a == '2': + birth_date=dataentering.birthdate("employee",20,60) + if age(birth_date)-age(hire_date)>=20: try: - birth_date=date(year,month,day) - except ValueError: - import traceback - traceback.print_exc() + 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!!!!-------------") 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") + 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': while True: first_name=input("Enter first name (max 15 char): ") @@ -207,65 +144,16 @@ def f2(conn,cur): 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!!") + hire_date=dataentering.date2("employee",birth_date,"hire",20,60) + try: + cur.execute("update employees set hire_date='{}' where emp_no={}".format(hire_date,emp_no)) + conn.commit() + except mysql.connector.Error as err: + print(err.msg) + print("-----------Value addition was unsuccessful!!!!-------------") + else: + print("Updated hire date...") - try: - hire_date=date(hyear,hmonth,hday) - except ValueError: - import traceback - traceback.print_exc() - else: - if age(birth_date)-age(hire_date)>=20: - try: - cur.execute("update employees set hire_date='{}' where emp_no={}".format(hire_date,emp_no)) - conn.commit() - except mysql.connector.Error as err: - print(err.msg) - print("-----------Value addition was unsuccessful!!!!-------------") - break - else: - print("Updated hire date...") - break - else: - print("Employee must atleast be 20 years of age when hired!!") if a=='7': print("1.Show the password") print("2.Change the password") diff --git a/employeepanel.py b/employeepanel.py index d09ae8f..d7cecb4 100644 --- a/employeepanel.py +++ b/employeepanel.py @@ -1,23 +1,10 @@ -import pickle import mysql.connector import createaccount -conn=None -cur=None -def ep(): - global conn - global cur +def ep(conn,cur): print("\nWelcome employee!!") print("Please log in with your creds (emp_id and password):") - 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() - while True: print("---------------------Employee Panel--------------------") print("1.Employee login.") @@ -53,9 +40,9 @@ def ep(): password=record[0][1] a=input("Enter your password:") if a==password: - choice=menu(emp_no) + choice=menu(emp_no,conn,cur) if choice=="1": - createaccount.ep1() + createaccount.ep1(conn,cur) elif choice=="2": break elif choice=="3": @@ -72,9 +59,7 @@ def ep(): print("Wrong password!!") break -def menu(x): - global conn - global cur +def menu(x,conn,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])) diff --git a/hireemployee.py b/hireemployee.py index b83a5ea..59bf5f1 100644 --- a/hireemployee.py +++ b/hireemployee.py @@ -1,166 +1,20 @@ from datetime import date -import pickle import mysql.connector -import connection +import dataentering -def age(birthdate): - today = date.today() - age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day)) - return age - -query,cur=connection.cc() -def ap1(): - global query,cur +def ap1(query,cur): 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!") + emp_no=dataentering.primary_key_no("emp_no") #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") + birth_date=dataentering.birthdate("employee",20,60) +#Employee name + first_name,last_name=dataentering.name() #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!!") + gender=dataentering.gender() #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!!") + hire_date=dataentering.date2("Employee",birth_date,"hire",20,60) print("=========== Final Data ===========") @@ -194,15 +48,3 @@ def ap1(): else: print("Password added successfully!!!") break - -import editemployee -def ap3(): - editemployee.ap3(query,cur) - -import fireemployee -def ap2(): - fireemployee.ap2(query,cur) - -import showemployee -def ap4(): - showemployee.ap4(cur) \ No newline at end of file diff --git a/main.py b/main.py index f6af9ed..50d5d22 100644 --- a/main.py +++ b/main.py @@ -1,13 +1,15 @@ import setup import check import accounttype +import connection +query,cur=connection.cc() while True: print("1.Continue") print("2.Quit") a=input("Enter your choice(1,2): ") if a == "1": if not check.check(): - accounttype.acctype() + accounttype.acctype(query,cur) break else: setup.setup() From 01f3b97e9e3dd3b65a97ec57c7b846aefb4f8f3c Mon Sep 17 00:00:00 2001 From: Om Date: Sun, 4 Dec 2022 16:36:54 +0530 Subject: [PATCH 03/18] updated branch info in readme --- README.md | 33 +++++++-------------------------- 1 file changed, 7 insertions(+), 26 deletions(-) diff --git a/README.md b/README.md index cd09493..e7fb34b 100644 --- a/README.md +++ b/README.md @@ -1,32 +1,13 @@ -# Bank Management System: -First of all, whole code is written by me and nothing has been copy pasted fron anywhere. +# Branch Information: +The purpose of this branch is to shorten the number of lines of code by removing duplicate lines +as much as possible. -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... +- I have not tested the whole code over here, so if anyone finds any bug, please post it in the issues section + and I will look after it then # More information/Structure/Wiki +[Main and tested branch](https://github.com/OJASisLive/Bank-Management-System-Python-SQL/tree/main) + [Wiki](https://github.com/OJASisLive/Bank-Management-System-Python-SQL/wiki) # About: From ee076156d4a18ba88bb5ea1f80d697848081f5ea Mon Sep 17 00:00:00 2001 From: Om Date: Sun, 4 Dec 2022 16:39:11 +0530 Subject: [PATCH 04/18] updated branch info in readme --- README.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.md b/README.md index e7fb34b..e7eec97 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ The purpose of this branch is to shorten the number of lines of code by removing duplicate lines as much as possible. -- I have not tested the whole code over here, so if anyone finds any bug, please post it in the issues section +- I have not tested the whole code over here, so if anyone finds any bug, please post it in the [issues section](https://github.com/OJASisLive/Bank-Management-System-Python-SQL/issues/new/choose) and I will look after it then # More information/Structure/Wiki From 8e4cb159de0ddee0f1f617a48cf8a982aa1a21a1 Mon Sep 17 00:00:00 2001 From: Om Date: Sun, 4 Dec 2022 18:24:47 +0530 Subject: [PATCH 05/18] fixed first issue --- createaccount.py | 162 +++-------------------------------------------- employeepanel.py | 5 +- setup.py | 6 +- 3 files changed, 14 insertions(+), 159 deletions(-) diff --git a/createaccount.py b/createaccount.py index 7438c8e..087c53e 100644 --- a/createaccount.py +++ b/createaccount.py @@ -1,108 +1,17 @@ -from datetime import date - +import dataentering 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 ep1(query,cur): print("-------------Create account Process-------------") #client number - while True: - acc_no=input("Enter acc_no (max 5 int): ") - if len(acc_no) <= 5: - try: - acc_no=int(acc_no) - print("Done OK") - except ValueError: - print("acc_no should be an integer!!") - else: - break - else: - print("Maximum length is 5!") + acc_no=dataentering.primary_key_no("acc_no") #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)>=10: - break - else: - print("Account holder must be atleast 10 years of age!!") -#client 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") + birth_date=dataentering.birthdate("Client",10,100) +#client name + first_name,last_name=dataentering.name() #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!!") - + gender=dataentering.gender() #client Account Type while True: print("1.Savings account") @@ -118,56 +27,7 @@ def ep1(query,cur): print("Wrong input!!") #Account creation date - while True: - while True: - hyear=input("Enter account_creation 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 account_creation 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 account_creation 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: - acc_creation_date=date(hyear,hmonth,hday) - except ValueError: - import traceback - traceback.print_exc() - else: - if age(birth_date)-age(acc_creation_date)>=10: - break - else: - print("client must atleast be 10 years of age!!") + acc_creation_date=dataentering.date2("client",birth_date,"account_creation",10,100) #client password/pin while True: password=input("Enter client login password(max 8 characters, min 4): ") @@ -206,12 +66,10 @@ def ep1(query,cur): else: print("Maximum 25 characters") - - 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,acc_type,first_name,last_name,gender,birth_date,acc_creation_date,mobile_no,email_id,pass) " + "(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) try: @@ -221,6 +79,4 @@ def ep1(query,cur): print(err.msg) print("-----------Value addition was unsuccessful!!!!-------------") else: - print("Values added successfully!!") - cur.close() - query.close() \ No newline at end of file + print("Values added successfully!!") \ No newline at end of file diff --git a/employeepanel.py b/employeepanel.py index d7cecb4..2ea8334 100644 --- a/employeepanel.py +++ b/employeepanel.py @@ -1,4 +1,3 @@ -import mysql.connector import createaccount def ep(conn,cur): @@ -40,7 +39,7 @@ def ep(conn,cur): password=record[0][1] a=input("Enter your password:") if a==password: - choice=menu(emp_no,conn,cur) + choice=menu(emp_no,cur) if choice=="1": createaccount.ep1(conn,cur) elif choice=="2": @@ -59,7 +58,7 @@ def ep(conn,cur): print("Wrong password!!") break -def menu(x,conn,cur): +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])) diff --git a/setup.py b/setup.py index 7c55a98..bc233d9 100644 --- a/setup.py +++ b/setup.py @@ -23,13 +23,13 @@ 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," + " `accd` date NOT NULL," " `mobile_no` varchar(20) NOT NULL," " `email_id` varchar(25) NOT NULL," " `pass` varchar(8) NOT NULL" From 0d263749f3f2e513e989f4d830372991ff770d85 Mon Sep 17 00:00:00 2001 From: Om Date: Sat, 24 Dec 2022 00:09:13 +0530 Subject: [PATCH 06/18] Initial commit --- editemployee.py => src/main/OmJShah/admin/editemployee.py | 2 +- fireemployee.py => src/main/OmJShah/admin/fireemployee.py | 0 hireemployee.py => src/main/OmJShah/admin/hireemployee.py | 3 +-- showemployee.py => src/main/OmJShah/admin/showemployee.py | 2 -- .../main/OmJShah/employee/createaccount.py | 2 +- .../main/OmJShah/employee/editaccount.py | 3 --- check.py => src/main/OmJShah/initialization/check.py | 0 setup.py => src/main/OmJShah/initialization/setup.py | 2 +- main.py => src/main/OmJShah/main.py | 8 ++++---- accounttype.py => src/main/OmJShah/panels/accounttype.py | 4 ++-- adminpanel.py => src/main/OmJShah/panels/adminpanel.py | 8 ++++---- .../main/OmJShah/panels/employeepanel.py | 2 +- connection.py => src/main/OmJShah/tools/connection.py | 0 dataentering.py => src/main/OmJShah/tools/dataentering.py | 0 14 files changed, 15 insertions(+), 21 deletions(-) rename editemployee.py => src/main/OmJShah/admin/editemployee.py (99%) rename fireemployee.py => src/main/OmJShah/admin/fireemployee.py (100%) rename hireemployee.py => src/main/OmJShah/admin/hireemployee.py (97%) rename showemployee.py => src/main/OmJShah/admin/showemployee.py (96%) rename createaccount.py => src/main/OmJShah/employee/createaccount.py (98%) rename editaccount.py => src/main/OmJShah/employee/editaccount.py (94%) rename check.py => src/main/OmJShah/initialization/check.py (100%) rename setup.py => src/main/OmJShah/initialization/setup.py (99%) rename main.py => src/main/OmJShah/main.py (75%) rename accounttype.py => src/main/OmJShah/panels/accounttype.py (93%) rename adminpanel.py => src/main/OmJShah/panels/adminpanel.py (85%) rename employeepanel.py => src/main/OmJShah/panels/employeepanel.py (98%) rename connection.py => src/main/OmJShah/tools/connection.py (100%) rename dataentering.py => src/main/OmJShah/tools/dataentering.py (100%) diff --git a/editemployee.py b/src/main/OmJShah/admin/editemployee.py similarity index 99% rename from editemployee.py rename to src/main/OmJShah/admin/editemployee.py index bb215e9..7eb2fc6 100644 --- a/editemployee.py +++ b/src/main/OmJShah/admin/editemployee.py @@ -1,6 +1,6 @@ import mysql.connector from datetime import date -import dataentering +from tools import dataentering def age(birthdate): today = date.today() diff --git a/fireemployee.py b/src/main/OmJShah/admin/fireemployee.py similarity index 100% rename from fireemployee.py rename to src/main/OmJShah/admin/fireemployee.py diff --git a/hireemployee.py b/src/main/OmJShah/admin/hireemployee.py similarity index 97% rename from hireemployee.py rename to src/main/OmJShah/admin/hireemployee.py index 59bf5f1..c1cab84 100644 --- a/hireemployee.py +++ b/src/main/OmJShah/admin/hireemployee.py @@ -1,6 +1,5 @@ -from datetime import date import mysql.connector -import dataentering +from tools import dataentering def ap1(query,cur): print("-------------Hire Employee Process-------------") diff --git a/showemployee.py b/src/main/OmJShah/admin/showemployee.py similarity index 96% rename from showemployee.py rename to src/main/OmJShah/admin/showemployee.py index eb26833..fa89c0d 100644 --- a/showemployee.py +++ b/src/main/OmJShah/admin/showemployee.py @@ -1,5 +1,3 @@ -import mysql.connector - def ap4(cur): cur.execute("select * from employees") results=cur.fetchall() diff --git a/createaccount.py b/src/main/OmJShah/employee/createaccount.py similarity index 98% rename from createaccount.py rename to src/main/OmJShah/employee/createaccount.py index 087c53e..eaa80ab 100644 --- a/createaccount.py +++ b/src/main/OmJShah/employee/createaccount.py @@ -1,4 +1,4 @@ -import dataentering +from tools import dataentering import mysql.connector def ep1(query,cur): diff --git a/editaccount.py b/src/main/OmJShah/employee/editaccount.py similarity index 94% rename from editaccount.py rename to src/main/OmJShah/employee/editaccount.py index d4ce64c..8fc0a48 100644 --- a/editaccount.py +++ b/src/main/OmJShah/employee/editaccount.py @@ -1,6 +1,3 @@ -import pickle -import mysql.connector - from datetime import date def age(birthdate): diff --git a/check.py b/src/main/OmJShah/initialization/check.py similarity index 100% rename from check.py rename to src/main/OmJShah/initialization/check.py diff --git a/setup.py b/src/main/OmJShah/initialization/setup.py similarity index 99% rename from setup.py rename to src/main/OmJShah/initialization/setup.py index bc233d9..303a131 100644 --- a/setup.py +++ b/src/main/OmJShah/initialization/setup.py @@ -1,4 +1,4 @@ -import check +from initialization import check import pickle import mysql.connector diff --git a/main.py b/src/main/OmJShah/main.py similarity index 75% rename from main.py rename to src/main/OmJShah/main.py index 50d5d22..a31c458 100644 --- a/main.py +++ b/src/main/OmJShah/main.py @@ -1,7 +1,7 @@ -import setup -import check -import accounttype -import connection +from initialization import setup +from initialization import check +from panels import accounttype +from tools import connection query,cur=connection.cc() while True: print("1.Continue") diff --git a/accounttype.py b/src/main/OmJShah/panels/accounttype.py similarity index 93% rename from accounttype.py rename to src/main/OmJShah/panels/accounttype.py index 052630b..bbe254d 100644 --- a/accounttype.py +++ b/src/main/OmJShah/panels/accounttype.py @@ -1,5 +1,5 @@ -import adminpanel -import employeepanel +from panels import adminpanel +from panels import employeepanel def acctype(query,cur): while True: print("--------------Account Selector Menu--------------") diff --git a/adminpanel.py b/src/main/OmJShah/panels/adminpanel.py similarity index 85% rename from adminpanel.py rename to src/main/OmJShah/panels/adminpanel.py index 11221ed..612eb24 100644 --- a/adminpanel.py +++ b/src/main/OmJShah/panels/adminpanel.py @@ -1,7 +1,7 @@ -import hireemployee -import fireemployee -import editemployee -import showemployee +from admin import hireemployee +from admin import fireemployee +from admin import editemployee +from admin import showemployee def ap(query,conn): print("\nWelcome Admin!!") diff --git a/employeepanel.py b/src/main/OmJShah/panels/employeepanel.py similarity index 98% rename from employeepanel.py rename to src/main/OmJShah/panels/employeepanel.py index 2ea8334..6220229 100644 --- a/employeepanel.py +++ b/src/main/OmJShah/panels/employeepanel.py @@ -1,4 +1,4 @@ -import createaccount +from employee import createaccount def ep(conn,cur): print("\nWelcome employee!!") diff --git a/connection.py b/src/main/OmJShah/tools/connection.py similarity index 100% rename from connection.py rename to src/main/OmJShah/tools/connection.py diff --git a/dataentering.py b/src/main/OmJShah/tools/dataentering.py similarity index 100% rename from dataentering.py rename to src/main/OmJShah/tools/dataentering.py From 0426782c170a4c6ad078669eea03df33a99b9ca6 Mon Sep 17 00:00:00 2001 From: Om Date: Sat, 24 Dec 2022 00:15:37 +0530 Subject: [PATCH 07/18] updated readme info for specific branch --- README.md | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index e7eec97..2a48215 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,7 @@ # Branch Information: -The purpose of this branch is to shorten the number of lines of code by removing duplicate lines -as much as possible. +The purpose of this branch is to organize the code in packages and modules. This will soon be merged into the "[shorten-the-code](https://github.com/OJASisLive/Bank-Management-System-Python-SQL/tree/shorten-the-code)" branch. + +After merger, this branch will be deleted. - I have not tested the whole code over here, so if anyone finds any bug, please post it in the [issues section](https://github.com/OJASisLive/Bank-Management-System-Python-SQL/issues/new/choose) and I will look after it then From b4ae5a74a269128eae4e5de53dacbd219577a1da Mon Sep 17 00:00:00 2001 From: Om Date: Sat, 24 Dec 2022 21:32:11 +0530 Subject: [PATCH 08/18] added edit client options. --- .gitignore | 1 + src/main/OmJShah/admin/editemployee.py | 147 +++++++-------------- src/main/OmJShah/employee/createaccount.py | 47 +------ src/main/OmJShah/employee/deleteaccount.py | 0 src/main/OmJShah/employee/editaccount.py | 144 +++++++++++++++++++- src/main/OmJShah/initialization/setup.py | 5 - src/main/OmJShah/panels/employeepanel.py | 7 +- src/main/OmJShah/tools/dataentering.py | 60 ++++++++- 8 files changed, 253 insertions(+), 158 deletions(-) create mode 100644 src/main/OmJShah/employee/deleteaccount.py diff --git a/.gitignore b/.gitignore index d92380b..248fbda 100644 --- a/.gitignore +++ b/.gitignore @@ -5,3 +5,4 @@ links.txt tempCodeRunnerFile.py start program.bat README.md +.vscode/ \ No newline at end of file diff --git a/src/main/OmJShah/admin/editemployee.py b/src/main/OmJShah/admin/editemployee.py index 7eb2fc6..6a374d8 100644 --- a/src/main/OmJShah/admin/editemployee.py +++ b/src/main/OmJShah/admin/editemployee.py @@ -6,16 +6,17 @@ def age(birthdate): today = date.today() age = today.year - birthdate.year - ((today.month, today.day) < (birthdate.month, birthdate.day)) return age -emp_no=0 +emp_no=None hire_date=None birth_date=None + def ap3(conn,cur): - global emp_no - global birth_date - global hire_date + 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) @@ -23,13 +24,15 @@ def ap3(conn,cur): 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 results == []: - print(results) + if len(results)==0: print("That employee number does not exist.") else: results1=results[0] @@ -45,113 +48,60 @@ def ap3(conn,cur): f2(conn,cur) def f2(conn,cur): - global emp_no - global birth_date - global hire_date + 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") - 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: + query="update employees set emp_no=%s where emp_no=%s" + data=(en,emp_no) + done=dataentering.tableupdate(conn,cur,query,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: - 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!!!!-------------") - else: - print("Updated birth date...") + 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': - 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") + 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': - 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") + 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': - 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 gender...") - 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 gender...") - break - - else: - print("Wrong input!!") + 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) - try: - cur.execute("update employees set hire_date='{}' where emp_no={}".format(hire_date,emp_no)) - conn.commit() - except mysql.connector.Error as err: - print(err.msg) - print("-----------Value addition was unsuccessful!!!!-------------") - else: + 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': @@ -171,12 +121,11 @@ def f2(conn,cur): elif lp<4: print("Minimum 4 characters to be entered.") else: - try: - cur.execute("UPDATE empass set pass=LPAD({},{},'0') where emp_no={}".format(password,lp,emp_no)) - conn.commit() - except mysql.connector.Error as err: - print(err.msg) - print("-----------Password change was unsuccessful!!!!-------------") - 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/src/main/OmJShah/employee/createaccount.py b/src/main/OmJShah/employee/createaccount.py index eaa80ab..6f16f00 100644 --- a/src/main/OmJShah/employee/createaccount.py +++ b/src/main/OmJShah/employee/createaccount.py @@ -9,7 +9,7 @@ def ep1(query,cur): #client Birth date birth_date=dataentering.birthdate("Client",10,100) #client name - first_name,last_name=dataentering.name() + first_name,last_name=dataentering.fname(),dataentering.lname() #client Gender gender=dataentering.gender() #client Account Type @@ -29,42 +29,13 @@ def ep1(query,cur): #Account creation date acc_creation_date=dataentering.date2("client",birth_date,"account_creation",10,100) #client password/pin - 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 + password,lp=dataentering.clientpassword() #mobile no - 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("acc_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!!") + mobile_no,lmn=dataentering.mobileno() #email-id - while True: - email_id=input("Enter client Email ID (max 25 char):") - if len(email_id)<26: - break - else: - print("Maximum 25 characters") + 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) @@ -72,11 +43,7 @@ def ep1(query,cur): "(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) - try: - cur.execute(add_client, data_client) - query.commit() - except mysql.connector.Error as err: - print(err.msg) - print("-----------Value addition was unsuccessful!!!!-------------") - else: + + done=dataentering.tableupdate(query,cur,add_client,data_client) + if done: 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..e69de29 diff --git a/src/main/OmJShah/employee/editaccount.py b/src/main/OmJShah/employee/editaccount.py index 8fc0a48..a38833c 100644 --- a/src/main/OmJShah/employee/editaccount.py +++ b/src/main/OmJShah/employee/editaccount.py @@ -1,22 +1,154 @@ from datetime import date +from tools import dataentering +import mysql.connector + +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 -acc_no=0 -acc_creation_date=None -birth_date=None + 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("input ~ to quit") acc_no=input("Enter acc_no (max 5 int) to edit details: ") + if acc_no=="~": break if len(acc_no) <= 5: try: acc_no=int(acc_no) print("Done OK") except ValueError: print("acc_no should be an integer!!") - else: - break else: - print("Maximum length is 5!") \ No newline at end of file + 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 employee 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") + 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/initialization/setup.py b/src/main/OmJShah/initialization/setup.py index 303a131..08f74c1 100644 --- a/src/main/OmJShah/initialization/setup.py +++ b/src/main/OmJShah/initialization/setup.py @@ -41,7 +41,6 @@ " `emp_no` int(5) NOT NULL," " `pass` varchar(8) NOT NULL," " PRIMARY KEY (`emp_no`)," - " FOREIGN KEY(`emp_no`) REFERENCES employees(emp_no)" ") " ) @@ -52,7 +51,6 @@ " `balance` int NOT NULL," " `loan` enum('YES','NO') NOT NULL," " PRIMARY KEY (`acc_no`)," - " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" ") " ) @@ -62,7 +60,6 @@ " `balance` int NOT NULL," " `overdraft` int NOT NULL," " PRIMARY KEY (`acc_no`)," - " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" ") " ) @@ -76,7 +73,6 @@ " `amt-per-month` int NOT NULL," " `remaining_amt` int NOT NULL," " PRIMARY KEY (`acc_no`)," - " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" ") " ) @@ -86,7 +82,6 @@ " `overdraft_amt` int NOT NULL," " `od_with_interest_remaining` int NOT NULL," " PRIMARY KEY (`acc_no`)," - " FOREIGN KEY(`acc_no`) REFERENCES clients(acc_no)" ") " ) diff --git a/src/main/OmJShah/panels/employeepanel.py b/src/main/OmJShah/panels/employeepanel.py index 6220229..b8f441b 100644 --- a/src/main/OmJShah/panels/employeepanel.py +++ b/src/main/OmJShah/panels/employeepanel.py @@ -1,4 +1,5 @@ from employee import createaccount +from employee import editaccount def ep(conn,cur): print("\nWelcome employee!!") @@ -12,8 +13,6 @@ def ep(conn,cur): if ch == "1": print("------------login panel-------------") elif ch == "2": - cur.close() - conn.close() break else: print("Wrong input!!!(1 or 2 only)") @@ -43,14 +42,12 @@ def ep(conn,cur): if choice=="1": createaccount.ep1(conn,cur) elif choice=="2": - break + editaccount.ep2(conn,cur) elif choice=="3": break elif choice=="4": break elif choice=="0": - cur.close() - conn.close() break else: print("Wrong input!") diff --git a/src/main/OmJShah/tools/dataentering.py b/src/main/OmJShah/tools/dataentering.py index 50ab857..5adc439 100644 --- a/src/main/OmJShah/tools/dataentering.py +++ b/src/main/OmJShah/tools/dataentering.py @@ -1,4 +1,5 @@ from datetime import date +import mysql.connector def age(birthdate): today = date.today() @@ -80,7 +81,7 @@ def birthdate(person,minage,maxage): print("Maximum age is {} years!!!".format(maxage)) print("\nwrong input\n") -def name(): +def fname(): #Employee name and client name while True: first_name=input("Enter first name (max 15 char): ") @@ -88,7 +89,9 @@ def name(): 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: @@ -96,7 +99,7 @@ def name(): else: print("Max 15 characters") - return first_name,last_name + return last_name def gender(): #Employee Gender and client gender @@ -168,4 +171,55 @@ def date2(person,birth_date,hire_or_creation,minage,maxage): break else: print("{} must atleast be {} years of age!!".format(person,maxage)) - return hire_date \ No newline at end of file + 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 was unsuccessful!!!!-------------") + else: + return bool(True) \ No newline at end of file From 75e8bbfc2159dca06bb071e9aeca1a7487a6ff06 Mon Sep 17 00:00:00 2001 From: Om J Shah <79356504+OJASisLive@users.noreply.github.com> Date: Sat, 24 Dec 2022 22:00:04 +0530 Subject: [PATCH 09/18] Update README.md --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 2a48215..3387133 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ -# Branch Information: +# Latest Branch Info: +I have successfully merged the "organize-the-code" branch into this branch. The former branch is deleted now. + +# Old Branch Information: The purpose of this branch is to organize the code in packages and modules. This will soon be merged into the "[shorten-the-code](https://github.com/OJASisLive/Bank-Management-System-Python-SQL/tree/shorten-the-code)" branch. After merger, this branch will be deleted. @@ -17,4 +20,4 @@ This project aims to create a bridge between Python and SQL and use it in real w This project is currently under development... # Done by: -Om J Shah \ No newline at end of file +Om J Shah From 0cde1aeab5d103f0466b7e1f67739c4623a5107d Mon Sep 17 00:00:00 2001 From: Om J Shah <79356504+OJASisLive@users.noreply.github.com> Date: Sat, 24 Dec 2022 22:02:05 +0530 Subject: [PATCH 10/18] Update README.md --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 3387133..4bf3bc6 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,7 @@ # Latest Branch Info: +The purpose of this branch is to shorten the code by referencing duplicate code blocks. + +# NOTE: I have successfully merged the "organize-the-code" branch into this branch. The former branch is deleted now. # Old Branch Information: From 62009b36d212176006cb5fdb6f3006b8da8875a9 Mon Sep 17 00:00:00 2001 From: Om Date: Thu, 29 Dec 2022 14:53:43 +0530 Subject: [PATCH 11/18] Added method to show client table --- src/main/OmJShah/admin/editemployee.py | 1 - src/main/OmJShah/employee/createaccount.py | 1 - src/main/OmJShah/employee/deleteaccount.py | 42 ++++++++++++++++++++++ src/main/OmJShah/employee/editaccount.py | 5 ++- src/main/OmJShah/panels/employeepanel.py | 35 ++++++++++-------- src/main/OmJShah/tools/dataentering.py | 1 - 6 files changed, 64 insertions(+), 21 deletions(-) diff --git a/src/main/OmJShah/admin/editemployee.py b/src/main/OmJShah/admin/editemployee.py index 6a374d8..d9320d3 100644 --- a/src/main/OmJShah/admin/editemployee.py +++ b/src/main/OmJShah/admin/editemployee.py @@ -1,4 +1,3 @@ -import mysql.connector from datetime import date from tools import dataentering diff --git a/src/main/OmJShah/employee/createaccount.py b/src/main/OmJShah/employee/createaccount.py index 6f16f00..42b6bdc 100644 --- a/src/main/OmJShah/employee/createaccount.py +++ b/src/main/OmJShah/employee/createaccount.py @@ -1,5 +1,4 @@ from tools import dataentering -import mysql.connector def ep1(query,cur): print("-------------Create account Process-------------") diff --git a/src/main/OmJShah/employee/deleteaccount.py b/src/main/OmJShah/employee/deleteaccount.py index e69de29..604693f 100644 --- a/src/main/OmJShah/employee/deleteaccount.py +++ b/src/main/OmJShah/employee/deleteaccount.py @@ -0,0 +1,42 @@ +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] + first_name=results1[2] + last_name=results1[3] + 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,) + done=dataentering.tableupdate(conn,cur,query,data) + if done: + print("Deleted {} {}'s account.".format(first_name,last_name)) + break + else: + print("Deletion was unsuccessful") + else: + break diff --git a/src/main/OmJShah/employee/editaccount.py b/src/main/OmJShah/employee/editaccount.py index a38833c..2fbdad5 100644 --- a/src/main/OmJShah/employee/editaccount.py +++ b/src/main/OmJShah/employee/editaccount.py @@ -1,6 +1,5 @@ from datetime import date from tools import dataentering -import mysql.connector acc_no=None first_name=None @@ -23,7 +22,7 @@ def ep2(conn,cur): print("input ~ to quit") acc_no=input("Enter acc_no (max 5 int) to edit details: ") if acc_no=="~": break - if len(acc_no) <= 5: + elif len(acc_no) <= 5: try: acc_no=int(acc_no) print("Done OK") @@ -34,7 +33,7 @@ def ep2(conn,cur): cur.execute("select * from clients where acc_no={}".format(acc_no)) results=cur.fetchall() if len(results)==0: - print("That employee number does not exist.") + print("That account number does not exist.") else: results1=results[0] first_name=results1[2] diff --git a/src/main/OmJShah/panels/employeepanel.py b/src/main/OmJShah/panels/employeepanel.py index b8f441b..58099f6 100644 --- a/src/main/OmJShah/panels/employeepanel.py +++ b/src/main/OmJShah/panels/employeepanel.py @@ -1,21 +1,24 @@ 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):") - - while True: - print("---------------------Employee Panel--------------------") - print("1.Employee login.") - print("2.Quit.") - ch = input("Enter your choice:") - if ch == "1": - print("------------login panel-------------") - elif ch == "2": - break - else: - print("Wrong input!!!(1 or 2 only)") + 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: @@ -36,7 +39,8 @@ def ep(conn,cur): else: while True: password=record[0][1] - a=input("Enter your password:") + a=input("\nEnter your password to continue:") + print("Input ~ to quit.") if a==password: choice=menu(emp_no,cur) if choice=="1": @@ -44,13 +48,14 @@ def ep(conn,cur): elif choice=="2": editaccount.ep2(conn,cur) elif choice=="3": - break + deleteaccount.ep3(conn,cur) elif choice=="4": - break + showaccounts.ep4(cur) elif choice=="0": break else: print("Wrong input!") + elif a == "~" : break else: print("Wrong password!!") break diff --git a/src/main/OmJShah/tools/dataentering.py b/src/main/OmJShah/tools/dataentering.py index 5adc439..4049cc9 100644 --- a/src/main/OmJShah/tools/dataentering.py +++ b/src/main/OmJShah/tools/dataentering.py @@ -73,7 +73,6 @@ def birthdate(person,minage,maxage): else: if age(birth_date)>=minage and age(birth_date)<=maxage: return birth_date - break else: if age(birth_date) Date: Thu, 29 Dec 2022 14:55:13 +0530 Subject: [PATCH 12/18] implemented changes --- src/main/OmJShah/employee/showaccounts.py | 11 +++++++++++ src/main/OmJShah/tests.py | 8 ++++++++ 2 files changed, 19 insertions(+) create mode 100644 src/main/OmJShah/employee/showaccounts.py create mode 100644 src/main/OmJShah/tests.py 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/tests.py b/src/main/OmJShah/tests.py new file mode 100644 index 0000000..74a1dfb --- /dev/null +++ b/src/main/OmJShah/tests.py @@ -0,0 +1,8 @@ +from employee import deleteaccount +from tools import connection +from admin import showemployee +from employee import showaccounts +conn,cur=connection.cc() +showaccounts.ep4(cur) +#showemployee.ap4(cur) +#deleteaccount.ep3(conn,cur) \ No newline at end of file From dcd5518e3d099234ccd431842bae1f31479a1fc8 Mon Sep 17 00:00:00 2001 From: Om Date: Thu, 29 Dec 2022 21:39:30 +0530 Subject: [PATCH 13/18] Implemented addition of data in savings and current tables --- src/main/OmJShah/employee/createaccount.py | 27 ++++++++++++++++++++++ src/main/OmJShah/initialization/setup.py | 4 ++-- src/main/OmJShah/tests.py | 3 ++- src/main/OmJShah/tools/dataentering.py | 20 ++++++++++++++-- 4 files changed, 49 insertions(+), 5 deletions(-) diff --git a/src/main/OmJShah/employee/createaccount.py b/src/main/OmJShah/employee/createaccount.py index 42b6bdc..fb37626 100644 --- a/src/main/OmJShah/employee/createaccount.py +++ b/src/main/OmJShah/employee/createaccount.py @@ -45,4 +45,31 @@ def ep1(query,cur): 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/initialization/setup.py b/src/main/OmJShah/initialization/setup.py index 08f74c1..e88fe29 100644 --- a/src/main/OmJShah/initialization/setup.py +++ b/src/main/OmJShah/initialization/setup.py @@ -58,7 +58,7 @@ "CREATE TABLE `current` (" " `acc_no` int(5) NOT NULL," " `balance` int NOT NULL," - " `overdraft` int NOT NULL," + " `overdraft` enum('YES','NO') NOT NULL," " PRIMARY KEY (`acc_no`)," ") " ) @@ -140,7 +140,7 @@ def querycheck(): print("already exists.") existing+=1 else: - print(err.msg()) + print(err.msg) else: print("OK") if existing==7: diff --git a/src/main/OmJShah/tests.py b/src/main/OmJShah/tests.py index 74a1dfb..3a4e29c 100644 --- a/src/main/OmJShah/tests.py +++ b/src/main/OmJShah/tests.py @@ -5,4 +5,5 @@ conn,cur=connection.cc() showaccounts.ep4(cur) #showemployee.ap4(cur) -#deleteaccount.ep3(conn,cur) \ No newline at end of file +#deleteaccount.ep3(conn,cur) +#alter table current modify column overdraft enum('YES','NO'); \ No newline at end of file diff --git a/src/main/OmJShah/tools/dataentering.py b/src/main/OmJShah/tools/dataentering.py index 4049cc9..b02121e 100644 --- a/src/main/OmJShah/tools/dataentering.py +++ b/src/main/OmJShah/tools/dataentering.py @@ -219,6 +219,22 @@ def tableupdate(conn,cur,query,data): conn.commit() except mysql.connector.Error as err: print(err.msg) - print("-----------Value addition was unsuccessful!!!!-------------") + print("-----------Value addition/deletion was unsuccessful!!!!-------------") else: - return bool(True) \ No newline at end of file + 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") \ No newline at end of file From 74ae71b84b454bdf68af25c51550d42548e4d978 Mon Sep 17 00:00:00 2001 From: Om Date: Fri, 30 Dec 2022 00:00:00 +0530 Subject: [PATCH 14/18] Fixed bugs, implemented extra deletion --- src/main/OmJShah/employee/deleteaccount.py | 13 +++++++++++-- src/main/OmJShah/panels/employeepanel.py | 5 +++-- src/main/OmJShah/tests.py | 4 +++- 3 files changed, 17 insertions(+), 5 deletions(-) diff --git a/src/main/OmJShah/employee/deleteaccount.py b/src/main/OmJShah/employee/deleteaccount.py index 604693f..f0c7957 100644 --- a/src/main/OmJShah/employee/deleteaccount.py +++ b/src/main/OmJShah/employee/deleteaccount.py @@ -22,6 +22,9 @@ def ep3(conn,cur): print("That account number does not exist.") else : results1=results[0] + acc_type=results1[1] + if acc_type == 'S': acc_type="savings" + if acc_type == 'C': acc_type="current" first_name=results1[2] last_name=results1[3] print(first_name,last_name,"found.") @@ -32,10 +35,16 @@ def ep3(conn,cur): 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: - print("Deleted {} {}'s account.".format(first_name,last_name)) - break + 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: diff --git a/src/main/OmJShah/panels/employeepanel.py b/src/main/OmJShah/panels/employeepanel.py index 58099f6..91cba8b 100644 --- a/src/main/OmJShah/panels/employeepanel.py +++ b/src/main/OmJShah/panels/employeepanel.py @@ -39,8 +39,9 @@ def ep(conn,cur): else: while True: password=record[0][1] - a=input("\nEnter your password to continue:") - print("Input ~ to quit.") + print("\nInput ~ to quit.") + a=input("Enter your password to continue:") + print() if a==password: choice=menu(emp_no,cur) if choice=="1": diff --git a/src/main/OmJShah/tests.py b/src/main/OmJShah/tests.py index 3a4e29c..167b1de 100644 --- a/src/main/OmJShah/tests.py +++ b/src/main/OmJShah/tests.py @@ -6,4 +6,6 @@ showaccounts.ep4(cur) #showemployee.ap4(cur) #deleteaccount.ep3(conn,cur) -#alter table current modify column overdraft enum('YES','NO'); \ No newline at end of file +#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 From 907b06a728a64fc85c44a02af26bca082132e556 Mon Sep 17 00:00:00 2001 From: Om Date: Fri, 30 Dec 2022 15:21:18 +0530 Subject: [PATCH 15/18] Added Client panel, fixed bugs... --- src/main/OmJShah/admin/hireemployee.py | 2 +- src/main/OmJShah/employee/editaccount.py | 17 ++++---- src/main/OmJShah/initialization/setup.py | 10 ++--- src/main/OmJShah/main.py | 2 +- src/main/OmJShah/panels/accounttype.py | 7 ++-- src/main/OmJShah/panels/clientpanel.py | 51 ++++++++++++++++++++++++ src/main/OmJShah/tests.py | 7 +--- src/main/OmJShah/tools/connection.py | 20 ++++++---- src/main/OmJShah/tools/dataentering.py | 5 +-- 9 files changed, 87 insertions(+), 34 deletions(-) create mode 100644 src/main/OmJShah/panels/clientpanel.py diff --git a/src/main/OmJShah/admin/hireemployee.py b/src/main/OmJShah/admin/hireemployee.py index c1cab84..fed7e35 100644 --- a/src/main/OmJShah/admin/hireemployee.py +++ b/src/main/OmJShah/admin/hireemployee.py @@ -9,7 +9,7 @@ def ap1(query,cur): #Employee Birth date birth_date=dataentering.birthdate("employee",20,60) #Employee name - first_name,last_name=dataentering.name() + first_name,last_name=dataentering.fname(),dataentering.lname() #Employee Gender gender=dataentering.gender() #Employee hire date diff --git a/src/main/OmJShah/employee/editaccount.py b/src/main/OmJShah/employee/editaccount.py index 2fbdad5..cf290ef 100644 --- a/src/main/OmJShah/employee/editaccount.py +++ b/src/main/OmJShah/employee/editaccount.py @@ -19,7 +19,7 @@ def age(birthdate): 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("input ~ to quit") + 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: @@ -45,13 +45,13 @@ def ep2(conn,cur): 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("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) @@ -132,6 +132,7 @@ def ep2f2(conn,cur): 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) diff --git a/src/main/OmJShah/initialization/setup.py b/src/main/OmJShah/initialization/setup.py index e88fe29..9e94974 100644 --- a/src/main/OmJShah/initialization/setup.py +++ b/src/main/OmJShah/initialization/setup.py @@ -40,7 +40,7 @@ "CREATE TABLE `empass` (" " `emp_no` int(5) NOT NULL," " `pass` varchar(8) NOT NULL," - " PRIMARY KEY (`emp_no`)," + " PRIMARY KEY (`emp_no`)" ") " ) @@ -50,7 +50,7 @@ " `acc_no` int(5) NOT NULL," " `balance` int NOT NULL," " `loan` enum('YES','NO') NOT NULL," - " PRIMARY KEY (`acc_no`)," + " PRIMARY KEY (`acc_no`)" ") " ) @@ -59,7 +59,7 @@ " `acc_no` int(5) NOT NULL," " `balance` int NOT NULL," " `overdraft` enum('YES','NO') NOT NULL," - " PRIMARY KEY (`acc_no`)," + " PRIMARY KEY (`acc_no`)" ") " ) @@ -72,7 +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`)," + " PRIMARY KEY (`acc_no`)" ") " ) @@ -81,7 +81,7 @@ " `acc_no` int(5) NOT NULL," " `overdraft_amt` int NOT NULL," " `od_with_interest_remaining` int NOT NULL," - " PRIMARY KEY (`acc_no`)," + " PRIMARY KEY (`acc_no`)" ") " ) diff --git a/src/main/OmJShah/main.py b/src/main/OmJShah/main.py index a31c458..40fdd60 100644 --- a/src/main/OmJShah/main.py +++ b/src/main/OmJShah/main.py @@ -2,13 +2,13 @@ from initialization import check from panels import accounttype from tools import connection -query,cur=connection.cc() 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: diff --git a/src/main/OmJShah/panels/accounttype.py b/src/main/OmJShah/panels/accounttype.py index bbe254d..bdcae35 100644 --- a/src/main/OmJShah/panels/accounttype.py +++ b/src/main/OmJShah/panels/accounttype.py @@ -1,12 +1,13 @@ 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': @@ -24,9 +25,9 @@ def acctype(query,cur): 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/src/main/OmJShah/panels/clientpanel.py b/src/main/OmJShah/panels/clientpanel.py new file mode 100644 index 0000000..383d54d --- /dev/null +++ b/src/main/OmJShah/panels/clientpanel.py @@ -0,0 +1,51 @@ +from tools import dataentering +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): + print("1.Show Balance") + print("2.Deposit money") + print("3.Withdraw money") + if acc_type=='savings': + print("4.Ask for loan") + print("5.Check loan status") + else: + print("4.Check overdraft status") + 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": + pass + elif choice=="3": + pass + elif choice=="4": + pass + elif choice=="5": + pass + else: + print("Wrong input!!!!\n") diff --git a/src/main/OmJShah/tests.py b/src/main/OmJShah/tests.py index 167b1de..61c983b 100644 --- a/src/main/OmJShah/tests.py +++ b/src/main/OmJShah/tests.py @@ -1,11 +1,8 @@ from employee import deleteaccount from tools import connection -from admin import showemployee -from employee import showaccounts +from panels import clientpanel conn,cur=connection.cc() -showaccounts.ep4(cur) -#showemployee.ap4(cur) -#deleteaccount.ep3(conn,cur) +clientpanel.cp(conn,cur) #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 index 3fc55f4..70bd1ef 100644 --- a/src/main/OmJShah/tools/connection.py +++ b/src/main/OmJShah/tools/connection.py @@ -1,13 +1,17 @@ +from initialization import check import mysql.connector import pickle def cc(): 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() - return conn,cur \ No newline at end of file + if not check.check(): + 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() + 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 index b02121e..327cb8a 100644 --- a/src/main/OmJShah/tools/dataentering.py +++ b/src/main/OmJShah/tools/dataentering.py @@ -19,7 +19,6 @@ def primary_key_no(x): print("{} should be an integer!!".format(x)) else: return emp_no - break else: print("Maximum length is 5!") @@ -174,7 +173,7 @@ def date2(person,birth_date,hire_or_creation,minage,maxage): def mobileno(): while True: - mobile_no_str=input("Enter mobile no. (7 to 15 int)") + 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 @@ -194,7 +193,7 @@ def mobileno(): def email(): while True: - email_id=input("Enter client Email ID (max 25 char):") + email_id=input("Enter client Email ID (max 25 char): ") if len(email_id)<26: break else: From a8240058caa4674e65eed74dcf8172d60ce49c9e Mon Sep 17 00:00:00 2001 From: Om Date: Sat, 31 Dec 2022 01:56:17 +0530 Subject: [PATCH 16/18] 2 methods added for clients --- photos/cash_in_hand.png | Bin 0 -> 14373 bytes src/main/OmJShah/client/depositmoney.py | 37 +++++++++++++++++++++++ src/main/OmJShah/client/redeemcode.py | 13 ++++++++ src/main/OmJShah/initialization/setup.py | 10 +++++- src/main/OmJShah/panels/clientpanel.py | 13 +++++--- src/main/OmJShah/tools/dataentering.py | 30 +++++++++++++++++- 6 files changed, 96 insertions(+), 7 deletions(-) create mode 100644 photos/cash_in_hand.png create mode 100644 src/main/OmJShah/client/depositmoney.py create mode 100644 src/main/OmJShah/client/redeemcode.py diff --git a/photos/cash_in_hand.png b/photos/cash_in_hand.png new file mode 100644 index 0000000000000000000000000000000000000000..4135927ca1e33eb164b1348c1cc11e2a0ee05924 GIT binary patch literal 14373 zcmeHuXIN9|w=a$(Go#pP0R%@yMT8hb6(M2)6_BPP5Qq{dB1khrsEJO*LKQ`6LPVu0 zMMR_%5lJkBfRvz=0D(km2q8e)&fTE@bMBcr<^JzE_uKujpFAY&{jPVd^{(~%t+n=T zhZEMTSE{X)lapJ0?C4=9Il1LTIk{zfewAPR=JeBF!H;EFC+mZ9#Vs16;2%F7YzkQ%T zg2>m@&MKy7E4b8EZOpm|Yk2C7MX_Gp!tA++#zGB&#vo~KdM~+> zldOgqnX9_NrB>D!BYG0Y)A`R$TM;vNJV#Zk0{FEm?(maMu85MCq)^ARDE zl+Wt%Tt5o}Wt`wCGM#JL;j7T0>VHLQN`YzvrX+$7pgSgMr$#av!(Z3R$-T!I631G) z#4`JgT?t48qE4UmmJMLjRwkxFV^Y;}M;9znS0ghy5q!gkhnD4V$9pat6Js0?6ch!n zzt0lVwPc$rEPW)&`PA+}q;pFN88X0p4M99f8&&^uj?2}m&qyBZvaaj3%<0xpKp&Ox{_<|qJEiMTjNv~nr%mcCPUQ&V*R z&S%)s74uRKzc@lRRVn5Pyb8(iJSC5@P-!NR`sd~F+Dc5|S!E|+2vJeRA&6HaWTVvx z9PAaRkb)0CJ;gg3PwG<$BQ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>j1m9& z$fvl1S&V~<8u=mP6ga2rSeYUG+63KG(PfZhYeEV*%pp<5ixG+Y%Nu%1_jnW;Nl+N5X8Nu(d*3vu+4*hC9ii3pqi0lHP?rXQvS92w^bN=k1E z=gV&t__npcH4)gn(|HI?ym27-CO~~WZJ@*CoqrfN{izXH-uw3IZd+aO3etEr?chXB z;9j-s{$;UMC790@1^j?kWH-aO;tPWejx=Ic#i0mMZkC!~57HiabQ1!4>Rr8>n^sh< z6G*o9-wL#l-5Nh?PADEnp`m=J|LRyRVrnfoe?7VHBs{;CyXDG?`=^pKJ8FQefSo5N za3hmmgsJ(Dll=18ygZMV0#Y=cbUYlMKdeR`ochFgl5e&*!OTdXTVv^?Sw#sJn{k{i z^vzPZ)hR6qL*`8iW-35FxPU_smikWo0oeJb3Vt11NF(qaQhe>esd1`6uwt*=n0o|n zo$793Dmbz3y^*&0g|n!yzm@8?ECVQY0ZxNHya2u#W|m{2pHC?G*rjFH1XI;o+xIPC z_u?e`;!haGxyatN@Mhz6sZcOG$6?lWn*#WCrCoR)c=zHnHy>cGn@K`6hcY2g*Mq4o t=>M=F_}>R8V8Z?nU#2sa)d9cE*UTNBg{XnA^vTH`J96T1@xily{x7$cjWPfL literal 0 HcmV?d00001 diff --git a/src/main/OmJShah/client/depositmoney.py b/src/main/OmJShah/client/depositmoney.py new file mode 100644 index 0000000..d0651d0 --- /dev/null +++ b/src/main/OmJShah/client/depositmoney.py @@ -0,0 +1,37 @@ +from tools import dataentering +def cp2(conn,cur,acc_type,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=dataentering.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] + + deposit_amt=dataentering.amounts("deposit",cash_in_hand,acc_type) + if deposit_amt: + query2="update {} set balance = balance+{} where acc_no = %s".format(acc_type,deposit_amt) + data2=(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-{} where acc_no = %s".format(acc_type,deposit_amt) + data2=(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/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/initialization/setup.py b/src/main/OmJShah/initialization/setup.py index 9e94974..51fb5be 100644 --- a/src/main/OmJShah/initialization/setup.py +++ b/src/main/OmJShah/initialization/setup.py @@ -85,6 +85,14 @@ ") " ) +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`)" + ") " +) + ############################################################################################ query="" @@ -143,7 +151,7 @@ def querycheck(): print(err.msg) else: print("OK") - if existing==7: + if existing==8: with open("firsttime.txt","w") as f: f.write("False") ans=True diff --git a/src/main/OmJShah/panels/clientpanel.py b/src/main/OmJShah/panels/clientpanel.py index 383d54d..183cebf 100644 --- a/src/main/OmJShah/panels/clientpanel.py +++ b/src/main/OmJShah/panels/clientpanel.py @@ -1,4 +1,6 @@ from tools import dataentering +from client import redeemcode +from client import depositmoney def cp(conn,cur): print("\n------------------Client Panel------------------") print("Welcome client!!") @@ -26,11 +28,12 @@ def cmenu(conn,cur,acc_no,acc_type): print("1.Show Balance") print("2.Deposit money") print("3.Withdraw money") + print("4.Redeem Code") if acc_type=='savings': - print("4.Ask for loan") - print("5.Check loan status") + print("5.Ask for loan") + print("6.Check loan status") else: - print("4.Check overdraft status") + print("5.Check overdraft status") print("~ to quit") choice=input("Enter your choice: ") if choice=="~": pass @@ -40,11 +43,11 @@ def cmenu(conn,cur,acc_no,acc_type): print("Your balance is: ",balance[0][0]) print() elif choice=="2": - pass + depositmoney.cp2(conn,cur,acc_type,acc_no) elif choice=="3": pass elif choice=="4": - pass + redeemcode.cp4(conn,cur,acc_type,acc_no) elif choice=="5": pass else: diff --git a/src/main/OmJShah/tools/dataentering.py b/src/main/OmJShah/tools/dataentering.py index 327cb8a..285b353 100644 --- a/src/main/OmJShah/tools/dataentering.py +++ b/src/main/OmJShah/tools/dataentering.py @@ -236,4 +236,32 @@ def balance(): if bank_balance>=1000: return bank_balance else: - print("Minimum balance is 1000 currency") \ No newline at end of file + print("Minimum balance is 1000 currency") + +#Withdraw amount and Deposit amount +def amounts(deposit_or_withdraw,cash_in_hand,acc_type): + while True: + print() + print("--------------------{} screen-------------------") + amt=input("Enter amount to {}: ".format(deposit_or_withdraw)) + try: + amt=int(amt) + print("Done OK") + except ValueError: + print("{} amount should be an integer!!".format(deposit_or_withdraw)) + else: + if amt Date: Sat, 31 Dec 2022 16:45:23 +0530 Subject: [PATCH 17/18] Added some more client methods --- firsttime.txt | 1 - src/main/OmJShah/client/depositmoney.py | 22 +++-------- src/main/OmJShah/client/loan_od.py | 3 ++ src/main/OmJShah/client/transfermoney.py | 49 ++++++++++++++++++++++++ src/main/OmJShah/client/withdrawmoney.py | 28 ++++++++++++++ src/main/OmJShah/initialization/check.py | 4 +- src/main/OmJShah/initialization/setup.py | 8 ++-- src/main/OmJShah/panels/clientpanel.py | 19 +++++++-- src/main/OmJShah/tests.py | 8 ++-- src/main/OmJShah/tools/connection.py | 2 +- src/main/OmJShah/tools/dataentering.py | 44 ++++++++++++++------- 11 files changed, 142 insertions(+), 46 deletions(-) delete mode 100644 firsttime.txt create mode 100644 src/main/OmJShah/client/loan_od.py create mode 100644 src/main/OmJShah/client/transfermoney.py create mode 100644 src/main/OmJShah/client/withdrawmoney.py 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/src/main/OmJShah/client/depositmoney.py b/src/main/OmJShah/client/depositmoney.py index d0651d0..0ddf3d7 100644 --- a/src/main/OmJShah/client/depositmoney.py +++ b/src/main/OmJShah/client/depositmoney.py @@ -1,22 +1,12 @@ from tools import dataentering def cp2(conn,cur,acc_type,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=dataentering.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] + 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+{} where acc_no = %s".format(acc_type,deposit_amt) - data2=(acc_no,) + 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" @@ -26,8 +16,8 @@ def cp2(conn,cur,acc_type,acc_no): print("Deposit of {} currency successful".format(deposit_amt)) print() else: - query2="update {} set balance = balance-{} where acc_no = %s".format(acc_type,deposit_amt) - data2=(acc_no,) + 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") diff --git a/src/main/OmJShah/client/loan_od.py b/src/main/OmJShah/client/loan_od.py new file mode 100644 index 0000000..ee71c9d --- /dev/null +++ b/src/main/OmJShah/client/loan_od.py @@ -0,0 +1,3 @@ +from tools import dataentering +def cp5(conn,cur,acc_type,acc_no): + pass \ 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/initialization/check.py b/src/main/OmJShah/initialization/check.py index 0dbeb76..69b4620 100644 --- a/src/main/OmJShah/initialization/check.py +++ b/src/main/OmJShah/initialization/check.py @@ -1,11 +1,11 @@ def check(): try: - with open("firsttime.txt","r") as a: + with open("files//firsttime.txt","r") as a: if a.read().strip()=="True": return True else: return False except FileNotFoundError: - with open("firsttime.txt","w") as a: + with open("files//firsttime.txt","w") as a: a.write("True") return True \ No newline at end of file diff --git a/src/main/OmJShah/initialization/setup.py b/src/main/OmJShah/initialization/setup.py index 51fb5be..d10e5ad 100644 --- a/src/main/OmJShah/initialization/setup.py +++ b/src/main/OmJShah/initialization/setup.py @@ -100,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] @@ -108,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] @@ -152,7 +152,7 @@ def querycheck(): else: print("OK") if existing==8: - with open("firsttime.txt","w") as f: + with open("files//firsttime.txt","w") as f: f.write("False") ans=True @@ -167,7 +167,7 @@ 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() diff --git a/src/main/OmJShah/panels/clientpanel.py b/src/main/OmJShah/panels/clientpanel.py index 183cebf..beac826 100644 --- a/src/main/OmJShah/panels/clientpanel.py +++ b/src/main/OmJShah/panels/clientpanel.py @@ -1,6 +1,9 @@ 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!!") @@ -25,15 +28,18 @@ def cp(conn,cur): 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") - print("6.Check loan status") + 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 @@ -45,10 +51,15 @@ def cmenu(conn,cur,acc_no,acc_type): elif choice=="2": depositmoney.cp2(conn,cur,acc_type,acc_no) elif choice=="3": - pass + withdrawmoney.cp3(conn,cur,acc_type,acc_no) elif choice=="4": redeemcode.cp4(conn,cur,acc_type,acc_no) elif choice=="5": - pass + loan_od.cp5(conn,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/tests.py b/src/main/OmJShah/tests.py index 61c983b..163a11a 100644 --- a/src/main/OmJShah/tests.py +++ b/src/main/OmJShah/tests.py @@ -1,8 +1,6 @@ -from employee import deleteaccount -from tools import connection -from panels import clientpanel -conn,cur=connection.cc() -clientpanel.cp(conn,cur) +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 index 70bd1ef..4e5d229 100644 --- a/src/main/OmJShah/tools/connection.py +++ b/src/main/OmJShah/tools/connection.py @@ -5,7 +5,7 @@ def cc(): global cur global conn if not check.check(): - cred = open("cred.dat","rb") + cred = open("files//cred.dat","rb") dat=pickle.load(cred) cred.close() Passwo=dat[0] diff --git a/src/main/OmJShah/tools/dataentering.py b/src/main/OmJShah/tools/dataentering.py index 285b353..0f89da1 100644 --- a/src/main/OmJShah/tools/dataentering.py +++ b/src/main/OmJShah/tools/dataentering.py @@ -168,7 +168,7 @@ def date2(person,birth_date,hire_or_creation,minage,maxage): elif age(birth_date)-age(hire_date)>=minage: break else: - print("{} must atleast be {} years of age!!".format(person,maxage)) + print("{} must atleast be {} years of age!!".format(person,minage)) return hire_date def mobileno(): @@ -239,29 +239,47 @@ def balance(): print("Minimum balance is 1000 currency") #Withdraw amount and Deposit amount -def amounts(deposit_or_withdraw,cash_in_hand,acc_type): +def amounts(deposit_or_withdraw_or_transfer,cash_in_hand_or_balance,acc_type): while True: print() - print("--------------------{} screen-------------------") - amt=input("Enter amount to {}: ".format(deposit_or_withdraw)) + 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)) + print("{} amount should be an integer!!".format(deposit_or_withdraw_or_transfer)) else: - if amt Date: Sun, 1 Jan 2023 13:01:16 +0530 Subject: [PATCH 18/18] Initialised loan and overdraft methods (Untested) --- src/main/OmJShah/client/loan_od.py | 77 +++++++++++++++++++++- src/main/OmJShah/employee/deleteaccount.py | 56 +++++++++------- src/main/OmJShah/panels/clientpanel.py | 2 +- 3 files changed, 110 insertions(+), 25 deletions(-) diff --git a/src/main/OmJShah/client/loan_od.py b/src/main/OmJShah/client/loan_od.py index ee71c9d..60ea87f 100644 --- a/src/main/OmJShah/client/loan_od.py +++ b/src/main/OmJShah/client/loan_od.py @@ -1,3 +1,76 @@ from tools import dataentering -def cp5(conn,cur,acc_type,acc_no): - pass \ No newline at end of file +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/employee/deleteaccount.py b/src/main/OmJShah/employee/deleteaccount.py index f0c7957..9f57fdb 100644 --- a/src/main/OmJShah/employee/deleteaccount.py +++ b/src/main/OmJShah/employee/deleteaccount.py @@ -23,29 +23,41 @@ def ep3(conn,cur): else : results1=results[0] acc_type=results1[1] - if acc_type == 'S': acc_type="savings" - if acc_type == 'C': acc_type="current" + 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] - 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 + 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 from {} table was unsuccessful".format(acc_type)) + print("Deletion was unsuccessful") else: - print("Deletion was unsuccessful") - else: - break + break diff --git a/src/main/OmJShah/panels/clientpanel.py b/src/main/OmJShah/panels/clientpanel.py index beac826..597ad57 100644 --- a/src/main/OmJShah/panels/clientpanel.py +++ b/src/main/OmJShah/panels/clientpanel.py @@ -55,7 +55,7 @@ def cmenu(conn,cur,acc_no,acc_type): elif choice=="4": redeemcode.cp4(conn,cur,acc_type,acc_no) elif choice=="5": - loan_od.cp5(conn,cur,acc_type,acc_no) + 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()