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
This commit is contained in:
@@ -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<std::string> 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)
|
||||
{
|
||||
|
||||
@@ -1467,3 +1467,45 @@ inline void displayNewNotification(util::Vector<const Notification*> 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<std::string, const Invoice*> 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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user