diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp index 5d35aa1..e3a85b0 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp @@ -472,7 +472,7 @@ Returns: */ util::Map Controller::getAllInvoices() { - auto invoices = m_paymentManagementService.getAllInvoice(); + auto invoices = m_paymentManagementService.getAllInvoices(); util::Map readOnlyInvoice; for (int iterator = 0; iterator < invoices.getSize(); iterator++) { @@ -489,7 +489,7 @@ Parameters: Returns: - void */ -void Controller::confirmPayment(std::string invoiceID) +void Controller::confirmPayment(const std::string& invoiceID) { m_paymentManagementService.confirmPayment(invoiceID); } diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h index b045dec..35241a0 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h @@ -65,7 +65,7 @@ public: void removeComboPackage(const std::string& comboPackageID); util::Map getInvoicesByUser(); util::Map getAllInvoices(); - void confirmPayment(std::string invoiceID); + void confirmPayment(const std::string& invoiceID); void completePayment(const std::string& invoiceID, util::PaymentMode paymentMode); util::Vector getNotifications(); void deleteNotification(const std::string& notificationID); diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp index c28d31c..1fc1ff8 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp @@ -394,7 +394,7 @@ Parameters: Returns: - util::Map&: Map of invoice IDs to invoice objects */ -util::Map& PaymentManagementService::getAllInvoice() +util::Map& PaymentManagementService::getAllInvoices() { return m_dataStore.getInvoices(); } @@ -410,26 +410,22 @@ Returns: Throws: - 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(); int invoiceIndex = currentInvoices.find(invoiceID); - if (invoiceIndex != -1) + if (invoiceIndex == -1) { - Invoice* invoice = currentInvoices.getValueAt(invoiceIndex); - 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); - } + throw std::runtime_error("Payment confirmation failed: invalid invoice ID."); } - 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); } \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.h index 79d525a..8961a2d 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.h @@ -28,8 +28,8 @@ public: void generateInvoice(ServiceBooking* booking); util::Map getInvoices(const std::string& customerID); void completePayment(const std::string& invoiceID, util::PaymentMode paymentMode); - util::Map& getAllInvoice(); - void confirmPayment(std::string invoiceID); + util::Map& getAllInvoices(); + void confirmPayment(const std::string& invoiceID); void sendPaymentReminders(); void sendNotification(User* user, const std::string& title, const std::string& message) override; void attach(User* user) override; diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp index 85a890a..76a1901 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp @@ -503,7 +503,7 @@ void AdminMenu::displayUsers() /* Function: confirmPayment 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: - invoiceID: std::string, ID of the invoice to confirm Returns: @@ -520,19 +520,19 @@ void AdminMenu::confirmPayment() util::pressEnter(); return; } - bool hasPaidInvoice = false; + bool hasConfirmableInvoice = false; for (int index = 0; index < invoiceList.getSize(); ++index) { const Invoice* invoice = invoiceList.getValueAt(index); if (invoice && invoice->getStatus() == util::PaymentStatus::PAID) { - hasPaidInvoice = true; + hasConfirmableInvoice = true; break; } } - if (!hasPaidInvoice) + if (!hasConfirmableInvoice) { - std::cout << "No pending invoices available for payment.\n"; + std::cout << "No invoices awaiting confirmation.\n"; util::pressEnter(); return; }