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
@@ -27,11 +27,16 @@ bool ZenvyController::deactivateEmployee(const std::string& id)
return m_employeeManagementService->deactivateEmployee(id);
}
void ZenvyController::updateProfile(const std::string& name,const std::string& phone)
void ZenvyController::updateProfile(const std::string& name, const std::string& phone)
{
m_employeeManagementService->updateProfile(name,phone);
}
void ZenvyController::updateSalary(const std::string& employeeId, const double basicSalary, const double houseRentAllowance, const double foodAllowance, const double employeePFContribution, const double employerPFContribution)
{
m_payslipManagementService->updateSalary(employeeId, basicSalary, houseRentAllowance, foodAllowance, employeePFContribution, employerPFContribution);
}
std::shared_ptr<const Employee> ZenvyController::getCurrentEmployee()
{
return m_employeeManagementService->getCurrentEmployee();
@@ -40,6 +45,8 @@ std::shared_ptr<const Employee> ZenvyController::getCurrentEmployee()
std::shared_ptr<const Employee> ZenvyController::getEmployee(const std::string& id)
{
}
Employees ZenvyController::getEmployees()
{
return m_employeeManagementService->getEmployees();
}
@@ -51,4 +51,7 @@ public:
std::shared_ptr<const Employee> getEmployee(const std::string&);
std::shared_ptr<const Employee> getCurrentEmployee();
void updateProfile(const std::string&,const std::string&);
//payslip management
void updateSalary(const std::string&, const double, const double, const double, const double, const double);
};
@@ -27,8 +27,4 @@ employeeMap& DataStore::getEmployees()
return m_employees;
}
std::shared_ptr<Employee>& DataStore::getAuthenticatedUser()
{
return m_authenticatedEmployee;
}
@@ -36,7 +36,6 @@ public:
DataStore(DataStore&&) = delete;
DataStore& operator=(DataStore&&) = delete;
employeeMap& getEmployees();
std::shared_ptr<Employee>& getAuthenticatedUser();
logMap& getLogs();
std::shared_ptr<Employee>& getAuthenticatedEmployee();
void setAuthenticatedEmployee(std::shared_ptr < Employee>);
@@ -32,9 +32,9 @@ double Payroll::getEmployerPFContribution() const
return m_employerPFContribution;
}
void Payroll::setPayrollID(const std::string& id)
void Payroll::setBasicSalary(double basicSalary)
{
m_id = id;
m_basicSalary = basicSalary;
}
void Payroll::setHouseRentAllowance(double value)
+5 -5
View File
@@ -25,9 +25,9 @@ public:
double getFoodAllowance() const;
double getEmployeePFContribution() const;
double getEmployerPFContribution() const;
void setPayrollID(const std::string& id);
void setHouseRentAllowance(double value);
void setFoodAllowance(double value);
void setEmployeePFContribution(double value);
void setEmployerPFContribution(double value);
void setBasicSalary(double);
void setHouseRentAllowance(double);
void setFoodAllowance(double);
void setEmployeePFContribution(double);
void setEmployerPFContribution(double);
};
@@ -61,8 +61,8 @@ void AuthenticationManagementService::changePassword(const std::string& password
}
void AuthenticationManagementService::logout() {
if (m_dataStore.getAuthenticatedUser()) {
m_dataStore.getAuthenticatedUser() = nullptr;
if (m_dataStore.getAuthenticatedEmployee()) {
m_dataStore.getAuthenticatedEmployee() = nullptr;
}
else {
throw std::runtime_error("No user currently logged In...");
@@ -102,6 +102,7 @@ bool EmployeeManagementService::deactivateEmployee(const std::string& id)
Employees EmployeeManagementService::getEmployees()
{
}
std::shared_ptr<const Employee> EmployeeManagementService::getEmployee(const std::string& id)
@@ -14,6 +14,7 @@ public:
EmployeeManagementService() : m_dataStore(DataStore::getInstance()) {};
void createEmployee(Enums::EmployeeType, Enums::EmployeeDesignation, const std::string&, const std::string&, const std::string&);
bool deactivateEmployee(const std::string&);
Employees getEmployees();
std::shared_ptr<const Employee> getEmployee(const std::string&);
void updateProfile(const std::string&,const std::string&);
@@ -1 +1,24 @@
#include "PayslipManagementService.h"
void PayslipManagementService::updateSalary(const std::string& employeeId, const double basicSalary, const double houseRentAllowance, const double foodAllowance, const double employeePFContribution, const double employerPFContribution)
{
if (m_dataStore.getAuthenticatedEmployee()->getEmployeeType() == Enums::EmployeeType::FINANCE) {
auto findedEmployee = m_dataStore.getEmployees().find(employeeId);
if (findedEmployee != m_dataStore.getEmployees().end())
{
(findedEmployee->second)->getPayroll()->setBasicSalary(basicSalary);
(findedEmployee->second)->getPayroll()->setHouseRentAllowance(houseRentAllowance);
(findedEmployee->second)->getPayroll()->setFoodAllowance(foodAllowance);
(findedEmployee->second)->getPayroll()->setEmployeePFContribution(employeePFContribution);
(findedEmployee->second)->getPayroll()->setEmployerPFContribution(employerPFContribution);
}
else
{
throw std::runtime_error("Employee not found, unable to update the salary");
}
}
else
{
throw std::runtime_error("Unauthorized access");
}
}
@@ -1,5 +1,7 @@
#pragma once
#include "DataStore.h"
#include <string>
#include<stdexcept>
#include"DataStore.h"
class PayslipManagementService
{
@@ -7,4 +9,5 @@ private:
DataStore& m_dataStore;
public:
PayslipManagementService() : m_dataStore(DataStore::getInstance()) {};
void updateSalary(const std::string&, const double, const double, const double, const double, const double);
};
@@ -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();
};