Fix payslip lookup logic and enable view option for finance executive

<UserStory> EMP010 : View Payslip </UserStory>

<Changes>
 - Refactored getPayslipForMonth() to fetch payroll and payslips via employee data
 - Added validation for invalid employee ID
 - Simplified payslip search using employee-specific payslip records
 - Enabled “View Payslip” option in Finance Executive menu
 - Minor UI cleanup in payslip view (spacing and screen clear)
</Changes>

<Review>
Smitha Mohan
</Review>
This commit is contained in:
Princy Jerin
2026-04-16 14:09:28 +05:30
parent 47ca953eac
commit 04ef7744f7
3 changed files with 17 additions and 14 deletions
@@ -89,21 +89,21 @@ void PayslipManagementService::savePayrolls()
std::pair<std::shared_ptr<Payroll>, std::shared_ptr<Payslip>> PayslipManagementService::getPayslipForMonth(const std::string& employeeId, int year, int month)
{
auto& payrolls = m_dataStore.getPayrolls();
auto& payslips = m_dataStore.getPayslips();
for (const auto& payrollsPair : payrolls)
auto& employees = m_dataStore.getEmployees();
auto employeeIterator = employees.find(employeeId);
if (employeeIterator == employees.end())
{
const auto& payroll = payrollsPair.second;
if (payroll->getEmployeeId() == employeeId)
throw std::runtime_error("Employee not found!");
}
auto payroll = employeeIterator->second->getPayroll();
auto& payslips = employeeIterator->second->getEmployeePayslips();
for (const auto& payslipPair : payslips)
{
const auto& payslip = payslipPair.second;
{
auto payslipIterator = payslips.find(payroll->getId());
if (payslipIterator != payslips.end())
if (payslip->getTimestamp().getYear() == year && payslip->getTimestamp().getMonth() == month)
{
const auto& payslip = payslipIterator->second;
if (payslip->getTimestamp().getYear() == year && payslip->getTimestamp().getMonth() == month)
{
return { payroll, payslip };
}
return { payroll, payslip };
}
}
}
@@ -65,6 +65,8 @@ bool FinanceExecutiveMenu::handleOperation(int choice)
{
switch (choice)
{
case 2:
viewPayslip(m_zenvyController);
case 4:
viewEmployees(m_zenvyController);
break;
@@ -304,7 +304,7 @@ inline void viewPayslip(std::shared_ptr<ZenvyController> controller)
util::clear();
std::cout << "Enter the year: ";
util::read(year);
std::cout << "\nEnter the month: ";
std::cout << "Enter the month: ";
util::read(month);
auto employee = controller->getCurrentEmployee();
if (!employee)
@@ -318,7 +318,8 @@ inline void viewPayslip(std::shared_ptr<ZenvyController> controller)
auto payslip = result.second;
if (payroll && payslip)
{
std::cout << "\nPayslip for " << employee->getEmployeeName() << " (" << year << "-" << std::setw(2) << std::setfill('0') << month << ")\n\n";
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";