From cb3bed4050e54dc8a4b300aecb0388733c97a885 Mon Sep 17 00:00:00 2001 From: Jissin Mathew Date: Wed, 20 May 2026 17:48:41 +0530 Subject: [PATCH 1/4] Implement Complete Payments PAY002: Complete Payments 1. Integrated Controller with PaymentManagementService to support payment completion workflow. 2. Implemented PaymentManagementService::completePayment with validation for invoice ID, payment mode, and status update. 3. Enhanced CustomerMenu with helper functions to display pending invoices in tabular format and allow index-based selection. 4. Added CustomerMenu::selectPaymentMode to capture payment mode choice (OFFLINE/ONLINE). 5. Updated CustomerMenu::completePayments to handle invoice selection, payment mode input, and trigger payment completion via Controller. 6. Implemented notification logic to send confirmation to customers upon successful payment. Acceptance Criteria: 1. Payment status marked completed. 2. Confirmation message shown. 3. Confirmation notification sent. Precondition: 1. Customer is logged into the system. 2. At least one pending invoice exists for the customer. 3. Datastore is available for storing invoices and updating payment status. Steps: 1. Navigate to Customer menu and choose "Complete Payments". - Verify that the system lists pending invoices with tabular details. 2. Select an invoice by index. - Verify that the chosen invoice is retrieved correctly. 3. Enter payment mode (OFFLINE/ONLINE). - Verify that the selected mode is applied to the invoice. 4. Confirm payment completion. - Verify that the invoice status changes to COMPLETED. - Verify that a confirmation message is displayed. - Verify that a notification is sent to the customer. Sreeja Reghukumar, please review --- .../controllers/Controller.cpp | 13 ++- .../controllers/Controller.h | 5 + .../models/ServiceBooking.cpp | 6 +- .../models/ServiceBooking.h | 8 +- .../services/PaymentManagementService.cpp | 41 ++++++++ .../views/CustomerMenu.cpp | 95 +++++++++++++++++++ 6 files changed, 160 insertions(+), 8 deletions(-) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp index d536e8a..97a2b90 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp @@ -1,4 +1,6 @@ #include "Controller.h" +#include "User.h" +#include "Invoice.h" bool Controller::login(const std::string& username, const std::string& password) { @@ -121,11 +123,20 @@ void Controller::removeComboPackage(const std::string& comboPackageID) util::Map Controller::getInvoicesByUser() { - return util::Map(); + User* currentUser = m_authenticationManagementService.getAuthenticatedUser(); + util::Map currentUserInvoices = m_paymentManagementService.getInvoices(currentUser->getId()); + util::Map userInvoicesReadOnly; + for (int iterator = 0; iterator < currentUserInvoices.getSize(); iterator++) + { + Invoice* currentInvoice = currentUserInvoices.getValueAt(iterator); + userInvoicesReadOnly.insert(currentInvoice->getId(), currentInvoice); + } + return userInvoicesReadOnly; } void Controller::completePayment(const std::string& invoiceID, util::PaymentMode paymentMode) { + m_paymentManagementService.completePayment(invoiceID, paymentMode); } util::Vector Controller::getNotifications() diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h index 3aabb58..874d10a 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h @@ -2,6 +2,8 @@ #include "Map.h" #include #include "Enums.h" +#include "PaymentManagementService.h" +#include "AuthenticationManagementService.h" class Service; class ComboPackage; @@ -14,6 +16,9 @@ class Notification; class Controller { +private: + AuthenticationManagementService m_authenticationManagementService; + PaymentManagementService m_paymentManagementService; public: bool login(const std::string& username, const std::string& password); void logout(); diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.cpp index 1fdfaf0..aeb7f4d 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.cpp @@ -18,7 +18,7 @@ ServiceBooking::ServiceBooking( const std::string& vehicleBrand, const std::string& vehicleModel, const std::string& assignedTechnicianId, - const std::string& assignedTechnician, + const User* assignedTechnician, double discountPercentage ) : m_id("SRV" + std::to_string(++m_uid)), @@ -80,7 +80,7 @@ const std::string& ServiceBooking::getAssignedTechnicianId() const return m_assignedTechnicianId; } -const std::string& ServiceBooking::getAssignedTechnician() const +const User* ServiceBooking::getAssignedTechnician() const { return m_assignedTechnician; } @@ -135,7 +135,7 @@ void ServiceBooking::setAssignedTechnicianId(const std::string& assignedTechnici m_assignedTechnicianId = assignedTechnicianId; } -void ServiceBooking::setAssignedTechnician(const std::string& assignedTechnician) +void ServiceBooking::setAssignedTechnician(const User* assignedTechnician) { m_assignedTechnician = assignedTechnician; } diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.h index 5ecc1b0..8996d36 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.h @@ -19,7 +19,7 @@ private: std::string m_vehicleBrand; std::string m_vehicleModel; std::string m_assignedTechnicianId; - std::string m_assignedTechnician; + const User* m_assignedTechnician; double m_discountPercentage; public: ServiceBooking(); @@ -34,7 +34,7 @@ public: const std::string& vehicleBrand, const std::string& vehicleModel, const std::string& assignedTechnicianId, - const std::string& assignedTechnician, + const User* assignedTechnician, double discountPercentage ); const std::string& getId() const; @@ -46,7 +46,7 @@ public: const std::string& getVehicleBrand() const; const std::string& getVehicleModel() const; const std::string& getAssignedTechnicianId() const; - const std::string& getAssignedTechnician() const; + const User* getAssignedTechnician() const; double getDiscountPercentage() const; void setId(const std::string& id); void setStatus(const util::ServiceJobStatus& status); @@ -57,6 +57,6 @@ public: void setVehicleBrand(const std::string& vehicleBrand); void setVehicleModel(const std::string& vehicleModel); void setAssignedTechnicianId(const std::string& assignedTechnicianId); - void setAssignedTechnician(const std::string& assignedTechnician); + void setAssignedTechnician(const User* assignedTechnician); void setDiscountPercentage(double discountPercentage); }; \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp index 786ebcf..185c362 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp @@ -1 +1,42 @@ #include "PaymentManagementService.h" +#include "Invoice.h" +#include "Enums.h" +#include "ServiceBooking.h" +#include "Timestamp.h" + +util::Map PaymentManagementService::getInvoices(const std::string& customerID) +{ + util::Map& currentInvoices = m_dataStore.getInvoices(); + util::Map currentUserInvoices; + for (int iterator = 0; iterator < currentInvoices.getSize(); iterator++) + { + Invoice* currentInvoice = currentInvoices.getValueAt(iterator); + if (currentInvoice->getBooking()->getCustomerId() == customerID) + { + currentUserInvoices.insert(currentInvoice->getId(), currentInvoice); + } + } + return currentUserInvoices; +} + +void PaymentManagementService::completePayment(const std::string& invoiceID, util::PaymentMode paymentMode) +{ + auto& currentInvoices = m_dataStore.getInvoices(); + int invoiceIndex = currentInvoices.find(invoiceID); + if (invoiceIndex != -1) + { + Invoice* invoice = currentInvoices.getValueAt(invoiceIndex); + User* currentUser = invoice->getBooking()->getCustomer(); + invoice->setPaymentMethod(paymentMode); + invoice->setPaymentDate(util::Timestamp()); + invoice->setStatus(util::PaymentStatus::COMPLETED); + std::string title, message; + title = "Payment successful"; + message = "Payment successful for invoice ID " + invoiceID; + sendNotification(currentUser, title, message); + } + else + { + throw std::runtime_error("Payment failed: invalid invoice ID."); + } +} \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp index 047f471..3a18df4 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp @@ -1,6 +1,13 @@ +#include +#include #include "CustomerMenu.h" #include "InputHelper.h" #include "OutputHelper.h" +#include "Invoice.h" +#include "Enums.h" +#include "ServiceBooking.h" +#include "User.h" +#include "Timestamp.h" void CustomerMenu::showMenu() { @@ -55,8 +62,96 @@ void CustomerMenu::viewServiceHistory() { } +static std::string selectInvoiceFromUserForPayment(const util::Map& currentInvoices) +{ + int currentIndex = 1, choice; + util::Map pendingInvoicesForPayment; + std::cout << std::left + << std::setw(6) << "Index" + << std::setw(12) << "BookingID" + << std::setw(15) << "VehicleBrand" + << std::setw(15) << "VehicleNumber" + << std::setw(12) << "TechID" + << std::setw(20) << "TechnicianName" + << std::setw(10) << "Discount(%)" + << std::setw(12) << "TotalAmount" + << std::setw(20) << "InvoiceDate" + << std::endl; + for (int iterator = 0; iterator < currentInvoices.getSize(); iterator++) + { + const Invoice* currentInvoice = currentInvoices.getValueAt(iterator); + if (currentInvoice && currentInvoice->getStatus() == util::PaymentStatus::PENDING) + { + std::cout << std::left + << std::setw(6) << currentIndex + << std::setw(12) << currentInvoice->getBookingId() + << std::setw(15) << currentInvoice->getBooking()->getVehicleBrand() + << std::setw(15) << currentInvoice->getBooking()->getVehicleNumber() + << std::setw(12) << currentInvoice->getBooking()->getAssignedTechnician()->getId() + << std::setw(20) << currentInvoice->getBooking()->getAssignedTechnician()->getName() + << std::setw(10) << currentInvoice->getDiscountPercentage() + << std::setw(12) << currentInvoice->getTotalAmount() + << std::setw(20) << currentInvoice->getInvoiceDate().toString() + << std::endl; + pendingInvoicesForPayment.insert(currentIndex++, currentInvoice); + } + } + if (pendingInvoicesForPayment.getSize() == 0) + { + std::cout << "No pending invoices available for payment.\n"; + return ""; + } + std::cout << "Select the Invoice to pay (Index): "; + util::read(choice); + int selectedIndex = pendingInvoicesForPayment.find(choice); + if (selectedIndex != -1) + { + const Invoice* selectedInvoice = pendingInvoicesForPayment.getValueAt(selectedIndex); + return selectedInvoice->getId(); + } + else + { + std::cout << "Invalid choice.\n"; + return ""; + } +} + +static util::PaymentMode selectPaymentMode() +{ + int choice; + std::cout << "Enter the payment Mode\n1.OFFLINE\n2.ONLINE\nChoice: "; + util::read(choice); + if (choice == 1) + { + std::cout << "Offline mode selected.\n"; + return util::PaymentMode::OFFLINE; + } + else if (choice == 2) + { + std::cout << "Online mode selected.\n"; + return util::PaymentMode::ONLINE; + } + else + { + std::cout << "Invalid choice, Offline mode selected.\n"; + return util::PaymentMode::OFFLINE; + } +} + void CustomerMenu::completePayments() { + util::clear(); + int paymentModeChoice; + util::Map 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"; } void CustomerMenu::viewInvoices() From 461857f97185a483763b04feac3af92fcf47ab5d Mon Sep 17 00:00:00 2001 From: Jissin Mathew Date: Wed, 20 May 2026 19:54:14 +0530 Subject: [PATCH 2/4] Implement View Invoices for Customer PAY003: View Invoices 1. Added CustomerMenu::viewInvoices to fetch invoices via Controller and display them to the customer. 2. Implemented displayInvoices helper to show invoice details including booking, vehicle, technician, discount, total amount, invoice date, and payment status. 3. Enhanced invoice display to include a tabular breakdown of inventory items (ItemName, Quantity, Price) used in the service. 4. Updated ServiceBooking to store assigned technician as a const User* for richer technician details in invoice output. Acceptance Criteria: 1. Invoice details should show total cost and discounts. 2. Invoice details should show list of parts used. Precondition: 1. Customer is logged into the system. 2. At least one invoice exists for the customer in the datastore. 3. Inventory items are linked to the invoice. Steps: 1. Navigate to Customer menu and choose "View Invoices". - Verify that the system lists invoice details including booking ID, vehicle info, technician, discount, total amount, invoice date, and payment status. 2. Check the parts list under each invoice. - Verify that inventory items are displayed in tabular form with ItemName, Quantity, and Price. 3. Confirm that discounts and total cost are shown correctly. Sreeja Reghukumar, please review --- .../models/ServiceBooking.cpp | 6 +- .../models/ServiceBooking.h | 8 +-- .../views/CustomerMenu.cpp | 60 +++++++++++++++++++ 3 files changed, 67 insertions(+), 7 deletions(-) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.cpp index 1fdfaf0..aeb7f4d 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.cpp @@ -18,7 +18,7 @@ ServiceBooking::ServiceBooking( const std::string& vehicleBrand, const std::string& vehicleModel, const std::string& assignedTechnicianId, - const std::string& assignedTechnician, + const User* assignedTechnician, double discountPercentage ) : m_id("SRV" + std::to_string(++m_uid)), @@ -80,7 +80,7 @@ const std::string& ServiceBooking::getAssignedTechnicianId() const return m_assignedTechnicianId; } -const std::string& ServiceBooking::getAssignedTechnician() const +const User* ServiceBooking::getAssignedTechnician() const { return m_assignedTechnician; } @@ -135,7 +135,7 @@ void ServiceBooking::setAssignedTechnicianId(const std::string& assignedTechnici m_assignedTechnicianId = assignedTechnicianId; } -void ServiceBooking::setAssignedTechnician(const std::string& assignedTechnician) +void ServiceBooking::setAssignedTechnician(const User* assignedTechnician) { m_assignedTechnician = assignedTechnician; } diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.h index 5ecc1b0..8996d36 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/ServiceBooking.h @@ -19,7 +19,7 @@ private: std::string m_vehicleBrand; std::string m_vehicleModel; std::string m_assignedTechnicianId; - std::string m_assignedTechnician; + const User* m_assignedTechnician; double m_discountPercentage; public: ServiceBooking(); @@ -34,7 +34,7 @@ public: const std::string& vehicleBrand, const std::string& vehicleModel, const std::string& assignedTechnicianId, - const std::string& assignedTechnician, + const User* assignedTechnician, double discountPercentage ); const std::string& getId() const; @@ -46,7 +46,7 @@ public: const std::string& getVehicleBrand() const; const std::string& getVehicleModel() const; const std::string& getAssignedTechnicianId() const; - const std::string& getAssignedTechnician() const; + const User* getAssignedTechnician() const; double getDiscountPercentage() const; void setId(const std::string& id); void setStatus(const util::ServiceJobStatus& status); @@ -57,6 +57,6 @@ public: void setVehicleBrand(const std::string& vehicleBrand); void setVehicleModel(const std::string& vehicleModel); void setAssignedTechnicianId(const std::string& assignedTechnicianId); - void setAssignedTechnician(const std::string& assignedTechnician); + void setAssignedTechnician(const User* assignedTechnician); void setDiscountPercentage(double discountPercentage); }; \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp index 047f471..ae45dd7 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp @@ -1,6 +1,12 @@ +#include #include "CustomerMenu.h" #include "InputHelper.h" #include "OutputHelper.h" +#include "Invoice.h" +#include "Service.h" +#include "ServiceBooking.h" +#include "User.h" +#include "InventoryItem.h" void CustomerMenu::showMenu() { @@ -59,8 +65,62 @@ void CustomerMenu::completePayments() { } +static void displayInvoices(util::Map currentUserInvoices) +{ + if (currentUserInvoices.getSize() == 0) + { + std::cout << "No invoices found for this account." << std::endl; + util::pressEnter(); + return; + } + else + { + for (int index = 0; index < currentUserInvoices.getSize(); index++) + { + const Invoice* currentInvoice = currentUserInvoices.getValueAt(index); + if (currentInvoice) + { + std::cout << "\nInvoice Details\n"; + std::cout << "Booking ID: " << currentInvoice->getBookingId() << std::endl; + std::cout << "Vehicle Brand: " << currentInvoice->getBooking()->getVehicleBrand() << std::endl; + std::cout << "Vehicle Number: " << currentInvoice->getBooking()->getVehicleNumber() << std::endl; + std::cout << "Technician ID: " << currentInvoice->getBooking()->getAssignedTechnician()->getId() << std::endl; + std::cout << "Technician Name: " << currentInvoice->getBooking()->getAssignedTechnician()->getName() << std::endl; + std::cout << "Discount(%): " << currentInvoice->getDiscountPercentage() << std::endl; + std::cout << "Total Amount: " << currentInvoice->getTotalAmount() << std::endl; + std::cout << "Invoice Date: " << currentInvoice->getInvoiceDate().toString() << std::endl; + std::cout << "Payment Status: " << util::getPaymentStatusString(currentInvoice->getStatus()) << std::endl; + auto inventoryItemsInInvoice = currentInvoice->getParts(); + std::cout << "\nItems Used:\n"; + std::cout << std::left + << std::setw(20) << "ItemName" + << std::setw(10) << "Quantity" + << std::setw(10) << "Price" + << std::endl; + std::cout << std::string(40, '-') << std::endl; + for (int iterator = 0; iterator < inventoryItemsInInvoice.getSize(); iterator++) + { + InventoryItem* currentItem = inventoryItemsInInvoice.getValueAt(iterator); + std::cout << std::left + << std::setw(20) << currentItem->getPartName() + << std::setw(10) << currentItem->getQuantity() + << std::setw(10) << currentItem->getPrice() + << std::endl; + } + } + else + { + throw std::runtime_error("Null invoice encountered while displaying invoices."); + } + } + } +} + void CustomerMenu::viewInvoices() { + util::clear(); + util::Map currentUserInvoices = m_controller.getInvoicesByUser(); + displayInvoices(currentUserInvoices); } void CustomerMenu::viewNotifications() From 61f70a54f6ae2a71288b6b4ea14806fd55ea260c Mon Sep 17 00:00:00 2001 From: Jissin Mathew Date: Wed, 20 May 2026 14:57:10 +0530 Subject: [PATCH 3/4] Implement Generate Invoice PAY001: Generate Invoice 1. Added Utility.h to project configuration for supporting invoice generation utilities. 2. Updated Invoice model to use string-based keys for parts mapping instead of integer keys. 3. Implemented PaymentManagementService::generateInvoice to aggregate labour cost, parts cost, and apply discounts. 4. Integrated invoice creation with Factory to instantiate Invoice objects and persist them into datastore. 5. Enhanced Enums with PaymentMode::NOTSET to handle default invoice state. Acceptance Criteria: 1. Invoice auto-generates for each service booking once jobs are completed. 2. Invoice shows a clear breakdown of charges including labour cost, parts cost, discount, and total amount. Precondition: 1. Service booking exists with at least one service and required inventory items. 2. Datastore is available for storing invoices. 3. Payment mode and status enums are properly configured. Steps: 1. Complete all jobs in a service booking. - Verify that PaymentManagementService::generateInvoice is triggered. 2. Check datastore for newly created invoice. - Verify that invoice contains booking ID, labour cost, parts cost, discount, and total amount. 3. Inspect invoice details. - Verify that breakdown of charges is accurate and discount is applied correctly. 4. Confirm invoice status. - Verify that invoice is created with PaymentMode::NOTSET and PaymentStatus::PENDING. Sreeja Reghukumar, please review --- .../Trenser.VehicleServiceSystem.vcxproj | 1 + ...enser.VehicleServiceSystem.vcxproj.filters | 3 + .../models/Invoice.cpp | 7 ++- .../models/Invoice.h | 10 ++-- .../models/JobCard.cpp | 8 +-- .../models/JobCard.h | 10 ++-- .../services/PaymentManagementService.cpp | 56 +++++++++++++++++++ .../utilities/Enums.h | 5 +- .../utilities/Utility.h | 15 +++++ 9 files changed, 97 insertions(+), 18 deletions(-) create mode 100644 Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Utility.h diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj index a65c46d..819264c 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj @@ -176,6 +176,7 @@ + diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj.filters b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj.filters index 77d0509..7c17f4e 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj.filters +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj.filters @@ -233,5 +233,8 @@ Header Files\Models + + Header Files\Utilities + \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/Invoice.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/Invoice.cpp index ba7bc84..507f274 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/Invoice.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/Invoice.cpp @@ -16,7 +16,8 @@ Invoice::Invoice( const std::string& bookingId, ServiceBooking* booking, const util::Timestamp& invoiceDate, - double laborCost, const util::Map& parts, double partsCost, double discountPercentage, @@ -63,7 +64,7 @@ double Invoice::getLaborCost() const return m_laborCost; } -const util::Map& Invoice::getParts() const +const util::Map& Invoice::getParts() const { return m_parts; } @@ -123,7 +124,7 @@ void Invoice::setLaborCost(double laborCost) m_laborCost = laborCost; } -void Invoice::setParts(const util::Map& parts) +void Invoice::setParts(const util::Map& parts) { m_parts = parts; } diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/Invoice.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/Invoice.h index 212d33f..f78f7c9 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/Invoice.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/Invoice.h @@ -16,7 +16,7 @@ private: ServiceBooking* m_booking; util::Timestamp m_invoiceDate; double m_laborCost; - util::Map m_parts; + util::Map m_parts; double m_partsCost; double m_discountPercentage; double m_totalAmount; @@ -30,8 +30,8 @@ public: const std::string& bookingId, ServiceBooking* booking, const util::Timestamp& invoiceDate, - double laborCost, const util::Map& parts, + double laborCost, + const util::Map& parts, double partsCost, double discountPercentage, double totalAmount, @@ -44,7 +44,7 @@ public: ServiceBooking* getBooking() const; const util::Timestamp& getInvoiceDate() const; double getLaborCost() const; - const util::Map& getParts() const; + const util::Map& getParts() const; double getPartsCost() const; double getDiscountPercentage() const; double getTotalAmount() const; @@ -56,7 +56,7 @@ public: void setBooking(ServiceBooking* booking); void setInvoiceDate(const util::Timestamp& invoiceDate); void setLaborCost(double laborCost); - void setParts(const util::Map& parts); + void setParts(const util::Map& parts); void setPartsCost(double partsCost); void setDiscountPercentage(double discountPercentage); void setTotalAmount(double totalAmount); diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/JobCard.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/JobCard.cpp index 04e9195..b9f1eee 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/JobCard.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/JobCard.cpp @@ -7,7 +7,7 @@ JobCard::JobCard() m_booking(nullptr), m_service(nullptr), m_technician(nullptr), - m_status(ServiceJobStatus()) {} + m_status(util::ServiceJobStatus()) {} JobCard::JobCard(const std::string& bookingId, ServiceBooking* booking, @@ -16,7 +16,7 @@ JobCard::JobCard(const std::string& bookingId, const std::string& technicianId, User* technician, const util::Timestamp& assignedDate, - ServiceJobStatus status, + util::ServiceJobStatus status, const util::Timestamp& completionDate ) : m_id("JC" + std::to_string(++m_uid)), @@ -70,7 +70,7 @@ const util::Timestamp& JobCard::getAssignedDate() const return m_assignedDate; } -ServiceJobStatus JobCard::getStatus() const +util::ServiceJobStatus JobCard::getStatus() const { return m_status; } @@ -120,7 +120,7 @@ void JobCard::setAssignedDate(const util::Timestamp& assignedDate) m_assignedDate = assignedDate; } -void JobCard::setStatus(ServiceJobStatus status) +void JobCard::setStatus(util::ServiceJobStatus status) { m_status = status; } diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/JobCard.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/JobCard.h index 15a8a5d..880767a 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/JobCard.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/models/JobCard.h @@ -1,12 +1,12 @@ #pragma once #include +#include "Enums.h" #include "Timestamp.h" class ServiceBooking; class Service; class User; -enum class ServiceJobStatus : int; class JobCard { @@ -20,7 +20,7 @@ private: std::string m_technicianId; User* m_technician; util::Timestamp m_assignedDate; - ServiceJobStatus m_status; + util::ServiceJobStatus m_status; util::Timestamp m_completionDate; public: @@ -32,7 +32,7 @@ public: const std::string& technicianId, User* technician, const util::Timestamp& assignedDate, - ServiceJobStatus status, + util::ServiceJobStatus status, const util::Timestamp& completionDate ); const std::string& getId() const; @@ -43,7 +43,7 @@ public: const std::string& getTechnicianId() const; User* getTechnician() const; const util::Timestamp& getAssignedDate() const; - ServiceJobStatus getStatus() const; + util::ServiceJobStatus getStatus() const; const util::Timestamp& getCompletionDate() const; void setId(const std::string& id); void setBookingId(const std::string& bookingId); @@ -53,6 +53,6 @@ public: void setTechnicianId(const std::string& technicianId); void setTechnician(User* technician); void setAssignedDate(const util::Timestamp& assignedDate); - void setStatus(ServiceJobStatus status); + void setStatus(util::ServiceJobStatus status); void setCompletionDate(const util::Timestamp& completionDate); }; \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp index 786ebcf..8f391c5 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp @@ -1 +1,57 @@ #include "PaymentManagementService.h" +#include "ServiceBooking.h" +#include "Service.h" +#include "InventoryItem.h" +#include "Utility.h" +#include "Factory.h" +#include "Timestamp.h" +#include "Invoice.h" +#include "JobCard.h" +#include "Enums.h" + +static void createInventoryItemsMap(util::Map& completeInventoryItemMapOfBooking, const Service* currentService) +{ + auto& currentRequiredInventoryItems = currentService->getRequiredInventoryItems(); + for (int iterator = 0; iterator < currentRequiredInventoryItems.getSize(); iterator++) + { + auto& currentRequiredInventoryItem = currentRequiredInventoryItems.getValueAt(iterator); + completeInventoryItemMapOfBooking.insert(currentRequiredInventoryItem->getId(), currentRequiredInventoryItem); + } +} + +void PaymentManagementService::generateInvoice(ServiceBooking* booking) +{ + if (!booking) + { + throw std::runtime_error("Invoice generation failed: booking is null."); + } + double totalLabourCost = 0, totalPartsCost = 0, totalServiceCost = 0; + double discountPercentage = booking->getDiscountPercentage(); + std::string bookingID = booking->getId(); + util::Map servicesInTheBookedService = booking->getServices(); + util::Map completeInventoryItemMapOfBooking; + util::Map currentJobCards = m_dataStore.getJobCards(); + for (int iterator = 0; iterator < currentJobCards.getSize(); iterator++) + { + JobCard* currentJobCard = currentJobCards.getValueAt(iterator); + if (currentJobCard->getBookingId() == bookingID && currentJobCard->getStatus() != util::ServiceJobStatus::COMPLETED) + { + throw std::runtime_error("Invoice generation failed: not all job cards are completed for booking '" + bookingID + "'."); + } + } + for (int iterator = 0; iterator < servicesInTheBookedService.getSize(); iterator++) + { + Service* currentService = servicesInTheBookedService.getValueAt(iterator); + if (currentService) + { + createInventoryItemsMap(completeInventoryItemMapOfBooking, currentService); + totalLabourCost += currentService->getLaborCost(); + totalPartsCost += calculatePartsCost(currentService); + } + } + totalServiceCost = totalLabourCost + totalPartsCost; + totalServiceCost -= (totalServiceCost * (discountPercentage / 100)); + Invoice* invoice = Factory::getObject(bookingID, booking, util::Timestamp(), totalLabourCost, completeInventoryItemMapOfBooking, totalPartsCost, discountPercentage, totalServiceCost, util::Timestamp(), util::PaymentMode::NOTSET, util::PaymentStatus::PENDING); + util::Map& currentInvoices = m_dataStore.getInvoices(); + currentInvoices.insert(invoice->getId(), invoice); +} \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Enums.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Enums.h index 24bbdcd..5b615b5 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Enums.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Enums.h @@ -13,7 +13,8 @@ namespace util enum class PaymentMode { ONLINE, - OFFLINE + OFFLINE, + NOTSET }; enum class PaymentStatus @@ -73,6 +74,8 @@ namespace util return "ONLINE"; case PaymentMode::OFFLINE: return "OFFLINE"; + case PaymentMode::NOTSET: + return "NOTSET"; } throw std::invalid_argument("Invalid PaymentMode"); } diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Utility.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Utility.h new file mode 100644 index 0000000..cb9b990 --- /dev/null +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Utility.h @@ -0,0 +1,15 @@ +#pragma once +#include "Service.h" +#include "InventoryItem.h" + +inline double calculatePartsCost(const Service* service) +{ + double cost = 0; + auto& requiredInventoryItems = service->getRequiredInventoryItems(); + int requiredInventoryItemsSize = requiredInventoryItems.getSize(); + for (int index = 0; index < requiredInventoryItemsSize; index++) + { + cost += requiredInventoryItems.getValueAt(index)->getPrice(); + } + return cost; +} \ No newline at end of file From f1d146a37c645add49b3862fb8c9c161c1eeb1fe Mon Sep 17 00:00:00 2001 From: Jissin Mathew Date: Fri, 22 May 2026 13:21:51 +0530 Subject: [PATCH 4/4] Add documentation headers across system modules --- .../controllers/Controller.cpp | 21 ++++++++- .../services/PaymentManagementService.cpp | 41 +++++++++++++++++ .../views/CustomerMenu.cpp | 44 +++++++++++++++++++ 3 files changed, 104 insertions(+), 2 deletions(-) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp index 97a2b90..91f72fc 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp @@ -121,6 +121,15 @@ void Controller::removeComboPackage(const std::string& comboPackageID) { } +/* +Function: getInvoicesByUser +Description: Retrieves all invoices associated with the currently authenticated user. + Converts them into a read-only map before returning. +Parameters: + - None +Returns: + - util::Map containing the user’s invoices +*/ util::Map Controller::getInvoicesByUser() { User* currentUser = m_authenticationManagementService.getAuthenticatedUser(); @@ -134,6 +143,15 @@ util::Map Controller::getInvoicesByUser() return userInvoicesReadOnly; } +/* +Function: completePayment +Description: Completes payment for a specific invoice using the given payment mode. +Parameters: + - invoiceID: std::string, ID of the invoice to be paid + - paymentMode: util::PaymentMode, mode of payment (e.g., ONLINE, OFFLINE) +Returns: + - void +*/ void Controller::completePayment(const std::string& invoiceID, util::PaymentMode paymentMode) { m_paymentManagementService.completePayment(invoiceID, paymentMode); @@ -154,5 +172,4 @@ void Controller::configureNotifications(const std::string& userID, bool paymentN void Controller::runSystemChecks() { -} - +} \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp index 094e104..8b67c7d 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/PaymentManagementService.cpp @@ -9,6 +9,15 @@ #include "JobCard.h" #include "Enums.h" +/* +Function: createInventoryItemsMap (static helper) +Description: Builds a map of inventory items required for a given service and adds them to the booking’s inventory map. +Parameters: + - completeInventoryItemMapOfBooking: util::Map&, map to store inventory items for the booking + - currentService: const Service*, pointer to the current service +Returns: + - void +*/ static void createInventoryItemsMap(util::Map& completeInventoryItemMapOfBooking, const Service* currentService) { auto& currentRequiredInventoryItems = currentService->getRequiredInventoryItems(); @@ -19,6 +28,18 @@ static void createInventoryItemsMap(util::Map& comp } } +/* +Function: generateInvoice +Description: Generates an invoice for a completed service booking. + Validates that all job cards are completed, calculates labor and parts cost, applies discount, + and stores the invoice in the datastore. +Parameters: + - booking: ServiceBooking*, pointer to the service booking +Returns: + - void +Throws: + - std::runtime_error if booking is null or job cards are incomplete +*/ void PaymentManagementService::generateInvoice(ServiceBooking* booking) { if (!booking) @@ -56,6 +77,14 @@ void PaymentManagementService::generateInvoice(ServiceBooking* booking) currentInvoices.insert(invoice->getId(), invoice); } +/* +Function: getInvoices +Description: Retrieves all invoices associated with a specific customer. +Parameters: + - customerID: std::string, ID of the customer +Returns: + - util::Map containing the customer’s invoices +*/ util::Map PaymentManagementService::getInvoices(const std::string& customerID) { util::Map& currentInvoices = m_dataStore.getInvoices(); @@ -71,6 +100,18 @@ util::Map PaymentManagementService::getInvoices(const std return currentUserInvoices; } +/* +Function: completePayment +Description: Completes payment for a specific invoice. Updates payment method, date, and status, + then sends a notification to the customer. +Parameters: + - invoiceID: std::string, ID of the invoice + - paymentMode: util::PaymentMode, mode of payment (e.g., ONLINE, OFFLINE) +Returns: + - void +Throws: + - std::runtime_error if the invoice ID is invalid +*/ void PaymentManagementService::completePayment(const std::string& invoiceID, util::PaymentMode paymentMode) { auto& currentInvoices = m_dataStore.getInvoices(); diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp index a9f4d21..9f1d696 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/CustomerMenu.cpp @@ -64,6 +64,14 @@ void CustomerMenu::viewServiceHistory() { } +/* +Function: selectInvoiceFromUserForPayment (static helper) +Description: Lists all pending invoices for the customer and allows selection by index. +Parameters: + - currentInvoices: util::Map&, map of customer invoices +Returns: + - std::string: ID of the selected invoice, or empty string if none selected +*/ static std::string selectInvoiceFromUserForPayment(const util::Map& currentInvoices) { int currentIndex = 1, choice; @@ -118,6 +126,14 @@ static std::string selectInvoiceFromUserForPayment(const util::Map, customer’s invoices +Returns: + - void +Throws: + - std::runtime_error if a null invoice is encountered +*/ static void displayInvoices(util::Map currentUserInvoices) { if (currentUserInvoices.getSize() == 0) @@ -206,6 +242,14 @@ static void displayInvoices(util::Map currentUserIn } } +/* +Function: viewInvoices +Description: Displays invoices associated with the customer by calling displayInvoices. +Parameters: + - None +Returns: + - void +*/ void CustomerMenu::viewInvoices() { util::clear();