Refactored employee creation menu and centralized helper logic
<SRS> SRS02 : Employee Management </SRS> <Changes> - Removed duplicate employee creation helper functions from AdminMenu and HRManagerMenu - Centralized employee creation flow into MenuHelper.cpp - Updated createEmployee to use current employee type for access control - Fixed parameter order bug in createEmployee (email, name, phone) - Improved menu titles for all roles (removed generic system header) - Added util::pressEnter() for better UX on invalid input across menus - Added newline before pause in InputHelper::pressEnter - Cleaned up minor formatting issues </Changes>
This commit is contained in:
@@ -13,7 +13,7 @@
|
||||
#include "FileManager.h"
|
||||
#include "ApplicationConfig.h"
|
||||
|
||||
void EmployeeManagementService::createEmployee(Enums::EmployeeType employeeType, Enums::EmployeeDesignation employeeDesignation, const std::string& email, const std::string& name, const std::string& phone)
|
||||
void EmployeeManagementService::createEmployee(Enums::EmployeeType employeeType, Enums::EmployeeDesignation employeeDesignation, const std::string& email, const std::string& name, const std::string& phone)
|
||||
{
|
||||
std::shared_ptr<Employee> authenticatedEmployee = m_dataStore.getAuthenticatedEmployee();
|
||||
if (!authenticatedEmployee)
|
||||
|
||||
@@ -25,6 +25,7 @@ namespace util
|
||||
|
||||
inline void pressEnter()
|
||||
{
|
||||
std::cout << std::endl;
|
||||
system("pause");
|
||||
}
|
||||
}
|
||||
@@ -4,87 +4,6 @@
|
||||
#include "OutputHelper.h"
|
||||
#include "MenuHelper.h"
|
||||
|
||||
static Enums::EmployeeType getEmployeeType()
|
||||
{
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Select Employee Type"
|
||||
"\n1. HR Employee"
|
||||
"\n2. IT Executive"
|
||||
"\n3. Team Executive"
|
||||
"\n4. Finance Executive"
|
||||
"\n5. Talent Executive"
|
||||
"\n6. General Employee";
|
||||
util::read(choice);
|
||||
switch (choice)
|
||||
{
|
||||
case 1:
|
||||
return Enums::EmployeeType::HR;
|
||||
case 2:
|
||||
return Enums::EmployeeType::IT;
|
||||
case 3:
|
||||
return Enums::EmployeeType::TEAM;
|
||||
case 4:
|
||||
return Enums::EmployeeType::FINANCE;
|
||||
case 5:
|
||||
return Enums::EmployeeType::TAG;
|
||||
case 6:
|
||||
return Enums::EmployeeType::GENERAL;
|
||||
default:
|
||||
return Enums::EmployeeType::INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
static Enums::EmployeeDesignation getEmployeeDesignation()
|
||||
{
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Select Employee Designation"
|
||||
"\n1. SENIOR"
|
||||
"\n2. JUNIOR";
|
||||
util::read(choice);
|
||||
switch (choice)
|
||||
{
|
||||
case 1:
|
||||
return Enums::EmployeeDesignation::SENIOR;
|
||||
case 2:
|
||||
return Enums::EmployeeDesignation::JUNIOR;
|
||||
default:
|
||||
return Enums::EmployeeDesignation::INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
static void createEmployee(std::shared_ptr<ZenvyController> controller)
|
||||
{
|
||||
Enums::EmployeeType employeeType = getEmployeeType();
|
||||
Enums::EmployeeDesignation employeeDesignation = Enums::EmployeeDesignation::INVALID;
|
||||
std::string name, email, phone;
|
||||
switch (employeeType)
|
||||
{
|
||||
case Enums::EmployeeType::INVALID:
|
||||
std::cout << "Invalid Choice";
|
||||
util::pressEnter();
|
||||
return;
|
||||
case Enums::EmployeeType::GENERAL:
|
||||
employeeDesignation = getEmployeeDesignation();
|
||||
if (employeeDesignation == Enums::EmployeeDesignation::INVALID)
|
||||
{
|
||||
std::cout << "Invalid Choice";
|
||||
util::pressEnter();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
std::cout << "Enter Name: ";
|
||||
util::read(name);
|
||||
std::cout << "Enter Email: ";
|
||||
util::read(email);
|
||||
std::cout << "Enter Phone: ";
|
||||
util::read(phone);
|
||||
controller->createEmployee(employeeType, employeeDesignation, name, email, phone);
|
||||
std::cout << "\nCreated Employee Successfully.";
|
||||
}
|
||||
|
||||
void AdminMenu::run()
|
||||
{
|
||||
bool isMenuActive = true;
|
||||
@@ -129,6 +48,7 @@ bool AdminMenu::handleOperation(int choice)
|
||||
return false;
|
||||
default:
|
||||
std::cout << "Enter a valid choice!" << std::endl;
|
||||
util::pressEnter();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ void EmployeeMenu::run()
|
||||
{
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Zenvy - The HR Management System\n1. Apply Leave\n2. View Payslip\n3. View Payslip History\n4. Raise Ticke\n5. View Ticket\n6. View Ticket History\n7. View Employees\n8. Search Employee\n9. View Team Members\n10. Book Meeting Room\n11. View Booking History\n12. View Notification\n13. View Announcements\n14. Update Profile\n15. Logout\nEnter your Choice: ";
|
||||
std::cout << "Employee Menu\n1. Apply Leave\n2. View Payslip\n3. View Payslip History\n4. Raise Ticke\n5. View Ticket\n6. View Ticket History\n7. View Employees\n8. Search Employee\n9. View Team Members\n10. Book Meeting Room\n11. View Booking History\n12. View Notification\n13. View Announcements\n14. Update Profile\n15. Logout\nEnter your Choice: ";
|
||||
util::read(choice);
|
||||
if (!handleOperation(choice))
|
||||
{
|
||||
@@ -79,6 +79,7 @@ bool EmployeeMenu::handleOperation(int choice)
|
||||
return false;
|
||||
default:
|
||||
std::cout << "Enter a valid choice!" << std::endl;
|
||||
util::pressEnter();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ void FinanceExecutiveMenu::run()
|
||||
{
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Zenvy - The HR Management System\n1. Apply Leave\n2. View Payslip\n3. View Payslip History\n4. View Employees\n5. Search Employee\n6. View Notification\n7. View Announcements\n8. Resolve Ticket\n9. Generate Payslip\n10. Update Payroll\n11. Update Profile\n12. Logout\nEnter your Choice: ";
|
||||
std::cout << "Finance Executive Menu\n1. Apply Leave\n2. View Payslip\n3. View Payslip History\n4. View Employees\n5. Search Employee\n6. View Notification\n7. View Announcements\n8. Resolve Ticket\n9. Generate Payslip\n10. Update Payroll\n11. Update Profile\n12. Logout\nEnter your Choice: ";
|
||||
util::read(choice);
|
||||
if (!handleOperation(choice))
|
||||
{
|
||||
@@ -130,6 +130,7 @@ bool FinanceExecutiveMenu::handleOperation(int choice)
|
||||
return false;
|
||||
default:
|
||||
std::cout << "Enter a valid choice!" << std::endl;
|
||||
util::pressEnter();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -4,84 +4,6 @@
|
||||
#include "OutputHelper.h"
|
||||
#include "MenuHelper.h"
|
||||
|
||||
static Enums::EmployeeType getEmployeeType()
|
||||
{
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Select Employee Type"
|
||||
"\n1. IT Executive"
|
||||
"\n2. Team Executive"
|
||||
"\n3. Finance Executive"
|
||||
"\n4. Talent Executive"
|
||||
"\n5. General Employee";
|
||||
util::read(choice);
|
||||
switch (choice)
|
||||
{
|
||||
case 1:
|
||||
return Enums::EmployeeType::IT;
|
||||
case 2:
|
||||
return Enums::EmployeeType::TEAM;
|
||||
case 3:
|
||||
return Enums::EmployeeType::FINANCE;
|
||||
case 4:
|
||||
return Enums::EmployeeType::TAG;
|
||||
case 5:
|
||||
return Enums::EmployeeType::GENERAL;
|
||||
default:
|
||||
return Enums::EmployeeType::INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
static Enums::EmployeeDesignation getEmployeeDesignation()
|
||||
{
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Select Employee Designation"
|
||||
"\n1. SENIOR"
|
||||
"\n2. JUNIOR";
|
||||
util::read(choice);
|
||||
switch (choice)
|
||||
{
|
||||
case 1:
|
||||
return Enums::EmployeeDesignation::SENIOR;
|
||||
case 2:
|
||||
return Enums::EmployeeDesignation::JUNIOR;
|
||||
default:
|
||||
return Enums::EmployeeDesignation::INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
static void createEmployee(std::shared_ptr<ZenvyController> controller)
|
||||
{
|
||||
Enums::EmployeeType employeeType = getEmployeeType();
|
||||
Enums::EmployeeDesignation employeeDesignation = Enums::EmployeeDesignation::INVALID;
|
||||
std::string name, email, phone;
|
||||
switch (employeeType)
|
||||
{
|
||||
case Enums::EmployeeType::INVALID:
|
||||
std::cout << "Invalid Choice";
|
||||
util::pressEnter();
|
||||
return;
|
||||
case Enums::EmployeeType::GENERAL:
|
||||
employeeDesignation = getEmployeeDesignation();
|
||||
if (employeeDesignation == Enums::EmployeeDesignation::INVALID)
|
||||
{
|
||||
std::cout << "Invalid Choice";
|
||||
util::pressEnter();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
std::cout << "Enter Name: ";
|
||||
util::read(name);
|
||||
std::cout << "Enter Email: ";
|
||||
util::read(email);
|
||||
std::cout << "Enter Phone: ";
|
||||
util::read(phone);
|
||||
controller->createEmployee(employeeType, employeeDesignation, name, email, phone);
|
||||
std::cout << "\nCreated Employee Successfully.";
|
||||
}
|
||||
|
||||
void HRManagerMenu::run()
|
||||
{
|
||||
bool isMenuActive = true;
|
||||
@@ -91,7 +13,7 @@ void HRManagerMenu::run()
|
||||
{
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Zenvy - The HR Management System\n1. Apply Leave\n2. View Payslip\n3. View Payslip History\n4. View Employees\n5. Search Employee\n6. View Notification\n7. View Announcements\n8. Create Employee\n9. Regularize Attendance\n10. Update Leave Request\n11. Register CandidateAsEmployee\n12. Update Profile\n13. Deactivate Employee\n14. Logout\nEnter your Choice: ";
|
||||
std::cout << "HR Manager Menu\n1. Apply Leave\n2. View Payslip\n3. View Payslip History\n4. View Employees\n5. Search Employee\n6. View Notification\n7. View Announcements\n8. Create Employee\n9. Regularize Attendance\n10. Update Leave Request\n11. Register CandidateAsEmployee\n12. Update Profile\n13. Deactivate Employee\n14. Logout\nEnter your Choice: ";
|
||||
util::read(choice);
|
||||
if (!handleOperation(choice))
|
||||
{
|
||||
@@ -130,11 +52,11 @@ bool HRManagerMenu::handleOperation(int choice)
|
||||
break;
|
||||
case 7:
|
||||
m_zenvyController.viewAnnouncements();
|
||||
break;
|
||||
break;*/
|
||||
case 8:
|
||||
m_zenvyController.createEmployee();
|
||||
createEmployee(m_zenvyController);
|
||||
break;
|
||||
case 9:
|
||||
/*case 9:
|
||||
m_zenvyController.regularizeAttenance();
|
||||
break;
|
||||
case 10:
|
||||
@@ -152,6 +74,7 @@ bool HRManagerMenu::handleOperation(int choice)
|
||||
return false;
|
||||
default:
|
||||
std::cout << "Enter a valid choice!" << std::endl;
|
||||
util::pressEnter();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ void ITExecutiveMenu::run()
|
||||
{
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Zenvy - The HR Management System\n1. Apply Leave\n2. View Payslip\n3. View Payslip History\n4. View Employees\n5. Search Employee\n6. View Notification\n7. View Announcements\n8. Resolve Ticket\n9. Update Profile\n10. Logout\nEnter your Choice: ";
|
||||
std::cout << "IT Executive Menu\n1. Apply Leave\n2. View Payslip\n3. View Payslip History\n4. View Employees\n5. Search Employee\n6. View Notification\n7. View Announcements\n8. Resolve Ticket\n9. Update Profile\n10. Logout\nEnter your Choice: ";
|
||||
util::read(choice);
|
||||
if (!handleOperation(choice))
|
||||
{
|
||||
@@ -63,6 +63,7 @@ bool ITExecutiveMenu::handleOperation(int choice)
|
||||
return false;
|
||||
default:
|
||||
std::cout << "Enter a valid choice!" << std::endl;
|
||||
util::pressEnter();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -1 +1,103 @@
|
||||
#include <stdexcept>
|
||||
#include "MenuHelper.h"
|
||||
|
||||
static Enums::EmployeeType getEmployeeType(Enums::EmployeeType employeeType)
|
||||
{
|
||||
int choice;
|
||||
util::clear();
|
||||
static const std::map<Enums::EmployeeType, std::vector<Enums::EmployeeType>> employeeTypeOptions = {
|
||||
{ Enums::EmployeeType::ADMIN, {
|
||||
Enums::EmployeeType::HR,
|
||||
Enums::EmployeeType::IT,
|
||||
Enums::EmployeeType::TEAM,
|
||||
Enums::EmployeeType::FINANCE,
|
||||
Enums::EmployeeType::TAG,
|
||||
Enums::EmployeeType::GENERAL
|
||||
}},
|
||||
{ Enums::EmployeeType::HR, {
|
||||
Enums::EmployeeType::IT,
|
||||
Enums::EmployeeType::TEAM,
|
||||
Enums::EmployeeType::FINANCE,
|
||||
Enums::EmployeeType::TAG,
|
||||
Enums::EmployeeType::GENERAL
|
||||
}}
|
||||
};
|
||||
static const std::map<Enums::EmployeeType, std::string> labels = {
|
||||
{ Enums::EmployeeType::HR, "HR Employee" },
|
||||
{ Enums::EmployeeType::IT, "IT Executive" },
|
||||
{ Enums::EmployeeType::TEAM, "Team Executive" },
|
||||
{ Enums::EmployeeType::FINANCE, "Finance Executive" },
|
||||
{ Enums::EmployeeType::TAG, "Talent Executive" },
|
||||
{ Enums::EmployeeType::GENERAL, "General Employee" }
|
||||
};
|
||||
auto it = employeeTypeOptions.find(employeeType);
|
||||
if (it == employeeTypeOptions.end())
|
||||
{
|
||||
throw std::runtime_error("You do not have the authority to create a new Employee!");
|
||||
}
|
||||
const auto& options = it->second;
|
||||
std::cout << "Select Employee Type\n";
|
||||
for (int index = 0; index < options.size(); ++index)
|
||||
{
|
||||
std::cout << index + 1 << ". " << labels.at(options[index]) << "\n";
|
||||
}
|
||||
std::cout << "Enter Choice: ";
|
||||
util::read(choice);
|
||||
if (choice >= 1 && choice <= options.size())
|
||||
{
|
||||
return options[choice - 1];
|
||||
}
|
||||
return Enums::EmployeeType::INVALID;
|
||||
}
|
||||
|
||||
static Enums::EmployeeDesignation getEmployeeDesignation()
|
||||
{
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Select Employee Designation"
|
||||
"\n1. SENIOR"
|
||||
"\n2. JUNIOR"
|
||||
"\nEnter Choice: ";
|
||||
util::read(choice);
|
||||
switch (choice)
|
||||
{
|
||||
case 1:
|
||||
return Enums::EmployeeDesignation::SENIOR;
|
||||
case 2:
|
||||
return Enums::EmployeeDesignation::JUNIOR;
|
||||
default:
|
||||
return Enums::EmployeeDesignation::INVALID;
|
||||
}
|
||||
}
|
||||
|
||||
void createEmployee(std::shared_ptr<ZenvyController> controller)
|
||||
{
|
||||
auto currentEmployee = controller->getCurrentEmployee();
|
||||
Enums::EmployeeType employeeType = getEmployeeType(currentEmployee->getEmployeeType());
|
||||
Enums::EmployeeDesignation employeeDesignation = Enums::EmployeeDesignation::INVALID;
|
||||
std::string name, email, phone;
|
||||
switch (employeeType)
|
||||
{
|
||||
case Enums::EmployeeType::INVALID:
|
||||
std::cout << "Invalid Choice";
|
||||
util::pressEnter();
|
||||
return;
|
||||
case Enums::EmployeeType::GENERAL:
|
||||
employeeDesignation = getEmployeeDesignation();
|
||||
if (employeeDesignation == Enums::EmployeeDesignation::INVALID)
|
||||
{
|
||||
std::cout << "Invalid Choice";
|
||||
util::pressEnter();
|
||||
return;
|
||||
}
|
||||
break;
|
||||
}
|
||||
std::cout << "Enter Name: ";
|
||||
util::read(name);
|
||||
std::cout << "Enter Email: ";
|
||||
util::read(email);
|
||||
std::cout << "Enter Phone: ";
|
||||
util::read(phone);
|
||||
controller->createEmployee(employeeType, employeeDesignation, email, name, phone);
|
||||
std::cout << "\nCreated Employee Successfully.";
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
#include "MenuHelper.h"
|
||||
#include "InputHelper.h"
|
||||
#include "OutputHelper.h"
|
||||
#include "Enums.h"
|
||||
|
||||
void createEmployee(std::shared_ptr<ZenvyController> controller);
|
||||
|
||||
inline void updateProfile(std::shared_ptr<ZenvyController> m_zenvyController)
|
||||
{
|
||||
@@ -48,7 +51,6 @@ inline void updateProfile(std::shared_ptr<ZenvyController> m_zenvyController)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline std::map<int, std::shared_ptr<const Employee>> listEmployees(const std::shared_ptr<ZenvyController>& controller)
|
||||
{
|
||||
auto employees = controller->getEmployees();
|
||||
|
||||
@@ -13,7 +13,7 @@ void TalentExecutiveMenu::run()
|
||||
{
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Zenvy - The HR Management System\n1. Apply Leave\n2. View Payslip\n3. View Payslip History\n4. View Employees\n5. Search Employee\n6. View Notification\n7. View Announcements\n8. Create New Job\n9. View Job Opening\n10. Add Candidate\n11. UpdateCandidate Status\n12. View Shortlisted Candidate\n13. Update Profile\n14. Logout\nEnter your Choice: ";
|
||||
std::cout << "Talent Executive Menu\n1. Apply Leave\n2. View Payslip\n3. View Payslip History\n4. View Employees\n5. Search Employee\n6. View Notification\n7. View Announcements\n8. Create New Job\n9. View Job Opening\n10. Add Candidate\n11. UpdateCandidate Status\n12. View Shortlisted Candidate\n13. Update Profile\n14. Logout\nEnter your Choice: ";
|
||||
util::read(choice);
|
||||
if (!handleOperation(choice))
|
||||
{
|
||||
@@ -75,6 +75,7 @@ bool TalentExecutiveMenu::handleOperation(int choice)
|
||||
return false;
|
||||
default:
|
||||
std::cout << "Enter a valid choice!" << std::endl;
|
||||
util::pressEnter();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ void TeamExecutiveMenu::run()
|
||||
{
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Zenvy - The HR Management System\n1. Apply Leave\n2. View Payslip\n3. View Payslip History\n4. View Employees\n5. Search Employee\n6. View Notification\n7. View Announcements\n8. Create Team\n9. Update Team\n10. Remove Team\n11. Assign Employee\n12. Unassign Employee\n13. View Teams\n14. Update Profile\n15. Logout\nEnter your Choice: ";
|
||||
std::cout << "Team Executive Menu\n1. Apply Leave\n2. View Payslip\n3. View Payslip History\n4. View Employees\n5. Search Employee\n6. View Notification\n7. View Announcements\n8. Create Team\n9. Update Team\n10. Remove Team\n11. Assign Employee\n12. Unassign Employee\n13. View Teams\n14. Update Profile\n15. Logout\nEnter your Choice: ";
|
||||
util::read(choice);
|
||||
if (!handleOperation(choice))
|
||||
{
|
||||
@@ -78,6 +78,7 @@ bool TeamExecutiveMenu::handleOperation(int choice)
|
||||
return false;
|
||||
default:
|
||||
std::cout << "Enter a valid choice!" << std::endl;
|
||||
util::pressEnter();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ void TeamLeadMenu::run()
|
||||
{
|
||||
int choice;
|
||||
util::clear();
|
||||
std::cout << "Zenvy - The HR Management System\n1. Apply Leave\n2. View Payslip\n3. View Payslip History\n4. Raise Ticke\n5. View Ticket\n6. View Ticket History\n7. View Employees\n8. Search Employee\n9. View Team Members\n10. Book Meeting Room\n11. View Booking History\n12. View Notification\n13. View Announcements\n4. Regularize Attendance\n15. Update Leave Request\n16. Update Profile\n17. Logout\nEnter your Choice: ";
|
||||
std::cout << "Team Lead Menu\n1. Apply Leave\n2. View Payslip\n3. View Payslip History\n4. Raise Ticke\n5. View Ticket\n6. View Ticket History\n7. View Employees\n8. Search Employee\n9. View Team Members\n10. Book Meeting Room\n11. View Booking History\n12. View Notification\n13. View Announcements\n4. Regularize Attendance\n15. Update Leave Request\n16. Update Profile\n17. Logout\nEnter your Choice: ";
|
||||
util::read(choice);
|
||||
if (!handleOperation(choice))
|
||||
{
|
||||
@@ -84,6 +84,7 @@ bool TeamLeadMenu::handleOperation(int choice)
|
||||
return false;
|
||||
default:
|
||||
std::cout << "Enter a valid choice!" << std::endl;
|
||||
util::pressEnter();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user