Implement View Invoices for Customer
<UserStory> PAY003: View Invoices </UserStory>
<Changes>
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.
</Changes>
<Test>
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.
</Test>
<Review>
Sreeja Reghukumar, please review
</Review>
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
};
|
||||
@@ -1,6 +1,12 @@
|
||||
#include <iomanip>
|
||||
#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<std::string, const Invoice*> 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<std::string, const Invoice*> currentUserInvoices = m_controller.getInvoicesByUser();
|
||||
displayInvoices(currentUserInvoices);
|
||||
}
|
||||
|
||||
void CustomerMenu::viewNotifications()
|
||||
|
||||
Reference in New Issue
Block a user