diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp index 45c6fe4..03a2bfa 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp @@ -23,7 +23,6 @@ Date:19-May-2026 #include "ServiceBooking.h" #include "ServiceManagementService.h" #include "Timestamp.h" -#include "Timestamp.h" #include "User.h" #include "UserManagementService.h" #include "Utility.h" @@ -817,6 +816,10 @@ void ServiceManagementService::createJobCard(const std::string& bookingID, const } currentBooking->setAssignedTechnician(selectedTechnician); currentBooking->setAssignedTechnicianId(selectedTechnician->getId()); + if (currentBooking->getStatus() == util::ServiceJobStatus::PENDING) + { + currentBooking->setStatus(util::ServiceJobStatus::STARTED); + } std::string title = "Job card created"; std::string message = "Job card created for the service and you are assigned for that."; JobCard* jobCard = Factory::getObject(bookingID, currentBooking, currentService, serviceID, technicianID, selectedTechnician, util::Timestamp(), util::ServiceJobStatus::STARTED, util::Timestamp()); diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp index 39f9148..e086def 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/UserManagementService.cpp @@ -315,7 +315,7 @@ util::Map UserManagementService::getUsers(util::UserType typ for (int iterator = 0; iterator < currentUsers.getSize(); iterator++) { User* currentUser = currentUsers.getValueAt(iterator); - if (currentUser->getUserType() == type) + if (currentUser && currentUser->getState() == util::State::ACTIVE && currentUser->getUserType() == type) { filteredUsersMap.insert(currentUser->getId(), currentUser); } diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp index abec3a6..d218535 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp @@ -341,14 +341,16 @@ Returns: void AdminMenu::assignJob() { util::clear(); + std::cout << "Assign Job to Technician\n"; std::string selectedService; bool hasPendingService = false; auto currentBookings = m_controller.getServiceBookings(); + auto pendingServiceBookings = filterActiveServiceBookings(currentBookings); auto availableTechnicians = m_controller.getUsers(util::UserType::TECHNICIAN); - int bookingsSize = currentBookings.getSize(); + int bookingsSize = pendingServiceBookings.getSize(); util::Map serviceBookingsMap; util::Map currentAvailableTechniciansMap; - if (listServiceBookings(currentBookings, bookingsSize, serviceBookingsMap)) + if (listServiceBookings(pendingServiceBookings, bookingsSize, serviceBookingsMap)) { const ServiceBooking* selectedService = selectPendingServiceBookings(serviceBookingsMap); if (selectedService) @@ -364,14 +366,19 @@ void AdminMenu::assignJob() { m_controller.createJobCard(selectedService->getId(), selectedTechnician->getId(), servicesInBooking.getValueAt(iterator)->getId()); } + std::cout << "Job card created for each service and technician successfully assigned.\n\n"; } } else { - std::cout << "No technicians are currently available."; + std::cout << "No technicians are currently available.\n\n"; } } } + else + { + std::cout << "No pending service bookings available.\n\n"; + } util::pressEnter(); } diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp index d354a3c..05f85cf 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp @@ -358,6 +358,7 @@ Returns: void CustomerMenu::viewInvoices() { util::clear(); + std::cout << "View Invoices\n"; util::Map currentUserInvoices = m_controller.getInvoicesByUser(); displayInvoices(currentUserInvoices); util::pressEnter(); @@ -393,4 +394,4 @@ void CustomerMenu::configureNotifications() util::clear(); std::cout << "Notification preferences updated successfully.\n"; util::pressEnter(); -} +} \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h index a09950d..c370dd4 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h @@ -154,6 +154,28 @@ inline void selectInventoryItems(util::Map& c } } +/* +Function: filterActiveServiceBookings +Description: Filters the given service bookings and returns only bookings with PENDING status. +Parameters: + - currentBookings: util::Map, collection of current service bookings +Returns: + - util::Map: map containing only active (PENDING) service bookings +*/ +inline util::Map filterActiveServiceBookings(util::Map currentBookings) +{ + util::Map activeServcieBookings; + for (int iterator = 0; iterator < currentBookings.getSize(); iterator++) + { + const ServiceBooking* currentServiceBooking = currentBookings.getValueAt(iterator); + if (currentServiceBooking && currentServiceBooking->getStatus() == util::ServiceJobStatus::PENDING) + { + activeServcieBookings.insert(currentServiceBooking->getId(), currentServiceBooking); + } + } + return activeServcieBookings; +} + /* Function: listServiceBookings Description: Lists all pending service bookings and maps them to indices for selection. @@ -166,48 +188,46 @@ Returns: */ inline bool listServiceBookings(util::Map& currentBookings, int& bookingsSize, util::Map& serviceBookingsMap) { + if (currentBookings.getSize() == 0) + { + return false; + } int currentIndex = 1; - bool hasPendingService = false; + std::cout << "\nSelect Service Booking" << std::endl; std::cout << std::left << std::setw(10) << "Index" - << std::setw(10) << "ID" - << std::setw(12) << "Status" - << std::setw(12) << "CustID" - << std::setw(20) << "Customer" - << std::setw(15) << "VehicleNo" - << std::setw(15) << "Brand" - << std::setw(15) << "Model" - << std::setw(20) << "Technician" - << std::setw(15) << "TechnicianID" + << std::setw(10) << "ID" + << std::setw(12) << "Status" + << std::setw(12) << "CustID" + << std::setw(20) << "Customer" + << std::setw(15) << "VehicleNo" + << std::setw(15) << "Brand" + << std::setw(15) << "Model" + << std::setw(20) << "Technician" + << std::setw(15) << "TechnicianID" << std::endl; - for (int iterator = 0; iterator < bookingsSize; iterator++) + for (int iterator = 0; iterator < bookingsSize; iterator++) { - const ServiceBooking* currentBooking = currentBookings.getValueAt(iterator); - if (currentBooking && currentBooking->getStatus() == util::ServiceJobStatus::PENDING) + const ServiceBooking* currentBooking = currentBookings.getValueAt(iterator); + if (currentBooking && currentBooking->getStatus() == util::ServiceJobStatus::PENDING) { - hasPendingService = true; - const User* currentAssignedTechnician = currentBooking->getAssignedTechnician(); - std::cout << std::left - << std::setw(10) << currentIndex - << std::setw(10) << currentBooking->getId() - << std::setw(12) << util::getServiceJobStatusString(currentBooking->getStatus()) - << std::setw(12) << currentBooking->getCustomerId() - << std::setw(20) << currentBooking->getCustomer()->getName() - << std::setw(15) << currentBooking->getVehicleNumber() - << std::setw(15) << currentBooking->getVehicleBrand() - << std::setw(15) << currentBooking->getVehicleModel() - << std::setw(20) << ((currentAssignedTechnician == nullptr || currentAssignedTechnician->getName().empty()) ? "Null" : currentAssignedTechnician->getName()) - << std::setw(15) << ((currentAssignedTechnician == nullptr || currentAssignedTechnician->getId().empty()) ? "Null" : currentAssignedTechnician->getId()) - << std::endl; - serviceBookingsMap.insert(currentIndex++, currentBooking); + const User* currentAssignedTechnician = currentBooking->getAssignedTechnician(); + std::cout << std::left + << std::setw(10) << currentIndex + << std::setw(10) << currentBooking->getId() + << std::setw(12) << util::getServiceJobStatusString(currentBooking->getStatus()) + << std::setw(12) << currentBooking->getCustomerId() + << std::setw(20) << currentBooking->getCustomer()->getName() + << std::setw(15) << currentBooking->getVehicleNumber() + << std::setw(15) << currentBooking->getVehicleBrand() + << std::setw(15) << currentBooking->getVehicleModel() + << std::setw(20) << ((currentAssignedTechnician == nullptr || currentAssignedTechnician->getName().empty()) ? "NULL" : currentAssignedTechnician->getName()) + << std::setw(15) << ((currentAssignedTechnician == nullptr || currentAssignedTechnician->getId().empty()) ? "NULL" : currentAssignedTechnician->getId()) + << std::endl; + serviceBookingsMap.insert(currentIndex++, currentBooking); + } } - } - if (!hasPendingService) - { - std::cout << "No pending service available." << std::endl; - return false; - } - return true; + return true; } /* @@ -221,15 +241,15 @@ Returns: inline const ServiceBooking* selectPendingServiceBookings(util::Map& serviceBookingsMap) { int userInputIndex; - std::cout << "Enter a valid service index: "; + std::cout << "\nEnter a valid service index: "; util::read(userInputIndex); if (serviceBookingsMap.find(userInputIndex) != -1) { - return serviceBookingsMap.getValueAt(userInputIndex); + return serviceBookingsMap.getValueAt(serviceBookingsMap.find(userInputIndex)); } else { - std::cout << "Enter a valid index."; + std::cout << "Enter a valid index.\n\n"; return nullptr; } } @@ -248,6 +268,7 @@ inline void listAvailableTechnicians(util::Map current { bool hasTechnicians = false; int currentIndex = 1; + std::cout << "\nSelect Technician\n"; std::cout << std::left << std::setw(6) << "Index" << std::setw(15) << "Technician ID" @@ -270,7 +291,7 @@ inline void listAvailableTechnicians(util::Map current } if (!hasTechnicians) { - std::cout << "No technicians currently available."; + std::cout << "No technicians currently available.\n\n"; } } @@ -283,17 +304,18 @@ Returns: - const User*: Pointer to the selected technician, or nullptr if invalid */ inline const User* selectTechnician(util::Map& currentAvailableTechniciansMap) +{ + int userInputIndex; + std::cout << "\nEnter valid technician index: "; + util::read(userInputIndex); + if (currentAvailableTechniciansMap.find(userInputIndex) != -1) { - int userInputIndex; - util::read(userInputIndex); - if (currentAvailableTechniciansMap.find(userInputIndex) != -1) - { - return currentAvailableTechniciansMap.getValueAt(userInputIndex); - } - else - { - std::cout << "Enter a valid index."; - return nullptr; + return currentAvailableTechniciansMap.getValueAt(currentAvailableTechniciansMap.find(userInputIndex)); + } + else + { + std::cout << "Enter a valid index.\n\n"; + return nullptr; } } @@ -406,57 +428,61 @@ Throws: */ inline void displayInvoices(util::Map currentUserInvoices) { - if (currentUserInvoices.getSize() == 0) + if (currentUserInvoices.getSize() == 0) { - std::cout << "No invoices found for this account." << std::endl; - util::pressEnter(); + std::cout << "No invoices found for this account." << std::endl << std::endl; return; } - else + else { - for (int index = 0; index < currentUserInvoices.getSize(); index++) - { - const Invoice* currentInvoice = currentUserInvoices.getValueAt(index); - if (currentInvoice) - { - const User* currentTechnician = currentInvoice->getBooking()->getAssignedTechnician(); - std::cout << "\nInvoice Details\n"; - std::cout << "Booking ID: " << currentInvoice->getBookingId() << std::endl; - std::cout << "Vehicle Brand: " << currentInvoice->getBooking()->getVehicleBrand() << std::endl; - std::cout << "Vehicle Number: " << currentInvoice->getBooking()->getVehicleNumber() << std::endl; - std::cout << "Technician ID: " << - ((currentTechnician != nullptr && currentTechnician->getId() != "") ? - currentTechnician->getId() : "Null") << std::endl; - std::cout << "Technician Name: " << - ((currentTechnician != nullptr && currentTechnician->getName() != "") ? - currentTechnician->getName() : "Null") << std::endl; - std::cout << "Discount(%): " << currentInvoice->getDiscountPercentage() << std::endl; - std::cout << "Total Amount: " << currentInvoice->getTotalAmount() << std::endl; - std::cout << "Invoice Date: " << currentInvoice->getInvoiceDate().toString() << std::endl; - std::cout << "Payment Status: " << util::getPaymentStatusString(currentInvoice->getStatus()) << std::endl; - auto inventoryItemsInInvoice = currentInvoice->getParts(); - std::cout << "\nItems Used:\n"; - std::cout << std::left - << std::setw(20) << "ItemName" - << std::setw(10) << "Quantity" - << std::setw(10) << "Price" - << std::endl; - std::cout << std::string(40, '-') << std::endl; - for (int iterator = 0; iterator < inventoryItemsInInvoice.getSize(); iterator++) - { - InventoryItem* currentItem = inventoryItemsInInvoice.getValueAt(iterator); - std::cout << std::left - << std::setw(20) << currentItem->getPartName() - << std::setw(10) << currentItem->getQuantity() - << std::setw(10) << currentItem->getPrice() - << std::endl; - } -} - else + for (int index = 0; index < currentUserInvoices.getSize(); index++) { - throw std::runtime_error("Null invoice encountered while displaying invoices."); - util::pressEnter(); - } + const Invoice* currentInvoice = currentUserInvoices.getValueAt(index); + if (currentInvoice) + { + const User* currentTechnician = currentInvoice->getBooking()->getAssignedTechnician(); + std::cout << "\nInvoice Details\n"; + std::cout << "Booking ID: " << currentInvoice->getBookingId() << std::endl; + std::cout << "Vehicle Brand: " << currentInvoice->getBooking()->getVehicleBrand() << std::endl; + std::cout << "Vehicle Number: " << currentInvoice->getBooking()->getVehicleNumber() << std::endl; + std::cout << "Technician ID: " << + ((currentTechnician != nullptr && currentTechnician->getId() != "") ? + currentTechnician->getId() : "Null") << std::endl; + std::cout << "Technician Name: " << + ((currentTechnician != nullptr && currentTechnician->getName() != "") ? + currentTechnician->getName() : "Null") << std::endl; + std::cout << "Discount(%): " << currentInvoice->getDiscountPercentage() << std::endl; + std::cout << "Total Amount: " << currentInvoice->getTotalAmount() << std::endl; + std::cout << "Invoice Date: " << currentInvoice->getInvoiceDate().toString() << std::endl; + std::cout << "Payment Status: " << util::getPaymentStatusString(currentInvoice->getStatus()) << std::endl; + auto inventoryItemsInInvoice = currentInvoice->getParts(); + if (inventoryItemsInInvoice.isEmpty()) + { + std::cout << "No inventory items used.\n\n"; + continue; + } + std::cout << "\nItems Used:\n"; + std::cout << std::left + << std::setw(20) << "ItemName" + << std::setw(10) << "Quantity" + << std::setw(10) << "Price" + << std::endl; + std::cout << std::string(40, '-') << std::endl; + for (int iterator = 0; iterator < inventoryItemsInInvoice.getSize(); iterator++) + { + InventoryItem* currentItem = inventoryItemsInInvoice.getValueAt(iterator); + std::cout << std::left + << std::setw(20) << currentItem->getPartName() + << std::setw(10) << currentItem->getQuantity() + << std::setw(10) << currentItem->getPrice() + << std::endl; + } + } + else + { + throw std::runtime_error("Null invoice encountered while displaying invoices."); + util::pressEnter(); + } } } }