Refactored employee selection and cleaned up menu logic
<SRS> SRS02 : Employee Management </SRS> <Changes> - Removed getSelectedUserId() from FinanceExecutiveMenu - Added reusable selectEmployeeId() in MenuHelper - Simplified deactivateEmployee() using common selection logic - Fixed missing break in HRManagerMenu </Changes> <Review> Smitha Mohan </Review>
This commit is contained in:
@@ -28,53 +28,11 @@ void FinanceExecutiveMenu::run()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
std::string FinanceExecutiveMenu::getSelectedUserId()
|
|
||||||
{
|
|
||||||
int choice;
|
|
||||||
std::map<int, std::shared_ptr<const Employee>> employeeList;
|
|
||||||
int index = 0;
|
|
||||||
auto allEmployees = m_zenvyController->getEmployees();
|
|
||||||
util::clear();
|
|
||||||
std::cout << "Select the Employee\n";
|
|
||||||
for (auto& currentEmployee : allEmployees)
|
|
||||||
{
|
|
||||||
if (currentEmployee->getEmployeeType() == Enums::EmployeeType::ADMIN)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
employeeList[++index] = currentEmployee;
|
|
||||||
}
|
|
||||||
std::cout << std::left
|
|
||||||
<< std::setw(10) << "Index"
|
|
||||||
<< std::setw(15) << "Employee ID"
|
|
||||||
<< std::setw(20) << "Name"
|
|
||||||
<< std::setw(20) << "Employee Type" << std::endl;
|
|
||||||
for (const auto& employee : employeeList)
|
|
||||||
{
|
|
||||||
std::cout << std::left << std::setw(10) << employee.first
|
|
||||||
<< std::setw(15) << employee.second->getId()
|
|
||||||
<< std::setw(20) << employee.second->getEmployeeName()
|
|
||||||
<< std::setw(20) << Enums::getEmployeeTypeString(employee.second->getEmployeeType())
|
|
||||||
<< std::endl;
|
|
||||||
}
|
|
||||||
std::cout << "Enter the Index: ";
|
|
||||||
util::read(choice);
|
|
||||||
auto employeeIterator = employeeList.find(choice);
|
|
||||||
if (employeeIterator != employeeList.end())
|
|
||||||
{
|
|
||||||
return (employeeIterator->second->getId());
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid Index");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void FinanceExecutiveMenu::updatePayroll()
|
void FinanceExecutiveMenu::updatePayroll()
|
||||||
{
|
{
|
||||||
std::string employeeId;
|
std::string employeeId;
|
||||||
double basicSalary, houseRentAllowance, foodAllowance, employeePFContribution, employerPFContribution;
|
double basicSalary, houseRentAllowance, foodAllowance, employeePFContribution, employerPFContribution;
|
||||||
employeeId = getSelectedUserId();
|
employeeId = selectEmployeeId(m_zenvyController->getEmployees());
|
||||||
util::clear();
|
util::clear();
|
||||||
if (employeeId != "") {
|
if (employeeId != "") {
|
||||||
std::cout << "Enter the New Basic Salary: ";
|
std::cout << "Enter the New Basic Salary: ";
|
||||||
|
|||||||
@@ -13,7 +13,6 @@ public:
|
|||||||
FinanceExecutiveMenu() : m_zenvyController(std::make_shared<ZenvyController>()) {};
|
FinanceExecutiveMenu() : m_zenvyController(std::make_shared<ZenvyController>()) {};
|
||||||
void run();
|
void run();
|
||||||
bool handleOperation(int);
|
bool handleOperation(int);
|
||||||
std::string getSelectedUserId();
|
|
||||||
void updatePayroll();
|
void updatePayroll();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -70,6 +70,7 @@ bool HRManagerMenu::handleOperation(int choice)
|
|||||||
break;
|
break;
|
||||||
case 13:
|
case 13:
|
||||||
deactivateEmployee(m_zenvyController);
|
deactivateEmployee(m_zenvyController);
|
||||||
|
break;
|
||||||
case 14:
|
case 14:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
|
|||||||
@@ -100,4 +100,5 @@ void createEmployee(std::shared_ptr<ZenvyController> controller)
|
|||||||
util::read(phone);
|
util::read(phone);
|
||||||
controller->createEmployee(employeeType, employeeDesignation, email, name, phone);
|
controller->createEmployee(employeeType, employeeDesignation, email, name, phone);
|
||||||
std::cout << "\nCreated Employee Successfully.";
|
std::cout << "\nCreated Employee Successfully.";
|
||||||
|
util::pressEnter();
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -65,60 +65,57 @@ 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)
|
inline std::string selectEmployeeId(std::vector<std::shared_ptr<const Employee>> allEmployees)
|
||||||
{
|
{
|
||||||
auto employees = controller->getEmployees();
|
int choice;
|
||||||
std::map<int, std::shared_ptr<const Employee>> employeeList;
|
std::map<int, std::shared_ptr<const Employee>> employeeList;
|
||||||
|
int index = 0;
|
||||||
|
util::clear();
|
||||||
|
std::cout << "Select the Employee\n";
|
||||||
|
for (auto& currentEmployee : allEmployees)
|
||||||
|
{
|
||||||
|
if (currentEmployee->getEmployeeType() == Enums::EmployeeType::ADMIN)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
employeeList[++index] = currentEmployee;
|
||||||
|
}
|
||||||
std::cout << std::left
|
std::cout << std::left
|
||||||
<< std::setw(5) << "Index"
|
<< std::setw(10) << "Index"
|
||||||
<< std::setw(15) << "ID"
|
<< std::setw(15) << "Employee ID"
|
||||||
<< std::setw(25) << "Name"
|
<< std::setw(20) << "Name"
|
||||||
<< "\n";
|
<< std::setw(20) << "Employee Type" << std::endl;
|
||||||
int index = 1;
|
for (const auto& employee : employeeList)
|
||||||
for (auto& activeEmployees : employees)
|
|
||||||
{
|
{
|
||||||
std::cout << std::left
|
std::cout << std::left << std::setw(10) << employee.first
|
||||||
<< std::setw(5) << index
|
<< std::setw(15) << employee.second->getId()
|
||||||
<< std::setw(15) << activeEmployees->getId()
|
<< std::setw(20) << employee.second->getEmployeeName()
|
||||||
<< std::setw(25) << activeEmployees->getEmployeeName()
|
<< std::setw(20) << Enums::getEmployeeTypeString(employee.second->getEmployeeType())
|
||||||
<< "\n";
|
<< std::endl;
|
||||||
employeeList[index] = activeEmployees;
|
|
||||||
++index;
|
|
||||||
}
|
}
|
||||||
if (employeeList.empty())
|
std::cout << "Enter the Index: ";
|
||||||
|
util::read(choice);
|
||||||
|
auto employeeIterator = employeeList.find(choice);
|
||||||
|
if (employeeIterator != employeeList.end())
|
||||||
{
|
{
|
||||||
std::cout << "No active employees available.\n";
|
return (employeeIterator->second->getId());
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
throw std::runtime_error("Invalid Index");
|
||||||
}
|
}
|
||||||
return employeeList;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
inline void deactivateEmployee(const std::shared_ptr<ZenvyController>& controller)
|
inline void deactivateEmployee(const std::shared_ptr<ZenvyController>& controller)
|
||||||
{
|
{
|
||||||
auto employeeList = listEmployees(controller);
|
if(controller->deactivateEmployee(selectEmployeeId(controller->getEmployees())))
|
||||||
if (employeeList.empty())
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
int choice;
|
|
||||||
util::clear();
|
|
||||||
std::cout << "\nEnter the index of the employee to deactivate: ";
|
|
||||||
util::read(choice);
|
|
||||||
auto iterator = employeeList.find(choice);
|
|
||||||
if (iterator != employeeList.end())
|
|
||||||
{
|
|
||||||
std::string id = iterator->second->getId();
|
|
||||||
bool success = controller->deactivateEmployee(id);
|
|
||||||
if (success)
|
|
||||||
{
|
{
|
||||||
std::cout << "Employee deactivated successfully\n";
|
std::cout << "Employee deactivated successfully\n";
|
||||||
|
util::pressEnter();
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
std::cout << "Employee not found\n";
|
std::cout << "Employee not found\n";
|
||||||
|
util::pressEnter();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Invalid index.\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user