Files
Training-Team2-Zenvy-Jan26/Trenser.Zenvy/Trenser.Zenvy/views/FinanceExecutiveMenu.cpp
T
joelthomastrenser 03be8f81d2 Refactored employee creation menu and centralized helper logic
<SRS> SRS02 : Employee Management </SRS>

<Changes>
 - Removed duplicate employee creation helper functions from AdminMenu and HRManagerMenu
 - Centralized employee creation flow into MenuHelper.cpp
 - Updated createEmployee to use current employee type for access control
 - Fixed parameter order bug in createEmployee (email, name, phone)
 - Improved menu titles for all roles (removed generic system header)
 - Added util::pressEnter() for better UX on invalid input across menus
 - Added newline before pause in InputHelper::pressEnter
 - Cleaned up minor formatting issues
</Changes>
2026-04-10 13:33:41 +05:30

139 lines
3.5 KiB
C++

#include <iostream>
#include "FinanceExecutiveMenu.h"
#include "InputHelper.h"
#include "OutputHelper.h"
#include "MenuHelper.h"
void FinanceExecutiveMenu::run()
{
bool isMenuActive = true;
while (isMenuActive)
{
try
{
int choice;
util::clear();
std::cout << "Finance Executive Menu\n1. Apply Leave\n2. View Payslip\n3. View Payslip History\n4. View Employees\n5. Search Employee\n6. View Notification\n7. View Announcements\n8. Resolve Ticket\n9. Generate Payslip\n10. Update Payroll\n11. Update Profile\n12. Logout\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();
}
}
}
std::string FinanceExecutiveMenu::getSelectedUserId()
{
int choice;
std::map<int, std::shared_ptr<const Employee>> employeeList;
int index = 0;
auto allEmployees = m_zenvyController->getEmployees();
for (auto& currentEmployee : allEmployees)
{
if (currentEmployee->getEmployeeType() == Enums::EmployeeType::ADMIN)
{
continue;
}
employeeList[++index] = currentEmployee;
}
std::cout << std::left
<< std::setw(6) << "Index"
<< std::setw(15) << "Employee Id"
<< std::setw(25) << "Name" << std::endl;
for (const auto& employee : employeeList)
{
std::cout << std::left << std::setw(6) << employee.first
<< std::setw(15) << employee.second->getId()
<< std::setw(25) << employee.second->getEmployeeName()
<< 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");
}
}
void FinanceExecutiveMenu::updatePayroll()
{
std::string employeeId;
double basicSalary, houseRentAllowance, foodAllowance, employeePFContribution, employerPFContribution;
employeeId = getSelectedUserId();
if (employeeId != "") {
std::cout << "Enter the New Basic Salary: ";
util::read(basicSalary);
std::cout << "Enter the New House Rent Allowance: ";
util::read(houseRentAllowance);
std::cout << "Enter the New Food Allowance: ";
util::read(foodAllowance);
std::cout << "Enter the New EmployeePFContribution: ";
util::read(employeePFContribution);
std::cout << "Enter the New EmplyerPFContribution: ";
util::read(employerPFContribution);
m_zenvyController->updateSalary(employeeId, basicSalary, houseRentAllowance, foodAllowance, employeePFContribution, employerPFContribution);
}
else {
throw std::runtime_error("Unexpected error occured");
}
}
bool FinanceExecutiveMenu::handleOperation(int choice)
{
switch (choice)
{
//case 1:
// m_zenvyController.applyLeave();
// break;
//case 2:
// m_zenvyController.viewPayslip();
// break;
//case 3:
// m_zenvyController.viewPayslipHistory();
// break;
//case 4:
// m_zenvyController.viewEmployees();
// break;
//case 5:
// m_zenvyController.searchEmployee();
// break;
//case 6:
// m_zenvyController.viewNotifications();
// break;
//case 7:
// m_zenvyController.viewAnnouncements();
// break;
//case 8:
// m_zenvyController.resolveTicket();
// break;
//case 9:
// m_zenvyController.generatePayslip();
// break;
case 10:
updatePayroll();
break;
case 11:
updateProfile(m_zenvyController);
break;
case 12:
return false;
default:
std::cout << "Enter a valid choice!" << std::endl;
util::pressEnter();
}
return true;
}