1c717bb9fa
Changes:
1. Added missing include for MenuHelper.h in project, AdminMenu, and CustomerMenu.
2. Updated PaymentManagementService::completePayment to guard against duplicate completion by checking status before updating.
3. Enhanced ServiceManagementService::createJobCard with null checks for inventory items and safe stock decrement logic.
4. Added null check for job card creation in ServiceManagementService and throw runtime error if creation fails.
5. Refactored ServiceManagementService::removeService to use m_dataStore.getServices() reference instead of getServices() copy.
6. Renamed helper function hasAllJobCardsinServiceBookingCompleted to hasCompletedAllJobs for clarity and updated usage in completeJob.
7. Fixed ServiceJobStatus string conversion in Enums.h to correctly return "PENDING" instead of "STARTED".
8. Added support for parsing "PENDING" string to ServiceJobStatus::PENDING in Enums.h.
9. Cleaned up AdminMenu.cpp by removing redundant static helper functions (listServiceBookings, selectPendingServiceBookings, listAvailableTechnicians, selectTechnician, selectInventoryItems, selectServicesToRemove).
10. Replaced removed helpers with shared MenuHelper usage and added util::pressEnter() calls for consistent user flow.
11. Simplified CustomerMenu.cpp by removing redundant static helpers (selectInvoiceFromUserForPayment, selectPaymentMode, displayInvoices) and moved logic to shared helpers.
12. General formatting and comment cleanup across AdminMenu.cpp and CustomerMenu.cpp for consistency.
163 lines
4.2 KiB
C++
163 lines
4.2 KiB
C++
#include <iomanip>
|
||
#include <iostream>
|
||
#include "CustomerMenu.h"
|
||
#include "InputHelper.h"
|
||
#include "MenuHelper.h"
|
||
#include "OutputHelper.h"
|
||
#include "Invoice.h"
|
||
#include "Enums.h"
|
||
#include "ServiceBooking.h"
|
||
#include "User.h"
|
||
#include "Timestamp.h"
|
||
#include "Service.h"
|
||
#include "InventoryItem.h"
|
||
|
||
void CustomerMenu::showMenu()
|
||
{
|
||
bool isMenuActive = true;
|
||
while (isMenuActive)
|
||
{
|
||
try
|
||
{
|
||
int choice;
|
||
util::clear();
|
||
std::cout << "" << std::endl;
|
||
util::read(choice);
|
||
if (!handleOperation(choice))
|
||
{
|
||
isMenuActive = false;
|
||
}
|
||
}
|
||
catch (const std::exception& e)
|
||
{
|
||
std::cout << "Exception: " << e.what() << std::endl;
|
||
util::pressEnter();
|
||
}
|
||
}
|
||
}
|
||
|
||
bool CustomerMenu::handleOperation(int choice)
|
||
{
|
||
return false;
|
||
}
|
||
|
||
void CustomerMenu::logout()
|
||
{
|
||
}
|
||
|
||
void CustomerMenu::changePassword()
|
||
{
|
||
}
|
||
|
||
void CustomerMenu::updateDetails()
|
||
{
|
||
}
|
||
|
||
void CustomerMenu::selectService()
|
||
{
|
||
}
|
||
|
||
void CustomerMenu::selectComboPackage()
|
||
{
|
||
}
|
||
|
||
/*
|
||
Function: viewServiceHistory
|
||
Description: Displays the customer’s past service bookings in tabular format,
|
||
including booking ID, technician, vehicle details, discount percentage, and status.
|
||
Parameters:
|
||
- None
|
||
Returns:
|
||
- void
|
||
*/
|
||
void CustomerMenu::viewServiceHistory()
|
||
{
|
||
util::clear();
|
||
bool hasServiceHistory = false;
|
||
const User* currentUser = m_controller.getAuthenticatedUser();
|
||
std::string currentUserID = currentUser->getId();
|
||
util::Map<std::string, const ServiceBooking*> serviceBookingsByCurrentUser = m_controller.getServiceBookingsByUser(currentUserID);
|
||
if (serviceBookingsByCurrentUser.getSize() != 0)
|
||
{
|
||
std::cout << std::left
|
||
<< std::setw(12) << "Booking ID"
|
||
<< std::setw(20) << "Technician"
|
||
<< std::setw(15) << "Vehicle Brand"
|
||
<< std::setw(15) << "Vehicle Number"
|
||
<< std::setw(15) << "Vehicle Model"
|
||
<< std::setw(10) << "Discount %"
|
||
<< std::setw(12) << "Status"
|
||
<< std::endl;
|
||
for (int iterator = 0; iterator < serviceBookingsByCurrentUser.getSize(); iterator++)
|
||
{
|
||
const ServiceBooking* currentBooking = serviceBookingsByCurrentUser.getValueAt(iterator);
|
||
std::string technicianName = currentBooking->getAssignedTechnician() == nullptr
|
||
? "Not Assigned"
|
||
: currentBooking->getAssignedTechnician()->getName();
|
||
std::cout << std::left
|
||
<< std::setw(12) << currentBooking->getId()
|
||
<< std::setw(20) << technicianName
|
||
<< std::setw(15) << currentBooking->getVehicleBrand()
|
||
<< std::setw(15) << currentBooking->getVehicleNumber()
|
||
<< std::setw(15) << currentBooking->getVehicleModel()
|
||
<< std::setw(10) << currentBooking->getDiscountPercentage()
|
||
<< std::setw(12) << util::getServiceJobStatusString(currentBooking->getStatus())
|
||
<< std::endl;
|
||
hasServiceHistory = true;
|
||
}
|
||
}
|
||
if (!hasServiceHistory)
|
||
{
|
||
std::cout << "No history available." << std::endl;
|
||
}
|
||
util::pressEnter();
|
||
}
|
||
|
||
/*
|
||
Function: completePayments
|
||
Description: Allows the customer to complete pending payments for invoices.
|
||
Validates invoice selection and payment mode before completing payment.
|
||
Parameters:
|
||
- None
|
||
Returns:
|
||
- void
|
||
*/
|
||
void CustomerMenu::completePayments()
|
||
{
|
||
util::clear();
|
||
util::Map<std::string, const Invoice*> currentInvoices = m_controller.getInvoicesByUser();
|
||
std::string selectedID = selectInvoiceFromUserForPayment(currentInvoices);
|
||
if (selectedID == "")
|
||
{
|
||
std::cout << "Payment failed.\n";
|
||
return;
|
||
}
|
||
util::PaymentMode paymentMode = selectPaymentMode();
|
||
m_controller.completePayment(selectedID, paymentMode);
|
||
std::cout << "Payment completed successfully.\n";
|
||
util::pressEnter();
|
||
}
|
||
|
||
/*
|
||
Function: viewInvoices
|
||
Description: Displays invoices associated with the customer by calling displayInvoices.
|
||
Parameters:
|
||
- None
|
||
Returns:
|
||
- void
|
||
*/
|
||
void CustomerMenu::viewInvoices()
|
||
{
|
||
util::clear();
|
||
util::Map<std::string, const Invoice*> currentUserInvoices = m_controller.getInvoicesByUser();
|
||
displayInvoices(currentUserInvoices);
|
||
util::pressEnter();
|
||
}
|
||
|
||
void CustomerMenu::viewNotifications()
|
||
{
|
||
}
|
||
|
||
void CustomerMenu::configureNotifications()
|
||
{
|
||
} |