Compare commits

..

16 Commits

Author SHA1 Message Date
Avinash Rajesh c5f87a0c68 Add standardized documentation headers 2026-05-25 10:54:35 +05:30
Avinash Rajesh 337fb00e1f Merge branch 'feature-admin-management-menu' into feature-admin-management 2026-05-21 19:41:39 +05:30
Avinash Rajesh 33a3677f6e Merge branch 'feature-admin-management-adm007' into feature-admin-management 2026-05-21 19:22:52 +05:30
Avinash Rajesh 3a8db0cdae Merge branch 'feature-admin-management-adm006' into feature-admin-management 2026-05-21 19:16:50 +05:30
Avinash Rajesh 7c993521a2 Merge branch 'feature-admin-management-adm005' into feature-admin-management 2026-05-21 19:10:58 +05:30
Avinash Rajesh ef2fa6d521 Merge branch 'feature-admin-management-adm004' into feature-admin-management 2026-05-21 19:06:44 +05:30
Avinash Rajesh c8647eedd9 Merge branch 'feature-admin-management-adm003' into feature-admin-management 2026-05-21 19:02:57 +05:30
Avinash Rajesh 665d9192fa Merge branch 'feature-admin-management-adm002' into feature-admin-management 2026-05-21 18:55:23 +05:30
Avinash Rajesh d161ac313c Implement Change Password Functionality
<UserStory> ADM005: Change Password </UserStory>

<Changes>
    1. Added AuthenticationManagementService::changePassword to update the authenticated user’s password with validation.
    2. Integrated Controller::changePassword to delegate password update requests to AuthenticationManagementService.
    3. Enhanced AdminMenu::changePassword to prompt for new password, validate strength using Validator, and confirm update.
    4. Added error handling to prevent password change when no user is logged in.
    5. Provided user feedback messages for invalid password attempts and successful updates.
</Changes>

<Test>

  Precondition:
  1. Admin is logged into the system.
  2. AuthenticationManagementService maintains active session.
  3. Validator is available for password strength checks.

  Steps:
  1. Navigate to Admin Menu and select "Change Password".
  2. Enter old password incorrectly.
    - Verify that system rejects the attempt and displays error.
  3. Enter new password that fails validation (length/complexity).
    - Verify that system rejects with "Error: Password is not strong enough!".
  4. Enter valid old password and strong new password.
    - Verify that system confirms "Password changed successfully" and updates the user’s password.
</Test>

<Review>
Sreeja Reghukumar
</Review>
2026-05-21 15:12:16 +05:30
Avinash Rajesh fa08d4a90f Implement Login Functionality
<UserStory> ADM003: Login </UserStory>

<Changes>
    1. Added credential input handling in UserInterface::login with username and password prompts.
    2. Integrated Controller::login to validate credentials and retrieve authenticated user.
    3. Implemented role-based menu navigation: Admin → AdminMenu, Technician → TechnicianMenu, Customer → CustomerMenu.
    4. Added error handling for invalid credentials and unknown user types with clear feedback messages.
    5. Included util::clear for screen refresh and structured output formatting during login.
</Changes>

<Test>

  Precondition:
  1. Valid user accounts exist in the system (Admin, Technician, Customer).
  2. Controller is connected to UserManagementService for authentication.
  3. UserInterface is initialized with role-specific menus.

  Steps:
  1. Launch UserInterface and select "Login".
  2. Enter incorrect username or password.
    - Verify that system displays "Error: Invalid Username or Password".
  3. Enter valid admin credentials.
    - Verify that AdminMenu is displayed successfully.
  4. Enter valid technician or customer credentials.
    - Verify that TechnicianMenu or CustomerMenu is displayed accordingly.
</Test>

<Review>
Sreeja Reghukumar
</Review>
2026-05-21 15:09:04 +05:30
Avinash Rajesh b230e3062c Implement Remove Customer or Technician Functionality
<UserStory> ADM002: Remove Technician or Customer </UserStory>

<Changes>
    1. Integrated UserManagementService and ServiceManagementService into Controller for user removal operations.
    2. Added Controller::removeUser to validate user existence, cancel related service bookings and technician jobs, and mark user inactive.
    3. Updated JobCard and ServiceBooking models to use util::ServiceJobStatus consistently and store technician references as User* instead of strings.
    4. Extended util::ServiceJobStatus enum with PENDING and CANCELLED states, including string conversion support.
    5. Implemented ServiceManagementService methods to cancel customer service bookings and technician jobs, with inventory restocking and notifications.
    6. Enhanced AdminMenu::removeUser to list active users, validate index input, confirm deletion, and invoke Controller::removeUser.
    7. Added helper functions in AdminMenu to filter active users and display them with formatted output including user type.
</Changes>

<Test>

  Precondition:
  1. Admin is logged into the system.
  2. Technician accounts exist in the system.
  3. Technician has active job assignments.

  Steps:
  1. Navigate to Admin Menu and select "Remove User".
  2. System displays list of active users with IDs, usernames, and user types.
    - Verify that inactive users are excluded from the list.
  3. Admin selects technician ID for removal.
    - Verify that system confirms deletion before proceeding.
  4. Technician is removed from job assignment list.
    - Verify that associated jobs are cancelled, inventory is restocked, and notifications are sent.
</Test>

<Review>
Sreeja Reghukumar
</Review>
2026-05-21 15:07:25 +05:30
Avinash Rajesh 2bdf0eb741 Implement Add Technician Functionality
<UserStory> ADM001: Add Technician </UserStory>

<Changes>
    1. Added UserManagementService integration in Controller to support technician account creation.
    2. Updated Controller::createTechnician method to call createUser with util::UserType::TECHNICIAN.
    3. Renamed parameter from 'phone' to 'phoneNumber' for clarity and consistency.
    4. Enhanced AdminMenu::addTechnician with input validation for password, email, and phone number.
    5. Added success and error handling messages in AdminMenu for technician creation workflow.
</Changes>

<Test>

  Precondition:
  1. Admin is logged into the system.
  2. UserManagementService is available and connected.
  3. No existing technician account with the same username/email.

  Steps:
  1. Navigate to Admin Menu and select "Add Technician".
  2. Enter technician details (username, password, email, phone number).
    - Verify that invalid password/email/phone inputs are rejected with error messages.
  3. Enter valid technician details.
    - Verify that uniqueness is checked and duplicate accounts are not created.
  4. Submit valid details.
    - Verify that technician account is created successfully and confirmation message is displayed.
</Test>

<Review>
Sreeja Reghukumar
</Review>
2026-05-21 15:06:32 +05:30
Avinash Rajesh a6e19017ca Implement Create Combo Package Functionality
<UserStory> ADM006:Create Combo Package </UserStory>

<Changes>
    1. Added ServiceManagementService::createComboPackage to validate package name, included services, and discount percentage before creation.
    2. Integrated Controller::createComboPackage to delegate combo package creation to ServiceManagementService.
    3. Enhanced AdminMenu::createComboPackages to allow admin input for package name, service selection, and discount percentage.
    4. Implemented service validation to ensure only active services are selectable and that duplicate combos are prevented.
    5. Added formatted output for service listing with cost calculation and confirmation messages upon successful package creation.
</Changes>

<Test>

  Precondition:
  1. Admin is logged into the system.
  2. At least two active services exist in the system.
  3. ServiceManagementService is connected to DataStore for services and combo packages.

  Steps:
  1. Navigate to Admin Menu and select "Create Combo Package".
  2. Enter package name, select two active services, and provide discount percentage.
    - Verify that system validates service IDs and ensures discount is between 0 and 100.
  3. Attempt to create a package with invalid service IDs or duplicate services.
    - Verify that system rejects with appropriate error messages.
  4. Enter valid package details.
    - Verify that combo package is saved successfully and visible to customers.
</Test>

<Review>
Sreeja Reghukumar
</Review>
2026-05-21 13:08:24 +05:30
Avinash Rajesh ab6eed5ee6 Implement Remove Combo Package for admin
<UserStory> SER003: Remove Combo Package </UserStory>

<Changes>

Added integration between Controller and ServiceManagementService to support combo package removal.

Implemented ServiceManagementService::removeComboPackage with validation for package ID and marking state as INACTIVE.

Enhanced AdminMenu with displayComboPackagesWithIndex helper to show packages in tabular format with index.

Updated AdminMenu::selectComboPackage to allow selection of active packages only and return selected package ID.

Updated AdminMenu::removeComboPackage to prompt for selection, confirm removal, and provide success/failure feedback.
</Changes>

<Test>

Acceptance Criteria:

Admin selects package ID.

System confirms deletion.

Package removed from customer menu.

Precondition:

Admin is logged into the system.

At least one active combo package exists.

Datastore is available for storing combo packages.

Steps:

Navigate to Admin menu and choose "Remove Combo Package".

Verify that the system displays available active packages in tabular format with index.

Select a package ID from the list.

Verify that inactive packages are skipped and only active ones are selectable.

Confirm removal.

Verify that the package is marked INACTIVE and removed from customer menu.

Check customer view.

Verify that the removed package is no longer visible to customers.
</Test>

<Review>
Sreeja Reghukumar, please review
</Review>
2026-05-21 12:44:00 +05:30
joelthomastrenser 454af1b4ef Implement Admin and Technician Menus
Changes:
  - Added Admin Menu display with menu options
  - Added Technician Menu display with menu options
  - Added menu choice handling using switch case
  - Connected menu options to corresponding functions
  - Added invalid choice message
  - Added logout handling
  - Added missing function declarations in TechnicianMenu header
2026-05-21 10:46:23 +05:30
Avinash Rajesh df769a7528 Implement Logout functionality
<UserStory> ADM004: Logout </UserStory>

<Changes>
    1. Added AuthenticationManagementService::logout to clear authenticated user session.
    2. Integrated logout handling in Controller::logout to delegate session termination.
    3. Updated AdminMenu::logout and TechnicianMenu::logout to call Controller::logout for consistent session management.
    4. Extended TechnicianMenu.h with logout method declaration.
    5. Ensured session termination returns control to main menu after logout.
</Changes>

<Test>

  Precondition:
  1. User is logged into the system (Admin or Technician).
  2. AuthenticationManagementService maintains active session.
  3. Controller is connected to AuthenticationManagementService.

  Steps:
  1. Navigate to Admin or Technician Menu.
  2. Select "Logout" option.
    - Verify that AuthenticationManagementService::logout clears authenticated user.
  3. Session is terminated.
    - Verify that system confirms logout and invalidates session.
  4. Console returns to main menu.
    - Verify that user is redirected to main menu and must log in again to continue.
</Test>

<Review>
Sreeja Reghukumar
</Review>
2026-05-21 10:39:53 +05:30
24 changed files with 1132 additions and 816 deletions
@@ -171,7 +171,6 @@
<ClInclude Include="services\PaymentManagementService.h" /> <ClInclude Include="services\PaymentManagementService.h" />
<ClInclude Include="services\ServiceManagementService.h" /> <ClInclude Include="services\ServiceManagementService.h" />
<ClInclude Include="services\UserManagementService.h" /> <ClInclude Include="services\UserManagementService.h" />
<ClInclude Include="utilities\Config.h" />
<ClInclude Include="utilities\Enums.h" /> <ClInclude Include="utilities\Enums.h" />
<ClInclude Include="utilities\InputHelper.h" /> <ClInclude Include="utilities\InputHelper.h" />
<ClInclude Include="utilities\Map.h" /> <ClInclude Include="utilities\Map.h" />
@@ -182,7 +181,6 @@
<ClInclude Include="utilities\Vector.h" /> <ClInclude Include="utilities\Vector.h" />
<ClInclude Include="views\AdminMenu.h" /> <ClInclude Include="views\AdminMenu.h" />
<ClInclude Include="views\CustomerMenu.h" /> <ClInclude Include="views\CustomerMenu.h" />
<ClInclude Include="views\MenuHelper.h" />
<ClInclude Include="views\TechnicianMenu.h" /> <ClInclude Include="views\TechnicianMenu.h" />
<ClInclude Include="views\UserInterface.h" /> <ClInclude Include="views\UserInterface.h" />
</ItemGroup> </ItemGroup>
@@ -233,5 +233,8 @@
<ClInclude Include="models\ComboPackage.h"> <ClInclude Include="models\ComboPackage.h">
<Filter>Header Files\Models</Filter> <Filter>Header Files\Models</Filter>
</ClInclude> </ClInclude>
<ClInclude Include="utilities\Utility.h">
<Filter>Header Files\Utilities</Filter>
</ClInclude>
</ItemGroup> </ItemGroup>
</Project> </Project>
@@ -1,31 +1,24 @@
/* /*
File: Controller.cpp File: Controller.cpp
Description: Implementation file containing the method definitions of the Description: Implementation file containing the method definitions of the
Controller class, including authentication, user creation, Controller class, which manages authentication, users, services,
service purchasing, and system checks. combo packages, and inventory operations.
Author: Trenser Author: Trenser
Date:19-May-2026 Date:19-May-2026
*/ */
#include <stdexcept>
#include "Controller.h" #include "Controller.h"
#include "Enums.h" #include "ComboPackage.h"
#include "User.h" #include "User.h"
/*
Function: login
Description: Authenticates a user by delegating to the authentication management service.
Parameter: const std::string& username - users username
const std::string& password - users password
Return type: bool - true if login successful, false otherwise
*/
bool Controller::login(const std::string& username, const std::string& password) bool Controller::login(const std::string& username, const std::string& password)
{ {
return m_authenticationManagementService.login(username, password); return false;
} }
/* /*
Function: logout Function: logout
Description: Logs out the currently authenticated user. Description: Logs out the currently authenticated user by delegating
to the authentication management service.
Parameter: None Parameter: None
Return type: void Return type: void
*/ */
@@ -36,8 +29,9 @@ void Controller::logout()
/* /*
Function: changePassword Function: changePassword
Description: Changes the password of the currently authenticated user. Description: Updates the password of the authenticated user by delegating
Parameter: const std::string& newPassword - new password to set to the authentication management service.
Parameter: const std::string& newPassword - the new password to set
Return type: void Return type: void
*/ */
void Controller::changePassword(const std::string& newPassword) void Controller::changePassword(const std::string& newPassword)
@@ -45,51 +39,32 @@ void Controller::changePassword(const std::string& newPassword)
m_authenticationManagementService.changePassword(newPassword); m_authenticationManagementService.changePassword(newPassword);
} }
/* void Controller::createCustomer(const std::string& username, const std::string& password, const std::string& email, const std::string& phone)
Function: createCustomer
Description: Creates a new customer account with the provided details.
Parameter: const std::string& username - customers username
const std::string& name - customers name
const std::string& password - customers password
const std::string& email - customers email
const std::string& phone - customers phone number
Return type: void
*/
void Controller::createCustomer(const std::string& username, const std::string& name, const std::string& password, const std::string& email, const std::string& phone)
{ {
m_userManagementService.createUser(username, name, password, email, phone, util::UserType::CUSTOMER);
} }
/*
Function: getAuthenticatedUser
Description: Retrieves the currently authenticated user.
Parameter: None
Return type: const User* - pointer to the authenticated user
*/
const User* Controller::getAuthenticatedUser() const User* Controller::getAuthenticatedUser()
{ {
return m_authenticationManagementService.getAuthenticatedUser(); return nullptr;
}
void Controller::createTechnician(const std::string& username, const std::string& password, const std::string& email, const std::string& phone)
{
} }
/* /*
Function: updateUserDetails Function: createTechnician
Description: Updates the email and phone details of the currently authenticated user. Description: Creates a new technician account with provided details by
Parameter: const std::string& email - new email address delegating to the user management service.
const std::string& phone - new phone number Parameter: const std::string& username - technician's username
const std::string& password - technician's password
const std::string& email - technician's email address
const std::string& phoneNumber - technician's phone number
Return type: void Return type: void
*/ */
void Controller::createTechnician(const std::string& username, const std::string& name, const std::string& password, const std::string& email, const std::string& phoneNumber)
{
m_userManagementService.createUser(username, name, password, email, phoneNumber, util::UserType::TECHNICIAN);
}
void Controller::updateUserDetails(const std::string& email, const std::string& phone) void Controller::updateUserDetails(const std::string& email, const std::string& phone)
{ {
User* authenticatedUser = m_authenticationManagementService.getAuthenticatedUser();
if (authenticatedUser == nullptr)
{
throw std::runtime_error("No user currently logged in!");
}
m_userManagementService.updateUserDetails(authenticatedUser->getId(), email, phone);
} }
util::Map<std::string, const Service*> Controller::getServices() util::Map<std::string, const Service*> Controller::getServices()
@@ -97,37 +72,34 @@ util::Map<std::string, const Service*> Controller::getServices()
return util::Map<std::string, const Service*>(); return util::Map<std::string, const Service*>();
} }
/*
Function: getComboPackages
Description: Retrieves all available combo packages from the service
management service and constructs a read-only map.
Parameter: None
Return type: util::Map<std::string, const ComboPackage*>
*/
util::Map<std::string, const ComboPackage*> Controller::getComboPackages() util::Map<std::string, const ComboPackage*> Controller::getComboPackages()
{ {
return util::Map<std::string, const ComboPackage*>(); util::Map<std::string, ComboPackage*> currentAvailableComboPackages = m_serviceManagementService.getComboPackages();
util::Map<std::string, const ComboPackage*> readOnlyComboPackages;
for (int iterator = 0; iterator < currentAvailableComboPackages.getSize(); iterator++)
{
ComboPackage* currentComboPackage = currentAvailableComboPackages.getValueAt(iterator);
if (currentComboPackage)
{
readOnlyComboPackages.insert(currentComboPackage->getId(), currentComboPackage);
}
}
return readOnlyComboPackages;
} }
/*
Function: purchaseService
Description: Purchases one or more services for a vehicle by delegating to the service management service.
Parameter: const util::Vector<std::string>& serviceIDs - IDs of services to purchase
const std::string& vehicleNumber - vehicle registration number
const std::string& vehicleBrand - brand of the vehicle
const std::string& vehicleModel - model of the vehicle
Return type: void
*/
void Controller::purchaseService(const util::Vector<std::string>& serviceIDs, const std::string& vehicleNumber, const std::string& vehicleBrand, const std::string& vehicleModel) void Controller::purchaseService(const util::Vector<std::string>& serviceIDs, const std::string& vehicleNumber, const std::string& vehicleBrand, const std::string& vehicleModel)
{ {
m_serviceManagementService.purchaseService(serviceIDs, vehicleNumber, vehicleBrand, vehicleModel);
} }
/*
Function: purchaseComboPackage
Description: Purchases a combo package for a vehicle by delegating to the service management service.
Parameter: const std::string& comboPackageID - ID of the combo package
const std::string& vehicleNumber - vehicle registration number
const std::string& vehicleBrand - brand of the vehicle
const std::string& vehicleModel - model of the vehicle
Return type: void
*/
void Controller::purchaseComboPackage(const std::string& comboPackageID, const std::string& vehicleNumber, const std::string& vehicleBrand, const std::string& vehicleModel) void Controller::purchaseComboPackage(const std::string& comboPackageID, const std::string& vehicleNumber, const std::string& vehicleBrand, const std::string& vehicleModel)
{ {
m_serviceManagementService.purchaseComboPackage(comboPackageID, vehicleNumber, vehicleBrand, vehicleModel);
} }
util::Map<std::string, const InventoryItem*> Controller::getInventoryItems() util::Map<std::string, const InventoryItem*> Controller::getInventoryItems()
@@ -158,9 +130,22 @@ util::Map<std::string, const ServiceBooking*> Controller::getServiceBookingsByUs
return util::Map<std::string, const ServiceBooking*>(); return util::Map<std::string, const ServiceBooking*>();
} }
/*
Function: getUsers
Description: Retrieves all users from the user management service and
constructs a read-only map.
Parameter: None
Return type: util::Map<std::string, const User*>
*/
util::Map<std::string, const User*> Controller::getUsers() util::Map<std::string, const User*> Controller::getUsers()
{ {
return util::Map<std::string, const User*>(); auto listOfUsers = m_userManagementService.getUsers();
util::Map<std::string, const User*> readOnlyUserList;
for (int iterator = 0; iterator < listOfUsers.getSize(); iterator++)
{
readOnlyUserList.insert(listOfUsers.getKeyAt(iterator), listOfUsers.getValueAt(iterator));
}
return readOnlyUserList;
} }
util::Map<std::string, const User*> Controller::getUsers(util::UserType userType) util::Map<std::string, const User*> Controller::getUsers(util::UserType userType)
@@ -189,16 +174,49 @@ void Controller::completeJob(const std::string& jobID)
{ {
} }
/*
Function: removeUser
Description: Removes a user by ID. Cancels associated service bookings
and technician jobs before removing the user from the system.
Parameter: const std::string& userID - ID of the user to remove
Return type: void
*/
void Controller::removeUser(const std::string& userID) void Controller::removeUser(const std::string& userID)
{ {
User* user = m_userManagementService.getUser(userID);
if (!user)
{
throw std::runtime_error("Error User not Found.\n");
}
m_serviceManagementService.cancelCustomerServiceBookings(userID);
m_serviceManagementService.cancelTechnicianJobs(userID);
m_userManagementService.removeUser(userID);
} }
/*
Function: createComboPackage
Description: Creates a new combo package with specified services and discount
percentage by delegating to the service management service.
Parameter: const std::string& name - name of the combo package
const util::Vector<std::string>& serviceIDs - list of service IDs
double discountPercentage - discount percentage for the package
Return type: void
*/
void Controller::createComboPackage(const std::string& name, const util::Vector<std::string>& serviceIDs, double discountPercentage) void Controller::createComboPackage(const std::string& name, const util::Vector<std::string>& serviceIDs, double discountPercentage)
{ {
m_serviceManagementService.createComboPackage(name, serviceIDs, discountPercentage);
} }
/*
Function: removeComboPackage
Description: Removes a combo package by ID by delegating to the service
management service.
Parameter: const std::string& comboPackageID - ID of the combo package
Return type: void
*/
void Controller::removeComboPackage(const std::string& comboPackageID) void Controller::removeComboPackage(const std::string& comboPackageID)
{ {
m_serviceManagementService.removeComboPackage(comboPackageID);
} }
util::Map<std::string, const Invoice*> Controller::getInvoicesByUser() util::Map<std::string, const Invoice*> Controller::getInvoicesByUser()
@@ -223,14 +241,7 @@ void Controller::configureNotifications(const std::string& userID, bool paymentN
{ {
} }
/*
Function: runSystemChecks
Description: Runs system checks to ensure critical configurations, such as verifying admin existence.
Parameter: None
Return type: void
*/
void Controller::runSystemChecks() void Controller::runSystemChecks()
{ {
m_userManagementService.ensureAdminExists();
} }
@@ -1,18 +1,18 @@
/* /*
File: Controller.h File: Controller.h
Description: Header file declaring the Controller class, which coordinates Description: Header file declaring the Controller class, which manages
authentication, user management, service management, inventory, user authentication, inventory, services, bookings, job cards,
and notifications across the Vehicle Service System. invoices, and notifications in the system.
Author: Trenser Author: Trenser
Date:19-May-2026 Date:19-May-2026
*/ */
#pragma once #pragma once
#include "Map.h"
#include <string> #include <string>
#include "Map.h"
#include "Enums.h" #include "Enums.h"
#include "AuthenticationManagementService.h"
#include "UserManagementService.h" #include "UserManagementService.h"
#include "ServiceManagementService.h" #include "ServiceManagementService.h"
#include "AuthenticationManagementService.h"
class Service; class Service;
class ComboPackage; class ComboPackage;
@@ -26,16 +26,16 @@ class Notification;
class Controller class Controller
{ {
private: private:
AuthenticationManagementService m_authenticationManagementService; AuthenticationManagementService m_authenticationManagementService;
UserManagementService m_userManagementService; UserManagementService m_userManagementService;
ServiceManagementService m_serviceManagementService; ServiceManagementService m_serviceManagementService;
public: public:
bool login(const std::string& username, const std::string& password); bool login(const std::string& username, const std::string& password);
void logout(); void logout();
void changePassword(const std::string& newPassword); void changePassword(const std::string& newPassword);
void createCustomer(const std::string& username, const std::string& name, const std::string& password, const std::string& email, const std::string& phone); void createCustomer(const std::string& username, const std::string& password, const std::string& email, const std::string& phone);
const User* getAuthenticatedUser(); const User* getAuthenticatedUser();
void createTechnician(const std::string& username, const std::string& password, const std::string& email, const std::string& phone); void createTechnician(const std::string& username, const std::string& name, const std::string& password, const std::string& email, const std::string& phoneNumber);
void updateUserDetails(const std::string& email, const std::string& phone); void updateUserDetails(const std::string& email, const std::string& phone);
util::Map<std::string, const Service*> getServices(); util::Map<std::string, const Service*> getServices();
util::Map<std::string, const ComboPackage*> getComboPackages(); util::Map<std::string, const ComboPackage*> getComboPackages();
@@ -1,14 +1,44 @@
/*
File: JobCard.cpp
Description: Implementation file containing the method definitions of the
JobCard class, including constructors, getters, and setters
for job card attributes.
Author: Trenser
Date:19-May-2026
*/
#include "JobCard.h" #include "JobCard.h"
int JobCard::m_uid = 0; int JobCard::m_uid = 0;
/*
Function: JobCard
Description: Default constructor that initializes a new job card with
a unique ID and default values.
Parameter: None
Return type: Constructor
*/
JobCard::JobCard() JobCard::JobCard()
: m_id("JC" + std::to_string(++m_uid)), : m_id("JC" + std::to_string(++m_uid)),
m_booking(nullptr), m_booking(nullptr),
m_service(nullptr), m_service(nullptr),
m_technician(nullptr), m_technician(nullptr),
m_status(ServiceJobStatus()) {} m_status(util::ServiceJobStatus()) {}
/*
Function: JobCard
Description: Parameterized constructor that initializes a job card with
booking, service, technician, and status details.
Parameter: const std::string& bookingId - ID of the booking
ServiceBooking* booking - pointer to the booking object
Service* service - pointer to the service object
const std::string& serviceId - ID of the service
const std::string& technicianId - ID of the technician
User* technician - pointer to the technician object
const util::Timestamp& assignedDate - date when job was assigned
util::ServiceJobStatus status - current status of the job
const util::Timestamp& completionDate - date when job was completed
Return type: Constructor
*/
JobCard::JobCard(const std::string& bookingId, JobCard::JobCard(const std::string& bookingId,
ServiceBooking* booking, ServiceBooking* booking,
Service* service, Service* service,
@@ -16,7 +46,7 @@ JobCard::JobCard(const std::string& bookingId,
const std::string& technicianId, const std::string& technicianId,
User* technician, User* technician,
const util::Timestamp& assignedDate, const util::Timestamp& assignedDate,
ServiceJobStatus status, util::ServiceJobStatus status,
const util::Timestamp& completionDate const util::Timestamp& completionDate
) )
: m_id("JC" + std::to_string(++m_uid)), : m_id("JC" + std::to_string(++m_uid)),
@@ -30,101 +60,221 @@ JobCard::JobCard(const std::string& bookingId,
m_status(status), m_status(status),
m_completionDate(completionDate) {} m_completionDate(completionDate) {}
/*
Function: getId
Description: Retrieves the unique identifier of the job card.
Parameter: None
Return type: const std::string&
*/
const std::string& JobCard::getId() const const std::string& JobCard::getId() const
{ {
return m_id; return m_id;
} }
/*
Function: getBookingId
Description: Retrieves the booking ID associated with the job card.
Parameter: None
Return type: const std::string&
*/
const std::string& JobCard::getBookingId() const const std::string& JobCard::getBookingId() const
{ {
return m_bookingId; return m_bookingId;
} }
/*
Function: getBooking
Description: Retrieves the booking object associated with the job card.
Parameter: None
Return type: ServiceBooking*
*/
ServiceBooking* JobCard::getBooking() const ServiceBooking* JobCard::getBooking() const
{ {
return m_booking; return m_booking;
} }
/*
Function: getService
Description: Retrieves the service object associated with the job card.
Parameter: None
Return type: Service*
*/
Service* JobCard::getService() const Service* JobCard::getService() const
{ {
return m_service; return m_service;
} }
/*
Function: getServiceId
Description: Retrieves the service ID associated with the job card.
Parameter: None
Return type: const std::string&
*/
const std::string& JobCard::getServiceId() const const std::string& JobCard::getServiceId() const
{ {
return m_serviceId; return m_serviceId;
} }
/*
Function: getTechnicianId
Description: Retrieves the technician ID assigned to the job card.
Parameter: None
Return type: const std::string&
*/
const std::string& JobCard::getTechnicianId() const const std::string& JobCard::getTechnicianId() const
{ {
return m_technicianId; return m_technicianId;
} }
/*
Function: getTechnician
Description: Retrieves the technician object assigned to the job card.
Parameter: None
Return type: User*
*/
User* JobCard::getTechnician() const User* JobCard::getTechnician() const
{ {
return m_technician; return m_technician;
} }
/*
Function: getAssignedDate
Description: Retrieves the date when the job was assigned.
Parameter: None
Return type: const util::Timestamp&
*/
const util::Timestamp& JobCard::getAssignedDate() const const util::Timestamp& JobCard::getAssignedDate() const
{ {
return m_assignedDate; return m_assignedDate;
} }
ServiceJobStatus JobCard::getStatus() const /*
Function: getStatus
Description: Retrieves the current status of the job card.
Parameter: None
Return type: util::ServiceJobStatus
*/
util::ServiceJobStatus JobCard::getStatus() const
{ {
return m_status; return m_status;
} }
/*
Function: getCompletionDate
Description: Retrieves the completion date of the job card.
Parameter: None
Return type: const util::Timestamp&
*/
const util::Timestamp& JobCard::getCompletionDate() const const util::Timestamp& JobCard::getCompletionDate() const
{ {
return m_completionDate; return m_completionDate;
} }
/*
Function: setId
Description: Sets the unique identifier of the job card.
Parameter: const std::string& id - new job card ID
Return type: void
*/
void JobCard::setId(const std::string& id) void JobCard::setId(const std::string& id)
{ {
m_id = id; m_id = id;
} }
/*
Function: setBookingId
Description: Sets the booking ID for the job card.
Parameter: const std::string& bookingId - new booking ID
Return type: void
*/
void JobCard::setBookingId(const std::string& bookingId) void JobCard::setBookingId(const std::string& bookingId)
{ {
m_bookingId = bookingId; m_bookingId = bookingId;
} }
/*
Function: setBooking
Description: Sets the booking object for the job card.
Parameter: ServiceBooking* booking - pointer to the booking object
Return type: void
*/
void JobCard::setBooking(ServiceBooking* booking) void JobCard::setBooking(ServiceBooking* booking)
{ {
m_booking = booking; m_booking = booking;
} }
/*
Function: setService
Description: Sets the service object for the job card.
Parameter: Service* service - pointer to the service object
Return type: void
*/
void JobCard::setService(Service* service) void JobCard::setService(Service* service)
{ {
m_service = service; m_service = service;
} }
/*
Function: setServiceId
Description: Sets the service ID for the job card.
Parameter: const std::string& serviceId - new service ID
Return type: void
*/
void JobCard::setServiceId(const std::string& serviceId) void JobCard::setServiceId(const std::string& serviceId)
{ {
m_serviceId = serviceId; m_serviceId = serviceId;
} }
/*
Function: setTechnicianId
Description: Sets the technician ID for the job card.
Parameter: const std::string& technicianId - new technician ID
Return type: void
*/
void JobCard::setTechnicianId(const std::string& technicianId) void JobCard::setTechnicianId(const std::string& technicianId)
{ {
m_technicianId = technicianId; m_technicianId = technicianId;
} }
/*
Function: setTechnician
Description: Sets the technician object for the job card.
Parameter: User* technician - pointer to the technician object
Return type: void
*/
void JobCard::setTechnician(User* technician) void JobCard::setTechnician(User* technician)
{ {
m_technician = technician; m_technician = technician;
} }
/*
Function: setAssignedDate
Description: Sets the assigned date for the job card.
Parameter: const util::Timestamp& assignedDate - new assigned date
Return type: void
*/
void JobCard::setAssignedDate(const util::Timestamp& assignedDate) void JobCard::setAssignedDate(const util::Timestamp& assignedDate)
{ {
m_assignedDate = assignedDate; m_assignedDate = assignedDate;
} }
void JobCard::setStatus(ServiceJobStatus status) /*
Function: setStatus
Description: Sets the status of the job card.
Parameter: util::ServiceJobStatus status - new job status
Return type: void
*/
void JobCard::setStatus(util::ServiceJobStatus status)
{ {
m_status = status; m_status = status;
} }
/*
Function: setCompletionDate
Description: Sets the completion date for the job card.
Parameter: const util::Timestamp& completionDate - new completion date
Return type: void
*/
void JobCard::setCompletionDate(const util::Timestamp& completionDate) void JobCard::setCompletionDate(const util::Timestamp& completionDate)
{ {
m_completionDate = completionDate; m_completionDate = completionDate;
@@ -1,13 +1,20 @@
/*
File: JobCard.h
Description: Header file declaring the JobCard class, which represents
a service job card containing booking, service, technician,
and status details.
Author: Trenser
Date:19-May-2026
*/
#pragma once #pragma once
#include <string> #include <string>
#include "Timestamp.h" #include "Timestamp.h"
#include "Enums.h"
class ServiceBooking; class ServiceBooking;
class Service; class Service;
class User; class User;
enum class ServiceJobStatus : int;
class JobCard class JobCard
{ {
private: private:
@@ -20,9 +27,8 @@ private:
std::string m_technicianId; std::string m_technicianId;
User* m_technician; User* m_technician;
util::Timestamp m_assignedDate; util::Timestamp m_assignedDate;
ServiceJobStatus m_status; util::ServiceJobStatus m_status;
util::Timestamp m_completionDate; util::Timestamp m_completionDate;
public: public:
JobCard(); JobCard();
JobCard(const std::string& bookingId, JobCard(const std::string& bookingId,
@@ -32,7 +38,7 @@ public:
const std::string& technicianId, const std::string& technicianId,
User* technician, User* technician,
const util::Timestamp& assignedDate, const util::Timestamp& assignedDate,
ServiceJobStatus status, util::ServiceJobStatus status,
const util::Timestamp& completionDate const util::Timestamp& completionDate
); );
const std::string& getId() const; const std::string& getId() const;
@@ -43,7 +49,7 @@ public:
const std::string& getTechnicianId() const; const std::string& getTechnicianId() const;
User* getTechnician() const; User* getTechnician() const;
const util::Timestamp& getAssignedDate() const; const util::Timestamp& getAssignedDate() const;
ServiceJobStatus getStatus() const; util::ServiceJobStatus getStatus() const;
const util::Timestamp& getCompletionDate() const; const util::Timestamp& getCompletionDate() const;
void setId(const std::string& id); void setId(const std::string& id);
void setBookingId(const std::string& bookingId); void setBookingId(const std::string& bookingId);
@@ -53,6 +59,6 @@ public:
void setTechnicianId(const std::string& technicianId); void setTechnicianId(const std::string& technicianId);
void setTechnician(User* technician); void setTechnician(User* technician);
void setAssignedDate(const util::Timestamp& assignedDate); void setAssignedDate(const util::Timestamp& assignedDate);
void setStatus(ServiceJobStatus status); void setStatus(util::ServiceJobStatus status);
void setCompletionDate(const util::Timestamp& completionDate); void setCompletionDate(const util::Timestamp& completionDate);
}; };
@@ -13,31 +13,34 @@ int ServiceBooking::m_uid = 0;
/* /*
Function: ServiceBooking Function: ServiceBooking
Description: Default constructor that initializes a new service booking Description: Default constructor that initializes a new service booking
with a unique ID, no customer or technician, and zero discount. with a unique ID, no customer, and zero discount.
Parameter: None Parameter: None
Return type: Constructor Return type: Constructor
*/ */
ServiceBooking::ServiceBooking() ServiceBooking::ServiceBooking()
: m_id("SRV" + std::to_string(++m_uid)), : m_id("SRV" + std::to_string(++m_uid)),
m_customer(nullptr), m_customer(nullptr),
m_assignedTechnician(nullptr),
m_discountPercentage(0.0) {} m_discountPercentage(0.0) {}
/* /*
Function: ServiceBooking Function: ServiceBooking
Description: Parameterized constructor that initializes a service booking Description: Parameterized constructor that initializes a service booking
with customer, vehicle, services, and discount details. with customer, vehicle, technician, and discount details.
Parameter: util::ServiceJobStatus status - current booking status Parameter: const std::string& id - booking ID
util::ServiceJobStatus status - current booking status
const util::Map<std::string, Service*>& services - map of services const util::Map<std::string, Service*>& services - map of services
const std::string& customerId - ID of the customer const std::string& customerId - ID of the customer
User* customer - pointer to the customer object User* customer - pointer to the customer object
const std::string& vehicleNumber - vehicle registration number const std::string& vehicleNumber - vehicle registration number
const std::string& vehicleBrand - brand of the vehicle const std::string& vehicleBrand - brand of the vehicle
const std::string& vehicleModel - model of the vehicle const std::string& vehicleModel - model of the vehicle
const std::string& assignedTechnicianId - ID of the assigned technician
User* assignedTechnician - pointer to the technician object
double discountPercentage - discount applied to the booking double discountPercentage - discount applied to the booking
Return type: Constructor Return type: Constructor
*/ */
ServiceBooking::ServiceBooking( ServiceBooking::ServiceBooking(
const std::string& id,
util::ServiceJobStatus status, util::ServiceJobStatus status,
const util::Map<std::string, const util::Map<std::string,
Service*>& services, Service*>& services,
@@ -46,6 +49,8 @@ ServiceBooking::ServiceBooking(
const std::string& vehicleNumber, const std::string& vehicleNumber,
const std::string& vehicleBrand, const std::string& vehicleBrand,
const std::string& vehicleModel, const std::string& vehicleModel,
const std::string& assignedTechnicianId,
User* assignedTechnician,
double discountPercentage double discountPercentage
) )
: m_id("SRV" + std::to_string(++m_uid)), : m_id("SRV" + std::to_string(++m_uid)),
@@ -56,8 +61,8 @@ ServiceBooking::ServiceBooking(
m_vehicleNumber(vehicleNumber), m_vehicleNumber(vehicleNumber),
m_vehicleBrand(vehicleBrand), m_vehicleBrand(vehicleBrand),
m_vehicleModel(vehicleModel), m_vehicleModel(vehicleModel),
m_assignedTechnicianId(""), m_assignedTechnicianId(assignedTechnicianId),
m_assignedTechnician(nullptr), m_assignedTechnician(assignedTechnician),
m_discountPercentage(discountPercentage) m_discountPercentage(discountPercentage)
{ {
} }
@@ -171,6 +176,7 @@ User* ServiceBooking::getAssignedTechnician() const
{ {
return m_assignedTechnician; return m_assignedTechnician;
} }
/* /*
Function: getDiscountPercentage Function: getDiscountPercentage
Description: Retrieves the discount percentage applied to the booking. Description: Retrieves the discount percentage applied to the booking.
@@ -32,6 +32,7 @@ private:
public: public:
ServiceBooking(); ServiceBooking();
ServiceBooking( ServiceBooking(
const std::string& id,
util::ServiceJobStatus status, util::ServiceJobStatus status,
const util::Map<std::string, const util::Map<std::string,
Service*>& services, Service*>& services,
@@ -40,6 +41,8 @@ public:
const std::string& vehicleNumber, const std::string& vehicleNumber,
const std::string& vehicleBrand, const std::string& vehicleBrand,
const std::string& vehicleModel, const std::string& vehicleModel,
const std::string& assignedTechnicianId,
User* assignedTechnician,
double discountPercentage double discountPercentage
); );
const std::string& getId() const; const std::string& getId() const;
@@ -1,57 +1,16 @@
/* /*
File: AuthenticationManagementService.cpp File: AuthenticationManagementService.cpp
Description: Implementation file containing the method definitions of the Description: Implementation file containing the method definitions of the
AuthenticationManagementService class, including login, logout, AuthenticationManagementService class, including logout and
password change, and retrieval of the authenticated user. password change logic.
Author: Trenser Author: Trenser
Date:19-May-2026 Date:19-May-2026
*/ */
#include <stdexcept>
#include "AuthenticationManagementService.h" #include "AuthenticationManagementService.h"
#include "User.h" #include "User.h"
User* AuthenticationManagementService::m_authenticatedUser = nullptr; User* AuthenticationManagementService::m_authenticatedUser = nullptr;
/*
Function: login
Description: Authenticates a user by checking the provided username and password
against the stored users in the DataStore. If successful, sets the
authenticated user.
Parameter: const std::string& username - users username
const std::string& password - users password
Return type: bool - true if login successful, false otherwise
*/
bool AuthenticationManagementService::login(const std::string& username, const std::string& password)
{
util::Map<std::string, User*> users = m_dataStore.getUsers();
int usersMapSize = users.getSize();
for (int index = 0; index < usersMapSize; index++)
{
User* user = users.getValueAt(index);
if (username == user->getUserName())
{
if (password == user->getPassword())
{
m_authenticatedUser = user;
return true;
}
return false;
}
}
return false;
}
/*
Function: getAuthenticatedUser
Description: Retrieves the currently authenticated user.
Parameter: None
Return type: User* - pointer to the authenticated user
*/
User* AuthenticationManagementService::getAuthenticatedUser()
{
return m_authenticatedUser;
}
/* /*
Function: logout Function: logout
Description: Logs out the currently authenticated user by clearing the Description: Logs out the currently authenticated user by clearing the
@@ -1,98 +1,231 @@
/* /*
File: ServiceManagementService.cpp File: ServiceManagementService.cpp
Description: Implementation file containing the method definitions of the Description: Implementation file containing the method definitions of the
ServiceManagementService class, including service and combo package ServiceManagementService class, including service booking cancellation,
purchasing logic, booking creation, and notification handling. job card management, combo package creation, and removal logic.
Author: Trenser Author: Trenser
Date:19-May-2026 Date:19-May-2026
*/ */
#include <stdexcept>
#include "ServiceManagementService.h" #include "ServiceManagementService.h"
#include "AuthenticationManagementService.h" #include "DataStore.h"
#include "Service.h"
#include "ServiceBooking.h" #include "ServiceBooking.h"
#include "ComboPackage.h" #include "JobCard.h"
#include "Service.h"
#include "InventoryItem.h"
#include "Factory.h" #include "Factory.h"
#include "ComboPackage.h"
/* /*
Function: purchaseService Function: cancelCustomerServiceBookings
Description: Creates a new service booking for the authenticated user. Validates Description: Cancels all service bookings associated with a given customer or technician.
service IDs, retrieves services from the DataStore, and generates a Updates booking status, resets customer/technician assignments, sends notifications,
booking. Sends a notification upon successful booking. and restocks inventory items.
Parameter: const util::Vector<std::string>& serviceIDs - IDs of services to purchase Parameter: const std::string& userID - ID of the customer or technician
const std::string& vehicleNumber - vehicle registration number
const std::string& vehicleBrand - brand of the vehicle
const std::string& vehicleModel - model of the vehicle
Return type: void Return type: void
*/ */
void ServiceManagementService::purchaseService(const util::Vector<std::string>& serviceIDs, const std::string& vehicleNumber, const std::string& vehicleBrand, const std::string& vehicleModel) void ServiceManagementService::cancelCustomerServiceBookings(const std::string& userID)
{ {
AuthenticationManagementService m_authenticationManagementService; const int INCREMENT_VALUE = 1;
auto authenticatedUser = m_authenticationManagementService.getAuthenticatedUser(); auto& users = m_dataStore.getUsers();
if (authenticatedUser == nullptr) int userIndex = users.find(userID);
{ if (userIndex == -1)
throw std::runtime_error("No user is currently logged in!"); {
} throw std::runtime_error("User not found: " + userID);
auto& servicesMap = m_dataStore.getServices(); }
auto& serviceBookingMap = m_dataStore.getServiceBookings(); User* user = users.getValueAt(userIndex);
util::Map<std::string, Service*> selectedServices; if (user == nullptr)
int selectedServicesCount = serviceIDs.getSize(); {
for (int index = 0; index < selectedServicesCount; index++) throw std::runtime_error("User not found: " + userID);
{ }
int serviceIndex = servicesMap.find(serviceIDs[index]); util::UserType type = user->getUserType();
if (serviceIndex == -1) auto& bookings = DataStore::getInstance().getServiceBookings();
{ for (int bookingIterator = 0; bookingIterator < bookings.getSize(); bookingIterator++)
throw std::runtime_error("Service not found!"); {
} ServiceBooking* booking = bookings.getValueAt(bookingIterator);
Service* service = servicesMap.getValueAt(serviceIndex); if (booking != nullptr &&
selectedServices[service->getId()] = service; (booking->getCustomerId() == userID || booking->getAssignedTechnicianId() == userID))
} {
ServiceBooking* serviceBooking = Factory::getObject<ServiceBooking>(util::ServiceJobStatus::STARTED, selectedServices, authenticatedUser->getId(), authenticatedUser, vehicleNumber, vehicleBrand, vehicleModel, 0); if (booking->getStatus() == util::ServiceJobStatus::PENDING ||
if (serviceBooking == nullptr) booking->getStatus() == util::ServiceJobStatus::STARTED)
{ {
throw std::runtime_error("Failed to create service booking"); if (type == util::UserType::CUSTOMER)
} {
serviceBookingMap[serviceBooking->getId()] = serviceBooking; booking->setStatus(util::ServiceJobStatus::CANCELLED);
sendNotification(authenticatedUser, booking->setCustomer(nullptr);
"Service Booking succeeded", booking->setCustomerId("");
"Your service booking has been successfully placed with ID " + serviceBooking->getId()); User* assignedTechnician = booking->getAssignedTechnician();
sendNotification(assignedTechnician, "Customer Service Cancelled", "Uh?Oh. The customer has cancelled their service booking. Your assigned job card has been cancelled and the inventory has been restocked.");
}
else if (type == util::UserType::TECHNICIAN)
{
booking->setStatus(util::ServiceJobStatus::PENDING);
sendNotification(booking->getCustomer(), "Technician Unavailable", "Your assigned technician is no longer available. Your booking has been reset to pending, and we will reassign a new technician shortly.");
}
booking->setAssignedTechnician(nullptr);
booking->setAssignedTechnicianId("");
const auto& ListOfServices = booking->getServices();
for (int serviceIterator = 0; serviceIterator < ListOfServices.getSize(); serviceIterator++)
{
Service* service = ListOfServices.getValueAt(serviceIterator);
if (service != nullptr)
{
const auto& items = service->getRequiredInventoryItems();
for (int itemIterator = 0; itemIterator < items.getSize(); itemIterator++)
{
InventoryItem* item = items.getValueAt(itemIterator);
if (item != nullptr)
{
item->setQuantity(item->getQuantity() + INCREMENT_VALUE);
}
}
}
}
}
}
}
} }
/* /*
Function: purchaseComboPackage Function: cancelTechnicianJobs
Description: Creates a new service booking for a combo package. Validates the combo Description: Cancels all jobs assigned to a technician. Updates job status, sends notifications,
package ID, retrieves services from the package, and generates a booking and restocks inventory items used in the service.
with the applicable discount. Sends a notification upon successful booking. Parameter: const std::string& technicianID - ID of the technician
Return type: void
*/
void ServiceManagementService::cancelTechnicianJobs(const std::string& technicianID)
{
const int INCREMENT_VALUE = 1;
auto& jobs = m_dataStore.getJobCards();
for (int jobIterator = 0; jobIterator < jobs.getSize(); jobIterator++)
{
JobCard* job = jobs.getValueAt(jobIterator);
if (job != nullptr && job->getTechnicianId() == technicianID)
{
if (job->getStatus() == util::ServiceJobStatus::PENDING || job->getStatus() == util::ServiceJobStatus::STARTED)
{
job->setStatus(util::ServiceJobStatus::CANCELLED);
sendNotification(job->getTechnician(), "Job Cancelled", "The Job has cancelled. Your job card has been cancelled and the inventory has been restocked.");
Service* service = job->getService();
if (service != nullptr)
{
const auto& items = service->getRequiredInventoryItems();
for (int itemIterator = 0; itemIterator < items.getSize(); itemIterator++)
{
InventoryItem* item = items.getValueAt(itemIterator);
if (item != nullptr)
{
item->setQuantity(item->getQuantity() + INCREMENT_VALUE);
}
}
}
}
}
}
}
/*
Function: createComboPackage
Description: Creates a new combo package with two services and a discount percentage.
Validates service IDs, ensures uniqueness, and inserts the new package into the DataStore.
Parameter: const std::string& packageName - name of the combo package
const util::Vector<std::string>& serviceIDsInNewCombo - list of service IDs
double discountPercentage - discount percentage for the package
Return type: void
*/
void ServiceManagementService::createComboPackage(const std::string& packageName, const util::Vector<std::string>& serviceIDsInNewCombo, double discountPercentage)
{
if (packageName.empty())
{
throw std::invalid_argument("The Combo Package Name cannot be empty.\n");
}
if (serviceIDsInNewCombo.getSize() < 2 || serviceIDsInNewCombo.getSize() > 2)
{
throw std::invalid_argument("Combo package must contain only two services.");
}
if (discountPercentage < 0.0 || discountPercentage > 100.0)
{
throw std::invalid_argument("Discount percentage must be between 0 and 100.");
}
auto& servicesMap = m_dataStore.getServices();
for (int index = 0; index < serviceIDsInNewCombo.getSize(); index++)
{
const std::string serviceid = serviceIDsInNewCombo[index];
if (servicesMap.find(serviceid) == -1)
{
throw std::runtime_error("Service ID not found: " + serviceid);
}
}
auto& comboPackageMap = m_dataStore.getComboPackages();
for (int iterator = 0; iterator < comboPackageMap.getSize(); iterator++)
{
ComboPackage* existingCombos = comboPackageMap.getValueAt(iterator);
const util::Map<std::string, Service*>& servicesInsideExistingCombos = existingCombos->getServices();
if (servicesInsideExistingCombos.getSize() == serviceIDsInNewCombo.getSize())
{
bool isIdentical = true;
for (int serviceIterator = 0; serviceIterator < serviceIDsInNewCombo.getSize(); serviceIterator++)
{
const std::string& id = serviceIDsInNewCombo[serviceIterator];
if (servicesInsideExistingCombos.find(id) == -1)
{
isIdentical = false;
break;
}
}
if (isIdentical)
{
throw std::runtime_error("A combo package with the same services already exists.");
}
}
}
util::Map<std::string, Service*> selectedServices;
for (int iteratorOne = 0; iteratorOne < serviceIDsInNewCombo.getSize(); iteratorOne++)
{
const std::string& serviceId = serviceIDsInNewCombo[iteratorOne];
int serviceIndex = servicesMap.find(serviceId);
if (serviceIndex == -1)
{
throw std::runtime_error("Service ID not found: " + serviceId);
}
selectedServices.insert(serviceId, servicesMap.getValueAt(serviceIndex));
}
ComboPackage* newComboPackage = Factory::getObject<ComboPackage>(packageName, discountPercentage, selectedServices);
comboPackageMap.insert(newComboPackage->getId(), newComboPackage);
}
/*
Function: getComboPackages
Description: Retrieves all combo packages stored in the DataStore.
Parameter: None
Return type: util::Map<std::string, ComboPackage*>
*/
util::Map<std::string, ComboPackage*> ServiceManagementService::getComboPackages()
{
return m_dataStore.getComboPackages();
}
/*
Function: removeComboPackage
Description: Removes a combo package by marking it inactive. Throws an exception if the package ID is not found.
Parameter: const std::string& comboPackageID - ID of the combo package Parameter: const std::string& comboPackageID - ID of the combo package
const std::string& vehicleNumber - vehicle registration number
const std::string& vehicleBrand - brand of the vehicle
const std::string& vehicleModel - model of the vehicle
Return type: void Return type: void
*/ */
void ServiceManagementService::purchaseComboPackage(const std::string& comboPackageID, const std::string& vehicleNumber, const std::string& vehicleBrand, const std::string& vehicleModel) void ServiceManagementService::removeComboPackage(const std::string& comboPackageID)
{ {
AuthenticationManagementService m_authenticationManagementService; bool removed = false;
auto authenticatedUser = m_authenticationManagementService.getAuthenticatedUser(); util::Map<std::string, ComboPackage*>& currentComboPackages = m_dataStore.getComboPackages();
if (authenticatedUser == nullptr) for (int iterator = 0; iterator < currentComboPackages.getSize(); iterator++)
{ {
throw std::runtime_error("No user is currently logged in!"); ComboPackage* currentComboPackage = currentComboPackages.getValueAt(iterator);
} if (currentComboPackage && currentComboPackage->getId() == comboPackageID)
auto& comboPackagesMap = m_dataStore.getComboPackages(); {
auto& serviceBookingMap = m_dataStore.getServiceBookings(); currentComboPackage->setState(util::State::INACTIVE);
int comboPackageIndex = comboPackagesMap.find(comboPackageID); removed = true;
if (comboPackageIndex == -1) break;
{ }
throw std::runtime_error("Combo Package not found!"); }
} if (!removed)
const ComboPackage* comboPackage = comboPackagesMap[comboPackageID]; {
util::Map<std::string, Service*> selectedServices = comboPackage->getServices(); throw std::runtime_error("Combo package with ID '" + comboPackageID + "' not found.");
ServiceBooking* serviceBooking = Factory::getObject<ServiceBooking>(util::ServiceJobStatus::STARTED, selectedServices, authenticatedUser->getId(), authenticatedUser, vehicleNumber, vehicleBrand, vehicleModel, comboPackage->getDiscountPercentage()); }
if (serviceBooking == nullptr)
{
throw std::runtime_error("Failed to create combo package service booking");
}
serviceBookingMap[serviceBooking->getId()] = serviceBooking;
sendNotification(authenticatedUser,
"Combo Package Service Booking succeeded",
"Your service booking for the combo package has been successfully placed with ID " + serviceBooking->getId());
} }
@@ -37,7 +37,7 @@ public:
void completeJob(const std::string& jobID); void completeJob(const std::string& jobID);
void cancelCustomerServiceBookings(const std::string& customerID); void cancelCustomerServiceBookings(const std::string& customerID);
void cancelTechnicianJobs(const std::string& technicianID); void cancelTechnicianJobs(const std::string& technicianID);
void createComboPackage(const std::string& name, const util::Vector<std::string>& serviceIDs, double discountPercentage); void createComboPackage(const std::string& packageName, const util::Vector<std::string>& serviceIDs, double discountPercentage);
void removeComboPackage(const std::string& comboPackageID); void removeComboPackage(const std::string& comboPackageID);
void sendNotification(User* user, const std::string& title, const std::string& message) override; void sendNotification(User* user, const std::string& title, const std::string& message) override;
void attach(User* user) override; void attach(User* user) override;
@@ -1,112 +1,55 @@
/* /*
File: UserManagementService.cpp File: UserManagementService.cpp
Description: Implementation file containing the method definitions of the Description: Implementation file containing the method definitions of the
UserManagementService class, including user creation, updates, UserManagementService class, including user retrieval and removal logic.
and ensuring an admin account exists.
Author: Trenser Author: Trenser
Date:19-May-2026 Date:19-May-2026
*/ */
#include <stdexcept>
#include "User.h"
#include "Enums.h"
#include "Config.h"
#include "UserManagementService.h" #include "UserManagementService.h"
#include "ServiceManagementService.h" #include "User.h"
#include "PaymentManagementService.h"
#include "InventoryManagementService.h"
#include "Factory.h"
/* /*
Function: ensureAdminExists Function: getUsers
Description: Ensures that at least one admin user exists in the system. Description: Retrieves all users stored in the DataStore.
If no admin is found, creates a default admin user using
configuration constants.
Parameter: None Parameter: None
Return type: void Return type: util::Map<std::string, User*>
*/ */
void UserManagementService::ensureAdminExists() util::Map<std::string, User*> UserManagementService::getUsers()
{ {
auto& usersMap = m_dataStore.getUsers(); return m_dataStore.getUsers();
int usersMapSize = usersMap.getSize();
bool isAdminFound = false;
for (int index = 0; index < usersMapSize; index++)
{
User* user = usersMap.getValueAt(index);
if (user && user->getUserType() == util::UserType::ADMIN)
{
isAdminFound = true;
break;
}
}
if (!isAdminFound)
{
createUser(
config::admin::DEFAULT_ADMIN_USERNAME,
config::admin::DEFAULT_ADMIN_NAME,
config::admin::DEFAULT_ADMIN_PASSWORD,
config::admin::DEFAULT_ADMIN_EMAIL,
config::admin::DEFAULT_ADMIN_PHONE,
util::UserType::ADMIN);
}
} }
/* /*
Function: createUser Function: getUser
Description: Creates a new user with the provided details. Validates that Description: Retrieves a specific user by ID from the DataStore.
the username is unique, then attaches the user to relevant Parameter: const std::string& userID - ID of the user
management services (payment, service, inventory). Return type: User*
Parameter: const std::string& username - users username
const std::string& name - users name
const std::string& password - users password
const std::string& email - users email address
const std::string& phone - users phone number
util::UserType type - type of user (ADMIN, CUSTOMER, TECHNICIAN)
Return type: void
*/ */
void UserManagementService::createUser(const std::string& username, const std::string& name, const std::string& password, const std::string& email, const std::string& phone, util::UserType type) User* UserManagementService::getUser(const std::string& userID)
{ {
InventoryManagementService inventoryManagementService; int index = m_dataStore.getUsers().find(userID);
PaymentManagementService paymentManagementService;
ServiceManagementService serviceManagementService;
auto& usersMap = m_dataStore.getUsers();
int index = usersMap.findIf(
[&](const std::string&, User* user)
{
return user->getUserName() == username;
}
);
if (index != -1) if (index != -1)
{ {
throw std::runtime_error("Username already exists"); return m_dataStore.getUsers().getValueAt(index);
}
User* newUser = Factory::getObject<User>(username, password, name, phone, email, type);
usersMap.insert(newUser->getId(), newUser);
paymentManagementService.attach(newUser);
serviceManagementService.attach(newUser);
if (newUser->getUserType() == util::UserType::ADMIN)
{
inventoryManagementService.attach(newUser);
} }
return nullptr;
} }
/* /*
Function: updateUserDetails Function: removeUser
Description: Updates the email and phone details of an existing user. Description: Marks a user as inactive in the DataStore instead of deleting them.
Throws an exception if the user does not exist. Parameter: const std::string& userID - ID of the user to remove
Parameter: const std::string& userID - ID of the user to update
const std::string& email - new email address
const std::string& phone - new phone number
Return type: void Return type: void
*/ */
void UserManagementService::updateUserDetails(const std::string& userID, const std::string& email, const std::string& phone) void UserManagementService::removeUser(const std::string& userID)
{ {
auto& usersMap = m_dataStore.getUsers(); int index = m_dataStore.getUsers().find(userID);
int index = usersMap.find(userID); if (index != -1)
if (index == -1)
{ {
throw std::runtime_error("User does not exist!"); User* user = m_dataStore.getUsers().getValueAt(index);
if (user != nullptr)
{
user->setState(util::State::INACTIVE);
}
} }
User* user = usersMap.getValueAt(index); }
user->setEmail(email);
user->setPhone(phone);
}
@@ -1,8 +1,7 @@
/* /*
File: UserManagementService.h File: UserManagementService.h
Description: Header file declaring the UserManagementService class, which manages Description: Header file declaring the UserManagementService class, which manages
user creation, updates, retrieval, removal, notifications, and ensures user creation, updates, retrieval, removal, and notification handling.
the existence of an admin account.
Author: Trenser Author: Trenser
Date:19-May-2026 Date:19-May-2026
*/ */
@@ -29,5 +28,4 @@ public:
void removeUser(const std::string& userID); void removeUser(const std::string& userID);
util::Vector<Notification*> getUserNotifications(const std::string& userID); util::Vector<Notification*> getUserNotifications(const std::string& userID);
void deleteNotification(const std::string& notificationID, const std::string& userID); void deleteNotification(const std::string& notificationID, const std::string& userID);
void ensureAdminExists();
}; };
@@ -1,21 +0,0 @@
/*
File: Config.h
Description: Header file declaring configuration constants for the Vehicle Service System.
Includes default admin account details such as username, name, password,
email, and phone number.
Author: Trenser
Date:19-May-2026
*/
#pragma once
namespace config
{
namespace admin
{
constexpr const char* DEFAULT_ADMIN_USERNAME = "admin";
constexpr const char* DEFAULT_ADMIN_NAME = "admin";
constexpr const char* DEFAULT_ADMIN_PASSWORD = "";
constexpr const char* DEFAULT_ADMIN_EMAIL = "admin@vss";
constexpr const char* DEFAULT_ADMIN_PHONE = "0000000000";
}
}
@@ -24,8 +24,10 @@ namespace util
enum class ServiceJobStatus enum class ServiceJobStatus
{ {
PENDING,
STARTED, STARTED,
COMPLETED COMPLETED,
CANCELLED
}; };
enum class State enum class State
@@ -121,10 +123,14 @@ namespace util
{ {
switch (status) switch (status)
{ {
case ServiceJobStatus::PENDING:
return "PENDING";
case ServiceJobStatus::STARTED: case ServiceJobStatus::STARTED:
return "STARTED"; return "STARTED";
case ServiceJobStatus::COMPLETED: case ServiceJobStatus::COMPLETED:
return "COMPLETED"; return "COMPLETED";
case ServiceJobStatus::CANCELLED:
return "CANCELLED";
} }
throw std::invalid_argument("Invalid ServiceJobStatus"); throw std::invalid_argument("Invalid ServiceJobStatus");
} }
@@ -139,6 +145,14 @@ namespace util
{ {
return ServiceJobStatus::COMPLETED; return ServiceJobStatus::COMPLETED;
} }
if (value == "PENDING")
{
return ServiceJobStatus::PENDING;
}
if (value == "CANCELLED")
{
return ServiceJobStatus::CANCELLED;
}
throw std::invalid_argument("Invalid ServiceJobStatus string"); throw std::invalid_argument("Invalid ServiceJobStatus string");
} }
@@ -1,7 +1,7 @@
/* /*
File: Utility.h File: Utility.h
Description: Header file declaring utility functions used across the system, Description: Header file declaring utility functions used across the system,
including cost calculation for services and combo packages. including cost calculation for services based on required inventory items.
Author: Trenser Author: Trenser
Date:19-May-2026 Date:19-May-2026
*/ */
@@ -27,23 +27,3 @@ inline double calculatePartsCost(const Service* service)
} }
return cost; return cost;
} }
/*
Function: calculateComboServiceEstimatedCost
Description: Calculates the estimated total cost of a combo package by summing
the labor and parts costs of all services included in the package.
Parameter: const ComboPackage* comboPackage - pointer to the combo package object
Return type: double - estimated total cost of the combo package
*/
inline double calculateComboServiceEstimatedCost(const ComboPackage* comboPackage)
{
double cost = 0;
auto& services = comboPackage->getServices();
int servicesSize = services.getSize();
for (int index = 0; index < servicesSize; index++)
{
const Service* service = services.getValueAt(index);
cost += calculatePartsCost(service) + service->getLaborCost();
}
return cost;
}
@@ -1,43 +1,161 @@
/*
File: AdminMenu.cpp
Description: Implementation file containing the method definitions of the
AdminMenu class, including menu handling, inventory operations,
user management, and combo package management functions.
Author: Trenser
Date:19-May-2026
*/
#include <iostream>
#include <iomanip>
#include "AdminMenu.h" #include "AdminMenu.h"
#include "InputHelper.h" #include "InputHelper.h"
#include "OutputHelper.h" #include "OutputHelper.h"
#include "User.h"
#include "Validator.h"
#include "Service.h"
#include "Utility.h"
#include "ComboPackage.h"
#include "Enums.h"
/*
Function: showMenu
Description: Displays the admin menu and handles user input until logout is selected.
Parameter: None
Return type: void
*/
void AdminMenu::showMenu() void AdminMenu::showMenu()
{ {
bool isMenuActive = true; while (true)
while (isMenuActive) {
{ try
try {
{ int choice;
int choice; util::clear();
util::clear(); std::cout << "Admin Menu"
std::cout << "" << std::endl; << "\n1. View Stock Levels"
util::read(choice); << "\n2. Add Inventory Item"
if (!handleOperation(choice)) << "\n3. Remove Inventory Item"
{ << "\n4. Check Stock Availability"
isMenuActive = false; << "\n5. Assign Job to Technician"
} << "\n6. Add Technician"
} << "\n7. Remove Customer/Technician"
catch (const std::exception& e) << "\n8. Create Service"
{ << "\n9. Remove Service"
std::cout << "Exception: " << e.what() << std::endl; << "\n10. Create Combo Package"
util::pressEnter(); << "\n11. Remove Combo Package"
} << "\n12. View Notifications"
} << "\n13. Change Password"
<< "\n14. Logout"
<< "\nEnter a choice: ";
util::read(choice);
if (!handleOperation(choice))
{
break;
}
}
catch (const std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
util::pressEnter();
}
}
} }
/*
Function: handleOperation
Description: Executes the corresponding admin operation based on the selected menu choice.
Parameter: int choice - selected menu option
Return type: bool - true if menu continues, false if logout
*/
bool AdminMenu::handleOperation(int choice) bool AdminMenu::handleOperation(int choice)
{ {
return false; switch (choice)
{
case 1:
viewStockLevels();
break;
case 2:
addInventoryItem();
break;
case 3:
removeInventoryItem();
break;
case 4:
checkStockAvailability();
break;
case 5:
assignJob();
break;
case 6:
addTechnician();
break;
case 7:
removeUser();
break;
case 8:
createService();
break;
case 9:
removeService();
break;
case 10:
createComboPackages();
break;
case 11:
removeComboPackage();
break;
case 12:
viewNotifications();
break;
case 13:
changePassword();
break;
case 14:
logout();
return false;
default:
std::cout << "Enter a valid choice!" << std::endl;
util::pressEnter();
}
return true;
} }
/*
Function: logout
Description: Logs out the currently authenticated admin user.
Parameter: None
Return type: void
*/
void AdminMenu::logout() void AdminMenu::logout()
{ {
m_controller.logout();
} }
/*
Function: changePassword
Description: Allows the admin to change their password after validation.
Parameter: None
Return type: void
*/
void AdminMenu::changePassword() void AdminMenu::changePassword()
{ {
std::string newPassword;
while (true)
{
util::clear();
std::cout << "Enter new password: ";
util::read(newPassword);
if (!util::isPasswordValid(newPassword))
{
std::cout << "Error: Password is not strong enough!\n";
util::pressEnter();
continue;
}
m_controller.changePassword(newPassword);
std::cout << "Password changed successfully\n";
util::pressEnter();
break;
}
} }
void AdminMenu::viewStockLevels() void AdminMenu::viewStockLevels()
@@ -68,20 +186,329 @@ void AdminMenu::removeService()
{ {
} }
/*
Function: addTechnician
Description: Adds a new technician after validating username, password, email, and phone number.
Parameter: None
Return type: void
*/
void AdminMenu::addTechnician() void AdminMenu::addTechnician()
{ {
util::clear();
std::string username, name, password, email, phoneNumber;
std::cout << std::left << std::setw(25) << "Enter Technician Username: ";
util::read(username);
std::cout << std::left << std::setw(25) << "Enter Technician Name: ";
util::read(name);
std::cout << std::setw(25) << "Enter Technician Password: ";
util::read(password);
if(!util::isPasswordValid(password))
{
std::cout << "Error: Password is invalid!";
util::pressEnter();
return;
}
std::cout << std::setw(25) << "Enter Technician Email: ";
util::read(email);
if(!util::isEmailValid(email))
{
std::cout << "Error: Email is invalid!";
util::pressEnter();
return;
}
std::cout << std::setw(25) << "Enter Technician Phone: ";
util::read(phoneNumber);
if(!util::isPhoneNumberValid(phoneNumber))
{
std::cout << "Error: Phone Number is invalid!";
util::pressEnter();
return;
}
m_controller.createTechnician(username, name, password, email, phoneNumber);
std::cout << "\nTechnician Added Successfully.\n";
util::pressEnter();
} }
/*
Function: filterActiveUsers
Description: Filters out inactive users and returns a map of active users.
Parameter: const util::Map<std::string, const User*>& listOfUsers - all users
Return type: util::Map<std::string, const User*>
*/
static util::Map<std::string, const User*>
filterActiveUsers(const util::Map<std::string, const User*>& listOfUsers)
{
util::Map<std::string, const User*> activeUsers;
int inventorySize = listOfUsers.getSize();
for (int index = 0; index < inventorySize; index++)
{
const User* user = listOfUsers.getValueAt(index);
if (user != nullptr && user->getState() != util::State::INACTIVE)
{
activeUsers.insert(user->getId(), user);
}
}
return activeUsers;
}
/*
Function: displayAllActiveUsers
Description: Displays all active users in a tabular format with index, ID, username, and type.
Parameter: util::Map<std::string, const User*>& activeUsers - active users list
int activeUserCount - number of active users
Return type: void
*/
static void displayAllActiveUsers(util::Map<std::string, const User*>& activeUsers, int activeUserCount)
{
std::cout << std::left << std::setw(10) << "Index"
<< std::setw(15) << "User ID"
<< std::setw(25) << "Username"
<< std::setw(25) << "User Type"
<< std::endl;
for (int iterator = 0; iterator < activeUserCount; iterator++)
{
const User* user = activeUsers.getValueAt(iterator);
if (user != nullptr)
{
std::cout << std::left << std::setw(10) << (iterator + 1)
<< std::setw(15) << user->getId()
<< std::setw(25) << user->getUserName()
<< std::setw(25) << util::getUserTypeString(user->getUserType())
<< std::endl;
}
else
{
std::cout << "No users found.\n";
util::pressEnter();
return;
}
}
}
/*
Function: removeUser
Description: Removes a selected active user (customer or technician) from the system.
Parameter: None
Return type: void
*/
void AdminMenu::removeUser() void AdminMenu::removeUser()
{ {
util::clear();
int indexChoice;
auto listOfUsers = m_controller.getUsers();
auto listOfActiveUsers = filterActiveUsers(listOfUsers);
int activeUserCount = listOfActiveUsers.getSize();
if (activeUserCount < 1)
{
std::cout << "No Active users." << std::endl;
util::pressEnter();
return;
}
displayAllActiveUsers(listOfActiveUsers, activeUserCount);
std::cout << "Enter the index of the user to delete : ";
util::read(indexChoice);
if (indexChoice < 1 || indexChoice > activeUserCount)
{
std::cout << "Error Invaild index.\n" << std::endl;
util::pressEnter();
return;
}
const User* userToRemove = listOfActiveUsers.getValueAt(indexChoice - 1);
if (userToRemove != nullptr)
{
std::string userIdToRemove = userToRemove->getId();
m_controller.removeUser(userIdToRemove);
std::cout << userToRemove->getUserName() << " removed Successfully.\n";
}
util::pressEnter();
} }
/*
Function: selectServiceFromServices
Description: Displays active services and allows the admin to select one by index.
Parameter: const util::Map<std::string, const Service*>& services - list of services
Return type: const Service* - selected service
*/
static const Service* selectServiceFromServices(const util::Map<std::string, const Service*>& services)
{
util::Map<int, const Service*> activeServicesMap;
int currentIndex = 1;
int userInputIndex;
std::cout << std::left
<< std::setw(10) << "Index"
<< std::setw(15) << "Service ID"
<< std::setw(25) << "Service Name"
<< std::setw(15) << "Estimated Cost"
<< std::endl;
for (int index = 0; index < services.getSize(); index++)
{
const Service* currentService = services.getValueAt(index);
if (currentService->getState() != util::State::ACTIVE)
{
continue;
}
activeServicesMap.insert(currentIndex, currentService);
double partsCost = calculatePartsCost(currentService);
std::cout << std::left
<< std::setw(10) << currentIndex
<< std::setw(15) << currentService->getId()
<< std::setw(25) << currentService->getName()
<< std::setw(15) << (currentService->getLaborCost() + partsCost)
<< std::endl;
currentIndex++;
}
if (activeServicesMap.getSize() == 0)
{
std::cout << "No active services available." << std::endl;
return nullptr;
}
std::cout << "Enter service index: ";
util::read(userInputIndex);
if (activeServicesMap.find(userInputIndex) == -1)
{
std::cout << "Invalid service index." << std::endl;
return nullptr;
}
return activeServicesMap[userInputIndex];
}
/*
Function: createComboPackages
Description: Creates a new combo package by selecting two active services and applying a discount.
Parameter: None
Return type: void
*/
void AdminMenu::createComboPackages() void AdminMenu::createComboPackages()
{ {
util::clear();
auto serviceList = m_controller.getServices();
const int numberOfServicesInPackage = 2;
util::Vector<std::string> selectedServiceID;
for (int iterator = 0; iterator < numberOfServicesInPackage; iterator++)
{
const Service* chosenService = selectServiceFromServices(serviceList);
if (chosenService == nullptr)
{
std::cout << "Failed to create combo package!";
util::pressEnter();
return;
}
selectedServiceID.push_back(chosenService->getId());
util::clear();
}
std::string packageName;
double discountPercentage;
std::cout << "Enter combo package name: ";
util::read(packageName);
std::cout << "Enter discount percentage: ";
util::read(discountPercentage);
if (discountPercentage < 0.0 || discountPercentage > 100.0)
{
std::cout << "Error: Discount percentage must be between 0 and 100." << std::endl;
util::pressEnter();
return;
}
m_controller.createComboPackage(packageName, selectedServiceID, discountPercentage);
std::cout << "Combo package '" << packageName << "' created successfully." << std::endl;
util::pressEnter();
} }
/*
Function: displayComboPackagesWithIndex
Description: Displays combo packages with index, ID, name, and discount percentage.
Parameter: util::Map<int, const ComboPackage*>& currentComboPackageIndexMap - combo packages map
Return type: void
*/
static void displayComboPackagesWithIndex(util::Map<int, const ComboPackage*>& currentComboPackageIndexMap)
{
for (int iterator = 0; iterator < currentComboPackageIndexMap.getSize(); iterator++)
{
const ComboPackage* currentComboPackage = currentComboPackageIndexMap.getValueAt(iterator);
if (currentComboPackage == nullptr)
{
throw std::runtime_error("Error accessing the combopackage.\n");
}
if (iterator == 0)
{
std::cout << std::left
<< std::setw(8) << "Index"
<< std::setw(10) << "ID"
<< std::setw(20) << "Package Name"
<< std::setw(15) << "Discount (%)"
<< "\n";
}
std::cout << std::left
<< std::setw(8) << currentComboPackageIndexMap.getKeyAt(iterator)
<< std::setw(10) << currentComboPackage->getId()
<< std::setw(20) << currentComboPackage->getPackageName()
<< std::setw(15) << currentComboPackage->getDiscountPercentage()
<< "\n";
}
}
/*
Function: selectComboPackage
Description: Allows the admin to select an active combo package by index.
Parameter: util::Map<std::string, const ComboPackage*>& currentComboPackages - combo packages list
Return type: std::string - ID of the selected combo package
*/
static std::string selectComboPackage(util::Map<std::string, const ComboPackage*>& currentComboPackages)
{
util::Map<int, const ComboPackage*> currentComboPackageIndexMap;
if (currentComboPackages.getSize() == 0)
{
throw std::runtime_error("No combo packages are available.\n");
}
int currentIndex = 1, choice, selectedIndex;
for (int iterator = 0; iterator < currentComboPackages.getSize(); iterator++)
{
if (currentComboPackages.getValueAt(iterator)->getState() == util::State::INACTIVE)
{
continue;
}
currentComboPackageIndexMap.insert(currentIndex++, currentComboPackages.getValueAt(iterator));
}
if (currentComboPackageIndexMap.getSize() == 0)
{
throw std::runtime_error("No combo packages currently active.");
}
displayComboPackagesWithIndex(currentComboPackageIndexMap);
std::cout << "Enter your choice(Index): ";
util::read(choice);
selectedIndex = currentComboPackageIndexMap.find(choice);
if (selectedIndex != -1)
{
std::string selectedComboPackageID = currentComboPackageIndexMap.getValueAt(selectedIndex)->getId();
return selectedComboPackageID;
}
else
{
std::cout << "Enter a valid choice.\n";
return "";
}
}
/*
Function: removeComboPackage
Description: Removes a selected combo package from the system.
Parameter: None
Return type: void
*/
void AdminMenu::removeComboPackage() void AdminMenu::removeComboPackage()
{ {
util::clear();
util::Map<std::string, const ComboPackage*> currentComboPackages = m_controller.getComboPackages();
std::string selectedComboPackageID = selectComboPackage(currentComboPackages);
if (selectedComboPackageID != "")
{
m_controller.removeComboPackage(selectedComboPackageID);
std::cout << "Combo Package removed successfully.\n";
}
else
{
std::cout << "Combo package removal failed.\n";
}
util::pressEnter();
} }
void AdminMenu::viewNotifications() void AdminMenu::viewNotifications()
@@ -1,3 +1,11 @@
/*
File: AdminMenu.h
Description: Header file declaring the AdminMenu class, which provides
administrative operations such as inventory management,
user management, service configuration, and notifications.
Author: Trenser
Date:19-May-2026
*/
#pragma once #pragma once
#include "Controller.h" #include "Controller.h"
@@ -1,335 +1,54 @@
/*
File: CustomerMenu.cpp
Description: Implementation file containing the method definitions of the
CustomerMenu class, including menu handling, service selection,
combo package booking, profile updates, and password management.
Author: Trenser
Date:19-May-2026
*/
#include <iomanip>
#include "CustomerMenu.h" #include "CustomerMenu.h"
#include "Service.h"
#include "InventoryItem.h"
#include "ComboPackage.h"
#include "Service.h"
#include "InputHelper.h" #include "InputHelper.h"
#include "OutputHelper.h" #include "OutputHelper.h"
#include "Validator.h"
#include "Vector.h"
#include "Utility.h"
#include "Map.h"
/*
Function: showMenu
Description: Displays the customer menu and handles user input until logout is selected.
Parameter: None
Return type: void
*/
void CustomerMenu::showMenu() void CustomerMenu::showMenu()
{ {
while (true) bool isMenuActive = true;
{ while (isMenuActive)
try {
{ try
int choice; {
util::clear(); int choice;
std::cout << "Customer Menu" util::clear();
<< "\n1. Select a service" std::cout << "" << std::endl;
<< "\n2. Select a combo package" util::read(choice);
<< "\n3. Update Profile" if (!handleOperation(choice))
<< "\n4. Change Password" {
<< "\n5. View Service History" isMenuActive = false;
<< "\n6. Complete Payments" }
<< "\n7. View Invoices" }
<< "\n8. View Notifications" catch (const std::exception& e)
<< "\n9. Configure Notifications" {
<< "\n10. Logout" std::cout << "Exception: " << e.what() << std::endl;
<< "\nEnter a choice: "; util::pressEnter();
util::read(choice); }
if (!handleOperation(choice)) }
{
break;
}
}
catch (const std::exception& e)
{
std::cout << "Exception: " << e.what() << std::endl;
util::pressEnter();
}
}
} }
/*
Function: handleOperation
Description: Executes the corresponding customer operation based on the selected menu choice.
Parameter: int choice - selected menu option
Return type: bool - true if menu continues, false if logout
*/
bool CustomerMenu::handleOperation(int choice) bool CustomerMenu::handleOperation(int choice)
{ {
switch (choice) return false;
{
case 1:
selectService();
break;
case 2:
selectComboPackage();
break;
case 3:
updateDetails();
break;
case 4:
changePassword();
break;
case 5:
viewServiceHistory();
break;
case 6:
completePayments();
break;
case 7:
viewInvoices();
break;
case 8:
viewNotifications();
break;
case 9:
configureNotifications();
break;
case 10:
logout();
return false;
default:
std::cout << "Enter a valid choice!" << std::endl;
util::pressEnter();
}
return true;
} }
/*
Function: logout
Description: Logs out the currently authenticated customer user.
Parameter: None
Return type: void
*/
void CustomerMenu::logout() void CustomerMenu::logout()
{ {
m_controller.logout();
} }
/*
Function: changePassword
Description: Allows the customer to change their password after validation.
Parameter: None
Return type: void
*/
void CustomerMenu::changePassword() void CustomerMenu::changePassword()
{ {
std::string newPassword;
util::clear();
std::cout << "Enter new password: ";
util::read(newPassword);
m_controller.changePassword(newPassword);
if (!util::isPasswordValid(newPassword))
{
std::cout << "Error: Password is not strong enough!";
util::pressEnter();
return;
}
std::cout << "Password changed successfully";
util::pressEnter();
} }
/*
Function: updateDetails
Description: Allows the customer to update their email and phone number after validation.
Parameter: None
Return type: void
*/
void CustomerMenu::updateDetails() void CustomerMenu::updateDetails()
{ {
std::string email, phone;
util::clear();
std::cout << "Enter new email: ";
util::read(email);
if (!util::isEmailValid(email))
{
std::cout << "Error: Email is invalid!";
util::pressEnter();
return;
}
std::cout << "Enter new phone: ";
util::read(phone);
if (!util::isPhoneNumberValid(phone))
{
std::cout << "Error: Phone number is invalid!";
util::pressEnter();
return;
}
m_controller.updateUserDetails(email, phone);
std::cout << "Profile details updated successfully";
util::pressEnter();
} }
/*
Function: selectServiceFromServices
Description: Displays active services and allows the customer to select one by index.
Parameter: const util::Map<std::string, const Service*>& services - list of services
Return type: const Service* - selected service
*/
static const Service* selectServiceFromServices(const util::Map<std::string, const Service*>& services)
{
util::Map<int, const Service*> activeServicesMap;
int currentIndex = 1;
int userInputIndex;
std::cout << std::left
<< std::setw(10) << "Index"
<< std::setw(15) << "Service ID"
<< std::setw(25) << "Service Name"
<< std::setw(15) << "Estimated Cost"
<< std::endl;
for (int index = 0; index < services.getSize(); index++)
{
const Service* currentService = services.getValueAt(index);
if (currentService->getState() != util::State::ACTIVE)
{
continue;
}
activeServicesMap.insert(currentIndex, currentService);
double partsCost = calculatePartsCost(currentService);
std::cout << std::left
<< std::setw(10) << currentIndex
<< std::setw(15) << currentService->getId()
<< std::setw(25) << currentService->getName()
<< std::setw(15) << (currentService->getLaborCost() + partsCost)
<< std::endl;
currentIndex++;
}
if (activeServicesMap.getSize() == 0)
{
std::cout << "No active services available." << std::endl;
return nullptr;
}
std::cout << "Enter service index: ";
util::read(userInputIndex);
if (activeServicesMap.find(userInputIndex) == -1)
{
std::cout << "Invalid service index." << std::endl;
return nullptr;
}
return activeServicesMap[userInputIndex];
}
/*
Function: selectService
Description: Allows the customer to select a service, provide vehicle details,
and book the service through the controller.
Parameter: None
Return type: void
*/
void CustomerMenu::selectService() void CustomerMenu::selectService()
{ {
std::string vehicleNumber, vehicleBrand, vehicleModel;
auto services = m_controller.getServices();
util::Vector<std::string> selectedServices;
util::clear();
const Service* selectedService = selectServiceFromServices(services);
if (selectedService == nullptr)
{
std::cout << "Failed to book service!";
util::pressEnter();
return;
}
selectedServices.push_back(selectedService->getId());
util::clear();
std::cout << "Enter vehicle number: ";
util::read(vehicleNumber);
std::cout << "Enter vehicle brand: ";
util::read(vehicleBrand);
std::cout << "Enter vehicle model: ";
util::read(vehicleModel);
m_controller.purchaseService(selectedServices, vehicleNumber, vehicleBrand, vehicleModel);
std::cout << "Service has been booked successfully";
util::pressEnter();
} }
/*
Function: selectComboPackageFromPackages
Description: Displays active combo packages and allows the customer to select one by index.
Parameter: const util::Map<std::string, const ComboPackage*>& comboPackages - list of combo packages
Return type: const ComboPackage* - selected combo package
*/
static const ComboPackage* selectComboPackageFromPackages(const util::Map<std::string, const ComboPackage*>& comboPackages)
{
util::Map<int, const ComboPackage*> activeComboPackages;
int currentIndex = 1;
int userInputIndex;
std::cout << std::left
<< std::setw(10) << "Index"
<< std::setw(15) << "Combo Package ID"
<< std::setw(15) << "Combo Package Name"
<< std::setw(15) << "Estimate Cost"
<< std::endl;
for (int index = 0; index < comboPackages.getSize(); index++)
{
const ComboPackage* currentComboPackage = comboPackages.getValueAt(index);
if (currentComboPackage->getState() != util::State::ACTIVE)
{
continue;
}
activeComboPackages.insert(currentIndex, currentComboPackage);
std::cout << std::left
<< std::setw(10) << currentIndex
<< std::setw(15) << currentComboPackage->getId()
<< std::setw(25) << currentComboPackage->getPackageName()
<< std::setw(15) << calculateComboServiceEstimatedCost(currentComboPackage)
<< std::endl;
currentIndex++;
}
if (activeComboPackages.getSize() == 0)
{
std::cout << "No active combo packages available." << std::endl;
return nullptr;
}
std::cout << "Enter combo package index: ";
util::read(userInputIndex);
if (activeComboPackages.find(userInputIndex) == -1)
{
std::cout << "Invalid combo package index." << std::endl;
return nullptr;
}
return activeComboPackages[userInputIndex];
}
/*
Function: selectComboPackage
Description: Allows the customer to select a combo package, provide vehicle details,
and book the package through the controller.
Parameter: None
Return type: void
*/
void CustomerMenu::selectComboPackage() void CustomerMenu::selectComboPackage()
{ {
std::string vehicleNumber, vehicleBrand, vehicleModel;
auto comboPackages = m_controller.getComboPackages();
util::clear();
const ComboPackage* selectedComboPackage = selectComboPackageFromPackages(comboPackages);
if (selectedComboPackage == nullptr)
{
std::cout << "Failed to book combo package!";
util::pressEnter();
return;
}
util::clear();
std::cout << "Enter vehicle number: ";
util::read(vehicleNumber);
std::cout << "Enter vehicle brand: ";
util::read(vehicleBrand);
std::cout << "Enter vehicle model: ";
util::read(vehicleModel);
m_controller.purchaseComboPackage(selectedComboPackage->getId(), vehicleNumber, vehicleBrand, vehicleModel);
std::cout << "Combo Package has been booked successfully";
util::pressEnter();
} }
void CustomerMenu::viewServiceHistory() void CustomerMenu::viewServiceHistory()
@@ -350,4 +69,4 @@ void CustomerMenu::viewNotifications()
void CustomerMenu::configureNotifications() void CustomerMenu::configureNotifications()
{ {
} }
@@ -1,12 +1,3 @@
/*
File: CustomerMenu.h
Description: Header file declaring the CustomerMenu class, which provides
customer operations such as selecting services, booking combo
packages, updating profile details, managing payments, viewing
invoices, and configuring notifications.
Author: Trenser
Date:19-May-2026
*/
#pragma once #pragma once
#include "Controller.h" #include "Controller.h"
@@ -1,62 +0,0 @@
/*
File: MenuHelper.h
Description: Header file declaring the MenuHelper class, which provides
utility functions for menu-driven operations such as
notification selection and display.
Author: Trenser
Date:19-May-2026
*/
#pragma once
#include <string>
#include <iomanip>
#include "Notification.h"
#include "Map.h"
#include "InputHelper.h"
#include "OutputHelper.h"
/*
Function: selectNotification
Description: Displays a list of notifications with index, ID, title, and timestamp.
Allows the user to select a notification by index. Returns the selected
notification or nullptr if the selection is invalid.
Parameter: const util::Vector<const Notification*>& notifications - list of notifications
Return type: const Notification* - pointer to the selected notification
*/
inline const Notification* selectNotification(const util::Vector<const Notification*>& notifications)
{
if (notifications.getSize() == 0)
{
std::cout << "No notifications available." << std::endl;
return nullptr;
}
std::cout << std::left
<< std::setw(6) << "Index"
<< std::setw(15) << "ID"
<< std::setw(30) << "Title"
<< std::setw(25) << "Timestamp"
<< std::endl;
int currentIndex = 1;
for (int iterator = 0; iterator < notifications.getSize(); iterator++)
{
const Notification* currentNotification = notifications[iterator];
if (currentNotification)
{
std::cout << std::left
<< std::setw(6) << currentIndex
<< std::setw(15) << currentNotification->getId()
<< std::setw(30) << currentNotification->getTitle()
<< std::setw(25) << currentNotification->getCreatedAt().toString()
<< std::endl;
currentIndex++;
}
}
int selectedIndex;
std::cout << "Select notification: ";
util::read(selectedIndex);
if (selectedIndex < 1 || selectedIndex > notifications.getSize())
{
std::cout << "Invalid selection." << std::endl;
return nullptr;
}
return notifications[selectedIndex - 1];
}
@@ -1,36 +1,80 @@
/*
File: TechnicianMenu.cpp
Description: Implementation file containing the method definitions of the
TechnicianMenu class, including menu handling, job completion,
notification viewing, password management, and logout logic.
Author: Trenser
Date:19-May-2026
*/
#include "TechnicianMenu.h" #include "TechnicianMenu.h"
#include "InputHelper.h" #include "InputHelper.h"
#include "OutputHelper.h" #include "OutputHelper.h"
#include "Validator.h"
/*
Function: showMenu
Description: Displays the technician menu and handles user input until logout is selected.
Parameter: None
Return type: void
*/
void TechnicianMenu::showMenu() void TechnicianMenu::showMenu()
{ {
bool isMenuActive = true; while (true)
while (isMenuActive) {
{ try
try {
{ int choice;
int choice; util::clear();
util::clear(); std::cout << "Technician Menu"
std::cout << "" << std::endl; << "\n1. Mark Job as Completed"
util::read(choice); << "\n2. View Notifications"
if (!handleOperation(choice)) << "\n3. Change Password"
{ << "\n4. Logout"
isMenuActive = false; << "\nEnter a choice: ";
} util::read(choice);
} if (!handleOperation(choice))
catch (const std::exception& e) {
{ break;
std::cout << "Exception: " << e.what() << std::endl; }
util::pressEnter(); }
} catch (const std::exception& e)
} {
std::cout << "Exception: " << e.what() << std::endl;
util::pressEnter();
}
}
} }
/*
Function: handleOperation
Description: Executes the corresponding technician operation based on the selected menu choice.
Parameter: int choice - selected menu option
Return type: bool - true if menu continues, false if logout
*/
bool TechnicianMenu::handleOperation(int choice) bool TechnicianMenu::handleOperation(int choice)
{ {
return false; switch (choice)
{
case 1:
completeJob();
break;
case 2:
viewNotifications();
break;
case 3:
changePassword();
break;
case 4:
logout();
return false;
default:
std::cout << "Enter a valid choice!" << std::endl;
util::pressEnter();
}
return true;
} }
void TechnicianMenu::completeJob() void TechnicianMenu::completeJob()
{ {
} }
@@ -38,3 +82,41 @@ void TechnicianMenu::completeJob()
void TechnicianMenu::viewNotifications() void TechnicianMenu::viewNotifications()
{ {
} }
/*
Function: logout
Description: Logs out the currently authenticated technician user.
Parameter: None
Return type: void
*/
void TechnicianMenu::logout()
{
m_controller.logout();
}
/*
Function: changePassword
Description: Allows the technician to change their password after validation.
Parameter: None
Return type: void
*/
void TechnicianMenu::changePassword()
{
std::string newPassword;
while (true)
{
util::clear();
std::cout << "Enter new password: ";
util::read(newPassword);
if (!util::isPasswordValid(newPassword))
{
std::cout << "Error: Password is not strong enough!\n";
util::pressEnter();
continue;
}
m_controller.changePassword(newPassword);
std::cout << "Password changed successfully\n";
util::pressEnter();
break;
}
}
@@ -1,3 +1,11 @@
/*
File: TechnicianMenu.h
Description: Header file declaring the TechnicianMenu class, which provides
technician operations such as job completion, notification viewing,
password management, and logout functionality.
Author: Trenser
Date:19-May-2026
*/
#pragma once #pragma once
#include "Controller.h" #include "Controller.h"
@@ -10,4 +18,6 @@ public:
void showMenu(); void showMenu();
void completeJob(); void completeJob();
void viewNotifications(); void viewNotifications();
void logout();
void changePassword();
}; };
@@ -9,9 +9,7 @@ Date:19-May-2026
#include "UserInterface.h" #include "UserInterface.h"
#include "InputHelper.h" #include "InputHelper.h"
#include "OutputHelper.h" #include "OutputHelper.h"
#include "Enums.h"
#include "User.h" #include "User.h"
#include "Validator.h"
/* /*
Function: run Function: run
@@ -113,47 +111,7 @@ void UserInterface::login()
} }
} }
/*
Function: registerCustomer
Description: Registers a new customer by collecting and validating details such as
username, name, email, password, and phone number. Delegates creation
to the controller.
Parameter: None
Return type: void
*/
void UserInterface::registerCustomer() void UserInterface::registerCustomer()
{ {
std::string username, name, email, phone, password;
util::clear();
std::cout << "Enter username: ";
util::read(username);
std::cout << "Enter name: ";
util::read(name);
std::cout << "Enter email: ";
util::read(email);
if (!util::isEmailValid(email))
{
std::cout << "Error: Email is invalid!";
util::pressEnter();
return;
}
std::cout << "Enter password: ";
util::read(password);
if (!util::isPasswordValid(password))
{
std::cout << "Error: Password is invalid!";
util::pressEnter();
return;
}
std::cout << "Enter phone: ";
util::read(phone);
if (!util::isPhoneNumberValid(phone))
{
std::cout << "Error: Phone number is invalid!";
util::pressEnter();
return;
}
m_controller.createCustomer(username, name, password, email, phone);
std::cout << "Registration is successful";
util::pressEnter();
} }