Fixed Reviewed Changes

This commit is contained in:
Avinash Rajesh
2026-06-01 11:26:28 +05:30
committed by Joel Thomas
parent bb2fa84316
commit a3061f4749
5 changed files with 22 additions and 26 deletions
@@ -472,7 +472,7 @@ Returns:
*/ */
util::Map<std::string, const Invoice*> Controller::getAllInvoices() util::Map<std::string, const Invoice*> Controller::getAllInvoices()
{ {
auto invoices = m_paymentManagementService.getAllInvoice(); auto invoices = m_paymentManagementService.getAllInvoices();
util::Map<std::string, const Invoice*> readOnlyInvoice; util::Map<std::string, const Invoice*> readOnlyInvoice;
for (int iterator = 0; iterator < invoices.getSize(); iterator++) for (int iterator = 0; iterator < invoices.getSize(); iterator++)
{ {
@@ -489,7 +489,7 @@ Parameters:
Returns: Returns:
- void - void
*/ */
void Controller::confirmPayment(std::string invoiceID) void Controller::confirmPayment(const std::string& invoiceID)
{ {
m_paymentManagementService.confirmPayment(invoiceID); m_paymentManagementService.confirmPayment(invoiceID);
} }
@@ -65,7 +65,7 @@ public:
void removeComboPackage(const std::string& comboPackageID); void removeComboPackage(const std::string& comboPackageID);
util::Map<std::string, const Invoice*> getInvoicesByUser(); util::Map<std::string, const Invoice*> getInvoicesByUser();
util::Map<std::string, const Invoice*> getAllInvoices(); util::Map<std::string, const Invoice*> getAllInvoices();
void confirmPayment(std::string invoiceID); void confirmPayment(const std::string& invoiceID);
void completePayment(const std::string& invoiceID, util::PaymentMode paymentMode); void completePayment(const std::string& invoiceID, util::PaymentMode paymentMode);
util::Vector<const Notification*> getNotifications(); util::Vector<const Notification*> getNotifications();
void deleteNotification(const std::string& notificationID); void deleteNotification(const std::string& notificationID);
@@ -394,7 +394,7 @@ Parameters:
Returns: Returns:
- util::Map<std::string, Invoice*>&: Map of invoice IDs to invoice objects - util::Map<std::string, Invoice*>&: Map of invoice IDs to invoice objects
*/ */
util::Map<std::string, Invoice*>& PaymentManagementService::getAllInvoice() util::Map<std::string, Invoice*>& PaymentManagementService::getAllInvoices()
{ {
return m_dataStore.getInvoices(); return m_dataStore.getInvoices();
} }
@@ -410,26 +410,22 @@ Returns:
Throws: Throws:
- std::runtime_error if the invoice ID is invalid - std::runtime_error if the invoice ID is invalid
*/ */
void PaymentManagementService::confirmPayment(std::string invoiceID) void PaymentManagementService::confirmPayment(const std::string& invoiceID)
{ {
std::string title, message;
auto& currentInvoices = m_dataStore.getInvoices(); auto& currentInvoices = m_dataStore.getInvoices();
int invoiceIndex = currentInvoices.find(invoiceID); int invoiceIndex = currentInvoices.find(invoiceID);
if (invoiceIndex != -1) if (invoiceIndex == -1)
{ {
Invoice* invoice = currentInvoices.getValueAt(invoiceIndex); throw std::runtime_error("Payment confirmation failed: invalid invoice ID.");
if (invoice && invoice->getStatus() != util::PaymentStatus::COMPLETED)
{
User* currentUser = invoice->getBooking()->getCustomer();
invoice->setPaymentDate(util::Timestamp());
invoice->setStatus(util::PaymentStatus::COMPLETED);
title = "Payment Confirmed";
message = "Payment Confirmed for Invoice ID " + invoiceID;
sendNotification(currentUser, title, message);
}
} }
else Invoice* invoice = currentInvoices.getValueAt(invoiceIndex);
if (!invoice || invoice->getStatus() != util::PaymentStatus::PAID)
{ {
throw std::runtime_error("Payment failed: invalid invoice ID."); throw std::runtime_error("Payment confirmation failed: invoice is not awaiting confirmation.");
} }
User* currentUser = invoice->getBooking()->getCustomer();
invoice->setStatus(util::PaymentStatus::COMPLETED);
std::string title = "Payment Confirmed";
std::string message = "Payment Confirmed for Invoice ID " + invoiceID;
sendNotification(currentUser, title, message);
} }
@@ -28,8 +28,8 @@ public:
void generateInvoice(ServiceBooking* booking); void generateInvoice(ServiceBooking* booking);
util::Map<std::string, Invoice*> getInvoices(const std::string& customerID); util::Map<std::string, Invoice*> getInvoices(const std::string& customerID);
void completePayment(const std::string& invoiceID, util::PaymentMode paymentMode); void completePayment(const std::string& invoiceID, util::PaymentMode paymentMode);
util::Map<std::string, Invoice*>& getAllInvoice(); util::Map<std::string, Invoice*>& getAllInvoices();
void confirmPayment(std::string invoiceID); void confirmPayment(const std::string& invoiceID);
void sendPaymentReminders(); void sendPaymentReminders();
void sendNotification(User* user, const std::string& title, const std::string& message) override; void sendNotification(User* user, const std::string& title, const std::string& message) override;
void attach(User* user) override; void attach(User* user) override;
@@ -503,7 +503,7 @@ void AdminMenu::displayUsers()
/* /*
Function: confirmPayment Function: confirmPayment
Description: Confirms payment for a selected invoice. Validates invoice status, updates payment date, Description: Confirms payment for a selected invoice. Validates invoice status, updates payment date,
sets status to PAID, and sends a notification to the customer. sets status to COMPLETED, and sends a notification to the customer.
Parameters: Parameters:
- invoiceID: std::string, ID of the invoice to confirm - invoiceID: std::string, ID of the invoice to confirm
Returns: Returns:
@@ -520,19 +520,19 @@ void AdminMenu::confirmPayment()
util::pressEnter(); util::pressEnter();
return; return;
} }
bool hasPaidInvoice = false; bool hasConfirmableInvoice = false;
for (int index = 0; index < invoiceList.getSize(); ++index) for (int index = 0; index < invoiceList.getSize(); ++index)
{ {
const Invoice* invoice = invoiceList.getValueAt(index); const Invoice* invoice = invoiceList.getValueAt(index);
if (invoice && invoice->getStatus() == util::PaymentStatus::PAID) if (invoice && invoice->getStatus() == util::PaymentStatus::PAID)
{ {
hasPaidInvoice = true; hasConfirmableInvoice = true;
break; break;
} }
} }
if (!hasPaidInvoice) if (!hasConfirmableInvoice)
{ {
std::cout << "No pending invoices available for payment.\n"; std::cout << "No invoices awaiting confirmation.\n";
util::pressEnter(); util::pressEnter();
return; return;
} }