Minor fixes in employee listing and menus
<SRS> SRS02 : Employee Management </SRS> <Changes> - Sorted active employees by ID when listing - Handled empty employee lists in menus - Stopped deactivation when no employee is selected - Showed "NULL" when team ID is missing - Removed unnecessary error throw in payroll menu </Changes> <Review> Smitha Mohan </Review>
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
#include <map>
|
||||
#include <algorithm>
|
||||
#include <stdexcept>
|
||||
#include "EmployeeManagementService.h"
|
||||
#include "Factory.h"
|
||||
@@ -13,6 +14,7 @@
|
||||
#include "GeneralEmployee.h"
|
||||
#include "FileManager.h"
|
||||
#include "ApplicationConfig.h"
|
||||
#include "StringHelper.h"
|
||||
|
||||
void EmployeeManagementService::createEmployee(Enums::EmployeeType employeeType, Enums::EmployeeDesignation employeeDesignation, const std::string& email, const std::string& name, const std::string& phone)
|
||||
{
|
||||
@@ -132,20 +134,31 @@ bool EmployeeManagementService::deactivateEmployee(const std::string& id)
|
||||
|
||||
Employees EmployeeManagementService::getEmployees()
|
||||
{
|
||||
Employees result;
|
||||
Employees activeEmployees;
|
||||
auto& employees = m_dataStore.getEmployees();
|
||||
if (employees.size() <= 0)
|
||||
{
|
||||
return result;
|
||||
return activeEmployees;
|
||||
}
|
||||
for (const auto& iterator : employees)
|
||||
{
|
||||
if (iterator.second->getEmployeeAccountStatus() == Enums::AccountStatus::ACTIVE)
|
||||
{
|
||||
result.push_back(iterator.second);
|
||||
activeEmployees.push_back(iterator.second);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
std::sort(
|
||||
activeEmployees.begin(),
|
||||
activeEmployees.end(),
|
||||
[](std::shared_ptr<const Employee> employeeOne,
|
||||
std::shared_ptr<const Employee> employeeTwo) -> bool
|
||||
{
|
||||
int employeeOneId = util::extractNumber(employeeOne->getId());
|
||||
int employeeTwoId = util::extractNumber(employeeTwo->getId());
|
||||
return employeeOneId < employeeTwoId;
|
||||
}
|
||||
);
|
||||
return activeEmployees;
|
||||
}
|
||||
|
||||
std::shared_ptr<const Employee> EmployeeManagementService::getCurrentEmployee()
|
||||
|
||||
@@ -49,9 +49,6 @@ void FinanceExecutiveMenu::updatePayroll()
|
||||
std::cout << "Payroll Updated";
|
||||
util::pressEnter();
|
||||
}
|
||||
else {
|
||||
throw std::runtime_error("Unexpected error occured");
|
||||
}
|
||||
}
|
||||
|
||||
bool FinanceExecutiveMenu::handleOperation(int choice)
|
||||
|
||||
@@ -72,6 +72,12 @@ inline std::string selectEmployeeId(std::vector<std::shared_ptr<const Employee>>
|
||||
std::map<int, std::shared_ptr<const Employee>> employeeList;
|
||||
int index = 0;
|
||||
util::clear();
|
||||
if (allEmployees.empty())
|
||||
{
|
||||
std::cout << "No employees found!";
|
||||
util::pressEnter();
|
||||
return "";
|
||||
}
|
||||
std::cout << "Select the Employee\n";
|
||||
for (auto& currentEmployee : allEmployees)
|
||||
{
|
||||
@@ -109,16 +115,21 @@ inline std::string selectEmployeeId(std::vector<std::shared_ptr<const Employee>>
|
||||
|
||||
inline void deactivateEmployee(const std::shared_ptr<ZenvyController>& controller)
|
||||
{
|
||||
if(controller->deactivateEmployee(selectEmployeeId(controller->getEmployees())))
|
||||
{
|
||||
std::cout << "Employee deactivated successfully\n";
|
||||
util::pressEnter();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Employee not found\n";
|
||||
util::pressEnter();
|
||||
}
|
||||
std::string selectedEmployeeId = selectEmployeeId(controller->getEmployees());
|
||||
if (selectedEmployeeId.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
if(controller->deactivateEmployee(selectedEmployeeId))
|
||||
{
|
||||
std::cout << "Employee deactivated successfully\n";
|
||||
util::pressEnter();
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Employee not found\n";
|
||||
util::pressEnter();
|
||||
}
|
||||
}
|
||||
|
||||
inline void viewEmployees(std::shared_ptr<ZenvyController> m_zenvyController)
|
||||
@@ -148,7 +159,7 @@ inline void viewEmployees(std::shared_ptr<ZenvyController> m_zenvyController)
|
||||
<< std::setw(25) << Enums::getEmployeeTypeString(iterator->getEmployeeType())
|
||||
<< std::setw(25) << iterator->getEmployeeEmail()
|
||||
<< std::setw(15) << iterator->getEmployeePhone()
|
||||
<< std::setw(10) << iterator->getEmployeeTeamId()
|
||||
<< std::setw(10) << (iterator->getEmployeeTeamId().empty() ? "NULL" : iterator->getEmployeeTeamId())
|
||||
<< std::endl;
|
||||
}
|
||||
util::pressEnter();
|
||||
|
||||
Reference in New Issue
Block a user