47b44ccaa0
<SRS> SRS02 : Employee Management </SRS> <Changes> - Added Payroll getHeaders, serialize and deserialize functions - Stored payrolls in DataStore - Loaded and saved payrolls along with employees - Linked payroll to employees during creation and load - Added employeeId to Payroll - Renamed TAG role to TALENT_ACQUISITION across the project - Added missing TalentExecutive case in Employee deserialization - Added constructor to TalentExecutive for FileManager integration - Renamed ID counters to m_uid for consistency - Updated salary values in ApplicationConfig </Changes> <Review> Smitha Mohan </Review>
180 lines
4.1 KiB
C++
180 lines
4.1 KiB
C++
#include <iostream>
|
|
#include <utility>
|
|
#include <memory>
|
|
#include <stdexcept>
|
|
#include "UserInterface.h"
|
|
#include "AdminMenu.h"
|
|
#include "EmployeeMenu.h"
|
|
#include "FinanceExecutiveMenu.h"
|
|
#include "HRManagerMenu.h"
|
|
#include "ITExecutiveMenu.h"
|
|
#include "TalentExecutiveMenu.h"
|
|
#include "TeamExecutiveMenu.h"
|
|
#include "TeamLeadMenu.h"
|
|
#include "ZenvyController.h"
|
|
#include "InputHelper.h"
|
|
#include "OutputHelper.h"
|
|
#include "Validator.h"
|
|
|
|
void UserInterface::run()
|
|
{
|
|
bool isMenuActive = true;
|
|
try
|
|
{
|
|
m_controller->loadStates();
|
|
}
|
|
catch (const std::exception& e)
|
|
{
|
|
std::cout << "Exception: " << e.what() << std::endl;
|
|
return;
|
|
}
|
|
while (isMenuActive)
|
|
{
|
|
try
|
|
{
|
|
int choice;
|
|
util::clear();
|
|
std::cout << "Zenvy - HR Management System\n1. Login\n2. Exit\nEnter your Choice: ";
|
|
util::read(choice);
|
|
if (!handleOperation(choice))
|
|
{
|
|
isMenuActive = false;
|
|
}
|
|
}
|
|
catch (const std::exception& e)
|
|
{
|
|
std::cout << "Exception: " << e.what() << std::endl;
|
|
util::pressEnter();
|
|
}
|
|
}
|
|
try
|
|
{
|
|
m_controller->persistStates();
|
|
}
|
|
catch (const std::exception& e)
|
|
{
|
|
std::cout << "Exception: " << e.what() << std::endl;
|
|
return;
|
|
}
|
|
}
|
|
|
|
bool UserInterface::handleOperation(int choice)
|
|
{
|
|
switch (choice)
|
|
{
|
|
case 1:
|
|
login();
|
|
break;
|
|
case 2:
|
|
std::cout << "Exiting..." << std::endl;
|
|
return false;
|
|
default:
|
|
std::cout << "Enter a valid choice!" << std::endl;
|
|
util::pressEnter();
|
|
}
|
|
return true;
|
|
}
|
|
|
|
void UserInterface::login()
|
|
{
|
|
std::string email, password;
|
|
util::clear();
|
|
std::cout << "Enter email: ";
|
|
util::read(email);
|
|
std::cout << "Enter password: ";
|
|
util::read(password);
|
|
AuthenticationDTO authenticationContext = m_controller->login(email, password);
|
|
Enums::LoginStatus loginStatus = std::get<0>(authenticationContext);
|
|
Enums::EmployeeType employeeType = std::get<1>(authenticationContext);
|
|
Enums::EmployeeDesignation employeeDesignation = std::get<2>(authenticationContext);
|
|
if (loginStatus == Enums::LoginStatus::USER_NOT_FOUND)
|
|
{
|
|
std::cout << "Error: User Not Found! Try Again\n";
|
|
util::pressEnter();
|
|
return;
|
|
}
|
|
if (loginStatus == Enums::LoginStatus::INVALID_PASSWORD)
|
|
{
|
|
std::cout << "Error: Invalid Password! Try Again\n";
|
|
util::pressEnter();
|
|
return;
|
|
}
|
|
if (loginStatus == Enums::LoginStatus::FIRST_LOGIN)
|
|
{
|
|
util::clear();
|
|
std::cout << "Warning: You're using the default password!\n"
|
|
<< "Please change it.\n";
|
|
std::cout << "Enter new password: \n";
|
|
util::read(password);
|
|
if (util::isPasswordValid(password))
|
|
{
|
|
m_controller->changePassword(password);
|
|
}
|
|
else
|
|
{
|
|
std::cout << "Error: Invalid Password\n";
|
|
util::pressEnter();
|
|
return;
|
|
}
|
|
}
|
|
util::clear();
|
|
// Route to appropriate menu
|
|
switch (employeeType)
|
|
{
|
|
case Enums::EmployeeType::ADMIN:
|
|
{
|
|
AdminMenu menu;
|
|
menu.run();
|
|
break;
|
|
}
|
|
case Enums::EmployeeType::HR:
|
|
{
|
|
HRManagerMenu menu;
|
|
menu.run();
|
|
break;
|
|
}
|
|
case Enums::EmployeeType::FINANCE:
|
|
{
|
|
FinanceExecutiveMenu menu;
|
|
menu.run();
|
|
break;
|
|
}
|
|
case Enums::EmployeeType::IT:
|
|
{
|
|
ITExecutiveMenu menu;
|
|
menu.run();
|
|
break;
|
|
}
|
|
case Enums::EmployeeType::TEAM:
|
|
{
|
|
TeamExecutiveMenu menu;
|
|
menu.run();
|
|
break;
|
|
}
|
|
case Enums::EmployeeType::TALENT_ACQUISITION:
|
|
{
|
|
TalentExecutiveMenu menu;
|
|
menu.run();
|
|
break;
|
|
}
|
|
case Enums::EmployeeType::GENERAL:
|
|
{
|
|
if (employeeDesignation == Enums::EmployeeDesignation::TEAM_LEAD)
|
|
{
|
|
TeamLeadMenu menu;
|
|
menu.run();
|
|
}
|
|
else
|
|
{
|
|
EmployeeMenu menu;
|
|
menu.run();
|
|
}
|
|
break;
|
|
}
|
|
default:
|
|
throw std::runtime_error("Error: Unsupported employee type!\n");
|
|
util::pressEnter();
|
|
break;
|
|
}
|
|
m_controller->logout();
|
|
} |