diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj index a65c46d..819264c 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj @@ -176,6 +176,7 @@ + diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp index d536e8a..de2d1cd 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp @@ -42,6 +42,7 @@ util::Map Controller::getComboPackages() void Controller::purchaseService(const util::Vector& serviceIDs, const std::string& vehicleNumber, const std::string& vehicleBrand, const std::string& vehicleModel) { + m_serviceManagementService.purchaseService(serviceIDs, vehicleNumber, vehicleBrand, vehicleModel); } void Controller::purchaseComboPackage(const std::string& comboPackageID, const std::string& vehicleNumber, const std::string& vehicleBrand, const std::string& vehicleModel) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h index 3aabb58..8512598 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h @@ -2,6 +2,7 @@ #include "Map.h" #include #include "Enums.h" +#include "ServiceManagementService.h" class Service; class ComboPackage; @@ -14,6 +15,8 @@ class Notification; class Controller { +private: + ServiceManagementService m_serviceManagementService; public: bool login(const std::string& username, const std::string& password); void logout(); diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.cpp index 1fdfaf0..51fc6ff 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.cpp @@ -5,10 +5,10 @@ int ServiceBooking::m_uid = 0; ServiceBooking::ServiceBooking() : m_id("SRV" + std::to_string(++m_uid)), m_customer(nullptr), + m_assignedTechnician(nullptr), m_discountPercentage(0.0) {} ServiceBooking::ServiceBooking( - const std::string& id, util::ServiceJobStatus status, const util::Map& services, @@ -17,8 +17,6 @@ ServiceBooking::ServiceBooking( const std::string& vehicleNumber, const std::string& vehicleBrand, const std::string& vehicleModel, - const std::string& assignedTechnicianId, - const std::string& assignedTechnician, double discountPercentage ) : m_id("SRV" + std::to_string(++m_uid)), @@ -29,8 +27,8 @@ ServiceBooking::ServiceBooking( m_vehicleNumber(vehicleNumber), m_vehicleBrand(vehicleBrand), m_vehicleModel(vehicleModel), - m_assignedTechnicianId(assignedTechnicianId), - m_assignedTechnician(assignedTechnician), + m_assignedTechnicianId(""), + m_assignedTechnician(nullptr), m_discountPercentage(discountPercentage) { } @@ -80,7 +78,7 @@ const std::string& ServiceBooking::getAssignedTechnicianId() const return m_assignedTechnicianId; } -const std::string& ServiceBooking::getAssignedTechnician() const +User* ServiceBooking::getAssignedTechnician() const { return m_assignedTechnician; } @@ -135,7 +133,7 @@ void ServiceBooking::setAssignedTechnicianId(const std::string& assignedTechnici m_assignedTechnicianId = assignedTechnicianId; } -void ServiceBooking::setAssignedTechnician(const std::string& assignedTechnician) +void ServiceBooking::setAssignedTechnician(User* assignedTechnician) { m_assignedTechnician = assignedTechnician; } diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.h index 5ecc1b0..84a8aac 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.h @@ -19,12 +19,11 @@ private: std::string m_vehicleBrand; std::string m_vehicleModel; std::string m_assignedTechnicianId; - std::string m_assignedTechnician; + User* m_assignedTechnician; double m_discountPercentage; public: ServiceBooking(); ServiceBooking( - const std::string& id, util::ServiceJobStatus status, const util::Map& services, @@ -33,8 +32,6 @@ public: const std::string& vehicleNumber, const std::string& vehicleBrand, const std::string& vehicleModel, - const std::string& assignedTechnicianId, - const std::string& assignedTechnician, double discountPercentage ); const std::string& getId() const; @@ -46,7 +43,7 @@ public: const std::string& getVehicleBrand() const; const std::string& getVehicleModel() const; const std::string& getAssignedTechnicianId() const; - const std::string& getAssignedTechnician() const; + User* getAssignedTechnician() const; double getDiscountPercentage() const; void setId(const std::string& id); void setStatus(const util::ServiceJobStatus& status); @@ -57,6 +54,6 @@ public: void setVehicleBrand(const std::string& vehicleBrand); void setVehicleModel(const std::string& vehicleModel); void setAssignedTechnicianId(const std::string& assignedTechnicianId); - void setAssignedTechnician(const std::string& assignedTechnician); + void setAssignedTechnician(User* assignedTechnician); void setDiscountPercentage(double discountPercentage); }; \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp index 156c12b..511d81f 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp @@ -1 +1,39 @@ +#include #include "ServiceManagementService.h" +#include "AuthenticationManagementService.h" +#include "Service.h" +#include "ServiceBooking.h" +#include "Factory.h" + +void ServiceManagementService::purchaseService(const util::Vector& serviceIDs, const std::string& vehicleNumber, const std::string& vehicleBrand, const std::string& vehicleModel) +{ + AuthenticationManagementService m_authenticationManagementService; + auto authenticatedUser = m_authenticationManagementService.getAuthenticatedUser(); + if (authenticatedUser == nullptr) + { + throw std::runtime_error("No user is currently logged in!"); + } + auto& servicesMap = m_dataStore.getServices(); + auto& serviceBookingMap = m_dataStore.getServiceBookings(); + util::Map selectedServices; + int selectedServicesCount = serviceIDs.getSize(); + for (int index = 0; index < selectedServicesCount; index++) + { + int serviceIndex = servicesMap.find(serviceIDs[index]); + if (serviceIndex == -1) + { + throw std::runtime_error("Service not found!"); + } + Service* service = servicesMap.getValueAt(serviceIndex); + selectedServices[service->getId()] = service; + } + ServiceBooking* serviceBooking = Factory::getObject(util::ServiceJobStatus::STARTED, selectedServices, authenticatedUser->getId(), authenticatedUser, vehicleNumber, vehicleBrand, vehicleModel, 0); + if (serviceBooking == nullptr) + { + throw std::runtime_error("Failed to create service booking"); + } + serviceBookingMap[serviceBooking->getId()] = serviceBooking; + sendNotification(authenticatedUser, + "Service Booking succeeded", + "Your service booking has been successfully placed with ID " + serviceBooking->getId()); +} diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Utility.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Utility.h new file mode 100644 index 0000000..0450c75 --- /dev/null +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Utility.h @@ -0,0 +1,15 @@ +#pragma once +#include "Service.h" +#include "InventoryItem.h" + +inline double calculatePartsCost(const Service* service) +{ + double cost = 0; + auto& requiredInventoryItems = service->getRequiredInventoryItems(); + int requiredInventoryItemsSize = requiredInventoryItems.getSize(); + for (int index = 0; index < requiredInventoryItemsSize; index++) + { + cost += requiredInventoryItems.getValueAt(index)->getPrice(); + } + return cost; +} diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp index 047f471..610347a 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp @@ -1,6 +1,12 @@ +#include #include "CustomerMenu.h" +#include "Service.h" +#include "InventoryItem.h" #include "InputHelper.h" #include "OutputHelper.h" +#include "Vector.h" +#include "Utility.h" +#include "Map.h" void CustomerMenu::showMenu() { @@ -43,8 +49,73 @@ void CustomerMenu::updateDetails() { } +static const Service* selectServiceFromServices(const util::Map& services) +{ + util::Map 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]; +} + void CustomerMenu::selectService() { + std::string vehicleNumber, vehicleBrand, vehicleModel; + auto services = m_controller.getServices(); + util::Vector 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(); } void CustomerMenu::selectComboPackage() diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h new file mode 100644 index 0000000..3ff1134 --- /dev/null +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h @@ -0,0 +1,46 @@ +#pragma once +#include +#include +#include "Notification.h" +#include "Map.h" +#include "InputHelper.h" +#include "OutputHelper.h" + +inline const Notification* selectNotification(const util::Vector& 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]; +}