Files
Training-Team2-Zenvy-Jan26/Trenser.Zenvy/Trenser.Zenvy/views/MenuHelper.cpp
T
2026-04-17 12:29:54 +05:30

253 lines
8.5 KiB
C++

/*
* File: MenuHelper.cpp
* Description: Inline functions and utilities for employee management,
* including profile handling, payslip viewing, search,
* and employee activation/deactivation.
* Author: Trenser
* Created: 08-Apr-2026
*/
#include <stdexcept>
#include "MenuHelper.h"
/*
* Function: getEmployeeType
* Description: Retrieves a valid employee type based on the authority of the current user
* Parameters:
* employeeType - the type of the employee requesting to create another employee
* Returns:
* Enums::EmployeeType - selected employee type or INVALID if choice is invalid
*/
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::TALENT_ACQUISITION,
Enums::EmployeeType::GENERAL
}},
{ Enums::EmployeeType::HR, {
Enums::EmployeeType::IT,
Enums::EmployeeType::TEAM,
Enums::EmployeeType::FINANCE,
Enums::EmployeeType::TALENT_ACQUISITION,
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::TALENT_ACQUISITION, "Talent Executive" },
{ Enums::EmployeeType::GENERAL, "General Employee" }
};
auto employeeOptionsIterator = employeeTypeOptions.find(employeeType);
if (employeeOptionsIterator == employeeTypeOptions.end())
{
throw std::runtime_error("You do not have the authority to create a new Employee!");
}
const auto& options = employeeOptionsIterator->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;
}
/*
* Function: getEmployeeDesignation
* Description: Retrieves the designation (Senior or Junior) for a new employee
* Parameters: None
* Returns:
* Enums::EmployeeDesignation - selected designation or INVALID if choice is 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;
}
}
/*
* Function: createEmployee
* Description: Creates a new employee record and adds it to the system
* Parameters:
* m_zenvyController - pointer to the ZenvyController managing employees
* Returns: void
*/
void createEmployee(ZenvyController* m_zenvyController)
{
auto currentEmployee = m_zenvyController->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);
m_zenvyController->createEmployee(employeeType, employeeDesignation, email, name, phone);
std::cout << "\nCreated Employee Successfully.";
util::pressEnter();
}
/*
* Function: updateDesignation
* Description: Updates the designation of an existing employee
* Parameters:
* m_zenvyController - pointer to the ZenvyController managing employees
* Returns: void
*/
void updateDesignation(ZenvyController* m_zenvyController)
{
std::string selectedEmployeeId = selectEmployeeId(m_zenvyController->getEmployees(Enums::EmployeeType::GENERAL));
if (selectedEmployeeId.empty())
{
return;
}
Enums::EmployeeDesignation designation = getEmployeeDesignation();
if (m_zenvyController->updateDesignation(selectedEmployeeId, designation))
{
std::cout << "Assigned Employee Role Successfully\n";
util::pressEnter();
}
else
{
std::cout << "Employee not found\n";
util::pressEnter();
}
}
/*
* Function: displayCandidateDetails
* Description: Displays details of shortlisted candidates
* Parameters:
* shorlistedCandidates - vector of candidate pointers to display
* Returns: void
*/
void displayCandidateDetails(const std::vector<Candidate*> shorlistedCandidates)
{
util::clear();
std::cout << std::left
<< std::setw(10) << "Index"
<< std::setw(10) << "ID"
<< std::setw(20) << "Name"
<< std::setw(15) << "Phone"
<< std::setw(15) << "Qualification"
<< std::setw(10) << "Status"
<< std::endl;
int index = 0;
for (auto& candidate : shorlistedCandidates)
{
std::cout << std::left
<< std::setw(10) << ++index
<< std::setw(10) << candidate->getCandidateId()
<< std::setw(20) << candidate->getCandidateName()
<< std::setw(15) << candidate->getCandidatePhone()
<< std::setw(15) << candidate->getCandidateQualification()
<< std::setw(10) << Enums::getCandidateStatusString(candidate->getCandidateStatus())
<< std::endl;
}
}
/*
* Function: addShortlistedCandidateAsEmployee
* Description: Converts a shortlisted candidate into an employee record
* Parameters:
* m_zenvyController - pointer to the ZenvyController managing employees
* Returns: void
*/
void addShortlistedCandidateAsEmployee(const ZenvyController* m_zenvyController)
{
int index;
std::string name, email, phone;
util::clear();
std::vector<Candidate*> shortlistedCandidates = m_zenvyController->getShorlistedCandidates();
if (shortlistedCandidates.empty())
{
std::cout << "No candidates Found!";
util::pressEnter();
return;
}
displayCandidateDetails(shortlistedCandidates);
std::cout << "Enter the Index: ";
util::read(index);
auto currentEmployee = m_zenvyController->getCurrentEmployee();
Enums::EmployeeType employeeType;
Enums::EmployeeDesignation employeeDesignation = Enums::EmployeeDesignation::INVALID;
if (index > 0 && index <= shortlistedCandidates.size())
{
employeeType = getEmployeeType(currentEmployee->getEmployeeType());
Candidate* candidate = shortlistedCandidates[index - 1];
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 email: ";
util::read(email);
name = candidate->getCandidateName();
phone = candidate->getCandidatePhone();
m_zenvyController->createEmployee(employeeType, employeeDesignation, email, name, phone);
candidate->setCandidateStatus(Enums::CandidateStatus::HIRED);
std::cout << "\nCreated Employee Successfully.";
util::pressEnter();
}
else
{
throw std::runtime_error("Enter a valid Index.");
}
}