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