Merged PR 966: UserStory EMP010 View Payslip

Related work items: #955
This commit is contained in:
Princy Jerin
2026-04-16 14:11:46 +05:30
committed by Joel Thomas
14 changed files with 95 additions and 9 deletions
@@ -76,3 +76,8 @@ void ZenvyController::persistStates()
m_payslipManagementService->savePayrolls();
m_payslipManagementService->savePayslips();
}
std::pair<std::shared_ptr<Payroll>, std::shared_ptr<Payslip>> ZenvyController::getPayslipForMonth(const std::string& employeeId, int year, int month)
{
return m_payslipManagementService->getPayslipForMonth(employeeId, year, month);
}
@@ -62,6 +62,7 @@ public:
//Payslip management
void updateSalary(const std::string&, double, double, double, double, double);
void generatePayslips();
std::pair<std::shared_ptr<Payroll>, std::shared_ptr<Payslip>>getPayslipForMonth(const std::string&, int, int);
//File Management
void loadStates();
@@ -19,7 +19,7 @@ Payroll::Payroll(const std::string& id,
m_houseRentAllowance(houseRentAllowance),
m_foodAllowance(foodAllowance),
m_employeePFContribution(employeePFContribution),
m_employerPFContribution(employerPFContribution)
m_employerPFContribution(employerPFContribution)
{
int idNumber = util::extractNumber(m_id);
if (idNumber > m_uid)
@@ -118,7 +118,6 @@ std::shared_ptr<Payroll> Payroll::deserialize(const std::string& record)
std::getline(serializedPayroll, foodAllowanceString, ',');
std::getline(serializedPayroll, employeePFString, ',');
std::getline(serializedPayroll, employerPFString, ',');
try
{
double basicSalary = std::stod(basicSalaryString);
@@ -145,4 +144,4 @@ std::shared_ptr<Payroll> Payroll::deserialize(const std::string& record)
std::string Payroll::getHeaders()
{
return "PayrollId,EmployeeId,BasicSalary,HouseRentAllowance,FoodAllowance,EmployeePFContribution,EmployerPFContribution";
}
}
@@ -1,6 +1,7 @@
#pragma once
#include <string>
#include <memory>
#include "Timestamp.h"
class Payroll
{
@@ -13,6 +14,7 @@ private:
double m_foodAllowance;
double m_employeePFContribution;
double m_employerPFContribution;
util::Timestamp m_timestamp;
public:
Payroll()
: m_id("PR" + std::to_string(++m_uid)),
@@ -87,6 +87,29 @@ void PayslipManagementService::savePayrolls()
payrollFileManager.save(payrolls);
}
std::pair<std::shared_ptr<Payroll>, std::shared_ptr<Payslip>> PayslipManagementService::getPayslipForMonth(const std::string& employeeId, int year, int month)
{
auto& employees = m_dataStore.getEmployees();
auto employeeIterator = employees.find(employeeId);
if (employeeIterator == employees.end())
{
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;
{
if (payslip->getTimestamp().getYear() == year && payslip->getTimestamp().getMonth() == month)
{
return { payroll, payslip };
}
}
}
return { nullptr, nullptr };
}
void PayslipManagementService::loadPayslips()
{
FileManager<Payslip> payslipFileManager(Config::File::PAYSLIP_FILE);
@@ -11,8 +11,9 @@ public:
PayslipManagementService() : m_dataStore(DataStore::getInstance()) {};
void updateSalary(const std::string&, double, double, double, double, double);
void generatePayslips();
std::pair<std::shared_ptr<Payroll>, std::shared_ptr<Payslip>>getPayslipForMonth(const std::string&, int, int);
void loadPayrolls();
void savePayrolls();
void loadPayslips();
void savePayslips();
};
};
@@ -33,14 +33,14 @@ bool EmployeeMenu::handleOperation(int choice)
{
switch (choice)
{
/*
case 1:
/*case 1:
m_zenvyController.applyLeave();
break;
break;*/
case 2:
m_zenvyController.viewPayslip();
viewPayslip(m_zenvyController);
break;
case 3:
/*case 3:
m_zenvyController.viewPayslipHistory();
break;
case 4 :
@@ -65,6 +65,8 @@ bool FinanceExecutiveMenu::handleOperation(int choice)
{
switch (choice)
{
case 2:
viewPayslip(m_zenvyController);
case 4:
viewEmployees(m_zenvyController);
break;
@@ -32,6 +32,9 @@ bool HRManagerMenu::handleOperation(int choice)
{
switch (choice)
{
case 2:
viewPayslip(m_zenvyController);
break;
case 4:
viewEmployees(m_zenvyController);
break;
@@ -32,6 +32,9 @@ bool ITExecutiveMenu::handleOperation(int choice)
{
switch (choice)
{
case 2:
viewPayslip(m_zenvyController);
break;
case 4:
viewEmployees(m_zenvyController);
break;
@@ -296,4 +296,42 @@ inline void searchEmployee(std::shared_ptr<ZenvyController> m_zenvyController)
std::cout << "No Employee found with this name" << std::endl;
}
util::pressEnter();
}
inline void viewPayslip(std::shared_ptr<ZenvyController> controller)
{
int year, month;
util::clear();
std::cout << "Enter the year: ";
util::read(year);
std::cout << "Enter the month: ";
util::read(month);
auto employee = controller->getCurrentEmployee();
if (!employee)
{
std::cout << "No authenticated employee.\n";
util::pressEnter();
return;
}
auto result = controller->getPayslipForMonth(employee->getId(), year, month);
auto payroll = result.first;
auto payslip = result.second;
if (payroll && payslip)
{
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";
std::cout << "Employee PF Contribution : " << payroll->getEmployeePFContribution() << "\n";
std::cout << "Employer PF Contribution : " << payroll->getEmployerPFContribution() << "\n";
std::cout << "----------------------------------------\n";
std::cout << "Net Salary (after deductions): " << payslip->getSalary() << "\n";
std::cout << "Generated on: " << payslip->getTimestamp().toString() << "\n";
}
else
{
std::cout << "Payslip not available for " << year << "-" << month << ".\n";
}
util::pressEnter();
}
@@ -32,6 +32,9 @@ bool TalentExecutiveMenu::handleOperation(int choice)
{
switch (choice)
{
case 2:
viewPayslip(m_zenvyController);
break;
case 4:
viewEmployees(m_zenvyController);
break;
@@ -32,6 +32,9 @@ bool TeamExecutiveMenu::handleOperation(int choice)
{
switch (choice)
{
case 2:
viewPayslip(m_zenvyController);
break;
case 4:
viewEmployees(m_zenvyController);
break;
@@ -32,6 +32,9 @@ bool TeamLeadMenu::handleOperation(int choice)
{
switch (choice)
{
case 2:
viewPayslip(m_zenvyController);
break;
case 7:
viewEmployees(m_zenvyController);
break;