0% found this document useful (0 votes)
8 views

PayRoll

The document outlines a Python program for managing a payroll system using MySQL. It includes functionalities for creating a database and table, adding employee records, displaying records, deleting records, modifying records, and generating payroll and salary slips. The program features a menu-driven interface for user interaction and employs the 'tabulate' library for formatted output.

Uploaded by

minsrathair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views

PayRoll

The document outlines a Python program for managing a payroll system using MySQL. It includes functionalities for creating a database and table, adding employee records, displaying records, deleting records, modifying records, and generating payroll and salary slips. The program features a menu-driven interface for user interaction and employs the 'tabulate' library for formatted output.

Uploaded by

minsrathair
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

# #PAYROLL Project

import mysql.connector
import datetime
from tabulate import tabulate
"""
from tabulate import tabulate
l=[(1,"John",100),(2,"Dan",200),(3,"Sam",300)]
print(tabulate(l))
print(tabulate(l,header=["M1","M2","M3"]))
print(tabulate(l,headers=["M1","M2","M3"],tablefmt='fancy_grid'))
print(tabulate(l,headers=["M1","M2","M3"],tablefmt='psql'))

"""
db=input("enter name of the database :")

mydb=mysql.connector.connect(host="localhost", user="root", password="root")


mycursor=mydb.cursor()

sql="CREATE DATABASE if not exists %s"% (db,)


mycursor.execute(sql)
print("Database created successfully...")
mycursor=mydb.cursor()
mycursor.execute("Use "+db)
TableName=input("Name of Table to be created :")
query="Create table if not exists "+TableName+" \
(mempno int primary key,\
mname varchar(15) not null,\
mjob varchar(15),\
BasicSalary int,\
DA float, HRA float, GrossSalary float,Tax Float, NetSalary float)"
print("Table "+TableName+" Created successfully.....")
mycursor.execute(query)
while True:
print("\n\n")
print("*"*95)
print("\t\t\t\t\t\t MAIN MENU")
print("*" * 95)
print("\t\t\t\t1. Adding Employee records")
print("\t\t\t\t2. For Displaying Record of All the Employees")
print("\t\t\t\t3. For Displaying Record of a perticular employee" )
print("\t\t\t\t4. For Deletes of all the Employees ")
print("\t\t\t\t5. For Deleting a Record of Particular Employee")
print("\t\t\t\t6. For Modification in a Record")
print("\t\t\t\t7. For Displaying Payroll")
print("\t\t\t\t8. For Displaying Salary slip for all Employee")
print("\t\t\t\t9. For Displaying Salary for particular Employee")
print("\t\t\t\t10. Exit")
print("Enter Choice ...:", end="")
ch=int(input())
if ch==1:
try:
print("Enter the employee information.....")
mempno=int(input("Enter employee no :"))
mname=input("Enter employee name :")
mjob=input("Enter employee Job :")
mbasic=float(input("Enter basic Salary :"))
if mjob.upper()=="OFFICER":
mda=mbasic*0.5
mhra=mbasic*0.35
mtax=mbasic*0.2
elif mjob.upper()=="MANAGER":
mda=mbasic*0.45
mhra= mbasic*0.30
mtax=mbasic*0.15
else:
mda=mbasic*0.40
mhra=mbasic*0.25
mtax=mbasic*0.1
mgross=mbasic+mda+mhra
mnet=mgross-mtax
rec=(mempno,mname,mjob,mbasic,mda,mhra,mgross,mtax,mnet)
query="insert into "+TableName+" values(%s,%s,%s,%s,%s,%s,%s,%s,%s)"
mycursor.execute(query,rec)
mydb.commit()
print("record added successfully....")
except Exception as e:
print("Something went Wrong",e)
elif ch==2:
try:
query="select * from "+TableName
mycursor.execute(query)
print(tabulate(mycursor,headers=["Empno","Name","Job","Basic
Salary","DA","HRA","Gross Salary","Tax","Net Salary"],tablefmt='psql'))
'''myrecords=mycursor.fetchall()
for rec in myrecords :
print(rec)'''
except:
print("Something went Wrong")
elif ch==3:
try:
en=input("Enter employee no. of the record to be displayed ....")
query="select * from "+TableName+" where mempno="+en
mycursor.execute(query)
myrecord=mycursor.fetchone()
print("\n\n Record of Employee No :"+en)
print(myrecord)
c=mycursor.rowcount
if c==-1:
print("Nothing to Display")
except:
print("Something Went Wrong")
elif ch==4:
try:
ch=input("Do you want to delete all the records (y/n) :")
if ch.upper()=="Y":
mycursor.execute("delete from "+TableName)
mydb.commit()
print("All the records are deleted....")
except:
print("Something went wrong")
elif ch==5:
try:
en=input("enter Employee no of the record to be deleted....")
query="delete from "+TableName+' where mempno ='+en
mycursor.execute(query)
mydb.commit()
c=mycursor.rowcount
if c>0:
print("Deletion Done...")
else:
print("Employee no ",en,' not found')
except:
print("Something went wrong")

elif ch==6:
try:
en=input("Enter eEmployee no. of the recor to be modified ...")
query="select * from "+TableName+' where mempno='+en
mycursor.execute(query)
myrecord=mycursor.fetchone()
c=mycursor.rowcount
if c==-1:
print("Empno "+en+' does not exist')
else:
mname=myrecord[1]
mjob=myrecord[2]
mbasic=myrecord[3]
print("Empno :",myrecord[0])
print("Name :", myrecord[1])
print("Job :", myrecord[2])
print("Basic :", myrecord[3])
print("DA :", myrecord[4])
print("HRA :",myrecord[5])
print("Gross :",myrecord[6])
print("Tax :",myrecord[7])
print("Net :", myrecord[8])
print("----------------------")
print("type Value to modify below or just press Enter for no change
")
x=input("Enter Name :")
if len(x)>0:
mname=x
x=input("ENter Job :")
if len(x)>0:
mjob=x
x=input("Enter Basic Salary :")
if len(x)>0:
mbasic=float(x)
query="update "+TableName+" set
mname="+"'"+mname+"'"+","+"mjob="+"'"+mjob+"'"+","+"BasicSalary="\
+str(mbasic)+" where mempno="+en
print(query)
mycursor.execute(query)
mydb.commit()
print("Record Modified")
except:
print("something went Wrong")
elif ch==7:
try:
query="Select * from "+TableName
mycursor.execute(query)
myrecords=mycursor.fetchall()
print("\n\n\n")
print(95*"*")
print("Employee Payroll".center(90))
print(95*"*")
now=datetime.datetime.now()
print("Current Date and Time :",end=" ")
print(now.strftime("%Y-%m-%d %H:%M:%S"))
print()
print(95*'-')
print('%-5s %-15s %-10s %-8s %-8s %-8s %-9s %-8s %-9s' %
("Empno","Name","job","Basic","DA","HRA","Gross","Tax","Net"))
print(95*"*")
for rec in myrecords:
print('%4d %-15s %-10s %-8.2f %-8.2f %8.2f %9.2f %8.2f %9.2f' %rec)
print(95*"*")
except:
print("Something Went Wrong")
elif ch==8:
try:
query="Select * from "+TableName
mycursor.execute(query)
now=datetime.datetime.now()
print("\n\n\n")
print("-"*95)
print("Salary Slip".center(90))
print("-"*95)
print("Current Date and Time :", end=" ")
print(now.strftime("%y-%m-%d %H:%M:%S"))
myrecords=mycursor.fetchall()
for rec in myrecords:
print("%4d %-15s %-10s %8.2f %10.2f %10.2f %10.2f %10.2f
%9.2f"%rec)
except:
print("Something went wrong")

elif ch==9:
try:
en=input("Enter employee number whose pay slip you want to retreive :")
query="Select * from "+TableName+" where mempno= "+en
mycursor.execute(query)
now=datetime.datetime.now()
print("\n\n\t\t\t\t\tSALARY SLIP ")
print("\t\t\t\t\t-----------")
print("current Date and Time :",end=" ")
print(now.strftime("%y-%m-%d %H:%M:%S"))
print(tabulate(mycursor,["Empno","Name","Job","BAsic
Salary","DA","HRA","Gross","Tax","Net Salary"],))
except Exception as e:
print("Something went wrong ",e)
elif ch==10:
break
else:
print("Wrong Choice.....")

You might also like