Compare commits
2 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 956ef58c79 | |||
| bdb8431773 |
@@ -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.");
|
||||
}
|
||||
const 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;
|
||||
}
|
||||
const 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