Implement Deactive Employee functionality
<UserStory> EMP002 : Deactivate Employee </UserStory> <Changes> - Added deactivateEmployee logic to set employee status to INACTIVE - Enabled Deactivate Employee option in AdminMenu - Implemented listing of active employees for selection - Connected UI flow for employee deactivation - Fix minor syntax issues </Changes> <Review> Smitha Mohan </Review>
This commit is contained in:
@@ -192,6 +192,9 @@
|
||||
<ClCompile Include="services\EmployeeManagementService.cpp">
|
||||
<Filter>Services</Filter>
|
||||
</ClCompile>
|
||||
<ClCompile Include="views\MenuHelper.cpp">
|
||||
<Filter>Views</Filter>
|
||||
</ClCompile>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="services\AuthenticationManagementService.h">
|
||||
@@ -338,6 +341,9 @@
|
||||
<ClInclude Include="services\EmployeeManagementService.h">
|
||||
<Filter>Services</Filter>
|
||||
</ClInclude>
|
||||
<ClInclude Include="views\MenuHelper.h">
|
||||
<Filter>Views</Filter>
|
||||
</ClInclude>
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<ClInclude Include="models\Employee.h">
|
||||
|
||||
@@ -50,7 +50,3 @@ Employees ZenvyController::getEmployees()
|
||||
{
|
||||
return m_employeeManagementService->getEmployees();
|
||||
}
|
||||
|
||||
std::shared_ptr<const Employee> ZenvyController::getEmployee(const std::string&) {
|
||||
|
||||
}
|
||||
|
||||
@@ -49,7 +49,7 @@ AuthenticationDTO AuthenticationManagementService::login(const std::string& emai
|
||||
|
||||
void AuthenticationManagementService::changePassword(const std::string& password)
|
||||
{
|
||||
std::shared_ptr<Employee> authenticatedUser = m_dataStore.getAuthenticatedUser();
|
||||
std::shared_ptr<Employee> authenticatedUser = m_dataStore.getAuthenticatedEmployee();
|
||||
if (authenticatedUser)
|
||||
{
|
||||
authenticatedUser->setEmployeePassword(password);
|
||||
|
||||
@@ -98,6 +98,14 @@ void EmployeeManagementService::createEmployee(Enums::EmployeeType employeeType,
|
||||
|
||||
bool EmployeeManagementService::deactivateEmployee(const std::string& id)
|
||||
{
|
||||
auto& employee = m_dataStore.getEmployees();
|
||||
auto iterator = employee.find(id);
|
||||
if (iterator == employee.end())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
iterator->second->setEmployeeAccountStatus(Enums::AccountStatus::INACTIVE);
|
||||
return true;
|
||||
}
|
||||
|
||||
Employees EmployeeManagementService::getEmployees()
|
||||
|
||||
@@ -118,10 +118,10 @@ bool AdminMenu::handleOperation(int choice)
|
||||
break;
|
||||
/*case 2:
|
||||
m_zenvyController.viewEmployee();
|
||||
break;
|
||||
case 3:
|
||||
m_zenvyController.deactivateEmployee();
|
||||
break;*/
|
||||
case 3:
|
||||
deactivateEmployee(m_zenvyController);
|
||||
break;
|
||||
case 5:
|
||||
updateProfile(m_zenvyController);
|
||||
break;
|
||||
|
||||
@@ -32,7 +32,8 @@ bool EmployeeMenu::handleOperation(int choice)
|
||||
{
|
||||
switch (choice)
|
||||
{
|
||||
/*case 1:
|
||||
/*
|
||||
case 1:
|
||||
m_zenvyController.applyLeave();
|
||||
break;
|
||||
case 2:
|
||||
@@ -49,11 +50,11 @@ bool EmployeeMenu::handleOperation(int choice)
|
||||
break;
|
||||
case 6:
|
||||
m_zenvyController.viewTicketHistory();
|
||||
break;*/
|
||||
/*case 7:
|
||||
break;
|
||||
case 7:
|
||||
viewEmployees();
|
||||
break;*/
|
||||
/*case 8:
|
||||
break;
|
||||
case 8:
|
||||
m_zenvyController.searchEmployee();
|
||||
break;
|
||||
case 9:
|
||||
|
||||
@@ -1,3 +1,4 @@
|
||||
|
||||
#include <iostream>
|
||||
#include "HRManagerMenu.h"
|
||||
#include "InputHelper.h"
|
||||
@@ -91,7 +92,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. Logout\nEnter your Choice: ";
|
||||
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: ";
|
||||
util::read(choice);
|
||||
if (!handleOperation(choice))
|
||||
{
|
||||
@@ -147,6 +148,8 @@ bool HRManagerMenu::handleOperation(int choice)
|
||||
updateProfile(m_zenvyController);
|
||||
break;
|
||||
case 13:
|
||||
deactivateEmployee(m_zenvyController);
|
||||
case 14:
|
||||
return false;
|
||||
default:
|
||||
std::cout << "Enter a valid choice!" << std::endl;
|
||||
|
||||
@@ -1,6 +1,13 @@
|
||||
#pragma once
|
||||
#include"ZenvyController.h"
|
||||
#include"InputHelper.h"
|
||||
#include <map>
|
||||
#include <memory>
|
||||
#include <vector>
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include "Employee.h"
|
||||
#include "ZenvyController.h"
|
||||
#include "MenuHelper.h"
|
||||
#include "InputHelper.h"
|
||||
#include"OutputHelper.h"
|
||||
|
||||
inline void updateProfile(std::shared_ptr<ZenvyController> m_zenvyController)
|
||||
@@ -10,7 +17,7 @@ inline void updateProfile(std::shared_ptr<ZenvyController> m_zenvyController)
|
||||
name = m_zenvyController->getCurrentEmployee()->getEmployeeName();
|
||||
phone = m_zenvyController->getCurrentEmployee()->getEmployeePhone();
|
||||
while (true)
|
||||
{
|
||||
{
|
||||
util::clear();
|
||||
std::cout << "Please choose the information you want to update:\n"
|
||||
"1. Name\n"
|
||||
@@ -19,7 +26,7 @@ inline void updateProfile(std::shared_ptr<ZenvyController> m_zenvyController)
|
||||
"Enter your choice: ";
|
||||
util::read(choice);
|
||||
switch (choice)
|
||||
{
|
||||
{
|
||||
case 1:
|
||||
std::cout << "Enter your updated Name :";
|
||||
util::read(name);
|
||||
@@ -33,10 +40,66 @@ inline void updateProfile(std::shared_ptr<ZenvyController> m_zenvyController)
|
||||
std::cout << "Profile Updated Successfully\n";
|
||||
break;
|
||||
case 3:
|
||||
return;
|
||||
return;
|
||||
default:
|
||||
std::cout << "Enter a valid choice!" << std::endl;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
inline std::map<int, std::shared_ptr<const Employee>> listActiveEmployees(const std::shared_ptr<ZenvyController>& controller)
|
||||
{
|
||||
auto employees = controller->getEmployees();
|
||||
std::map<int, std::shared_ptr<const Employee>> employeeList;
|
||||
int index = 1;
|
||||
std::cout << "Active Employees:\n";
|
||||
for (auto& activeEmployees : employees)
|
||||
{
|
||||
std::cout << std::setw(3) << index << ". "
|
||||
<< std::setw(10) << "ID: "
|
||||
<< std::setw(10) << activeEmployees->getEmployeeId()
|
||||
<< " | "
|
||||
<< std::setw(10) << "Name: "
|
||||
<< std::setw(20) << activeEmployees->getEmployeeName()
|
||||
<< "\n";
|
||||
employeeList[index] = activeEmployees;
|
||||
++index;
|
||||
}
|
||||
if (employeeList.empty())
|
||||
{
|
||||
std::cout << "No active employees available.\n";
|
||||
}
|
||||
return employeeList;
|
||||
}
|
||||
|
||||
void deactivateEmployee(const std::shared_ptr<ZenvyController>& controller)
|
||||
{
|
||||
auto employeeList = listActiveEmployees(controller);
|
||||
if (employeeList.empty())
|
||||
{
|
||||
return;
|
||||
}
|
||||
int choice;
|
||||
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->getEmployeeId();
|
||||
bool success = controller->deactivateEmployee(id);
|
||||
if (success)
|
||||
{
|
||||
std::cout << "Employee deactivated successfully\n";
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Employee not found\n";
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Invalid selection.\n";
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user