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:
@@ -27,11 +27,16 @@ bool ZenvyController::deactivateEmployee(const std::string& id)
|
|||||||
return m_employeeManagementService->deactivateEmployee(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);
|
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()
|
std::shared_ptr<const Employee> ZenvyController::getCurrentEmployee()
|
||||||
{
|
{
|
||||||
return m_employeeManagementService->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)
|
std::shared_ptr<const Employee> ZenvyController::getEmployee(const std::string& id)
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
Employees ZenvyController::getEmployees()
|
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> getEmployee(const std::string&);
|
||||||
std::shared_ptr<const Employee> getCurrentEmployee();
|
std::shared_ptr<const Employee> getCurrentEmployee();
|
||||||
void updateProfile(const std::string&,const std::string&);
|
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;
|
return m_employees;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<Employee>& DataStore::getAuthenticatedUser()
|
|
||||||
{
|
|
||||||
return m_authenticatedEmployee;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|||||||
@@ -36,7 +36,6 @@ public:
|
|||||||
DataStore(DataStore&&) = delete;
|
DataStore(DataStore&&) = delete;
|
||||||
DataStore& operator=(DataStore&&) = delete;
|
DataStore& operator=(DataStore&&) = delete;
|
||||||
employeeMap& getEmployees();
|
employeeMap& getEmployees();
|
||||||
std::shared_ptr<Employee>& getAuthenticatedUser();
|
|
||||||
logMap& getLogs();
|
logMap& getLogs();
|
||||||
std::shared_ptr<Employee>& getAuthenticatedEmployee();
|
std::shared_ptr<Employee>& getAuthenticatedEmployee();
|
||||||
void setAuthenticatedEmployee(std::shared_ptr < Employee>);
|
void setAuthenticatedEmployee(std::shared_ptr < Employee>);
|
||||||
|
|||||||
@@ -32,9 +32,9 @@ double Payroll::getEmployerPFContribution() const
|
|||||||
return m_employerPFContribution;
|
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)
|
void Payroll::setHouseRentAllowance(double value)
|
||||||
|
|||||||
@@ -25,9 +25,9 @@ public:
|
|||||||
double getFoodAllowance() const;
|
double getFoodAllowance() const;
|
||||||
double getEmployeePFContribution() const;
|
double getEmployeePFContribution() const;
|
||||||
double getEmployerPFContribution() const;
|
double getEmployerPFContribution() const;
|
||||||
void setPayrollID(const std::string& id);
|
void setBasicSalary(double);
|
||||||
void setHouseRentAllowance(double value);
|
void setHouseRentAllowance(double);
|
||||||
void setFoodAllowance(double value);
|
void setFoodAllowance(double);
|
||||||
void setEmployeePFContribution(double value);
|
void setEmployeePFContribution(double);
|
||||||
void setEmployerPFContribution(double value);
|
void setEmployerPFContribution(double);
|
||||||
};
|
};
|
||||||
@@ -61,8 +61,8 @@ void AuthenticationManagementService::changePassword(const std::string& password
|
|||||||
}
|
}
|
||||||
|
|
||||||
void AuthenticationManagementService::logout() {
|
void AuthenticationManagementService::logout() {
|
||||||
if (m_dataStore.getAuthenticatedUser()) {
|
if (m_dataStore.getAuthenticatedEmployee()) {
|
||||||
m_dataStore.getAuthenticatedUser() = nullptr;
|
m_dataStore.getAuthenticatedEmployee() = nullptr;
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
throw std::runtime_error("No user currently logged In...");
|
throw std::runtime_error("No user currently logged In...");
|
||||||
|
|||||||
@@ -102,6 +102,7 @@ bool EmployeeManagementService::deactivateEmployee(const std::string& id)
|
|||||||
|
|
||||||
Employees EmployeeManagementService::getEmployees()
|
Employees EmployeeManagementService::getEmployees()
|
||||||
{
|
{
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
std::shared_ptr<const Employee> EmployeeManagementService::getEmployee(const std::string& id)
|
std::shared_ptr<const Employee> EmployeeManagementService::getEmployee(const std::string& id)
|
||||||
|
|||||||
@@ -14,6 +14,7 @@ public:
|
|||||||
EmployeeManagementService() : m_dataStore(DataStore::getInstance()) {};
|
EmployeeManagementService() : m_dataStore(DataStore::getInstance()) {};
|
||||||
void createEmployee(Enums::EmployeeType, Enums::EmployeeDesignation, const std::string&, const std::string&, const std::string&);
|
void createEmployee(Enums::EmployeeType, Enums::EmployeeDesignation, const std::string&, const std::string&, const std::string&);
|
||||||
bool deactivateEmployee(const std::string&);
|
bool deactivateEmployee(const std::string&);
|
||||||
|
|
||||||
Employees getEmployees();
|
Employees getEmployees();
|
||||||
std::shared_ptr<const Employee> getEmployee(const std::string&);
|
std::shared_ptr<const Employee> getEmployee(const std::string&);
|
||||||
void updateProfile(const std::string&,const std::string&);
|
void updateProfile(const std::string&,const std::string&);
|
||||||
|
|||||||
@@ -1 +1,24 @@
|
|||||||
#include "PayslipManagementService.h"
|
#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
|
#pragma once
|
||||||
#include "DataStore.h"
|
#include <string>
|
||||||
|
#include<stdexcept>
|
||||||
|
#include"DataStore.h"
|
||||||
|
|
||||||
class PayslipManagementService
|
class PayslipManagementService
|
||||||
{
|
{
|
||||||
@@ -7,4 +9,5 @@ private:
|
|||||||
DataStore& m_dataStore;
|
DataStore& m_dataStore;
|
||||||
public:
|
public:
|
||||||
PayslipManagementService() : m_dataStore(DataStore::getInstance()) {};
|
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)
|
bool FinanceExecutiveMenu::handleOperation(int choice)
|
||||||
{
|
{
|
||||||
switch (choice)
|
switch (choice)
|
||||||
{
|
{
|
||||||
/*case 1:
|
//case 1:
|
||||||
m_zenvyController.applyLeave();
|
// m_zenvyController.applyLeave();
|
||||||
break;
|
// break;
|
||||||
case 2:
|
//case 2:
|
||||||
m_zenvyController.viewPayslip();
|
// m_zenvyController.viewPayslip();
|
||||||
break;
|
// break;
|
||||||
case 3:
|
//case 3:
|
||||||
m_zenvyController.viewPayslipHistory();
|
// m_zenvyController.viewPayslipHistory();
|
||||||
break;
|
// break;
|
||||||
case 4:
|
//case 4:
|
||||||
m_zenvyController.viewEmployees();
|
// m_zenvyController.viewEmployees();
|
||||||
break;
|
// break;
|
||||||
case 5:
|
//case 5:
|
||||||
m_zenvyController.searchEmployee();
|
// m_zenvyController.searchEmployee();
|
||||||
break;
|
// break;
|
||||||
case 6:
|
//case 6:
|
||||||
m_zenvyController.viewNotifications();
|
// m_zenvyController.viewNotifications();
|
||||||
break;
|
// break;
|
||||||
case 7:
|
//case 7:
|
||||||
m_zenvyController.viewAnnouncements();
|
// m_zenvyController.viewAnnouncements();
|
||||||
break;
|
// break;
|
||||||
case 8:
|
//case 8:
|
||||||
m_zenvyController.resolveTicket();
|
// m_zenvyController.resolveTicket();
|
||||||
break;
|
// break;
|
||||||
case 9:
|
//case 9:
|
||||||
m_zenvyController.generatePayslip();
|
// m_zenvyController.generatePayslip();
|
||||||
break;
|
// break;
|
||||||
case 10:
|
case 10:
|
||||||
m_zenvyController.updatePayroll();
|
updatePayroll();
|
||||||
break;*/
|
|
||||||
case 10:
|
|
||||||
updateProfile(m_zenvyController);
|
|
||||||
break;
|
break;
|
||||||
case 11:
|
case 11:
|
||||||
|
updateProfile(m_zenvyController);
|
||||||
|
break;
|
||||||
|
case 12:
|
||||||
return false;
|
return false;
|
||||||
default:
|
default:
|
||||||
std::cout << "Enter a valid choice!" << std::endl;
|
std::cout << "Enter a valid choice!" << std::endl;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,5 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include<memory>
|
#include<memory>
|
||||||
|
#include<stdexcept>
|
||||||
#include"ZenvyController.h"
|
#include"ZenvyController.h"
|
||||||
|
|
||||||
class FinanceExecutiveMenu
|
class FinanceExecutiveMenu
|
||||||
@@ -10,5 +11,7 @@ public:
|
|||||||
FinanceExecutiveMenu() : m_zenvyController(std::make_shared<ZenvyController>()) {};
|
FinanceExecutiveMenu() : m_zenvyController(std::make_shared<ZenvyController>()) {};
|
||||||
void run();
|
void run();
|
||||||
bool handleOperation(int);
|
bool handleOperation(int);
|
||||||
|
std::string getSelectedUserId();
|
||||||
|
void updatePayroll();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user