Implement Update Salary

<UserStory>EMP08: Update Salary Details</UserStory>

<Changes>
- Added `updateSalary` method in ZenvyController to connect payroll updates with PayslipManagementService
- Implemented `PayslipManagementService::updateSalary` with employee existence and Finance-role authorization checks
- Extended Payroll model with setter methods for salary components
- Improved error handling with clear runtime exceptions for invalid index selection, unauthorized access, and missing employees
</Changes>

<Review>
Smitha Mohan
</Review>
This commit is contained in:
Jissin Sam Mathew
2026-04-07 15:34:08 +05:30
committed by Joel Thomas
parent f75bbaaae8
commit 63627075ef
13 changed files with 136 additions and 47 deletions
@@ -28,47 +28,100 @@ void FinanceExecutiveMenu::run()
}
}
std::string FinanceExecutiveMenu::getSelectedUserId()
{
int choice;
std::map<int, std::shared_ptr<const Employee>> currentEmployeeList;
int index = 0;
for (auto& currentEmployee : m_zenvyController->getEmployees())
{
currentEmployeeList[++index] = currentEmployee;
}
for (auto& currentEmployee: currentEmployeeList)
{
std::cout << currentEmployee.first << ". Employee Id: " << currentEmployee.second->getEmployeeId() << "Name: " << currentEmployee.second->getEmployeeName() << std::endl;
}
std::cout << "Enter the Index: ";
util::read(choice);
if (currentEmployeeList.count(choice) == 0)
{
throw std::runtime_error("Enter a valid index");
}
else
{
auto selectedEmployee = currentEmployeeList.find(choice);
return (selectedEmployee->second->getEmployeeId());
}
}
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 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:
m_zenvyController.updatePayroll();
break;*/
case 10:
updateProfile(m_zenvyController);
updatePayroll();
break;
case 11:
updateProfile(m_zenvyController);
break;
case 12:
return false;
default:
std::cout << "Enter a valid choice!" << std::endl;
}
return true;
}
@@ -1,5 +1,6 @@
#pragma once
#include<memory>
#include<stdexcept>
#include"ZenvyController.h"
class FinanceExecutiveMenu
@@ -10,5 +11,7 @@ public:
FinanceExecutiveMenu() : m_zenvyController(std::make_shared<ZenvyController>()) {};
void run();
bool handleOperation(int);
std::string getSelectedUserId();
void updatePayroll();
};