From bdb8431773a3593650736a0670508606b5ce9e49 Mon Sep 17 00:00:00 2001 From: Avinash Rajesh Date: Thu, 18 Jun 2026 19:26:45 +0530 Subject: [PATCH 1/2] Customer Allowed to Create Service Bookings While Having Unpaid Invoices - Added verifyAllPaymentsCompleted() helper in MenuHelper.h to check if the authenticated customer has completed all invoices. - Integrated payment verification into CustomerMenu::selectService() to block new service bookings when pending payments exist. - Integrated payment verification into CustomerMenu::selectComboPackage() to block new combo package bookings when invoices are incomplete. - Implemented iteration over customer invoices to ensure only users with all payments marked as COMPLETED can proceed with new bookings. - Added user-facing messages to inform customers when bookings are denied due to outstanding payments. Fixes #2116 --- .../views/CustomerMenu.cpp | 14 +++++++ .../views/MenuHelper.h | 42 +++++++++++++++++++ 2 files changed, 56 insertions(+) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp index 09e145c..7b281d6 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp @@ -220,6 +220,13 @@ void CustomerMenu::selectService() util::pressEnter(); return; } + if (!verifyAllPaymentsCompleted(m_controller)) + { + std::cout << "Your booking cannot be processed because you have pending payments for previous services. Please complete all outstanding invoices before booking a new service." + << std::endl; + util::pressEnter(); + return; + } util::Vector selectedServices; const Service* selectedService = selectServiceFromServices(services); if (selectedService == nullptr) @@ -262,6 +269,13 @@ void CustomerMenu::selectComboPackage() util::pressEnter(); return; } + if (!verifyAllPaymentsCompleted(m_controller)) + { + std::cout << "Your booking cannot be processed because you have pending payments for previous services. Please complete all outstanding invoices before booking a new combo package." + << std::endl; + util::pressEnter(); + return; + } const ComboPackage* selectedComboPackage = selectComboPackageFromPackages(activeComboPackages); if (selectedComboPackage == nullptr) { diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h index 33cd5bd..6f6a1df 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h @@ -1467,3 +1467,45 @@ inline void displayNewNotification(util::Vector notificatio MB_ICONINFORMATION); } } + +/* +Function: verifyAllPaymentsCompleted +Description: Checks whether the authenticated customer has completed + all payments for their invoices. Iterates through all + invoices belonging to the customer and verifies that + each invoice has a payment status of COMPLETED. +Parameters: Controller& m_controller - + reference to the Controller object used to access + authenticated user and invoice data +Return type: bool + true if all invoices for the authenticated customer + are completed, false if any invoice is pending or not completed +Throws: std::runtime_error if no authenticated user is found +*/ +inline bool verifyAllPaymentsCompleted(Controller& m_controller) +{ + const User* authenticatedUser = m_controller.getAuthenticatedUser(); + if (!authenticatedUser) + { + throw std::runtime_error("No authenticated user found."); + } + std::string authenticatedUserId = authenticatedUser->getId(); + util::Map listOfInvoices = m_controller.getAllInvoices(); + for (int invoiceIndex = 0; invoiceIndex < listOfInvoices.getSize(); ++invoiceIndex) + { + const Invoice* invoice = listOfInvoices.getValueAt(invoiceIndex); + if (!invoice) + { + continue; + } + std::string customerId = invoice->getBooking()->getCustomerId(); + if (customerId == authenticatedUserId) + { + if (invoice->getStatus() != util::PaymentStatus::COMPLETED) + { + return false; + } + } + } + return true; +} From 956ef58c7963178e139cb773b9f0a764a4da3aae Mon Sep 17 00:00:00 2001 From: Joel Thomas Date: Thu, 18 Jun 2026 19:54:12 +0530 Subject: [PATCH 2/2] Implement review fixes --- .../Trenser.VehicleServiceSystem/views/MenuHelper.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h index 6f6a1df..dafd9ad 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/MenuHelper.h @@ -1489,7 +1489,7 @@ inline bool verifyAllPaymentsCompleted(Controller& m_controller) { throw std::runtime_error("No authenticated user found."); } - std::string authenticatedUserId = authenticatedUser->getId(); + const std::string& authenticatedUserId = authenticatedUser->getId(); util::Map listOfInvoices = m_controller.getAllInvoices(); for (int invoiceIndex = 0; invoiceIndex < listOfInvoices.getSize(); ++invoiceIndex) { @@ -1498,7 +1498,7 @@ inline bool verifyAllPaymentsCompleted(Controller& m_controller) { continue; } - std::string customerId = invoice->getBooking()->getCustomerId(); + const std::string& customerId = invoice->getBooking()->getCustomerId(); if (customerId == authenticatedUserId) { if (invoice->getStatus() != util::PaymentStatus::COMPLETED)