Employee Management System Project in Python

SpyroAI Avatar
\"Employee

Introduction:

Employer management can be a challenging endeavour, particularly for large firms. Monitoring the work output, attendance, and other pertinent information of employees takes a lot of time, effort, and resources. Systems for managing employees (EMS) are helpful in this situation. A software solution called an employee management system aids companies in effectively managing their personnel.

The Employee Management System Project in Python, a well-liked open-source language that can assist you in developing an effective EMS for your business, will be covered in this article. We will discuss how Python may be used to construct an EMS and its key features and functionalities.

What is an Employee Management System (EMS)?

Organizations can manage the data, performance, attendance, and other relevant data of their employees with the aid of a workforce management system (EMS), a software solution. It aids businesses in reducing their HR procedures and making educated decisions.

An EMS often has features like managing personnel data, tracking attendance, handling leaves of absence, administering payroll, evaluating performance, and more. To suit a company\’s specific requirements, these features might be changed.

Why Python for Employee Management Systems?

Popular open-source computer language Python is praised for being straightforward and user-friendly. It is commonly used in website designing, machine learning, and information science. Python offers a sizable library of packages and frameworks that facilitate the rapid development of complex applications.

As Python is simple to learn, has a simple syntax, and is very readable, it is a great choice for creating employee management systems. It also has a large developer community that contributes to its growth and supports its users.

Features of Employee Management System Project in Python:

the administration of employee data

An employee\’s personal data, employment record, and contact information should be stored and handled via an EMS feature. Lists, tuples, and dictionaries are just a few of the built-in data structures that Python offers to make managing and storing data simple.

Attendance monitoring

Employee attendance tracking should be an element of an EMS. Card readers, biometric systems, or manual entry can all serve this purpose. The OpenCV, face recognition, and pyzbar packages that Python offers make it simple to integrate biometric technology with an EMS.

Quit administration:

A component for managing employee leave, including sick leave, vacation leave, and personal leave, should be included in an EMS. The built-in datetime module of Python can be used to compute leave balances and keep track of leave requests.

Payroll administration:

A component for handling employee payroll, including salaries, overtime, and bonuses, ought to be included in an EMS. Payroll calculations and reporting mechanisms are made simple by Python\’s support for libraries like Pandas and NumPy.

Performance assessment:

A component for assessing employee productivity should be included in an EMS, such as the ability to set goals, monitor advancement, and offer feedback. Python offers libraries like Flask and Django that make it simple to create web-based solutions for performance measurement.

Installing Packages

To install the MySQL client package, type the following command:

pip install mysqlclient

To install the mysql-connector-python package, type the following command:

pip install mysql-connector-python

To install the pymysql package, type the following command:

pip install pymysql

Code Flow:

Creating a database in MySQL “employee”

import mysql.connector
#making Connection
con = mysql.connector.connect (
host = \" localhost \" , user = \" root \" , password = \"root\")
mycursor= con.cursor() #allows row-by-row processing of the result sets.
mycursor.execute(\"CREATE DATABASE \"employee\")

Creating a Table in MySQL

import mysql.connector
#making Connection
con = mysql.connector.connect (
host = \" localhost \" , user = \" root \" , password = \"root\" , database = \" employee \" )
mycursor= con.cursor()
mycursor.execute(\"CREATE TABLE empdata ( Id INT(11) PRIMARY KEY , Name VARCHAR(1800), Emial_Id TEXT(1800),Phone_no BIGINT( 11 ), Address TEXT(1000), Post TEXT(1000), Salary BIGINT(20))\")

Add Employee to employee management system project python

def Add_Employ():
print(\”{:>60}\”.format(\”–>>Add Employee Record<<–\”))
Id = input(\”Enter Employee Id: \”)

if (check_employee(Id) == True):
    print(\"Employee ID Already Exists\\nTry Again..\")
    press = input(\"Press Any Key To Continue..\")
    Add_Employ()
Name = input(\"Enter Employee Name: \")

if (check_employee_name(Name) == True):
    print(\"Employee Name Already Exists\\nTry Again..\")
    press = input(\"Press Any Key To Continue..\")
    Add_Employ
Email_Id = input(\"Enter Employee Email ID: \")
if(re.fullmatch(regex, Email_Id)):
    print(\"Valid Email\")
else:
    print(\"Invalid Email\")
    press = input(\"Press Any Key To Continue..\")
    Add_Employ()
Phone_no = input(\"Enter Employee Phone No.: \")
if(Pattern.match(Phone_no)):
    print(\"Valid Phone Number\")
else:
    print(\"Invalid Phone Number\")
    press = input(\"Press Any Key To Continue..\")
    Add_Employ()
Address = input(\"Enter Employee Address: \")
Post = input(\"Enter Employee Post: \")
Salary = input(\"Enter Employee Salary: \")
data = (Id, Name, Email_Id, Phone_no, Address, Post, Salary)

sql = \'insert into empdata values(%s,%s,%s,%s,%s,%s,%s)\'
c = con.cursor()


c.execute(sql, data)

con.commit()
print(\"Successfully Added Employee Record\")
press = input(\"Press Any Key To Continue..\")
menu()

Check Employee in employee management system project python

def check_employee_name(employee_name):

sql = \'select * from empdata where Name=%s\'

c = con.cursor(buffered=True)
data = (employee_name,)

c.execute(sql, data)


r = c.rowcount
if r == 1:
    return True
else:
    return False

def check_employee(employee_id):

sql = \'select * from empdata where Id=%s\'


c = con.cursor(buffered=True)
data = (employee_id,)


c.execute(sql, data)

r = c.rowcount
if r == 1:
    return True
else:
    return False

Adding Display Employee function to python employee management system

def Display_Employ():
print(\”{:>60}\”.format(\”–>> Display Employee Record <<–\”))

sql = \'select * from empdata\'
c = con.cursor()

c.execute(sql)

r = c.fetchall()
for i in r:
    print(\"Employee Id: \", i[0])
    print(\"Employee Name: \", i[1])
    print(\"Employee Email Id: \", i[2])
    print(\"Employee Phone No.: \", i[3])
    print(\"Employee Address: \", i[4])
    print(\"Employee Post: \", i[5])
    print(\"Employee Salary: \", i[6])
    print(\"\\n\")
press = input(\"Press Any key To Continue..\")
menu()

Add Update Employee function in employee management system python

def Update_Employ():
print(\”{:>60}\”.format(\”–>> Update Employee Record <<–\\n\”))
Id = input(\”Enter Employee Id: \”)

if(check_employee(Id) == False):
    print(\"Employee Record Not exists\\nTry Again\")
    press = input(\"Press Any Key To Continue..\")
    menu()
else:
    Email_Id = input(\"Enter Employee Email ID: \")
    if(re.fullmatch(regex, Email_Id)):
        print(\"Valid Email\")
    else:
        print(\"Invalid Email\")
        press = input(\"Press Any Key To Continue..\")
        Update_Employ()
    Phone_no = input(\"Enter Employee Phone No.: \")
    if(Pattern.match(Phone_no)):
        print(\"Valid Phone Number\")
    else:
        print(\"Invalid Phone Number\")
        press = input(\"Press Any Key To Continue..\")
        Update_Employ()
    Address = input(\"Enter Employee Address: \")

    sql = \'UPDATE empdata set Email_Id = %s, Phone_no = %s, Address = %s where Id = %s\'
    data = (Email_Id, Phone_no, Address, Id)
    c = con.cursor()


    c.execute(sql, data)


    con.commit()
    print(\"Updated Employee Record\")
    press = input(\"Press Any Key To Continue..\")
    menu()

To Promote Employees in python project on employee management system

def Promote_Employ():
print(\”{:>60}\”.format(\”–>> Promote Employee Record <<–\\n\”))
Id = input(\”Enter Employee Id: \”)

if(check_employee(Id) == False):
    print(\"Employee Record Not exists\\nTry Again\")
    press = input(\"Press Any Key To Continue..\")
    menu()
else:
    Amount  = int(input(\"Enter Increase Salary: \"))

    sql = \'select Salary from empdata where Id=%s\'
    data = (Id,)
    c = con.cursor()

    c.execute(sql, data)

    r = c.fetchone()
    t = r[0]+Amount

    sql = \'update empdata set Salary = %s where Id = %s\'
    d = (t, Id)

    c.execute(sql, d)

    con.commit()
    print(\"Employee Promoted\")
    press = input(\"Press Any key To Continue..\")
    menu()

Remove Employee from employee management system in python with database

def Remove_Employ():
print(\”{:>60}\”.format(\”–>> Remove Employee Record <<–\\n\”))
Id = input(\”Enter Employee Id: \”)

if(check_employee(Id) == False):
    print(\"Employee Record Not exists\\nTry Again\")
    press = input(\"Press Any Key To Continue..\")
    menu()
else:

    sql = \'delete from empdata where Id = %s\'
    data = (Id,)
    c = con.cursor()


    c.execute(sql, data)

    con.commit()
    print(\"Employee Removed\")
    press = input(\"Press Any key To Continue..\")
    menu()

Complete Source Code for Employee Management System Project in Python

#Employee Management System Using Python – spyroai.com

from os import system
import re

import mysql.connector

con = mysql.connector.connect(
host=\”localhost\”, user=\”username\”, password=\”yourpassword\”)

cursorObject = con.cursor()

cursorObject.execute(\”CREATE DATABASE employee\”)

regex = r\’\\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+.[A-Z|a-z]{2,}\\b\’

Pattern = re.compile(\”(0|91)?[7-9][0-9]{9}\”)

def Add_Employ():
print(\”{:>60}\”.format(\”–>>Add Employee Record<<–\”))
Id = input(\”Enter Employee Id: \”)

if (check_employee(Id) == True):
    print(\"Employee ID Already Exists\\nTry Again..\")
    press = input(\"Press Any Key To Continue..\")
    Add_Employ()
Name = input(\"Enter Employee Name: \")

if (check_employee_name(Name) == True):
    print(\"Employee Name Already Exists\\nTry Again..\")
    press = input(\"Press Any Key To Continue..\")
    Add_Employ
Email_Id = input(\"Enter Employee Email ID: \")
if(re.fullmatch(regex, Email_Id)):
    print(\"Valid Email\")
else:
    print(\"Invalid Email\")
    press = input(\"Press Any Key To Continue..\")
    Add_Employ()
Phone_no = input(\"Enter Employee Phone No.: \")
if(Pattern.match(Phone_no)):
    print(\"Valid Phone Number\")
else:
    print(\"Invalid Phone Number\")
    press = input(\"Press Any Key To Continue..\")
    Add_Employ()
Address = input(\"Enter Employee Address: \")
Post = input(\"Enter Employee Post: \")
Salary = input(\"Enter Employee Salary: \")
data = (Id, Name, Email_Id, Phone_no, Address, Post, Salary)

sql = \'insert into empdata values(%s,%s,%s,%s,%s,%s,%s)\'
c = con.cursor()

c.execute(sql, data)


con.commit()
print(\"Successfully Added Employee Record\")
press = input(\"Press Any Key To Continue..\")
menu()

def check_employee_name(employee_name):

sql = \'select * from empdata where Name=%s\'


c = con.cursor(buffered=True)
data = (employee_name,)


c.execute(sql, data)

r = c.rowcount
if r == 1:
    return True
else:
    return False

def check_employee(employee_id):

sql = \'select * from empdata where Id=%s\'


c = con.cursor(buffered=True)
data = (employee_id,)


c.execute(sql, data)

r = c.rowcount
if r == 1:
    return True
else:
    return False

def Display_Employ():
print(\”{:>60}\”.format(\”–>> Display Employee Record <<–\”))

sql = \'select * from empdata\'
c = con.cursor()

c.execute(sql)


r = c.fetchall()
for i in r:
    print(\"Employee Id: \", i[0])
    print(\"Employee Name: \", i[1])
    print(\"Employee Email Id: \", i[2])
    print(\"Employee Phone No.: \", i[3])
    print(\"Employee Address: \", i[4])
    print(\"Employee Post: \", i[5])
    print(\"Employee Salary: \", i[6])
    print(\"\\n\")
press = input(\"Press Any key To Continue..\")
menu()

def Update_Employ():
print(\”{:>60}\”.format(\”–>> Update Employee Record <<–\\n\”))
Id = input(\”Enter Employee Id: \”)

if(check_employee(Id) == False):
    print(\"Employee Record Not exists\\nTry Again\")
    press = input(\"Press Any Key To Continue..\")
    menu()
else:
    Email_Id = input(\"Enter Employee Email ID: \")
    if(re.fullmatch(regex, Email_Id)):
        print(\"Valid Email\")
    else:
        print(\"Invalid Email\")
        press = input(\"Press Any Key To Continue..\")
        Update_Employ()
    Phone_no = input(\"Enter Employee Phone No.: \")
    if(Pattern.match(Phone_no)):
        print(\"Valid Phone Number\")
    else:
        print(\"Invalid Phone Number\")
        press = input(\"Press Any Key To Continue..\")
        Update_Employ()
    Address = input(\"Enter Employee Address: \")

    sql = \'UPDATE empdata set Email_Id = %s, Phone_no = %s, Address = %s where Id = %s\'
    data = (Email_Id, Phone_no, Address, Id)
    c = con.cursor()


    c.execute(sql, data)

    con.commit()
    print(\"Updated Employee Record\")
    press = input(\"Press Any Key To Continue..\")
    menu()

def Promote_Employ():
print(\”{:>60}\”.format(\”–>> Promote Employee Record <<–\\n\”))
Id = input(\”Enter Employee Id: \”)

if(check_employee(Id) == False):
    print(\"Employee Record Not exists\\nTry Again\")
    press = input(\"Press Any Key To Continue..\")
    menu()
else:
    Amount  = int(input(\"Enter Increase Salary: \"))

    sql = \'select Salary from empdata where Id=%s\'
    data = (Id,)
    c = con.cursor()


    c.execute(sql, data)

    r = c.fetchone()
    t = r[0]+Amount

    sql = \'update empdata set Salary = %s where Id = %s\'
    d = (t, Id)

    c.execute(sql, d)


    con.commit()
    print(\"Employee Promoted\")
    press = input(\"Press Any key To Continue..\")
    menu()

def Remove_Employ():
print(\”{:>60}\”.format(\”–>> Remove Employee Record <<–\\n\”))
Id = input(\”Enter Employee Id: \”)

if(check_employee(Id) == False):
    print(\"Employee Record Not exists\\nTry Again\")
    press = input(\"Press Any Key To Continue..\")
    menu()
else:
    sql = \'delete from empdata where Id = %s\'
    data = (Id,)
    c = con.cursor()

    c.execute(sql, data)

    con.commit()
    print(\"Employee Removed\")
    press = input(\"Press Any key To Continue..\")
    menu()

def Search_Employ():
print(\”{:>60}\”.format(\”–>> Search Employee Record <<–\\n\”))
Id = input(\”Enter Employee Id: \”)

if(check_employee(Id) == False):
    print(\"Employee Record Not exists\\nTry Again\")
    press = input(\"Press Any Key To Continue..\")
    menu()
else:

    sql = \'select * from empdata where Id = %s\'
    data = (Id,)
    c = con.cursor()

    c.execute(sql, data)


    r = c.fetchall()
    for i in r:
        print(\"Employee Id: \", i[0])
        print(\"Employee Name: \", i[1])
        print(\"Employee Email Id: \", i[2])
        print(\"Employee Phone No.: \", i[3])
        print(\"Employee Address: \", i[4])
        print(\"Employee Post: \", i[5])
        print(\"Employee Salary: \", i[6])
        print(\"\\n\")
    press = input(\"Press Any key To Continue..\")
    menu()

def menu():
system(\”cls\”)
print(\”{:>60}\”.format(\”\”))
print(\”{:>60}\”.format(\”–>> Employee Management System <<–\”)) print(\”{:>60}\”.format(\”\”))
print(\”1. Add Employee\”)
print(\”2. Display Employee Record\”)
print(\”3. Update Employee Record\”)
print(\”4. Promote Employee Record\”)
print(\”5. Remove Employee Record\”)
print(\”6. Search Employee Record\”)
print(\”7. Exit\\n\”)
print(\”{:>60}\”.format(\”–>> Choice Options: [1/2/3/4/5/6/7] <<–\”))

ch = int(input(\"Enter your Choice: \"))
if ch == 1:
    system(\"cls\")
    Add_Employ()
elif ch == 2:
    system(\"cls\")
    Display_Employ()
elif ch == 3:
    system(\"cls\")
    Update_Employ()
elif ch == 4:
    system(\"cls\")
    Promote_Employ()
elif ch == 5:
    system(\"cls\")
    Remove_Employ()
elif ch == 6:
    system(\"cls\")
    Search_Employ()
elif ch == 7:
    system(\"cls\")
    print(\"{:>60}7\".format(\"Have A NIce Day :)\"))
    exit(0)
else:
    print(\"Invalid Choice!\")
    press = input(\"Press Any key To Continue..\")
    menu()

menu()