Compare commits
7 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 8a3ec278ce | |||
| 602b538830 | |||
| 86873d2a21 | |||
| c64f3cff72 | |||
| ce50467816 | |||
| 20475ace73 | |||
| 1e63b900ab |
+50
-48
@@ -543,50 +543,65 @@ static void restoreInventory(ServiceBooking* booking)
|
|||||||
|
|
||||||
/*
|
/*
|
||||||
Function: processBookingCancellation
|
Function: processBookingCancellation
|
||||||
Description: Cancels jobs and updates the status of a given booking. Sends notifications to the
|
Description: Handles cancellation or reassignment of a service booking based on user type.
|
||||||
specified user, resets technician assignment if needed, and restores inventory items.
|
Cancels associated job cards, updates booking status, clears technician assignments,
|
||||||
Parameter: ServiceBooking* booking - Pointer to the booking being cancelled
|
restores inventory, and sends appropriate notifications.
|
||||||
util::ServiceJobStatus newServiceBookingStatus - New status to assign to the booking
|
Parameters:
|
||||||
const std::string& notificationTitle - Title of the booking cancellation notification
|
ServiceBooking* booking - The booking to cancel or reset
|
||||||
const std::string& notificationMessage - Message body of the booking cancellation notification
|
|
||||||
User* notifyUser - User to notify about the cancellation
|
|
||||||
util::ServiceJobStatus jobCardStatus - New status to assign to associated job cards
|
|
||||||
const std::string& jobNotificationTitle - Title of the job cancellation notification
|
|
||||||
const std::string& jobNotificationMessage - Message body of the job cancellation notification
|
|
||||||
util::Map<std::string, JobCard*>& jobs - Collection of job cards to update
|
util::Map<std::string, JobCard*>& jobs - Collection of job cards to update
|
||||||
ServiceManagementService& currentService - Reference to the service for sending notifications
|
ServiceManagementService& currentService - Service layer for notifications
|
||||||
|
util::UserType userType - Type of user initiating cancellation (CUSTOMER or TECHNICIAN)
|
||||||
Return type: void
|
Return type: void
|
||||||
*/
|
*/
|
||||||
static void processBookingCancellation(ServiceBooking* booking,
|
static void processBookingCancellation(ServiceBooking* booking,
|
||||||
util::ServiceJobStatus newServiceBookingStatus,
|
util::Map<std::string, JobCard*>& jobs,
|
||||||
const std::string& notificationTitle,
|
ServiceManagementService& currentService,
|
||||||
const std::string& notificationMessage,
|
util::UserType userType)
|
||||||
User* notifyUser,
|
|
||||||
util::ServiceJobStatus jobCardStatus,
|
|
||||||
const std::string& jobNotificationTitle,
|
|
||||||
const std::string& jobNotificationMessage,
|
|
||||||
util::Map<std::string, JobCard*>& jobs, ServiceManagementService& currentService)
|
|
||||||
{
|
{
|
||||||
if (!booking || !notifyUser)
|
if (!booking)
|
||||||
{
|
{
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int jobIterator = 0; jobIterator < jobs.getSize(); ++jobIterator)
|
for (int jobIterator = 0; jobIterator < jobs.getSize(); ++jobIterator)
|
||||||
{
|
{
|
||||||
JobCard* jobCard = jobs.getValueAt(jobIterator);
|
JobCard* jobCard = jobs.getValueAt(jobIterator);
|
||||||
if (jobCard && jobCard->getBookingId() == booking->getId())
|
if (!jobCard || jobCard->getBookingId() != booking->getId() || jobCard->getStatus() == util::ServiceJobStatus::CANCELLED)
|
||||||
{
|
{
|
||||||
jobCard->setStatus(jobCardStatus);
|
continue;
|
||||||
currentService.sendNotification(notifyUser, jobNotificationTitle, jobNotificationMessage);
|
}
|
||||||
|
jobCard->setStatus(util::ServiceJobStatus::CANCELLED);
|
||||||
|
if (userType == util::UserType::CUSTOMER)
|
||||||
|
{
|
||||||
|
if (User* technician = booking->getAssignedTechnician())
|
||||||
|
{
|
||||||
|
const std::string jobTitle = "Job Cancelled";
|
||||||
|
const std::string jobMessage = "Your job card has been cancelled and the inventory has been restocked.";
|
||||||
|
currentService.sendNotification(technician, jobTitle, jobMessage);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
booking->setStatus(newServiceBookingStatus);
|
}
|
||||||
currentService.sendNotification(notifyUser, notificationTitle, notificationMessage);
|
if (userType == util::UserType::CUSTOMER)
|
||||||
if (newServiceBookingStatus == util::ServiceJobStatus::PENDING)
|
|
||||||
{
|
{
|
||||||
|
booking->setStatus(util::ServiceJobStatus::CANCELLED);
|
||||||
|
if (User* technician = booking->getAssignedTechnician())
|
||||||
|
{
|
||||||
|
const std::string title = "Customer Service Cancelled";
|
||||||
|
const std::string message = "Your assigned job card has been cancelled and the inventory has been restocked.";
|
||||||
|
currentService.sendNotification(technician, title, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if (userType == util::UserType::TECHNICIAN)
|
||||||
|
{
|
||||||
|
booking->setStatus(util::ServiceJobStatus::PENDING);
|
||||||
|
if (User* customer = booking->getCustomer())
|
||||||
|
{
|
||||||
|
const std::string title = "Technician Unavailable";
|
||||||
|
const std::string message = "Your booking has been reset to pending and we will reassign a new technician shortly.";
|
||||||
|
currentService.sendNotification(customer, title, message);
|
||||||
|
}
|
||||||
|
}
|
||||||
booking->setAssignedTechnician(nullptr);
|
booking->setAssignedTechnician(nullptr);
|
||||||
booking->setAssignedTechnicianId("");
|
booking->setAssignedTechnicianId("");
|
||||||
}
|
|
||||||
restoreInventory(booking);
|
restoreInventory(booking);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -624,21 +639,13 @@ void ServiceManagementService::cancelCustomerServiceBookings(const std::string&
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (booking->getStatus() != util::ServiceJobStatus::PENDING && booking->getStatus() != util::ServiceJobStatus::STARTED)
|
if (booking->getStatus() != util::ServiceJobStatus::PENDING &&
|
||||||
|
booking->getStatus() != util::ServiceJobStatus::STARTED &&
|
||||||
|
booking->getStatus() != util::ServiceJobStatus::IN_PROGRESS)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
User* assignedTechnician = booking->getAssignedTechnician();
|
processBookingCancellation(booking, jobs, *this, util::UserType::CUSTOMER);
|
||||||
std::string titleToTechnician = "Customer Service Cancelled";
|
|
||||||
std::string messageToTechnician = "The customer has cancelled their service booking. Your assigned job card has been cancelled and the inventory has been restocked.";
|
|
||||||
std::string jobTitle = "Job Cancelled";
|
|
||||||
std::string jobMessage = "The job has been cancelled. Your job card has been cancelled and the inventory has been restocked.";
|
|
||||||
processBookingCancellation(booking,
|
|
||||||
util::ServiceJobStatus::CANCELLED,
|
|
||||||
titleToTechnician, messageToTechnician, assignedTechnician,
|
|
||||||
util::ServiceJobStatus::CANCELLED,
|
|
||||||
jobTitle, jobMessage, jobs, *this
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -676,7 +683,9 @@ void ServiceManagementService::cancelTechnicianJobs(const std::string& technicia
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (booking->getStatus() != util::ServiceJobStatus::PENDING && booking->getStatus() != util::ServiceJobStatus::STARTED)
|
if (booking->getStatus() != util::ServiceJobStatus::PENDING &&
|
||||||
|
booking->getStatus() != util::ServiceJobStatus::STARTED &&
|
||||||
|
booking->getStatus() != util::ServiceJobStatus::IN_PROGRESS)
|
||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@@ -685,14 +694,7 @@ void ServiceManagementService::cancelTechnicianJobs(const std::string& technicia
|
|||||||
{
|
{
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
std::string title = "Technician Unavailable";
|
processBookingCancellation(booking, jobs, *this, util::UserType::TECHNICIAN);
|
||||||
std::string message = "Your assigned technician is no longer available. Your booking has been reset to pending and we will reassign a new technician shortly.";
|
|
||||||
processBookingCancellation(booking,
|
|
||||||
util::ServiceJobStatus::PENDING,
|
|
||||||
title, message, customer,
|
|
||||||
util::ServiceJobStatus::CANCELLED,
|
|
||||||
title, message, jobs, *this
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -736,7 +736,7 @@ inline std::string selectJobCardToUpdate(util::Map<std::string, const JobCard*>&
|
|||||||
util::Map<int, const JobCard* > incompleteJobCards;
|
util::Map<int, const JobCard* > incompleteJobCards;
|
||||||
if (assignedJobCards.getSize() == 0)
|
if (assignedJobCards.getSize() == 0)
|
||||||
{
|
{
|
||||||
std::cout << "No jobs available.\n\n";
|
std::cout << "\nNo jobs available.\n\n";
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
int currentIndex = 1;
|
int currentIndex = 1;
|
||||||
@@ -744,12 +744,12 @@ inline std::string selectJobCardToUpdate(util::Map<std::string, const JobCard*>&
|
|||||||
if (selectedJobStatusType == util::ServiceJobStatus::STARTED)
|
if (selectedJobStatusType == util::ServiceJobStatus::STARTED)
|
||||||
{
|
{
|
||||||
util::clear();
|
util::clear();
|
||||||
std::cout << "Select a job to update to Inprogress\n";
|
std::cout << "Select a job to mark as In Progress\n";
|
||||||
}
|
}
|
||||||
else if (selectedJobStatusType == util::ServiceJobStatus::IN_PROGRESS)
|
else if (selectedJobStatusType == util::ServiceJobStatus::IN_PROGRESS)
|
||||||
{
|
{
|
||||||
util::clear();
|
util::clear();
|
||||||
std::cout << "Select a job to update to Completed\n";
|
std::cout << "Select a job to mark as Completed\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@@ -780,7 +780,7 @@ inline std::string selectJobCardToUpdate(util::Map<std::string, const JobCard*>&
|
|||||||
incompleteJobCards.insert(currentIndex++, currentJobCard);
|
incompleteJobCards.insert(currentIndex++, currentJobCard);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
std::cout << "Select the Job Card to Update (Index): ";
|
std::cout << "Enter the job index to update: ";
|
||||||
util::read(choice);
|
util::read(choice);
|
||||||
int selectedJobCardIndex = incompleteJobCards.find(choice);
|
int selectedJobCardIndex = incompleteJobCards.find(choice);
|
||||||
if (selectedJobCardIndex != -1)
|
if (selectedJobCardIndex != -1)
|
||||||
|
|||||||
@@ -121,7 +121,7 @@ void TechnicianMenu::updateJobStatus()
|
|||||||
std::string selectedJobID;
|
std::string selectedJobID;
|
||||||
util::ServiceJobStatus selectedJobStatus = util::ServiceJobStatus::PENDING;
|
util::ServiceJobStatus selectedJobStatus = util::ServiceJobStatus::PENDING;
|
||||||
util::Map<std::string, const JobCard*> assignedJobCards = m_controller.getJobCardsByUser();
|
util::Map<std::string, const JobCard*> assignedJobCards = m_controller.getJobCardsByUser();
|
||||||
std::cout << "Select the type of job you want to update\n1.Started\n2.Inprogress\nChoice: ";
|
std::cout << "Select the type of job you want to update:\n1.Started\n2.In Progress\nChoice: ";
|
||||||
util::read(choice);
|
util::read(choice);
|
||||||
if (choice == 1)
|
if (choice == 1)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user