06d3760663
<UserStory> EMP003 : View Profile </UserStory> <Changes> - Avoid unecessary copies. </Changes> <Review> Smitha Mohan </Review>
282 lines
10 KiB
C++
282 lines
10 KiB
C++
#pragma once
|
|
#include <map>
|
|
#include <memory>
|
|
#include <vector>
|
|
#include <iostream>
|
|
#include <iomanip>
|
|
#include <utility>
|
|
#include "Enums.h"
|
|
#include"InputHelper.h"
|
|
#include"OutputHelper.h"
|
|
#include "Employee.h"
|
|
#include "ZenvyController.h"
|
|
#include "MenuHelper.h"
|
|
#include "Validator.h"
|
|
|
|
void createEmployee(std::shared_ptr<ZenvyController> controller);
|
|
|
|
inline void viewProfile(std::shared_ptr<ZenvyController> controller)
|
|
{
|
|
util::clear();
|
|
std::shared_ptr<const Employee> currentEmployee = controller->getCurrentEmployee();
|
|
if (currentEmployee)
|
|
{
|
|
std::cout << std::left
|
|
<< "Employee ID: " << currentEmployee->getId() << std::endl
|
|
<< "Name: " << currentEmployee->getEmployeeName() << std::endl
|
|
<< "Role: " << Enums::getEmployeeTypeString(currentEmployee->getEmployeeType()) << std::endl
|
|
<< "Email: " << currentEmployee->getEmployeeEmail() << std::endl
|
|
<< "Phone: " << currentEmployee->getEmployeePhone() << std::endl;
|
|
if (currentEmployee->getEmployeeType() == Enums::EmployeeType::GENERAL) {
|
|
if (auto generalEmployee = std::dynamic_pointer_cast<const GeneralEmployee>(currentEmployee))
|
|
{
|
|
std::cout << "Designation: " << Enums::getEmployeeDesignationString(generalEmployee->getDesignation()) << std::endl;
|
|
}
|
|
}
|
|
std::cout << "Team ID: " << (currentEmployee->getEmployeeTeamId().empty() ? "NULL " : (currentEmployee->getEmployeeTeamId())) << std::endl
|
|
<< "Team Status: " << Enums::getTeamStatusString(currentEmployee->getEmployeeTeamStatus()) << std::endl;
|
|
if (const auto& payroll = currentEmployee->getPayroll())
|
|
{
|
|
std::cout << std::endl
|
|
<< "Payroll Details" << std::endl
|
|
<< "Payroll ID: " << payroll->getId() << std::endl
|
|
<< "Basic Salary: " << payroll->getBasicSalary() << std::endl
|
|
<< "Employee PF Contribution: " << payroll->getEmployeePFContribution() << std::endl
|
|
<< "Employer PF Contribution: " << payroll->getEmployerPFContribution() << std::endl
|
|
<< "Food Allowance: " << payroll->getFoodAllowance() << std::endl
|
|
<< "House Rent Allowance: " << payroll->getHouseRentAllowance() << std::endl;
|
|
}
|
|
else
|
|
{
|
|
std::cout << "Unable to fetch the payroll details\n";
|
|
}
|
|
util::pressEnter();
|
|
}
|
|
else
|
|
{
|
|
throw std::runtime_error("Unexpected Error Occured");
|
|
}
|
|
}
|
|
|
|
inline void updateProfile(std::shared_ptr<ZenvyController> m_zenvyController)
|
|
{
|
|
int choice;
|
|
std::string name, phone;
|
|
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"
|
|
"2. Phone Number\n"
|
|
"3. Exit\n"
|
|
"Enter your choice: ";
|
|
util::read(choice);
|
|
switch (choice)
|
|
{
|
|
case 1:
|
|
std::cout << "Enter your updated Name: ";
|
|
util::read(name);
|
|
m_zenvyController->updateProfile(name, phone);
|
|
std::cout << "Profile Updated Successfully\n";
|
|
util::pressEnter();
|
|
break;
|
|
case 2:
|
|
std::cout << "Enter your updated phone Number: ";
|
|
util::read(phone);
|
|
if (!util::isPhoneNumberValid(phone))
|
|
{
|
|
std::cout << "Error: Invalid Phone Number";
|
|
util::pressEnter();
|
|
}
|
|
if (util::isPhoneDuplicate(phone, m_zenvyController->getEmployees()))
|
|
{
|
|
std::cout << "Error: Duplicate Phone Number!";
|
|
util::pressEnter();
|
|
return;
|
|
}
|
|
m_zenvyController->updateProfile(name, phone);
|
|
std::cout << "Profile Updated Successfully\n";
|
|
util::pressEnter();
|
|
break;
|
|
case 3:
|
|
return;
|
|
default:
|
|
std::cout << "Enter a valid choice!" << std::endl;
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
|
|
inline std::string selectEmployeeId(std::vector<std::shared_ptr<const Employee>> allEmployees)
|
|
{
|
|
int choice;
|
|
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)
|
|
{
|
|
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");
|
|
}
|
|
}
|
|
|
|
inline void deactivateEmployee(const std::shared_ptr<ZenvyController>& controller)
|
|
{
|
|
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)
|
|
{
|
|
util::clear();
|
|
std::cout << "Employee List\n";
|
|
auto employees = m_zenvyController->getEmployees();
|
|
if (employees.empty())
|
|
{
|
|
std::cout << "No employees found\n";
|
|
util::pressEnter();
|
|
return;
|
|
}
|
|
std::cout << std::left
|
|
<< std::setw(15) << "Employee ID"
|
|
<< std::setw(25) << "Name"
|
|
<< std::setw(25) << "Role"
|
|
<< std::setw(25) << "Email"
|
|
<< std::setw(15) << "Phone"
|
|
<< std::setw(10) << "TeamId"
|
|
<< std::endl;
|
|
for (const auto& iterator : employees)
|
|
{
|
|
std::cout << std::left
|
|
<< std::setw(15) << iterator->getId()
|
|
<< std::setw(25) << iterator->getEmployeeName()
|
|
<< std::setw(25) << Enums::getEmployeeTypeString(iterator->getEmployeeType())
|
|
<< std::setw(25) << iterator->getEmployeeEmail()
|
|
<< std::setw(15) << iterator->getEmployeePhone()
|
|
<< std::setw(10) << (iterator->getEmployeeTeamId().empty() ? "NULL" : iterator->getEmployeeTeamId())
|
|
<< std::endl;
|
|
}
|
|
util::pressEnter();
|
|
}
|
|
|
|
inline void searchEmployee(std::shared_ptr<ZenvyController>& m_zenvyController)
|
|
{
|
|
std::string name;
|
|
util::clear();
|
|
std::cout << "Enter Employee Name: ";
|
|
util::read(name);
|
|
std::pair<Enums::EmployeeType, std::vector<std::shared_ptr<const Employee>>> searchResults = m_zenvyController->searchEmployee(name);
|
|
if (!(searchResults.second).empty())
|
|
{
|
|
std::cout << std::left
|
|
<< std::setw(10) << "ID"
|
|
<< std::setw(20) << "Name"
|
|
<< std::setw(25) << "Email"
|
|
<< std::setw(15) << "Phone"
|
|
<< std::setw(20) << "Type"
|
|
<< std::setw(20) << "TeamStatus"
|
|
<< std::setw(15) << "TeamID";
|
|
if (searchResults.first == Enums::EmployeeType::FINANCE
|
|
|| searchResults.first == Enums::EmployeeType::HR
|
|
|| searchResults.first == Enums::EmployeeType::ADMIN)
|
|
{
|
|
std::cout << std::left
|
|
<< std::setw(17) << "PayrollID"
|
|
<< std::setw(20) << "BasicSalary"
|
|
<< std::setw(15) << "EmployeePF"
|
|
<< std::setw(15) << "EmployerPF"
|
|
<< std::setw(15) << "FoodAllowance"
|
|
<< std::setw(15) << "HouseRentAllowance";
|
|
}
|
|
std::cout << std::endl;
|
|
for (const auto& employee : searchResults.second)
|
|
{
|
|
if (employee->getEmployeeAccountStatus() == Enums::AccountStatus::ACTIVE)
|
|
{
|
|
std::cout << std::left
|
|
<< std::setw(10) << employee->getId()
|
|
<< std::setw(20) << employee->getEmployeeName()
|
|
<< std::setw(25) << employee->getEmployeeEmail()
|
|
<< std::setw(15) << employee->getEmployeePhone()
|
|
<< std::setw(20) << Enums::getEmployeeTypeString(employee->getEmployeeType())
|
|
<< std::setw(20) << Enums::getTeamStatusString(employee->getEmployeeTeamStatus());
|
|
if (employee->getEmployeeTeamId() == "")
|
|
{
|
|
std::cout << std::setw(15) << "NULL";
|
|
}
|
|
else
|
|
{
|
|
std::cout << std::setw(15) << employee->getEmployeeTeamId();
|
|
}
|
|
if (searchResults.first == Enums::EmployeeType::FINANCE
|
|
|| searchResults.first == Enums::EmployeeType::HR
|
|
|| searchResults.first == Enums::EmployeeType::ADMIN)
|
|
{
|
|
std::cout << std::left
|
|
<< std::setw(17) << employee->getPayroll()->getId()
|
|
<< std::setw(20) << employee->getPayroll()->getBasicSalary()
|
|
<< std::setw(15) << employee->getPayroll()->getEmployeePFContribution()
|
|
<< std::setw(15) << employee->getPayroll()->getEmployerPFContribution()
|
|
<< std::setw(15) << employee->getPayroll()->getFoodAllowance()
|
|
<< std::setw(15) << employee->getPayroll()->getHouseRentAllowance();
|
|
}
|
|
std::cout << std::endl;
|
|
}
|
|
}
|
|
}
|
|
else
|
|
{
|
|
std::cout << "No Employee found with this name" << std::endl;
|
|
}
|
|
util::pressEnter();
|
|
}
|