0% found this document useful (0 votes)
12 views29 pages

Employ Management System

Uploaded by

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

Employ Management System

Uploaded by

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

Employ Management System

An Employee Management System (EMS) is a vital tool for organizations


aiming to streamline and enhance their human resource operations. It
serves as a centralized platform for managing employee information,
from recruitment and onboarding to performance evaluation and
payroll processing. By automating various HR functions, such as
attendance tracking, leave management, and employee scheduling, an
EMS significantly reduces administrative workload, allowing HR
personnel to focus on strategic tasks that drive organizational growth.
Additionally, an effective EMS fosters better communication and
collaboration among team members. It provides employees with access
to their profiles, benefits, and performance metrics, empowering them
to take charge of their professional development. With features like
training management and skill assessments, organizations can identify
talent and facilitate career growth, ensuring that employees remain
engaged and motivated.
Moreover, data analytics capabilities within an EMS enable
organizations to make informed decisions by providing insights into
workforce trends, productivity levels, and employee satisfaction. By
leveraging this data, companies can implement strategies to enhance
retention and build a more skilled workforce. Overall, an Employee
Management System is an indispensable asset for any organization
looking to optimize its human resource processes and promote a
positive work environment.
1. Add Employee
2. Update Employee
3. View All Employees
4. Search Employee by ID
5. Search Employees by Department
6. Search Employees by Bonus
7. Search Employees by Salary Range
8. Search Employees by Manager
9. Delete Employee
Code
import csv

# Function to add a new employee to all CSV files


def add_employee():
# Collect employee information from the user
emp_id = input("Enter Employee ID: ")
name = input("Enter Employee Name: ")
age = input("Enter Employee Age: ")
dept_id = input("Enter Department ID (e.g., D001, D002): ")
dept_name = input("Enter Department Name: ")
address = input("Enter Employee Address: ")
phone = input("Enter Employee Phone Number: ")
email = input("Enter Employee Email: ")

# Salary Information
basic_salary = input("Enter Basic Salary: ")
allowances = input("Enter Allowances: ")
deductions = input("Enter Deductions: ")
bonus = input("Enter Bonus (0 if no bonus): ")

manager = input("Enter Department Manager Name: ")

# Append employee data to employees.csv


with open('D:\Computer sc\employees.csv', mode='a', newline='') as file:
writer = csv.writer(file)
writer.writerow([emp_id, name, age, dept_id, address, phone, email])
# Append department data to departments.csv
with open('D:\Computer sc\departments.csv', mode='a', newline='') as file:
writer = csv.writer(file)
writer.writerow([emp_id, name, dept_id, dept_name, manager])

# Append salary data to salaries.csv


with open('D:\Computer sc\salaries.csv', mode='a', newline='') as file:
writer = csv.writer(file)
writer.writerow([emp_id, name, dept_id, dept_name, basic_salary, allowances, deductions,
bonus])

print(f"Employee {name} added successfully to all files.")


return

# Function to update an employee record in all CSV files


def update_employee(emp_id):
# Update employee details in employees.csv
update_csv('employees.csv', emp_id, update_employee_record)

# Update department details in departments.csv


update_csv('departments.csv', emp_id, update_department_record)

# Update salary details in salaries.csv


update_csv('salaries.csv', emp_id, update_salary_record)

print(f"Employee {emp_id} record updated successfully.")


# Generic function to update a CSV file by employee ID
def update_csv(file_name, emp_id, update_func):
temp_file = 'temp.csv'

# Step 1: Read the original CSV and write updates to the temporary file
with open(file_name, mode='r', newline='') as file, open(temp_file, mode='w', newline='') as
temp:
reader = csv.reader(file)
writer = csv.writer(temp)

for row in reader:


if row[0] == emp_id: # Employee ID is in the first column of each file
updated_row = update_func(row) # Get updated record
writer.writerow(updated_row)
else:
writer.writerow(row)

# Step 2: Copy the temporary file back to the original file


with open(temp_file, mode='r', newline='') as temp, open(file_name, mode='w', newline='')
as file:
reader = csv.reader(temp)
writer = csv.writer(file)

for row in reader:


writer.writerow(row)

# Function to update employee details in employees.csv


def update_employee_record(row):
print("Updating employee details...")
print(f"Current Record: {row}")
row[1] = input(f"Update Name (current: {row[1]}): ") or row[1]
row[2] = input(f"Update Age (current: {row[2]}): ") or row[2]
row[3] = input(f"Update Department ID (current: {row[3]}): ") or row[3]
row[4] = input(f"Update Address (current: {row[4]}): ") or row[4]
row[5] = input(f"Update Phone Number (current: {row[5]}): ") or row[5]
row[6] = input(f"Update Email (current: {row[6]}): ") or row[6]
return row

# Function to update department details in departments.csv


def update_department_record(row):
print("Updating department details...")
print(f"Current Record: {row}")
row[2] = input(f"Update Department Name (current: {row[2]}): ") or row[2]
row[3] = input(f"Update Manager Name (current: {row[3]}): ") or row[3]
return row

# Function to update salary details in salaries.csv


def update_salary_record(row):
print("Updating salary details...")
print(f"Current Record: {row}")
row[4] = input(f"Update Basic Salary (current: {row[4]}): ") or row[4]
row[5] = input(f"Update Allowances (current: {row[5]}): ") or row[5]
row[6] = input(f"Update Deductions (current: {row[6]}): ") or row[6]
row[7] = input(f"Update Bonus (current: {row[7]}): ") or row[7]
return row

# Function to read data from a CSV file and return it as a list of dictionaries
def read_csv(file_name):
with open(file_name, mode='r', newline='') as file:
reader = csv.DictReader(file)
return list(reader)

# Function to view all employees with details from all three CSV files
def view_all_employees():
# Read data from all files
employees = read_csv('D:\Computer sc\employees.csv')
departments = read_csv('D:\Computer sc\departments.csv')
salaries = read_csv('D:\Computer sc\salaries.csv')

# Create a dictionary to store all employee details by Employee ID


all_details = {}

# Merge employees.csv
for emp in employees:
emp_id = emp['Employee ID']
all_details[emp_id] = {
'Employee ID': emp_id,
'Name': emp['Name'],
'Age': emp['Age'],
'Address': emp['Address'],
'Phone': emp['Contact Number'],
'Email': emp['Email']
}

# Merge departments.csv
for dept in departments:
emp_id = dept['Employee ID']
if emp_id in all_details:
all_details[emp_id].update({
'Department ID': dept['Department ID'],
'Department Name': dept['Department Name'],
'Manager': dept['Manager']
})

# Merge salaries.csv
for salary in salaries:
emp_id = salary['Employee ID']
if emp_id in all_details:
all_details[emp_id].update({
'Basic Salary': salary['Basic Salary'],
'Allowances': salary['Allowances'],
'Deductions': salary['Deductions'],
'Bonus': salary['Bonus']
})

# Print all employee details


for emp_id, details in all_details.items():
print(f"Employee ID: {details['Employee ID']}")
print(f"Name: {details['Name']}")
print(f"Age: {details['Age']}")
print(f"Address: {details['Address']}")
print(f"Phone: {details['Phone']}")
print(f"Email: {details['Email']}")
print(f"Department ID: {details.get('Department ID', 'N/A')}")
print(f"Department Name: {details.get('Department Name', 'N/A')}")
print(f"Manager: {details.get('Manager', 'N/A')}")
print(f"Basic Salary: {details.get('Basic Salary', 'N/A')}")
print(f"Allowances: {details.get('Allowances', 'N/A')}")
print(f"Deductions: {details.get('Deductions', 'N/A')}")
print(f"Bonus: {details.get('Bonus', 'N/A')}")
print("-" * 40)
return

# Function to delete an employee record from all CSV files


def delete_employee(emp_id):
# Delete employee record from employees.csv
delete_from_csv('employees.csv', emp_id)

# Delete employee record from departments.csv


delete_from_csv('departments.csv', emp_id)

# Delete employee record from salaries.csv


delete_from_csv('salaries.csv', emp_id)
print(f"Employee {emp_id} deleted successfully from all files.")

# Function to delete a record by Employee ID from a specific CSV file


def delete_from_csv(file_name, emp_id):
temp_file = 'temp.csv'

# Step 1: Read the original file and write non-deleted rows to the temporary file
with open(file_name, mode='r', newline='') as file, open(temp_file, mode='w', newline='') as
temp:
reader = csv.reader(file)
writer = csv.writer(temp)

header = next(reader) # Read the header row


writer.writerow(header) # Write the header to the temp file

for row in reader:


if row[0] != emp_id: # If Employee ID doesn't match, copy the row to the temp file
writer.writerow(row)

# Step 2: Copy the temporary file back to the original file


with open(temp_file, mode='r', newline='') as temp, open(file_name, mode='w', newline='')
as file:
reader = csv.reader(temp)
writer = csv.writer(file)

for row in reader:


writer.writerow(row)
return

# Function to search for an employee by Employee ID in all CSV files


def search_employee(emp_id):
# Read and store all data from the three CSV files
with open('D:\Computer sc\employees.csv', mode='r', newline='') as emp_file, \
open('D:\Computer sc\departments.csv', mode='r', newline='') as dept_file, \
open('D:\Computer sc\salaries.csv', mode='r', newline='') as sal_file:

# Read the employees.csv


emp_reader = csv.DictReader(emp_file)
employees = list(emp_reader)

# Read the departments.csv


dept_reader = csv.DictReader(dept_file)
departments = list(dept_reader)

# Read the salaries.csv


sal_reader = csv.DictReader(sal_file)
salaries = list(sal_reader)

# Search for the employee in employees.csv


employee = next((emp for emp in employees if emp['Employee ID'] == emp_id), None)
if not employee:
print(f"Employee with ID {emp_id} not found.")
return

# Search for the department and salary information using the same Employee ID
department = next((dept for dept in departments if dept['Employee ID'] == emp_id), None)
salary = next((sal for sal in salaries if sal['Employee ID'] == emp_id), None)

# Display the employee's details


print(f"Employee ID: {employee['Employee ID']}")
print(f"Name: {employee['Name']}")
print(f"Age: {employee['Age']}")
print(f"Address: {employee['Address']}")
print(f"Phone: {employee['Contact Number']}")
print(f"Email: {employee['Email']}")

if department:
print(f"Department ID: {department['Department ID']}")
print(f"Department Name: {department['Department Name']}")
print(f"Manager: {department['Manager']}")
else:
print("No department information found.")

if salary:
print(f"Basic Salary: {salary['Basic Salary']}")
print(f"Allowances: {salary['Allowances']}")
print(f"Deductions: {salary['Deductions']}")
print(f"Bonus: {salary['Bonus']}")
else:
print("No salary information found.")

print("-" * 40)

# Function to search employees by Department ID


def search_by_department(dept_id):
# Updated file paths with the specified directory
employees_file = r"D:\Computer sc\employees.csv"
departments_file = r"D:\Computer sc\departments.csv"

# Read and store all data from employees.csv and departments.csv


with open(employees_file, mode='r', newline='') as emp_file, \
open(departments_file, mode='r', newline='') as dept_file:

# Read the employees.csv


emp_reader = csv.DictReader(emp_file)
employees = list(emp_reader)

# Read the departments.csv


dept_reader = csv.DictReader(dept_file)
departments = list(dept_reader)

# Find all employees in the specified department


dept_employees = [dept for dept in departments if dept['Department ID'] == dept_id]

if not dept_employees:
print(f"No employees found in Department ID {dept_id}.")
return

# Display employees in the department


print(f"Employees in Department {dept_id}:")

for dept in dept_employees:


emp_id = dept['Employee ID']
# Find the corresponding employee details in employees.csv
employee = next((emp for emp in employees if emp['Employee ID'] == emp_id), None)

if employee:
print(f"\nEmployee ID: {employee['Employee ID']}")
print(f"Name: {employee['Name']}")
print(f"Age: {employee['Age']}")
print(f"Address: {employee['Address']}")
print(f"Phone: {employee['Contact Number']}")
print(f"Email: {employee['Email']}")
print(f"Department Name: {dept['Department Name']}")
print(f"Manager: {dept['Manager']}")
print("-" * 40)
else:
print(f"Details for Employee ID {emp_id} not found in employees.csv.")

# Function to search employees by Bonus


def search_by_bonus(bonus_amount):
# Updated file paths with the specified directory
employees_file = r"D:\Computer sc\employees.csv"
departments_file = r"D:\Computer sc\departments.csv"
salaries_file = r"D:\Computer sc\salaries.csv"

# Read and store all data from employees.csv, departments.csv, and salaries.csv
with open(employees_file, mode='r', newline='') as emp_file, \
open(departments_file, mode='r', newline='') as dept_file, \
open(salaries_file, mode='r', newline='') as sal_file:

# Read the employees.csv


emp_reader = csv.DictReader(emp_file)
employees = list(emp_reader)

# Read the departments.csv


dept_reader = csv.DictReader(dept_file)
departments = list(dept_reader)

# Read the salaries.csv and filter based on the given bonus


sal_reader = csv.DictReader(sal_file)
salaries = [sal for sal in sal_reader if sal['Bonus'] == str(bonus_amount)]

if not salaries:
print(f"No employees found with a bonus of {bonus_amount}.")
return

# Display employees with the matching bonus


print(f"Employees with a bonus of {bonus_amount}:")

for sal in salaries:


emp_id = sal['Employee ID']
# Find the corresponding employee details in employees.csv
employee = next((emp for emp in employees if emp['Employee ID'] == emp_id), None)
# Find the corresponding department details in departments.csv
department = next((dept for dept in departments if dept['Employee ID'] == emp_id), None)

if employee:
print(f"\nEmployee ID: {employee['Employee ID']}")
print(f"Name: {employee['Name']}")
print(f"Age: {employee['Age']}")
print(f"Address: {employee['Address']}")
print(f"Phone: {employee['Phone']}")
print(f"Email: {employee['Email']}")

if department:
print(f"Department ID: {department['Department ID']}")
print(f"Department Name: {department['Department Name']}")
print(f"Manager: {department['Manager']}")

print(f"Basic Salary: {sal['Basic Salary']}")


print(f"Allowances: {sal['Allowances']}")
print(f"Deductions: {sal['Deductions']}")
print(f"Bonus: {sal['Bonus']}")
print("-" * 40)
else:
print(f"Details for Employee ID {emp_id} not found in employees.csv.")

# Function to search employees by salary range


def search_by_salary_range(min_salary, max_salary):
# Updated file paths with the specified directory
employees_file = r"D:\Computer sc\employees.csv"
departments_file = r"D:\Computer sc\departments.csv"
salaries_file = r"D:\Computer sc\salaries.csv"

# Read and store all data from employees.csv, departments.csv, and salaries.csv
with open(employees_file, mode='r', newline='') as emp_file, \
open(departments_file, mode='r', newline='') as dept_file, \
open(salaries_file, mode='r', newline='') as sal_file:

# Read the employees.csv


emp_reader = csv.DictReader(emp_file)
employees = list(emp_reader)

# Read the departments.csv


dept_reader = csv.DictReader(dept_file)
departments = list(dept_reader)

# Read the salaries.csv and filter employees within the salary range
sal_reader = csv.DictReader(sal_file)
salaries = [sal for sal in sal_reader if min_salary <= float(sal['Basic Salary']) <= max_salary]
if not salaries:
print(f"No employees found with a salary between {min_salary} and {max_salary}.")
return

# Display employees with salaries in the specified range


print(f"Employees with a salary between {min_salary} and {max_salary}:")

for sal in salaries:


emp_id = sal['Employee ID']
# Find the corresponding employee details in employees.csv
employee = next((emp for emp in employees if emp['Employee ID'] == emp_id), None)
# Find the corresponding department details in departments.csv
department = next((dept for dept in departments if dept['Employee ID'] == emp_id), None)

if employee:
print(f"\nEmployee ID: {employee['Employee ID']}")
print(f"Name: {employee['Name']}")
print(f"Age: {employee['Age']}")
print(f"Address: {employee['Address']}")
print(f"Phone: {employee['Contact Number']}")
print(f"Email: {employee['Email']}")

if department:
print(f"Department ID: {department['Department ID']}")
print(f"Department Name: {department['Department Name']}")
print(f"Manager: {department['Manager']}")
print(f"Basic Salary: {sal['Basic Salary']}")
print(f"Allowances: {sal['Allowances']}")
print(f"Deductions: {sal['Deductions']}")
print(f"Bonus: {sal['Bonus']}")
print("-" * 40)
else:
print(f"Details for Employee ID {emp_id} not found in employees.csv.")

# Function to search employees by Manager's Name


def search_by_manager(manager_name):
# File paths
employees_file = r"D:\Computer sc\employees.csv"
departments_file = r"D:\Computer sc\departments.csv"

# Read and store all data from employees.csv and departments.csv


with open(employees_file, mode='r', newline='') as emp_file, \
open(departments_file, mode='r', newline='') as dept_file:

# Read the employees.csv


emp_reader = csv.DictReader(emp_file)
employees = list(emp_reader)

# Read the departments.csv and filter by manager's name


dept_reader = csv.DictReader(dept_file)
departments = [dept for dept in dept_reader if dept['Manager'] == manager_name]
if not departments:
print(f"No employees found working under manager: {manager_name}.")
return

# Display employees working under the specified manager


print(f"Employees working under manager: {manager_name}:")

for dept in departments:


emp_id = dept['Employee ID']
# Find the corresponding employee details in employees.csv
employee = next((emp for emp in employees if emp['Employee ID'] == emp_id), None)

if employee:
print(f"\nEmployee ID: {employee['Employee ID']}")
print(f"Name: {employee['Name']}")
print(f"Age: {employee['Age']}")
print(f"Address: {employee['Address']}")
print(f"Phone: {employee['Contact Number']}")
print(f"Email: {employee['Email']}")
print(f"Department ID: {dept['Department ID']}")
print(f"Department Name: {dept['Department Name']}")
print(f"Manager: {dept['Manager']}")
print("-" * 40)
else:
print(f"Details for Employee ID {emp_id} not found in employees.csv.")
return
#Main Program

print("--- Employee Management System ---")


print("1. Add Employee")
print("2. Update Employee")
print("3. View All Employees")
print("4. Search Employee by ID")
print("5. Search Employees by Department")
print("6. Search Employees by Bonus")
print("7. Search Employees by Salary Range")
print("8. Search Employees by Manager")
print("9. Delete Employee")
print("0. Exit")

# Get user choice


choice = input("Enter your choice: ")

# Execute based on user choice


if choice == '1':
add_employee()
elif choice == '2':
emp_id = input("Enter Employee ID to update: ")
update_employee(emp_id)
elif choice == '3':
view_all_employees()
elif choice == '4':
emp_id = input("Enter Employee ID to search: ")
search_employee(emp_id)
elif choice == '5':
dept_id = input("Enter Department ID to search: ")
search_by_department(dept_id)
elif choice == '6':
bonus_amount = input("Enter Bonus amount to search: ")
search_by_bonus(bonus_amount)
elif choice == '7':
min_salary = float(input("Enter minimum salary: "))
max_salary = float(input("Enter maximum salary: "))
search_by_salary_range(min_salary, max_salary)
elif choice == '8':
manager_name = input("Enter Manager's Name to search: ")
search_by_manager(manager_name)
elif choice == '9':
emp_id = input("Enter Employee ID to delete: ")
delete_employee(emp_id)
elif choice == '0':
print("Exiting the program.")
else:
print("Invalid choice. Please try again.")

Add Employee
Update employee
View All Employee
Search Employee by ID

Search Employees by Department


Search Employees by Bonus
Search Employees by Salary Range
Search Employees by Manager

Delete Employee

You might also like