Merge branch 'feature-admin-management-adm006' into feature-admin-management
This commit is contained in:
@@ -131,6 +131,7 @@ void Controller::removeUser(const std::string& userID)
|
||||
|
||||
void Controller::createComboPackage(const std::string& name, const util::Vector<std::string>& serviceIDs, double discountPercentage)
|
||||
{
|
||||
m_serviceManagementService.createComboPackage(name, serviceIDs, discountPercentage);
|
||||
}
|
||||
|
||||
void Controller::removeComboPackage(const std::string& comboPackageID)
|
||||
|
||||
+63
@@ -4,6 +4,8 @@
|
||||
#include "JobCard.h"
|
||||
#include "Service.h"
|
||||
#include "InventoryItem.h"
|
||||
#include "Factory.h"
|
||||
#include "ComboPackage.h"
|
||||
|
||||
void ServiceManagementService::cancelCustomerServiceBookings(const std::string& userID)
|
||||
{
|
||||
@@ -98,3 +100,64 @@ void ServiceManagementService::cancelTechnicianJobs(const std::string& technicia
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
+1
-1
@@ -29,7 +29,7 @@ public:
|
||||
void completeJob(const std::string& jobID);
|
||||
void cancelCustomerServiceBookings(const std::string& customerID);
|
||||
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 sendNotification(User* user, const std::string& title, const std::string& message) override;
|
||||
void attach(User* user) override;
|
||||
|
||||
@@ -4,6 +4,8 @@
|
||||
#include "OutputHelper.h"
|
||||
#include "User.h"
|
||||
#include "Validator.h"
|
||||
#include "Service.h"
|
||||
#include "Utility.h"
|
||||
|
||||
void AdminMenu::showMenu()
|
||||
{
|
||||
@@ -199,8 +201,82 @@ void AdminMenu::removeUser()
|
||||
util::pressEnter();
|
||||
}
|
||||
|
||||
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];
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
|
||||
void AdminMenu::removeComboPackage()
|
||||
|
||||
Reference in New Issue
Block a user