diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp index 0308ced..f6d3905 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp @@ -1080,7 +1080,7 @@ static bool hasCompletedAllJobs(std::string bookingId, util::MapgetBookingId() == bookingId) { - if (currentJob->getStatus() == util::ServiceJobStatus::STARTED || currentJob->getStatus() == util::ServiceJobStatus::INPROGRESS) + if (currentJob->getStatus() != util::ServiceJobStatus::COMPLETED && currentJob->getStatus() != util::ServiceJobStatus::CANCELLED) { return false; } @@ -1090,16 +1090,17 @@ static bool hasCompletedAllJobs(std::string bookingId, util::MapgetStatus() == util::ServiceJobStatus::STARTED) { - currentJob->setStatus(util::ServiceJobStatus::INPROGRESS); + currentJob->setStatus(util::ServiceJobStatus::IN_PROGRESS); jobStatusUpdated = true; } - else if (currentJob->getStatus() == util::ServiceJobStatus::INPROGRESS) + else if (currentJob->getStatus() == util::ServiceJobStatus::IN_PROGRESS) { currentJob->setStatus(util::ServiceJobStatus::COMPLETED); jobStatusUpdated = true; @@ -1146,12 +1147,10 @@ void ServiceManagementService::updateJobStatus(const std::string& jobID) } else { - throw std::runtime_error("Failed to update the job."); + throw std::runtime_error("Failed to update job status. Job may already be completed."); } if (!jobStatusUpdated) { - throw std::runtime_error("Failed to update the job"); + throw std::runtime_error("Failed to update job status. Job may already be completed."); } - - } \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Enums.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Enums.h index 01c4660..c167b28 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Enums.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Enums.h @@ -37,7 +37,7 @@ namespace util PENDING, STARTED, COMPLETED, - INPROGRESS, + IN_PROGRESS, CANCELLED }; @@ -210,8 +210,8 @@ namespace util return "COMPLETED"; case ServiceJobStatus::CANCELLED: return "CANCELLED"; - case ServiceJobStatus::INPROGRESS: - return "INPROGRESS"; + case ServiceJobStatus::IN_PROGRESS: + return "IN_PROGRESS"; } throw std::invalid_argument("Invalid ServiceJobStatus"); } @@ -244,9 +244,9 @@ namespace util { return ServiceJobStatus::CANCELLED; } - if (value == "INPROGRESS") + if (value == "IN_PROGRESS") { - return ServiceJobStatus::INPROGRESS; + return ServiceJobStatus::IN_PROGRESS; } throw std::invalid_argument("Invalid ServiceJobStatus string"); } diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h index 5cabad3..0a4136a 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h @@ -627,7 +627,6 @@ inline void displayInvoices(util::Map currentUserIn std::cout << "Unable to fetch the selected invoice\n"; doRun = false; } - } while (doRun); } } @@ -646,7 +645,7 @@ inline util::Map filterStartedJobCards(util::MapgetStatus() == util::ServiceJobStatus::STARTED || currentJobCard->getStatus() == util::ServiceJobStatus::INPROGRESS)) + if (currentJobCard && (currentJobCard->getStatus() == util::ServiceJobStatus::STARTED || currentJobCard->getStatus() == util::ServiceJobStatus::IN_PROGRESS)) { startedJobCards.insert(currentJobCard->getId(), currentJobCard); } @@ -659,13 +658,11 @@ Function: filterJobCards Description: Filters the given list of job cards and returns only those whose status matches the specified ServiceJobStatus. - Parameters: - assignedJobCards: util::Map& Map of job card IDs to JobCard pointers assigned to the technician. - selectedJobStatus: util::ServiceJobStatus The status type to filter job cards by. - Returns: - util::Map A map containing only job cards with the specified status. @@ -710,7 +707,7 @@ inline void displayAllJobs(util::Map& assignedJobCa for (int iterator = 0; iterator < assignedJobCards.getSize(); iterator++) { const JobCard* currentJobCard = assignedJobCards.getValueAt(iterator); - if (currentJobCard && (currentJobCard->getStatus() == util::ServiceJobStatus::STARTED || currentJobCard->getStatus() == util::ServiceJobStatus::INPROGRESS)) + if (currentJobCard && (currentJobCard->getStatus() == util::ServiceJobStatus::STARTED || currentJobCard->getStatus() == util::ServiceJobStatus::IN_PROGRESS)) { std::cout << std::left << std::setw(12) << currentJobCard->getBookingId() << std::setw(12) << currentJobCard->getId() @@ -745,7 +742,7 @@ inline std::string selectJobCardToUpdate(util::Map& util::clear(); std::cout << "Select a job to update to Inprogress\n"; } - else if (selectedJobStatusType == util::ServiceJobStatus::INPROGRESS) + else if (selectedJobStatusType == util::ServiceJobStatus::IN_PROGRESS) { util::clear(); std::cout << "Select a job to update to Completed\n"; diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/TechnicianMenu.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/TechnicianMenu.cpp index e358f88..5d125cc 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/TechnicianMenu.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/TechnicianMenu.cpp @@ -119,7 +119,7 @@ void TechnicianMenu::updateJobStatus() std::cout << "Update Job Status\n"; int choice; std::string selectedJobID; - util::ServiceJobStatus selectedJobStatus; + util::ServiceJobStatus selectedJobStatus = util::ServiceJobStatus::PENDING; util::Map assignedJobCards = m_controller.getJobCardsByUser(); std::cout << "Select the type of job you want to update\n1.Started\n2.Inprogress\nChoice: "; util::read(choice); @@ -129,11 +129,13 @@ void TechnicianMenu::updateJobStatus() } else if (choice == 2) { - selectedJobStatus = util::ServiceJobStatus::INPROGRESS; + selectedJobStatus = util::ServiceJobStatus::IN_PROGRESS; } else { - throw std::runtime_error("Invalid Index"); + std::cout << "Invalid choice. Please try again.\n"; + util::pressEnter(); + return; } util::Map selectedTypeJobCard = filterJobCards(assignedJobCards, selectedJobStatus); selectedJobID = selectJobCardToUpdate(selectedTypeJobCard, selectedJobStatus);