Computer Science

You might also like

Download as pdf or txt
Download as pdf or txt
You are on page 1of 20

Index

NO. DESCRIPTION
1. List of libraries
2. List of functions
3. About the project
4. Code
5. Output

List of libraries
1. mysql.connector mysql.connector is used for
connecting to a MySQL
database server from Python.

List of Functions

No Functions Uses
Sets
1 up
connect()
a connection, establishing a session with MySql
server.
2 cursor() Used to execute SQL commands.
3 execute() Used to run queries in MySQL and get
the result back in Python.
4 commit() Used to save data in the database.
5 close() Transfers data from buffer memory to a
file and closes the file.

6. fetchone Fetches only one record from the object


(cur) to a
variable (data).

7. fetchall() Fetches all the data from the object


(cur) to a variable (data).
8. .update() The update() method inserts the
specified items to the dictionary. The
specified items can be a dictionary, or
an iterable object with key value pairs.
9. .insert() Insert ( index, ‘name’) is used to insert
string ‘name’ before the character at
the given index.
10. def() def is the keyword used in python for
defining a function.

11. .delete() the del statement is used to delete


objects. It can be used to delete
variables, items from a list, attributes
from an object, or even delete entire
slices from a list or elements from other
mutable sequences. The syntax of the
del statement varies based on what you
want to delete.

ABOUT THE PROJECt


Title : Employee Payroll System
Introduction:
Welcome to the Employee Payroll Project – a modern
solution designed to streamline and enhance your
organization's payroll management process. This
project is dedicated to leveraging the power of
technology to simplify payroll tasks, increase accuracy,
and save valuable time for your team.
A sophisticated endeavor dedicated to reshaping the
way your organization approaches payroll
management. In an era marked by technological
advancements, this project stands as a testament to
our commitment to innovation and efficiency.
Objective:
Our goal is to create an efficient and user-friendly
payroll system that automates payroll calculations,
ensures compliance with regulatory requirements, and
provides insightful reporting. By implementing this
system, we aim to bring transparency and efficiency to
the entire payroll process.
Key Features:
• Employee Data Management:
Store and manage employee information,
including personal details, salary structures, and
tax-related information securely in the MySQL
database.
• Salary Calculation:
Automate the salary calculation process based on
predefined salary structures, deductions, and
allowances.
• Payroll Reporting:
Generate detailed payroll reports for a specific
period, aiding in transparency and compliance with
regulatory requirements.
• User-Friendly Interface:
Develop an intuitive and easy-to-navigate user
interface using Python, ensuring accessibility for
users with varying technical backgrounds.
Functionality:
• Employee Data Management:
Add, update, and delete employee records.
Store comprehensive employee information,
including personal details, employment history, and
tax- related data.
• Payroll Configuration:
Define and configure various salary structures,
allowances, and deductions.
Set up tax brackets and rules for accurate tax
calculations.
• Comprehensive Reporting:
Generate detailed payroll reports, including
payslips, tax statements, and salary summaries.
Customizable reports for management and
compliance purposes.
Conclusion:
In concluding our Employee Payroll Project, we reflect
on the journey we undertook to redefine and elevate
the payroll management experience for your
organization. The integration of MySQL and Python has
not only facilitated the automation of routine tasks but
has laid the foundation for a dynamic, scalable, and
intelligent system that adapts to the evolving needs of
your workforce.

Code
import mysql.connector as mycon
cn =
mycon.connect(host='localhost',user='root',password
="root",database="company")
cur = cn.cursor()
def showAll():
global cn
global cur
try:
query="select * from emp"
cur.execute(query)
results = cur.fetchall()
print("-"*45)
print('%5s'%"EMPNO",'%15s'%'EMP
NAME','%12s'%'DEPARTMENT','%10s'%'SALARY')
print("-"*45)
count=0
for row in results:
print('%5s' %
row[0],'%15s'%row[1],'%12s'%row[2],'%10s'%row[3])
count+=1
print("-"*10,"TOTAL RECORD :",count,"-"*18)
except:
print("error")
def addEmp():
global cn,cur
print("-"*10,"ADD NEW EMPLOYEE","-"*10)
eno = int(input("Enter employee number :"))
en = input("Enter employee name :")
dp = input("Enter department ")
sl = int(input("Enter Salary :"))
query="insert into emp
values("+str(eno)+",'"+en+"','"+dp+"',"+str(sl)+")"
cur.execute(query)
cn.commit()
#print(query)
print("RECORD ADDED SUCCESSFULLY!")
def searchEmp():
global cn,cur
print("-"*10,"SEARCH EMPLOYEE FORM","-"*10)
en = int(input("Enter Employee number to search
:"))
query="select * from emp where eno="+str(en)
cur.execute(query)
results = cur.fetchall()
if cur.rowcount<=0:
print("SORRY! NO MATCHING DETAILS
AVAILABLE")
else:
print("-"*45)
print('%5s'%"EMPNO",'%15s'%'EMP
NAME','%12s'%'DEPARTMENT','%10s'%'SALARY')
print("-"*45)
for row in results:
print('%5s' %
row[0],'%15s'%row[1],'%12s'%row[2],'%10s'%row[3])
print("-"*50)
def editEmp():
global cn,cur
print("-"*10,"EDIT EMPLOYEE FORM","-"*10)
en = int(input("Enter Employee number to edit :"))
query="select * from emp where eno="+str(en)
cur.execute(query)
results = cur.fetchall()
if cur.rowcount<=0:
print("SORRY! NO MATCHING DETAILS
AVAILABLE")
else:
print("-"*45)
print('%5s'%"EMPNO",'%15s'%'EMP
NAME','%12s'%'DEPARTMENT','%10s'%'SALARY')
print("-"*45)
for row in results:
print('%5s' %
row[0],'%15s'%row[1],'%12s'%row[2],'%10s'%row[3])
print("-"*50)
ans = input("Are you sure to update ? (y/n)")
if ans=="y" or ans=="Y":
d = input("Enter new department to update
(enter old value if not to update) :")
s = int(input("Enter new salary to update (enter
old value if not to update) :"))
query="update emp set dp='"+d+"',sl="+str(s) + "
where eno="+str(en)
cur.execute(query)
cn.commit()
print("RECORD UPDATED!")

def delEmp():
global cn,cur
print("-"*10,"DELETE EMPLOYEE FORM","-"*10)
en = int(input("Enter Employee number to delete
:"))
query="select * from emp where eno="+str(en)
cur.execute(query)
results = cur.fetchall()
if cur.rowcount<=0:
print("SORRY! NO MATCHING DETAILS
AVAILABLE!")
else:
print("-"*45)
print('%5s'%"EMPNO",'%15s'%'EMP
NAME','%12s'%'DEPARTMENT','%10s'%'SALARY')
print("-"*45)
for row in results:
print('%5s' %
row[0],'%15s'%row[1],'%12s'%row[2],'%10s'%row[3])
print("-"*50)
ans = input("Are you sure to delete ? (y/n)")
if ans=="y" or ans=="Y":
query="delete from emp where eno="+str(en)
cur.execute(query)
cn.commit()
print("RECORD DELETED!")
def clear():
for i in range(1,50):
print()

def generateSlip():

global cn,cur
print("-"*10,"SALARY SLIP","-"*10)
en = int(input("Enter Employee number to print
salary slip :"))
query="select * from emp where eno="+str(en)
cur.execute(query)
results = cur.fetchone()
if cur.rowcount<=0:
print("SORRY! NO MATCHING DETAILS
AVAILABLE!")
else:
clear()
print("EMPNO :",results[0]," "*20,"NAME
:",results[1])
print("DEPARTMENT :",results[2])
print("-"*50)
s = int(results[3])
hra = s * 12/100
da = s * 15/100
it = 1000
nps = (s+hra)*10/100
gross = s +hra+da+nps
ded = it + nps
net = gross - ded
tded=it + nps

print("%19s"%"EARNING","%27s"%"DEDUCTION")
print("-------------------------------------------------")
print("%20s"%"Basic :"+str(s),"%20s"%"INC. TAX
:"+str(it))
print("%20s"%"HRA :"+str(hra),"%20s"%"NPS
:"+str(nps))
print("%20s"%"DA :"+str(da))
print("%20s"%"NPS :"+str(nps))
print("-"*70)
print(" GROSS :",gross," NET SALARY :",net,"
TOTAL DED :",tded)
print("-"*70)
print("=== PRESS ANY KEY ===")
input()
def abc():
print("1. SHOW EMPLOYEE LIST ")
print("2. ADD NEW EMPLOYEE")
print("3. SEARCH EMPLOYEE ")
print("4. EDIT EMPLOYEE ")
print("5. DELETE EMPLOYEE ")
print("6. GENERATE PAY SLIP ")
print("7. EXIT")
ans = int(input("Enter your choice :"))
if ans==1:
showAll()
elif ans==2:
addEmp()
elif ans==3:
searchEmp()
elif ans==4:
editEmp()
elif ans==5:
delEmp()
elif ans==6:
generateSlip()
elif ans==7:
print("\nBye!!")
cn.close()
def pqr():
print("1. Contact us")
print("2. Enter your emp no. to see your info ")
print("3. EXIT")
an=int(input("enter ur option:"))
if an==1:
print("-"*60)
print(" "*20,"AUTHOR : RIYA KUNDANANI ")
print(" "*20,"EMAIL :
RIYAKUNDANANI8@GMAIL.COM")
print("-"*60)
elif an==2:
searchEmp()
elif an==3:
print("byee")
while True:
print("-"*15)
print("1. Admin menu")
print("2. user menu")
print("3. Exit")
print("-"*15)
answer=int(input("choose ur option:"))
if answer==1:
R=input("Enter password:")
if R=="Riya1234":
abc()
else:
print("Incorrect password")
elif answer==2:
pqr()
elif answer==3:
print("Bye!!")
break
Output

You might also like