Files
Jissin Mathew 61f70a54f6 Implement Generate Invoice
<UserStory> PAY001: Generate Invoice </UserStory>

<Changes>
    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.
</Changes>

<Test>

 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.
</Test>

<Review>
Sreeja Reghukumar, please review
</Review>
2026-05-21 16:05:10 +05:30

161 lines
3.0 KiB
C++

#include "Invoice.h"
int Invoice::m_uid = 0;
Invoice::Invoice()
: m_id("INV" + std::to_string(++m_uid)),
m_booking(nullptr),
m_laborCost(0.0),
m_partsCost(0.0),
m_discountPercentage(0.0),
m_totalAmount(0.0),
m_paymentMethod(util::PaymentMode()),
m_status(util::PaymentStatus()) {}
Invoice::Invoice(
const std::string& bookingId,
ServiceBooking* booking,
const util::Timestamp& invoiceDate,
double laborCost,
const util::Map<std::string,
InventoryItem*>& parts,
double partsCost,
double discountPercentage,
double totalAmount,
const util::Timestamp& paymentDate,
util::PaymentMode paymentMethod,
util::PaymentStatus status
)
: m_id("INV" + std::to_string(++m_uid)),
m_bookingId(bookingId),
m_booking(booking),
m_invoiceDate(invoiceDate),
m_laborCost(laborCost),
m_parts(parts),
m_partsCost(partsCost),
m_discountPercentage(discountPercentage),
m_totalAmount(totalAmount),
m_paymentDate(paymentDate),
m_paymentMethod(paymentMethod),
m_status(status) {}
const std::string& Invoice::getId() const
{
return m_id;
}
const std::string& Invoice::getBookingId() const
{
return m_bookingId;
}
ServiceBooking* Invoice::getBooking() const
{
return m_booking;
}
const util::Timestamp& Invoice::getInvoiceDate() const
{
return m_invoiceDate;
}
double Invoice::getLaborCost() const
{
return m_laborCost;
}
const util::Map<std::string, InventoryItem*>& Invoice::getParts() const
{
return m_parts;
}
double Invoice::getPartsCost() const
{
return m_partsCost;
}
double Invoice::getDiscountPercentage() const
{
return m_discountPercentage;
}
double Invoice::getTotalAmount() const
{
return m_totalAmount;
}
const util::Timestamp& Invoice::getPaymentDate() const
{
return m_paymentDate;
}
util::PaymentMode Invoice::getPaymentMethod() const
{
return m_paymentMethod;
}
util::PaymentStatus Invoice::getStatus() const
{
return m_status;
}
void Invoice::setId(const std::string& id)
{
m_id = id;
}
void Invoice::setBookingId(const std::string& bookingId)
{
m_bookingId = bookingId;
}
void Invoice::setBooking(ServiceBooking* booking)
{
m_booking = booking;
}
void Invoice::setInvoiceDate(const util::Timestamp& invoiceDate)
{
m_invoiceDate = invoiceDate;
}
void Invoice::setLaborCost(double laborCost)
{
m_laborCost = laborCost;
}
void Invoice::setParts(const util::Map<std::string, InventoryItem*>& parts)
{
m_parts = parts;
}
void Invoice::setPartsCost(double partsCost)
{
m_partsCost = partsCost;
}
void Invoice::setDiscountPercentage(double discountPercentage)
{
m_discountPercentage = discountPercentage;
}
void Invoice::setTotalAmount(double totalAmount)
{
m_totalAmount = totalAmount;
}
void Invoice::setPaymentDate(const util::Timestamp& paymentDate)
{
m_paymentDate = paymentDate;
}
void Invoice::setPaymentMethod(util::PaymentMode paymentMethod)
{
m_paymentMethod = paymentMethod;
}
void Invoice::setStatus(util::PaymentStatus status)
{
m_status = status;
}