Files
Training-Team2-Zenvy-Jan26/Trenser.Zenvy/Trenser.Zenvy/views/MenuHelper.h
T
2026-04-16 18:02:07 +05:30

371 lines
14 KiB
C++

#pragma once
#include <map>
#include <memory>
#include <vector>
#include <string>
#include <iostream>
#include <sstream>
#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(ZenvyController* m_zenvyController);
void updateDesignation(ZenvyController* m_zenvyController);
void displayCandidateDetails(const std::vector<const Candidate*> shorlistedCandidates);
void addShortlistedCandidateAsEmployee(const ZenvyController* m_zenvyController);
inline void viewPayslipHistory(ZenvyController* m_zenvyController)
{
auto employeePayslips = m_zenvyController->getCurrentEmployee()->getEmployeePayslips();
util::clear();
if (employeePayslips.empty())
{
std::cout << "No Payslips Generated";
util::pressEnter();
return;
}
std::cout << "Payslips\n" << std::endl;
std::cout << std::left
<< std::setw(15) << "Date"
<< std::setw(15) << "Payslip ID"
<< std::setw(15) << "Employee ID"
<< std::setw(12) << "Salary"
<< std::setw(25) << "TimeStamp"
<< std::endl;
for (const auto& payslip : employeePayslips)
{
std::ostringstream dateStream;
dateStream << payslip.second->getTimestamp().getYear() << " - " << Enums::getMonthString(Enums::getMonth(payslip.second->getTimestamp().getMonth()));
std::cout << std::left
<< std::setw(15) << dateStream.str()
<< std::setw(15) << payslip.first
<< std::setw(15) << payslip.second->getEmployeeId()
<< std::setw(12) << payslip.second->getSalary()
<< std::setw(25) << payslip.second->getTimestamp().toString()
<< std::endl;
}
util::pressEnter();
}
inline void viewProfile(ZenvyController* m_zenvyController)
{
util::clear();
const Employee* currentEmployee = m_zenvyController->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 = dynamic_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(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<const Employee*>& allEmployees)
{
int choice;
std::map<int, 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::setw(20) << "Employee Designation" << std::endl;
for (const auto& employee : employeeList)
{
auto generalEmployee = dynamic_cast<const GeneralEmployee*>(employee.second);
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());
if (generalEmployee)
{
std::cout << std::left
<< std::setw(20) << Enums::getEmployeeDesignationString(generalEmployee->getDesignation())
<< std::endl;
}
else
{
std::cout << std::left
<< std::setw(20) << "NULL"
<< 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 ZenvyController* m_zenvyController)
{
std::string selectedEmployeeId = selectEmployeeId(m_zenvyController->getEmployees());
if (selectedEmployeeId.empty())
{
return;
}
if (m_zenvyController->deactivateEmployee(selectedEmployeeId))
{
std::cout << "Employee deactivated successfully\n";
util::pressEnter();
}
else
{
std::cout << "Employee not found\n";
util::pressEnter();
}
}
inline void viewEmployees(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(ZenvyController* m_zenvyController)
{
std::string name;
util::clear();
std::cout << "Enter Employee Name: ";
util::read(name);
std::pair<Enums::EmployeeType, std::vector<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();
}
inline void viewPayslip(ZenvyController* m_zenvyController)
{
int year, month;
util::clear();
std::cout << "Enter the year: ";
util::read(year);
std::cout << "Enter the month: ";
util::read(month);
auto employee = m_zenvyController->getCurrentEmployee();
if (!employee)
{
std::cout << "No authenticated employee.\n";
util::pressEnter();
return;
}
auto result = m_zenvyController->getPayslipForMonth(employee->getId(), year, month);
auto payroll = result.first;
auto payslip = result.second;
if (payroll && payslip)
{
util::clear();
std::cout << "Payslip for " << employee->getEmployeeName() << " (" << year << "-" << std::setw(2) << std::setfill('0') << month << ")\n\n";
std::cout << "Basic Salary : " << payroll->getBasicSalary() << "\n";
std::cout << "House Rent Allowance : " << payroll->getHouseRentAllowance() << "\n";
std::cout << "Food Allowance : " << payroll->getFoodAllowance() << "\n";
std::cout << "Employee PF Contribution : " << payroll->getEmployeePFContribution() << "\n";
std::cout << "Employer PF Contribution : " << payroll->getEmployerPFContribution() << "\n";
std::cout << "----------------------------------------\n";
std::cout << "Net Salary (after deductions): " << payslip->getSalary() << "\n";
std::cout << "Generated on: " << payslip->getTimestamp().toString() << "\n";
}
else
{
std::cout << "Payslip not available for " << year << "-" << month << ".\n";
}
util::pressEnter();
}