Compare commits

...

3 Commits

Author SHA1 Message Date
joelthomastrenser 956ef58c79 Implement review fixes 2026-06-18 19:54:12 +05:30
Avinash Rajesh bdb8431773 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
2026-06-18 19:26:45 +05:30
Jissin Mathew b983337630 Merged PR 1196: Fix Service Booking Cancellation, Job Completion Exception, and Inventory Quantity Handling
Changes

- Added Controller::removeServiceBooking() with documentation and delegation to ServiceManagementService.

- Implemented ServiceManagementService::removeServiceBooking() to handle cancellation of pending bookings, enforce status validation, send notifications, and persist changes safely.

- Updated CustomerMenu to include a "Cancel Service Booking" option, wired into handleOperation, and implemented CustomerMenu::cancelServiceBooking() for user interaction.

- Ensured consistent declarations in Controller.h, ServiceManagementService.h, and CustomerMenu.h.

- Refactored ServiceManagementService::updateJobStatus() to use tracked job card references instead of raw pointers, ensuring consistent state updates.

- Added proper null checks and error handling for current job retrieval to prevent unexpected termination.

- Updated logic to mark tracked job records as MODIFIED when status transitions occur (`STARTED` → `IN_PROGRESS`, `IN_PROGRESS` → `COMPLETED`).

- Simplified control flow and indentation for better readability and maintainability.

- Added retrieval of tracked service bookings and inventory items in ServiceManagementService::createJobCard().

- Validated service booking ID and inventory item indices before proceeding with job card creation.

- Decremented inventory item quantities when job cards are created and marked corresponding tracked inventory records as `MODIFIED`.

- Updated tracked service booking state to `MODIFIED` when technician is assigned and job status changes.

- Persisted changes by saving job cards, service bookings, and inventory items to the datastore.

Fixes

#2105
#2076
#2075
#2074
2026-06-18 11:36:43 +05:30
2 changed files with 56 additions and 0 deletions
@@ -220,6 +220,13 @@ void CustomerMenu::selectService()
util::pressEnter(); util::pressEnter();
return; 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; util::Vector<std::string> selectedServices;
const Service* selectedService = selectServiceFromServices(services); const Service* selectedService = selectServiceFromServices(services);
if (selectedService == nullptr) if (selectedService == nullptr)
@@ -262,6 +269,13 @@ void CustomerMenu::selectComboPackage()
util::pressEnter(); util::pressEnter();
return; 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); const ComboPackage* selectedComboPackage = selectComboPackageFromPackages(activeComboPackages);
if (selectedComboPackage == nullptr) if (selectedComboPackage == nullptr)
{ {
@@ -1467,3 +1467,45 @@ inline void displayNewNotification(util::Vector<const Notification*> notificatio
MB_ICONINFORMATION); 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;
}