Change shared pointer to raw pointer in views

This commit is contained in:
Tinu Johnson
2026-04-16 18:02:07 +05:30
parent 9e05bac97c
commit 6a373b48df
20 changed files with 42 additions and 52 deletions
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#include <iostream> #include <iostream>
#include "AdminMenu.h" #include "AdminMenu.h"
#include"InputHelper.h" #include"InputHelper.h"
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#pragma once #pragma once
#include"ZenvyController.h" #include"ZenvyController.h"
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#include <iostream> #include <iostream>
#include<iomanip> #include<iomanip>
#include "EmployeeMenu.h" #include "EmployeeMenu.h"
@@ -4,14 +4,13 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#pragma once #pragma once
#include"ZenvyController.h" #include"ZenvyController.h"
class EmployeeMenu class EmployeeMenu
{ {
private: private:
ZenvyController m_zenvyController; ZenvyController* m_zenvyController;
public: public:
EmployeeMenu() : m_zenvyController(new ZenvyController()) {}; EmployeeMenu() : m_zenvyController(new ZenvyController()) {};
void run(); void run();
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#include <iostream> #include <iostream>
#include "FinanceExecutiveMenu.h" #include "FinanceExecutiveMenu.h"
#include "InputHelper.h" #include "InputHelper.h"
@@ -67,6 +66,15 @@ void FinanceExecutiveMenu::updatePayroll()
} }
} }
void FinanceExecutiveMenu::generatePayslips()
{
util::Timestamp currentTimestamp;
util::clear();
m_zenvyController->generatePayslips();
std::cout << "Generated payslips for the month of " << currentTimestamp.getMonth() << "-" << currentTimestamp.getYear() << " successfully.";
util::pressEnter();
}
/* /*
* Function: FinanceExecutiveMenu::handleOperation * Function: FinanceExecutiveMenu::handleOperation
* Description: Handles the finance executives menu choice and executes the corresponding action * Description: Handles the finance executives menu choice and executes the corresponding action
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#pragma once #pragma once
#include<memory> #include<memory>
#include<iostream> #include<iostream>
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#include <iostream> #include <iostream>
#include "HRManagerMenu.h" #include "HRManagerMenu.h"
#include "InputHelper.h" #include "InputHelper.h"
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#pragma once #pragma once
#include"ZenvyController.h" #include"ZenvyController.h"
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#include <iostream> #include <iostream>
#include "ITExecutiveMenu.h" #include "ITExecutiveMenu.h"
#include "InputHelper.h" #include "InputHelper.h"
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#pragma once #pragma once
#include"ZenvyController.h" #include"ZenvyController.h"
@@ -70,9 +70,9 @@ static Enums::EmployeeDesignation getEmployeeDesignation()
} }
} }
void createEmployee(std::shared_ptr<ZenvyController> controller) void createEmployee(ZenvyController* m_zenvyController)
{ {
auto currentEmployee = controller->getCurrentEmployee(); auto currentEmployee = m_zenvyController->getCurrentEmployee();
Enums::EmployeeType employeeType = getEmployeeType(currentEmployee->getEmployeeType()); Enums::EmployeeType employeeType = getEmployeeType(currentEmployee->getEmployeeType());
Enums::EmployeeDesignation employeeDesignation = Enums::EmployeeDesignation::INVALID; Enums::EmployeeDesignation employeeDesignation = Enums::EmployeeDesignation::INVALID;
std::string name, email, phone; std::string name, email, phone;
@@ -98,12 +98,12 @@ void createEmployee(std::shared_ptr<ZenvyController> controller)
util::read(email); util::read(email);
std::cout << "Enter Phone: "; std::cout << "Enter Phone: ";
util::read(phone); util::read(phone);
controller->createEmployee(employeeType, employeeDesignation, email, name, phone); m_zenvyController->createEmployee(employeeType, employeeDesignation, email, name, phone);
std::cout << "\nCreated Employee Successfully."; std::cout << "\nCreated Employee Successfully.";
util::pressEnter(); util::pressEnter();
} }
void updateDesignation(std::shared_ptr<ZenvyController> m_zenvyController) void updateDesignation(ZenvyController* m_zenvyController)
{ {
std::string selectedEmployeeId = selectEmployeeId(m_zenvyController->getEmployees(Enums::EmployeeType::GENERAL)); std::string selectedEmployeeId = selectEmployeeId(m_zenvyController->getEmployees(Enums::EmployeeType::GENERAL));
if (selectedEmployeeId.empty()) if (selectedEmployeeId.empty())
@@ -123,7 +123,7 @@ void createEmployee(std::shared_ptr<ZenvyController> controller)
} }
} }
void displayCandidateDetails(const std::vector<std::shared_ptr<Candidate>>& shorlistedCandidates) void displayCandidateDetails(const std::vector<Candidate*> shorlistedCandidates)
{ {
util::clear(); util::clear();
std::cout << std::left std::cout << std::left
@@ -148,12 +148,12 @@ void displayCandidateDetails(const std::vector<std::shared_ptr<Candidate>>& shor
} }
} }
void addShortlistedCandidateAsEmployee(const std::shared_ptr<ZenvyController>& controller) void addShortlistedCandidateAsEmployee(const ZenvyController* m_zenvyController)
{ {
int index; int index;
std::string name, email, phone; std::string name, email, phone;
util::clear(); util::clear();
std::vector<std::shared_ptr<Candidate>> shortlistedCandidates = controller->getShorlistedCandidates(); std::vector<Candidate*> shortlistedCandidates = m_zenvyController->getShorlistedCandidates();
if (shortlistedCandidates.empty()) if (shortlistedCandidates.empty())
{ {
std::cout << "No candidates Found!"; std::cout << "No candidates Found!";
@@ -163,13 +163,13 @@ void addShortlistedCandidateAsEmployee(const std::shared_ptr<ZenvyController>& c
displayCandidateDetails(shortlistedCandidates); displayCandidateDetails(shortlistedCandidates);
std::cout << "Enter the Index: "; std::cout << "Enter the Index: ";
util::read(index); util::read(index);
auto currentEmployee = controller->getCurrentEmployee(); auto currentEmployee = m_zenvyController->getCurrentEmployee();
Enums::EmployeeType employeeType; Enums::EmployeeType employeeType;
Enums::EmployeeDesignation employeeDesignation = Enums::EmployeeDesignation::INVALID; Enums::EmployeeDesignation employeeDesignation = Enums::EmployeeDesignation::INVALID;
if (index > 0 && index <= shortlistedCandidates.size()) if (index > 0 && index <= shortlistedCandidates.size())
{ {
employeeType = getEmployeeType(currentEmployee->getEmployeeType()); employeeType = getEmployeeType(currentEmployee->getEmployeeType());
std::shared_ptr<Candidate> candidate = shortlistedCandidates[index - 1]; Candidate* candidate = shortlistedCandidates[index - 1];
switch (employeeType) switch (employeeType)
{ {
case Enums::EmployeeType::INVALID: case Enums::EmployeeType::INVALID:
@@ -190,7 +190,7 @@ void addShortlistedCandidateAsEmployee(const std::shared_ptr<ZenvyController>& c
util::read(email); util::read(email);
name = candidate->getCandidateName(); name = candidate->getCandidateName();
phone = candidate->getCandidatePhone(); phone = candidate->getCandidatePhone();
controller->createEmployee(employeeType, employeeDesignation, email, name, phone); m_zenvyController->createEmployee(employeeType, employeeDesignation, email, name, phone);
candidate->setCandidateStatus(Enums::CandidateStatus::HIRED); candidate->setCandidateStatus(Enums::CandidateStatus::HIRED);
std::cout << "\nCreated Employee Successfully."; std::cout << "\nCreated Employee Successfully.";
util::pressEnter(); util::pressEnter();
+22 -23
View File
@@ -15,12 +15,14 @@
#include "MenuHelper.h" #include "MenuHelper.h"
#include "Validator.h" #include "Validator.h"
void createEmployee(std::shared_ptr<ZenvyController> controller); void createEmployee(ZenvyController* m_zenvyController);
void updateDesignation(std::shared_ptr<ZenvyController> m_zenvyController); void updateDesignation(ZenvyController* m_zenvyController);
void displayCandidateDetails(const std::vector<const Candidate*> shorlistedCandidates);
void addShortlistedCandidateAsEmployee(const ZenvyController* m_zenvyController);
inline void viewPayslipHistory(std::shared_ptr<ZenvyController> controller) inline void viewPayslipHistory(ZenvyController* m_zenvyController)
{ {
auto employeePayslips = controller->getCurrentEmployee()->getEmployeePayslips(); auto employeePayslips = m_zenvyController->getCurrentEmployee()->getEmployeePayslips();
util::clear(); util::clear();
if (employeePayslips.empty()) if (employeePayslips.empty())
{ {
@@ -51,10 +53,10 @@ inline void viewPayslipHistory(std::shared_ptr<ZenvyController> controller)
util::pressEnter(); util::pressEnter();
} }
inline void viewProfile(std::shared_ptr<ZenvyController> controller) inline void viewProfile(ZenvyController* m_zenvyController)
{ {
util::clear(); util::clear();
std::shared_ptr<const Employee> currentEmployee = controller->getCurrentEmployee(); const Employee* currentEmployee = m_zenvyController->getCurrentEmployee();
if (currentEmployee) if (currentEmployee)
{ {
std::cout << std::left std::cout << std::left
@@ -64,7 +66,7 @@ inline void viewProfile(std::shared_ptr<ZenvyController> controller)
<< "Email: " << currentEmployee->getEmployeeEmail() << std::endl << "Email: " << currentEmployee->getEmployeeEmail() << std::endl
<< "Phone: " << currentEmployee->getEmployeePhone() << std::endl; << "Phone: " << currentEmployee->getEmployeePhone() << std::endl;
if (currentEmployee->getEmployeeType() == Enums::EmployeeType::GENERAL) { if (currentEmployee->getEmployeeType() == Enums::EmployeeType::GENERAL) {
if (auto generalEmployee = std::dynamic_pointer_cast<const GeneralEmployee>(currentEmployee)) if (auto generalEmployee = dynamic_cast<const GeneralEmployee*>(currentEmployee))
{ {
std::cout << "Designation: " << Enums::getEmployeeDesignationString(generalEmployee->getDesignation()) << std::endl; std::cout << "Designation: " << Enums::getEmployeeDesignationString(generalEmployee->getDesignation()) << std::endl;
} }
@@ -94,10 +96,7 @@ inline void viewProfile(std::shared_ptr<ZenvyController> controller)
} }
} }
void displayCandidateDetails(const std::vector<std::shared_ptr<const Candidate>>& shorlistedCandidates); inline void updateProfile(ZenvyController* m_zenvyController)
void addShortlistedCandidateAsEmployee(const std::shared_ptr<ZenvyController>& controller);
inline void updateProfile(std::shared_ptr<ZenvyController> m_zenvyController)
{ {
int choice; int choice;
std::string name, phone; std::string name, phone;
@@ -148,10 +147,10 @@ inline void updateProfile(std::shared_ptr<ZenvyController> m_zenvyController)
} }
} }
inline std::string selectEmployeeId(std::vector<std::shared_ptr<const Employee>> allEmployees) inline std::string selectEmployeeId(std::vector<const Employee*>& allEmployees)
{ {
int choice; int choice;
std::map<int, std::shared_ptr<const Employee>> employeeList; std::map<int, const Employee*> employeeList;
int index = 0; int index = 0;
util::clear(); util::clear();
if (allEmployees.empty()) if (allEmployees.empty())
@@ -177,7 +176,7 @@ inline std::string selectEmployeeId(std::vector<std::shared_ptr<const Employee>>
<< std::setw(20) << "Employee Designation" << std::endl; << std::setw(20) << "Employee Designation" << std::endl;
for (const auto& employee : employeeList) for (const auto& employee : employeeList)
{ {
auto generalEmployee = std::dynamic_pointer_cast<const GeneralEmployee>(employee.second); auto generalEmployee = dynamic_cast<const GeneralEmployee*>(employee.second);
std::cout << std::left std::cout << std::left
<< std::setw(10) << employee.first << std::setw(10) << employee.first
<< std::setw(15) << employee.second->getId() << std::setw(15) << employee.second->getId()
@@ -209,14 +208,14 @@ inline std::string selectEmployeeId(std::vector<std::shared_ptr<const Employee>>
} }
} }
inline void deactivateEmployee(const std::shared_ptr<ZenvyController>& controller) inline void deactivateEmployee(const ZenvyController* m_zenvyController)
{ {
std::string selectedEmployeeId = selectEmployeeId(controller->getEmployees()); std::string selectedEmployeeId = selectEmployeeId(m_zenvyController->getEmployees());
if (selectedEmployeeId.empty()) if (selectedEmployeeId.empty())
{ {
return; return;
} }
if (controller->deactivateEmployee(selectedEmployeeId)) if (m_zenvyController->deactivateEmployee(selectedEmployeeId))
{ {
std::cout << "Employee deactivated successfully\n"; std::cout << "Employee deactivated successfully\n";
util::pressEnter(); util::pressEnter();
@@ -228,7 +227,7 @@ inline void deactivateEmployee(const std::shared_ptr<ZenvyController>& controlle
} }
} }
inline void viewEmployees(std::shared_ptr<ZenvyController> m_zenvyController) inline void viewEmployees(ZenvyController* m_zenvyController)
{ {
util::clear(); util::clear();
std::cout << "Employee List\n"; std::cout << "Employee List\n";
@@ -261,13 +260,13 @@ inline void viewEmployees(std::shared_ptr<ZenvyController> m_zenvyController)
util::pressEnter(); util::pressEnter();
} }
inline void searchEmployee(std::shared_ptr<ZenvyController> m_zenvyController) inline void searchEmployee(ZenvyController* m_zenvyController)
{ {
std::string name; std::string name;
util::clear(); util::clear();
std::cout << "Enter Employee Name: "; std::cout << "Enter Employee Name: ";
util::read(name); util::read(name);
std::pair<Enums::EmployeeType, std::vector<std::shared_ptr<const Employee>>> searchResults = m_zenvyController->searchEmployee(name); std::pair<Enums::EmployeeType, std::vector<const Employee*>> searchResults = m_zenvyController->searchEmployee(name);
if (!(searchResults.second).empty()) if (!(searchResults.second).empty())
{ {
std::cout << std::left std::cout << std::left
@@ -333,7 +332,7 @@ inline void searchEmployee(std::shared_ptr<ZenvyController> m_zenvyController)
util::pressEnter(); util::pressEnter();
} }
inline void viewPayslip(std::shared_ptr<ZenvyController> controller) inline void viewPayslip(ZenvyController* m_zenvyController)
{ {
int year, month; int year, month;
util::clear(); util::clear();
@@ -341,14 +340,14 @@ inline void viewPayslip(std::shared_ptr<ZenvyController> controller)
util::read(year); util::read(year);
std::cout << "Enter the month: "; std::cout << "Enter the month: ";
util::read(month); util::read(month);
auto employee = controller->getCurrentEmployee(); auto employee = m_zenvyController->getCurrentEmployee();
if (!employee) if (!employee)
{ {
std::cout << "No authenticated employee.\n"; std::cout << "No authenticated employee.\n";
util::pressEnter(); util::pressEnter();
return; return;
} }
auto result = controller->getPayslipForMonth(employee->getId(), year, month); auto result = m_zenvyController->getPayslipForMonth(employee->getId(), year, month);
auto payroll = result.first; auto payroll = result.first;
auto payslip = result.second; auto payslip = result.second;
if (payroll && payslip) if (payroll && payslip)
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#include <iostream> #include <iostream>
#include "TalentExecutiveMenu.h" #include "TalentExecutiveMenu.h"
#include "InputHelper.h" #include "InputHelper.h"
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#pragma once #pragma once
#include"ZenvyController.h" #include"ZenvyController.h"
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#include <iostream> #include <iostream>
#include "TeamExecutiveMenu.h" #include "TeamExecutiveMenu.h"
#include "InputHelper.h" #include "InputHelper.h"
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#pragma once #pragma once
#include"ZenvyController.h" #include"ZenvyController.h"
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#include <iostream> #include <iostream>
#include "TeamLeadMenu.h" #include "TeamLeadMenu.h"
#include "InputHelper.h" #include "InputHelper.h"
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#pragma once #pragma once
#include"ZenvyController.h" #include"ZenvyController.h"
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#include <iostream> #include <iostream>
#include <utility> #include <utility>
#include <stdexcept> #include <stdexcept>
@@ -4,7 +4,6 @@
* Author: Trenser * Author: Trenser
* Created: 02-Apr-2026 * Created: 02-Apr-2026
*/ */
#pragma once #pragma once
#include <utility> #include <utility>
#include "AdminMenu.h" #include "AdminMenu.h"