Compare commits
6 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| f1d146a37c | |||
| a3ad4d2e00 | |||
| 4a4309d585 | |||
| 61f70a54f6 | |||
| 461857f971 | |||
| cb3bed4050 |
+1
@@ -176,6 +176,7 @@
|
|||||||
<ClInclude Include="utilities\Map.h" />
|
<ClInclude Include="utilities\Map.h" />
|
||||||
<ClInclude Include="utilities\OutputHelper.h" />
|
<ClInclude Include="utilities\OutputHelper.h" />
|
||||||
<ClInclude Include="utilities\Timestamp.h" />
|
<ClInclude Include="utilities\Timestamp.h" />
|
||||||
|
<ClInclude Include="utilities\Utility.h" />
|
||||||
<ClInclude Include="utilities\Validator.h" />
|
<ClInclude Include="utilities\Validator.h" />
|
||||||
<ClInclude Include="utilities\Vector.h" />
|
<ClInclude Include="utilities\Vector.h" />
|
||||||
<ClInclude Include="views\AdminMenu.h" />
|
<ClInclude Include="views\AdminMenu.h" />
|
||||||
|
|||||||
+3
@@ -233,5 +233,8 @@
|
|||||||
<ClInclude Include="models\ComboPackage.h">
|
<ClInclude Include="models\ComboPackage.h">
|
||||||
<Filter>Header Files\Models</Filter>
|
<Filter>Header Files\Models</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="utilities\Utility.h">
|
||||||
|
<Filter>Header Files\Utilities</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
+36
-125
@@ -1,8 +1,6 @@
|
|||||||
#include "Controller.h"
|
#include "Controller.h"
|
||||||
#include "InventoryItem.h"
|
#include "User.h"
|
||||||
#include "Service.h"
|
#include "Invoice.h"
|
||||||
#include "ServiceBooking.h"
|
|
||||||
#include "JobCard.h"
|
|
||||||
|
|
||||||
bool Controller::login(const std::string& username, const std::string& password)
|
bool Controller::login(const std::string& username, const std::string& password)
|
||||||
{
|
{
|
||||||
@@ -34,23 +32,9 @@ void Controller::updateUserDetails(const std::string& email, const std::string&
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getServices
|
|
||||||
Description: Retrieves all available services in read-only form.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- util::Map<std::string, const Service*> containing all services
|
|
||||||
*/
|
|
||||||
util::Map<std::string, const Service*> Controller::getServices()
|
util::Map<std::string, const Service*> Controller::getServices()
|
||||||
{
|
{
|
||||||
util::Map<std::string, Service*> currentServices = m_serviceManagementService.getServices();
|
return util::Map<std::string, const Service*>();
|
||||||
util::Map<std::string, const Service*> readOnlyServices;
|
|
||||||
for (int iterator = 0; iterator < currentServices.getSize(); iterator++)
|
|
||||||
{
|
|
||||||
readOnlyServices.insert(currentServices.getValueAt(iterator)->getId(), currentServices.getValueAt(iterator));
|
|
||||||
}
|
|
||||||
return readOnlyServices;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
util::Map<std::string, const ComboPackage*> Controller::getComboPackages()
|
util::Map<std::string, const ComboPackage*> Controller::getComboPackages()
|
||||||
@@ -68,8 +52,7 @@ void Controller::purchaseComboPackage(const std::string& comboPackageID, const s
|
|||||||
|
|
||||||
util::Map<std::string, const InventoryItem*> Controller::getInventoryItems()
|
util::Map<std::string, const InventoryItem*> Controller::getInventoryItems()
|
||||||
{
|
{
|
||||||
util::Map<std::string, const InventoryItem*> dummyMap;
|
return util::Map<std::string, const InventoryItem*>();
|
||||||
return dummyMap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const InventoryItem* Controller::getInventoryItem(const std::string& inventoryItemID)
|
const InventoryItem* Controller::getInventoryItem(const std::string& inventoryItemID)
|
||||||
@@ -85,42 +68,14 @@ void Controller::removeInventoryItem(const std::string& inventoryItemID)
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getServiceBookings
|
|
||||||
Description: Retrieves all service bookings in read-only form.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- util::Map<std::string, const ServiceBooking*> containing service bookings
|
|
||||||
*/
|
|
||||||
util::Map<std::string, const ServiceBooking*> Controller::getServiceBookings()
|
util::Map<std::string, const ServiceBooking*> Controller::getServiceBookings()
|
||||||
{
|
{
|
||||||
auto serviceBookings = m_serviceManagementService.getServiceBookings();
|
return util::Map<std::string, const ServiceBooking*>();
|
||||||
util::Map<std::string, const ServiceBooking*> readOnlyServiceBookings;
|
|
||||||
for (int iterator = 0; iterator < serviceBookings.getSize(); iterator++)
|
|
||||||
{
|
|
||||||
readOnlyServiceBookings.insert(serviceBookings.getKeyAt(iterator), serviceBookings.getValueAt(iterator));
|
|
||||||
}
|
|
||||||
return readOnlyServiceBookings;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getServiceBookingsByUser
|
|
||||||
Description: Retrieves all service bookings for a specific user.
|
|
||||||
Parameters:
|
|
||||||
- userID: std::string, the user ID
|
|
||||||
Returns:
|
|
||||||
- util::Map<std::string, const ServiceBooking*> containing bookings for the user
|
|
||||||
*/
|
|
||||||
util::Map<std::string, const ServiceBooking*> Controller::getServiceBookingsByUser(const std::string userID)
|
util::Map<std::string, const ServiceBooking*> Controller::getServiceBookingsByUser(const std::string userID)
|
||||||
{
|
{
|
||||||
util::Map<std::string, const ServiceBooking*> readOnlyServiceBookingsByUserMap;
|
return util::Map<std::string, const ServiceBooking*>();
|
||||||
util::Map<std::string, ServiceBooking*> currentServiceBookingsByUser = m_serviceManagementService.getServiceBookings(userID);
|
|
||||||
for (int iterator = 0; iterator < currentServiceBookingsByUser.getSize(); iterator++)
|
|
||||||
{
|
|
||||||
readOnlyServiceBookingsByUserMap.insert(currentServiceBookingsByUser.getValueAt(iterator)->getId(), currentServiceBookingsByUser.getValueAt(iterator));
|
|
||||||
}
|
|
||||||
return readOnlyServiceBookingsByUserMap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
util::Map<std::string, const User*> Controller::getUsers()
|
util::Map<std::string, const User*> Controller::getUsers()
|
||||||
@@ -128,100 +83,30 @@ util::Map<std::string, const User*> Controller::getUsers()
|
|||||||
return util::Map<std::string, const User*>();
|
return util::Map<std::string, const User*>();
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getUsers
|
|
||||||
Description: Retrieves users filtered by user type.
|
|
||||||
Parameters:
|
|
||||||
- userType: util::UserType, type of user (CUSTOMER, TECHNICIAN, ADMIN)
|
|
||||||
Returns:
|
|
||||||
- util::Map<std::string, const User*> containing users of the specified type
|
|
||||||
*/
|
|
||||||
util::Map<std::string, const User*> Controller::getUsers(util::UserType userType)
|
util::Map<std::string, const User*> Controller::getUsers(util::UserType userType)
|
||||||
{
|
{
|
||||||
auto userMap = m_userManagementService.getUsers(userType);
|
return util::Map<std::string, const User*>();
|
||||||
util::Map<std::string, const User*> readOnlyUserMap;
|
|
||||||
for (int iterator = 0; iterator < userMap.getSize(); iterator++)
|
|
||||||
{
|
|
||||||
readOnlyUserMap.insert(userMap.getKeyAt(iterator), userMap.getValueAt(iterator));
|
|
||||||
}
|
|
||||||
return readOnlyUserMap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Function: createJobCard
|
|
||||||
Description: Creates a job card for a service booking assigned to a technician.
|
|
||||||
Parameters:
|
|
||||||
- bookingID: std::string, ID of the service booking
|
|
||||||
- technicianID: std::string, ID of the technician
|
|
||||||
- serviceID: std::string, ID of the service
|
|
||||||
Returns:
|
|
||||||
- void
|
|
||||||
*/
|
|
||||||
void Controller::createJobCard(const std::string& bookingID, const std::string& technicianID, const std::string& serviceID)
|
void Controller::createJobCard(const std::string& bookingID, const std::string& technicianID, const std::string& serviceID)
|
||||||
{
|
{
|
||||||
m_serviceManagementService.createJobCard(bookingID, technicianID, serviceID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Function: createService
|
|
||||||
Description: Creates a new service with associated inventory items and labor cost.
|
|
||||||
Parameters:
|
|
||||||
- name: std::string, name of the service
|
|
||||||
- inventoryItemIDs: Vector of inventory item IDs
|
|
||||||
- laborCost: double, labor cost
|
|
||||||
Returns:
|
|
||||||
- void
|
|
||||||
*/
|
|
||||||
void Controller::createService(const std::string& name, const util::Vector<std::string>& inventoryItemIDs, double laborCost)
|
void Controller::createService(const std::string& name, const util::Vector<std::string>& inventoryItemIDs, double laborCost)
|
||||||
{
|
{
|
||||||
m_serviceManagementService.createService(name, inventoryItemIDs, laborCost);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Function: removeService
|
|
||||||
Description: Removes a service from the system by ID.
|
|
||||||
Parameters:
|
|
||||||
- serviceID: std::string, ID of the service
|
|
||||||
Returns:
|
|
||||||
- void
|
|
||||||
*/
|
|
||||||
void Controller::removeService(const std::string& serviceID)
|
void Controller::removeService(const std::string& serviceID)
|
||||||
{
|
{
|
||||||
m_serviceManagementService.removeService(serviceID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getJobCardsByUser
|
|
||||||
Description: Retrieves job cards assigned to the authenticated technician.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- util::Map<std::string, const JobCard*> containing job cards
|
|
||||||
*/
|
|
||||||
util::Map<std::string, const JobCard*> Controller::getJobCardsByUser()
|
util::Map<std::string, const JobCard*> Controller::getJobCardsByUser()
|
||||||
{
|
{
|
||||||
const User* currentUser = getAuthenticatedUser();
|
return util::Map<std::string, const JobCard*>();
|
||||||
auto jobCardsAssignedToTechnician = m_serviceManagementService.getJobCards(currentUser->getId());
|
|
||||||
util::Map<std::string, const JobCard*> readOnlyJobCardMap;
|
|
||||||
for (int iterator = 0; iterator < jobCardsAssignedToTechnician.getSize(); iterator++)
|
|
||||||
{
|
|
||||||
JobCard* currentJobCard = jobCardsAssignedToTechnician.getValueAt(iterator);
|
|
||||||
readOnlyJobCardMap.insert(currentJobCard->getId(), currentJobCard);
|
|
||||||
}
|
|
||||||
return readOnlyJobCardMap;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Function: completeJob
|
|
||||||
Description: Marks a job card as completed.
|
|
||||||
Parameters:
|
|
||||||
- jobID: std::string, ID of the job card
|
|
||||||
Returns:
|
|
||||||
- void
|
|
||||||
*/
|
|
||||||
void Controller::completeJob(const std::string& jobID)
|
void Controller::completeJob(const std::string& jobID)
|
||||||
{
|
{
|
||||||
m_serviceManagementService.completeJob(jobID);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void Controller::removeUser(const std::string& userID)
|
void Controller::removeUser(const std::string& userID)
|
||||||
@@ -236,13 +121,40 @@ 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<std::string, const Invoice*> containing the user’s invoices
|
||||||
|
*/
|
||||||
util::Map<std::string, const Invoice*> Controller::getInvoicesByUser()
|
util::Map<std::string, const Invoice*> Controller::getInvoicesByUser()
|
||||||
{
|
{
|
||||||
return util::Map<std::string, const Invoice*>();
|
User* currentUser = m_authenticationManagementService.getAuthenticatedUser();
|
||||||
|
util::Map<std::string, Invoice*> currentUserInvoices = m_paymentManagementService.getInvoices(currentUser->getId());
|
||||||
|
util::Map<std::string, const Invoice*> userInvoicesReadOnly;
|
||||||
|
for (int iterator = 0; iterator < currentUserInvoices.getSize(); iterator++)
|
||||||
|
{
|
||||||
|
Invoice* currentInvoice = currentUserInvoices.getValueAt(iterator);
|
||||||
|
userInvoicesReadOnly.insert(currentInvoice->getId(), currentInvoice);
|
||||||
|
}
|
||||||
|
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)
|
void Controller::completePayment(const std::string& invoiceID, util::PaymentMode paymentMode)
|
||||||
{
|
{
|
||||||
|
m_paymentManagementService.completePayment(invoiceID, paymentMode);
|
||||||
}
|
}
|
||||||
|
|
||||||
util::Vector<const Notification*> Controller::getNotifications()
|
util::Vector<const Notification*> Controller::getNotifications()
|
||||||
@@ -261,4 +173,3 @@ void Controller::configureNotifications(const std::string& userID, bool paymentN
|
|||||||
void Controller::runSystemChecks()
|
void Controller::runSystemChecks()
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -2,9 +2,8 @@
|
|||||||
#include "Map.h"
|
#include "Map.h"
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
#include "ServiceManagementService.h"
|
#include "PaymentManagementService.h"
|
||||||
#include "UserManagementService.h"
|
#include "AuthenticationManagementService.h"
|
||||||
#include "InventoryManagementService.h"
|
|
||||||
|
|
||||||
class Service;
|
class Service;
|
||||||
class ComboPackage;
|
class ComboPackage;
|
||||||
@@ -18,8 +17,8 @@ class Notification;
|
|||||||
class Controller
|
class Controller
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
ServiceManagementService m_serviceManagementService;
|
AuthenticationManagementService m_authenticationManagementService;
|
||||||
UserManagementService m_userManagementService;
|
PaymentManagementService m_paymentManagementService;
|
||||||
public:
|
public:
|
||||||
bool login(const std::string& username, const std::string& password);
|
bool login(const std::string& username, const std::string& password);
|
||||||
void logout();
|
void logout();
|
||||||
|
|||||||
@@ -16,7 +16,8 @@ Invoice::Invoice(
|
|||||||
const std::string& bookingId,
|
const std::string& bookingId,
|
||||||
ServiceBooking* booking,
|
ServiceBooking* booking,
|
||||||
const util::Timestamp& invoiceDate,
|
const util::Timestamp& invoiceDate,
|
||||||
double laborCost, const util::Map<int,
|
double laborCost,
|
||||||
|
const util::Map<std::string,
|
||||||
InventoryItem*>& parts,
|
InventoryItem*>& parts,
|
||||||
double partsCost,
|
double partsCost,
|
||||||
double discountPercentage,
|
double discountPercentage,
|
||||||
@@ -63,7 +64,7 @@ double Invoice::getLaborCost() const
|
|||||||
return m_laborCost;
|
return m_laborCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
const util::Map<int, InventoryItem*>& Invoice::getParts() const
|
const util::Map<std::string, InventoryItem*>& Invoice::getParts() const
|
||||||
{
|
{
|
||||||
return m_parts;
|
return m_parts;
|
||||||
}
|
}
|
||||||
@@ -123,7 +124,7 @@ void Invoice::setLaborCost(double laborCost)
|
|||||||
m_laborCost = laborCost;
|
m_laborCost = laborCost;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Invoice::setParts(const util::Map<int, InventoryItem*>& parts)
|
void Invoice::setParts(const util::Map<std::string, InventoryItem*>& parts)
|
||||||
{
|
{
|
||||||
m_parts = parts;
|
m_parts = parts;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -16,7 +16,7 @@ private:
|
|||||||
ServiceBooking* m_booking;
|
ServiceBooking* m_booking;
|
||||||
util::Timestamp m_invoiceDate;
|
util::Timestamp m_invoiceDate;
|
||||||
double m_laborCost;
|
double m_laborCost;
|
||||||
util::Map<int, InventoryItem*> m_parts;
|
util::Map<std::string, InventoryItem*> m_parts;
|
||||||
double m_partsCost;
|
double m_partsCost;
|
||||||
double m_discountPercentage;
|
double m_discountPercentage;
|
||||||
double m_totalAmount;
|
double m_totalAmount;
|
||||||
@@ -30,8 +30,8 @@ public:
|
|||||||
const std::string& bookingId,
|
const std::string& bookingId,
|
||||||
ServiceBooking* booking,
|
ServiceBooking* booking,
|
||||||
const util::Timestamp& invoiceDate,
|
const util::Timestamp& invoiceDate,
|
||||||
double laborCost, const util::Map<int,
|
double laborCost,
|
||||||
InventoryItem*>& parts,
|
const util::Map<std::string,InventoryItem*>& parts,
|
||||||
double partsCost,
|
double partsCost,
|
||||||
double discountPercentage,
|
double discountPercentage,
|
||||||
double totalAmount,
|
double totalAmount,
|
||||||
@@ -44,7 +44,7 @@ public:
|
|||||||
ServiceBooking* getBooking() const;
|
ServiceBooking* getBooking() const;
|
||||||
const util::Timestamp& getInvoiceDate() const;
|
const util::Timestamp& getInvoiceDate() const;
|
||||||
double getLaborCost() const;
|
double getLaborCost() const;
|
||||||
const util::Map<int, InventoryItem*>& getParts() const;
|
const util::Map<std::string, InventoryItem*>& getParts() const;
|
||||||
double getPartsCost() const;
|
double getPartsCost() const;
|
||||||
double getDiscountPercentage() const;
|
double getDiscountPercentage() const;
|
||||||
double getTotalAmount() const;
|
double getTotalAmount() const;
|
||||||
@@ -56,7 +56,7 @@ public:
|
|||||||
void setBooking(ServiceBooking* booking);
|
void setBooking(ServiceBooking* booking);
|
||||||
void setInvoiceDate(const util::Timestamp& invoiceDate);
|
void setInvoiceDate(const util::Timestamp& invoiceDate);
|
||||||
void setLaborCost(double laborCost);
|
void setLaborCost(double laborCost);
|
||||||
void setParts(const util::Map<int, InventoryItem*>& parts);
|
void setParts(const util::Map<std::string, InventoryItem*>& parts);
|
||||||
void setPartsCost(double partsCost);
|
void setPartsCost(double partsCost);
|
||||||
void setDiscountPercentage(double discountPercentage);
|
void setDiscountPercentage(double discountPercentage);
|
||||||
void setTotalAmount(double totalAmount);
|
void setTotalAmount(double totalAmount);
|
||||||
|
|||||||
@@ -1,12 +1,13 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
#include <string>
|
#include <string>
|
||||||
#include "Timestamp.h"
|
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
|
#include "Timestamp.h"
|
||||||
|
|
||||||
class ServiceBooking;
|
class ServiceBooking;
|
||||||
class Service;
|
class Service;
|
||||||
class User;
|
class User;
|
||||||
|
|
||||||
|
|
||||||
class JobCard
|
class JobCard
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
|
|||||||
+134
@@ -1 +1,135 @@
|
|||||||
#include "PaymentManagementService.h"
|
#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"
|
||||||
|
|
||||||
|
/*
|
||||||
|
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<std::string, InventoryItem*>&, map to store inventory items for the booking
|
||||||
|
- currentService: const Service*, pointer to the current service
|
||||||
|
Returns:
|
||||||
|
- void
|
||||||
|
*/
|
||||||
|
static void createInventoryItemsMap(util::Map<std::string, InventoryItem*>& 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);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
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<std::string, Service*> servicesInTheBookedService = booking->getServices();
|
||||||
|
util::Map<std::string, InventoryItem*> completeInventoryItemMapOfBooking;
|
||||||
|
util::Map<std::string, JobCard*> 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<Invoice>(bookingID, booking, util::Timestamp(), totalLabourCost, completeInventoryItemMapOfBooking, totalPartsCost, discountPercentage, totalServiceCost, util::Timestamp(), util::PaymentMode::NOTSET, util::PaymentStatus::PENDING);
|
||||||
|
util::Map<std::string, Invoice*>& currentInvoices = m_dataStore.getInvoices();
|
||||||
|
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<std::string, Invoice*> containing the customer’s invoices
|
||||||
|
*/
|
||||||
|
util::Map<std::string, Invoice*> PaymentManagementService::getInvoices(const std::string& customerID)
|
||||||
|
{
|
||||||
|
util::Map<std::string, Invoice*>& currentInvoices = m_dataStore.getInvoices();
|
||||||
|
util::Map<std::string, Invoice*> 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;
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
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();
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
-323
@@ -1,324 +1 @@
|
|||||||
#include "ServiceManagementService.h"
|
#include "ServiceManagementService.h"
|
||||||
#include "UserManagementService.h"
|
|
||||||
#include "ServiceBooking.h"
|
|
||||||
#include "Factory.h"
|
|
||||||
#include "JobCard.h"
|
|
||||||
#include "Timestamp.h"
|
|
||||||
#include "Service.h"
|
|
||||||
#include "Enums.h"
|
|
||||||
#include "InventoryItem.h"
|
|
||||||
#include "AuthenticationManagementService.h"
|
|
||||||
#include "PaymentManagementService.h"
|
|
||||||
#include "NotificationManagementService.h"
|
|
||||||
#include "User.h"
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getServiceBookings
|
|
||||||
Description: Retrieves all service bookings from the datastore.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- util::Map<std::string, ServiceBooking*> containing all service bookings
|
|
||||||
*/
|
|
||||||
util::Map<std::string, ServiceBooking*> ServiceManagementService::getServiceBookings()
|
|
||||||
{
|
|
||||||
return m_dataStore.getServiceBookings();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getServiceBooking
|
|
||||||
Description: Retrieves a specific service booking by its ID.
|
|
||||||
Parameters:
|
|
||||||
- serviceID: std::string, ID of the service booking
|
|
||||||
Returns:
|
|
||||||
- ServiceBooking*: Pointer to the service booking, or nullptr if not found
|
|
||||||
*/
|
|
||||||
ServiceBooking* ServiceManagementService::getServiceBooking(const std::string& serviceID)
|
|
||||||
{
|
|
||||||
auto currentServiceBookings = getServiceBookings();
|
|
||||||
for (int iterator = 0; iterator < currentServiceBookings.getSize(); iterator++)
|
|
||||||
{
|
|
||||||
if (currentServiceBookings.getValueAt(iterator)->getId() == serviceID)
|
|
||||||
{
|
|
||||||
return currentServiceBookings.getValueAt(iterator);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: createJobCard
|
|
||||||
Description: Creates a job card for a given service booking, service, and technician.
|
|
||||||
Validates booking, service, technician, and inventory availability before creation.
|
|
||||||
Parameters:
|
|
||||||
- bookingID: std::string, ID of the service booking
|
|
||||||
- technicianID: std::string, ID of the technician
|
|
||||||
- serviceID: std::string, ID of the service
|
|
||||||
Returns:
|
|
||||||
- void
|
|
||||||
Throws:
|
|
||||||
- std::runtime_error if booking, service, technician, or inventory validation fails
|
|
||||||
*/
|
|
||||||
void ServiceManagementService::createJobCard(const std::string& bookingID, const std::string& technicianID, const std::string& serviceID)
|
|
||||||
{
|
|
||||||
UserManagementService m_userManagementService;
|
|
||||||
ServiceBooking* currentBooking = getServiceBooking(bookingID);
|
|
||||||
auto& currentJobCards = m_dataStore.getJobCards();
|
|
||||||
if (currentBooking == nullptr)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Service Booking not available");
|
|
||||||
}
|
|
||||||
auto& currentServices = currentBooking->getServices();
|
|
||||||
if (currentServices.find(serviceID) == -1)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Invalid service Id");
|
|
||||||
}
|
|
||||||
Service* currentService = currentServices.getValueAt(currentServices.find(serviceID));
|
|
||||||
User* selectedTechnician = m_userManagementService.getUser(technicianID);
|
|
||||||
if (selectedTechnician == nullptr)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Technician not available");
|
|
||||||
}
|
|
||||||
auto& inventoryItems = currentService->getRequiredInventoryItems();
|
|
||||||
for (int iterator = 0; iterator < inventoryItems.getSize(); iterator++)
|
|
||||||
{
|
|
||||||
InventoryItem* currentInventoryItem = inventoryItems.getValueAt(iterator);
|
|
||||||
if (currentInventoryItem->getQuantity() == 0)
|
|
||||||
{
|
|
||||||
std::string errorMessage = "Failed to create job card, " + currentInventoryItem->getPartName() + " is out of stock.";
|
|
||||||
throw std::runtime_error(errorMessage);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
int currentStockQuantity = currentInventoryItem->getQuantity();
|
|
||||||
currentInventoryItem->setQuantity(currentStockQuantity - 1);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
currentBooking->setAssignedTechnician(selectedTechnician);
|
|
||||||
currentBooking->setAssignedTechnicianId(selectedTechnician->getId());
|
|
||||||
std::string title = "Job card created";
|
|
||||||
std::string message = "Job card created for the service and you are assigned for that.";
|
|
||||||
JobCard* jobCard = Factory::getObject<JobCard>(bookingID, currentBooking, currentService, serviceID, technicianID, selectedTechnician, util::Timestamp(), util::ServiceJobStatus::STARTED, util::Timestamp());
|
|
||||||
currentJobCards.insert(jobCard->getId(), jobCard);
|
|
||||||
sendNotification(selectedTechnician,title, message);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: createService
|
|
||||||
Description: Creates a new service with associated inventory items and labor cost.
|
|
||||||
Validates inventory items before creation.
|
|
||||||
Parameters:
|
|
||||||
- name: std::string, name of the service
|
|
||||||
- inventoryItemIDs: util::Vector<std::string>, IDs of required inventory items
|
|
||||||
- laborCost: double, labor cost for the service
|
|
||||||
Returns:
|
|
||||||
- void
|
|
||||||
Throws:
|
|
||||||
- std::runtime_error if inventory items are not found or service creation fails
|
|
||||||
*/
|
|
||||||
void ServiceManagementService::createService(const std::string& name, const util::Vector<std::string>& inventoryItemIDs, double laborCost)
|
|
||||||
{
|
|
||||||
util::Map<std::string, InventoryItem*> currentServiceInventoryItems;
|
|
||||||
auto inventoryItems = m_dataStore.getInventoryItems();
|
|
||||||
for (int iteratorOne =0; iteratorOne < inventoryItemIDs.getSize(); iteratorOne++)
|
|
||||||
{
|
|
||||||
std::string currentItemID = inventoryItemIDs[iteratorOne];
|
|
||||||
bool itemFound = false;
|
|
||||||
for (int iteratorTwo = 0; iteratorTwo < inventoryItems.getSize(); iteratorTwo++)
|
|
||||||
{
|
|
||||||
InventoryItem* currentInventoryItem = inventoryItems.getValueAt(iteratorTwo);
|
|
||||||
if (currentInventoryItem && currentInventoryItem->getId() == currentItemID)
|
|
||||||
{
|
|
||||||
itemFound = true;
|
|
||||||
currentServiceInventoryItems.insert(currentInventoryItem->getId(), currentInventoryItem);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!itemFound)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Inventory item with ID '" + currentItemID + "' not found.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Service* newService = Factory::getObject<Service>(name, currentServiceInventoryItems, laborCost);
|
|
||||||
if (newService == nullptr)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Unable to create new service.");
|
|
||||||
}
|
|
||||||
util::Map<std::string, Service*>& currentServices = m_dataStore.getServices();
|
|
||||||
if (currentServices.find(newService->getId()) != -1)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Service with this ID Already exists.");
|
|
||||||
}
|
|
||||||
currentServices.insert(newService->getId(), newService);
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getServices
|
|
||||||
Description: Retrieves all services from the datastore.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- util::Map<std::string, Service*> containing all services
|
|
||||||
*/
|
|
||||||
util::Map<std::string, Service*> ServiceManagementService::getServices()
|
|
||||||
{
|
|
||||||
return m_dataStore.getServices();
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: removeService
|
|
||||||
Description: Marks a service as inactive by its ID.
|
|
||||||
Parameters:
|
|
||||||
- serviceID: std::string, ID of the service
|
|
||||||
Returns:
|
|
||||||
- void
|
|
||||||
Throws:
|
|
||||||
- std::runtime_error if the service is not found
|
|
||||||
*/
|
|
||||||
void ServiceManagementService::removeService(const std::string& serviceID)
|
|
||||||
{
|
|
||||||
util::Map<std::string, Service*> currentServices = getServices();
|
|
||||||
if (currentServices.find(serviceID) != -1)
|
|
||||||
{
|
|
||||||
currentServices.getValueAt(currentServices.find(serviceID))->setState(util::State::INACTIVE);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Service not found.");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getServiceBookings (overloaded)
|
|
||||||
Description: Retrieves all service bookings for a specific customer.
|
|
||||||
Parameters:
|
|
||||||
- customerID: std::string, ID of the customer
|
|
||||||
Returns:
|
|
||||||
- util::Map<std::string, ServiceBooking*> containing bookings for the customer
|
|
||||||
*/
|
|
||||||
util::Map<std::string, ServiceBooking*> ServiceManagementService::getServiceBookings(const std::string& customerID)
|
|
||||||
{
|
|
||||||
util::Map<std::string, ServiceBooking*> currentServiceBookings = getServiceBookings();
|
|
||||||
util::Map<std::string, ServiceBooking*> currentUserServiceBookings;
|
|
||||||
if (currentServiceBookings.getSize() != 0)
|
|
||||||
{
|
|
||||||
for (int iterator = 0; iterator < currentServiceBookings.getSize(); iterator++)
|
|
||||||
{
|
|
||||||
auto currentServiceBooking = currentServiceBookings.getValueAt(iterator);
|
|
||||||
if (currentServiceBooking->getCustomerId() == customerID)
|
|
||||||
{
|
|
||||||
currentUserServiceBookings.insert(currentServiceBooking->getId(), currentServiceBooking);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return currentUserServiceBookings;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: getJobCards
|
|
||||||
Description: Retrieves all job cards assigned to a specific technician.
|
|
||||||
Parameters:
|
|
||||||
- technicianID: std::string, ID of the technician
|
|
||||||
Returns:
|
|
||||||
- util::Map<std::string, JobCard*> containing job cards assigned to the technician
|
|
||||||
*/
|
|
||||||
util::Map<std::string, JobCard*> ServiceManagementService::getJobCards(const std::string& technicianID)
|
|
||||||
{
|
|
||||||
util::Map<std::string, JobCard*> jobCards = m_dataStore.getJobCards();
|
|
||||||
util::Map<std::string, JobCard*> technicianJobCards;
|
|
||||||
for (int iterator = 0; iterator < jobCards.getSize(); iterator++)
|
|
||||||
{
|
|
||||||
JobCard* currentJobCard = jobCards.getValueAt(iterator);
|
|
||||||
if (currentJobCard->getTechnicianId() == technicianID)
|
|
||||||
{
|
|
||||||
technicianJobCards.insert(currentJobCard->getId(), currentJobCard);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return technicianJobCards;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: hasAllJobCardsinServiceBookingCompleted (static helper)
|
|
||||||
Description: Checks if all job cards for a given service booking are completed.
|
|
||||||
Parameters:
|
|
||||||
- bookingId: std::string, ID of the service booking
|
|
||||||
- currentAssignedJobs: util::Map<std::string, JobCard*>&, map of assigned job cards
|
|
||||||
Returns:
|
|
||||||
- bool: True if all job cards are completed, False otherwise
|
|
||||||
*/
|
|
||||||
static bool hasAllJobCardsinServiceBookingCompleted(std::string bookingId, util::Map<std::string, JobCard*>& currentAssignedJobs)
|
|
||||||
{
|
|
||||||
for (int iterator = 0; iterator < currentAssignedJobs.getSize(); iterator++)
|
|
||||||
{
|
|
||||||
JobCard* currentJob = currentAssignedJobs.getValueAt(iterator);
|
|
||||||
if (currentJob->getBookingId() == bookingId)
|
|
||||||
{
|
|
||||||
if (currentJob->getStatus() == util::ServiceJobStatus::STARTED)
|
|
||||||
{
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: completeJob
|
|
||||||
Description: Marks a job card as completed for the authenticated technician.
|
|
||||||
If all job cards in the booking are completed, marks the booking as completed
|
|
||||||
and generates an invoice.
|
|
||||||
Parameters:
|
|
||||||
- jobID: std::string, ID of the job card
|
|
||||||
Returns:
|
|
||||||
- void
|
|
||||||
Throws:
|
|
||||||
- std::runtime_error if technician is not authenticated, job card not found, or job already completed
|
|
||||||
*/
|
|
||||||
void ServiceManagementService::completeJob(const std::string& jobID)
|
|
||||||
{
|
|
||||||
AuthenticationManagementService authenticationManagementService;
|
|
||||||
PaymentManagementService paymentManagementService;
|
|
||||||
bool jobStatusUpdated = false, serviceBookingCompleted;
|
|
||||||
JobCard* currentJob;
|
|
||||||
User* currentTechnician = authenticationManagementService.getAuthenticatedUser();
|
|
||||||
if (currentTechnician == nullptr)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Unable to fetch current technician.");
|
|
||||||
}
|
|
||||||
util::Map<std::string, JobCard*> currentAssignedJobs = getJobCards(currentTechnician->getId());
|
|
||||||
if (currentAssignedJobs.getSize() == 0)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("No job cards assigned to the technician.");
|
|
||||||
}
|
|
||||||
if (currentAssignedJobs.find(jobID) != -1)
|
|
||||||
{
|
|
||||||
currentJob = currentAssignedJobs.getValueAt(currentAssignedJobs.find(jobID));
|
|
||||||
if (currentJob == nullptr)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Unable to fetch current job.");
|
|
||||||
}
|
|
||||||
if (currentJob->getStatus() == util::ServiceJobStatus::STARTED)
|
|
||||||
{
|
|
||||||
currentJob->setStatus(util::ServiceJobStatus::COMPLETED);
|
|
||||||
jobStatusUpdated = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Failed to complete the job, some error occured or job already completed.");
|
|
||||||
}
|
|
||||||
if (!jobStatusUpdated)
|
|
||||||
{
|
|
||||||
throw std::runtime_error("Failed to complete the job, some error occured or job already completed.");
|
|
||||||
}
|
|
||||||
|
|
||||||
serviceBookingCompleted = hasAllJobCardsinServiceBookingCompleted(currentJob->getBookingId(), currentAssignedJobs);
|
|
||||||
if (serviceBookingCompleted)
|
|
||||||
{
|
|
||||||
currentJob->getBooking()->setStatus(util::ServiceJobStatus::COMPLETED);
|
|
||||||
paymentManagementService.generateInvoice(currentJob->getBooking());
|
|
||||||
std::string title = "Service Booking completed,Invoice Generated.\n";
|
|
||||||
std::string message = "Services completed for the booking and invoice generated.\n";
|
|
||||||
sendNotification(currentJob->getBooking()->getCustomer(), title, message);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
-1
@@ -22,7 +22,6 @@ public:
|
|||||||
void purchaseComboPackage(const std::string& comboPackageID, const std::string& vehicleNumber, const std::string& vehicleBrand, const std::string& vehicleModel);
|
void purchaseComboPackage(const std::string& comboPackageID, const std::string& vehicleNumber, const std::string& vehicleBrand, const std::string& vehicleModel);
|
||||||
util::Map<std::string, ServiceBooking*> getServiceBookings();
|
util::Map<std::string, ServiceBooking*> getServiceBookings();
|
||||||
util::Map<std::string, ServiceBooking*> getServiceBookings(const std::string& customerID);
|
util::Map<std::string, ServiceBooking*> getServiceBookings(const std::string& customerID);
|
||||||
ServiceBooking* getServiceBooking(const std::string& serviceID);
|
|
||||||
void createJobCard(const std::string& bookingID, const std::string& technicianID, const std::string& serviceID);
|
void createJobCard(const std::string& bookingID, const std::string& technicianID, const std::string& serviceID);
|
||||||
void createService(const std::string& name, const util::Vector<std::string>& inventoryItemIDs, double laborCost);
|
void createService(const std::string& name, const util::Vector<std::string>& inventoryItemIDs, double laborCost);
|
||||||
void removeService(const std::string& serviceID);
|
void removeService(const std::string& serviceID);
|
||||||
|
|||||||
-30
@@ -1,31 +1 @@
|
|||||||
#include "UserManagementService.h"
|
#include "UserManagementService.h"
|
||||||
#include "User.h"
|
|
||||||
|
|
||||||
util::Map<std::string, User*> UserManagementService::getUsers(util::UserType type)
|
|
||||||
{
|
|
||||||
util::Map<std::string, User*>& currentUsers = m_dataStore.getUsers();
|
|
||||||
util::Map<std::string, User*> filteredUsersMap;
|
|
||||||
for (int iterator = 0; iterator < currentUsers.getSize(); iterator++)
|
|
||||||
{
|
|
||||||
User* currentUser = currentUsers.getValueAt(iterator);
|
|
||||||
if (currentUser->getUserType() == type)
|
|
||||||
{
|
|
||||||
filteredUsersMap.insert(currentUser->getId(), currentUser);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return filteredUsersMap;
|
|
||||||
}
|
|
||||||
|
|
||||||
User* UserManagementService::getUser(const std::string& userID)
|
|
||||||
{
|
|
||||||
util::Map<std::string, User*>& currentUsers = m_dataStore.getUsers();
|
|
||||||
for (int iterator = 0; iterator < currentUsers.getSize(); iterator++)
|
|
||||||
{
|
|
||||||
User* currentUser = currentUsers.getValueAt(iterator);
|
|
||||||
if (currentUser->getId() == userID)
|
|
||||||
{
|
|
||||||
return currentUser;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -13,7 +13,8 @@ namespace util
|
|||||||
enum class PaymentMode
|
enum class PaymentMode
|
||||||
{
|
{
|
||||||
ONLINE,
|
ONLINE,
|
||||||
OFFLINE
|
OFFLINE,
|
||||||
|
NOTSET
|
||||||
};
|
};
|
||||||
|
|
||||||
enum class PaymentStatus
|
enum class PaymentStatus
|
||||||
@@ -24,7 +25,6 @@ namespace util
|
|||||||
|
|
||||||
enum class ServiceJobStatus
|
enum class ServiceJobStatus
|
||||||
{
|
{
|
||||||
PENDING,
|
|
||||||
STARTED,
|
STARTED,
|
||||||
COMPLETED
|
COMPLETED
|
||||||
};
|
};
|
||||||
@@ -74,6 +74,8 @@ namespace util
|
|||||||
return "ONLINE";
|
return "ONLINE";
|
||||||
case PaymentMode::OFFLINE:
|
case PaymentMode::OFFLINE:
|
||||||
return "OFFLINE";
|
return "OFFLINE";
|
||||||
|
case PaymentMode::NOTSET:
|
||||||
|
return "NOTSET";
|
||||||
}
|
}
|
||||||
throw std::invalid_argument("Invalid PaymentMode");
|
throw std::invalid_argument("Invalid PaymentMode");
|
||||||
}
|
}
|
||||||
@@ -126,8 +128,6 @@ namespace util
|
|||||||
return "STARTED";
|
return "STARTED";
|
||||||
case ServiceJobStatus::COMPLETED:
|
case ServiceJobStatus::COMPLETED:
|
||||||
return "COMPLETED";
|
return "COMPLETED";
|
||||||
case ServiceJobStatus::PENDING:
|
|
||||||
return "STARTED";
|
|
||||||
}
|
}
|
||||||
throw std::invalid_argument("Invalid ServiceJobStatus");
|
throw std::invalid_argument("Invalid ServiceJobStatus");
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -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;
|
||||||
|
}
|
||||||
@@ -1,12 +1,6 @@
|
|||||||
#include <iomanip>
|
|
||||||
#include "AdminMenu.h"
|
#include "AdminMenu.h"
|
||||||
#include "Service.h"
|
|
||||||
#include "InputHelper.h"
|
#include "InputHelper.h"
|
||||||
#include "OutputHelper.h"
|
#include "OutputHelper.h"
|
||||||
#include "ServiceBooking.h"
|
|
||||||
#include "Enums.h"
|
|
||||||
#include "Service.h"
|
|
||||||
#include "InventoryItem.h"
|
|
||||||
|
|
||||||
void AdminMenu::showMenu()
|
void AdminMenu::showMenu()
|
||||||
{
|
{
|
||||||
@@ -62,368 +56,16 @@ void AdminMenu::checkStockAvailability()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Function: listServiceBookings (static helper)
|
|
||||||
Description: Lists all pending service bookings and maps them to indices for selection.
|
|
||||||
Parameters:
|
|
||||||
- currentBookings: util::Map<std::string, const ServiceBooking*>&, current bookings
|
|
||||||
- bookingsSize: int&, number of bookings
|
|
||||||
- serviceBookingsMap: util::Map<int, const ServiceBooking*>&, map of indexed bookings
|
|
||||||
Returns:
|
|
||||||
- bool: True if pending services exist, False otherwise
|
|
||||||
*/
|
|
||||||
static bool listServiceBookings(util::Map<std::string, const ServiceBooking*>& currentBookings, int& bookingsSize, util::Map<int, const ServiceBooking*>& serviceBookingsMap)
|
|
||||||
{
|
|
||||||
int currentIndex = 1;
|
|
||||||
bool hasPendingService = false;
|
|
||||||
std::cout << std::left
|
|
||||||
<< std::setw(10) << "Index"
|
|
||||||
<< std::setw(10) << "ID"
|
|
||||||
<< std::setw(12) << "Status"
|
|
||||||
<< std::setw(12) << "CustID"
|
|
||||||
<< std::setw(20) << "Customer"
|
|
||||||
<< std::setw(15) << "VehicleNo"
|
|
||||||
<< std::setw(15) << "Brand"
|
|
||||||
<< std::setw(15) << "Model"
|
|
||||||
<< std::setw(20) << "Technician"
|
|
||||||
<< std::setw(15) << "TechID"
|
|
||||||
<< std::endl;
|
|
||||||
for (int iterator = 0; iterator < bookingsSize; iterator++)
|
|
||||||
{
|
|
||||||
const ServiceBooking* currentBooking = currentBookings.getValueAt(iterator);
|
|
||||||
if (currentBooking && currentBooking->getStatus() == util::ServiceJobStatus::PENDING)
|
|
||||||
{
|
|
||||||
hasPendingService = true;
|
|
||||||
std::cout << std::left
|
|
||||||
<< std::setw(10) << currentIndex
|
|
||||||
<< std::setw(10) << currentBooking->getId()
|
|
||||||
<< std::setw(12) << util::getServiceJobStatusString(currentBooking->getStatus())
|
|
||||||
<< std::setw(12) << currentBooking->getCustomerId()
|
|
||||||
<< std::setw(20) << currentBooking->getCustomer()->getName()
|
|
||||||
<< std::setw(15) << currentBooking->getVehicleNumber()
|
|
||||||
<< std::setw(15) << currentBooking->getVehicleBrand()
|
|
||||||
<< std::setw(15) << currentBooking->getVehicleModel()
|
|
||||||
<< std::setw(20) << (currentBooking->getAssignedTechnician() == nullptr ? "Null" : currentBooking->getAssignedTechnician()->getName())
|
|
||||||
<< std::setw(15) << (currentBooking->getAssignedTechnicianId().empty() ? "Null" : currentBooking->getAssignedTechnicianId())
|
|
||||||
<< std::endl;
|
|
||||||
serviceBookingsMap.insert(currentIndex++, currentBooking);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!hasPendingService)
|
|
||||||
{
|
|
||||||
std::cout << "No pending service available." << std::endl;
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: selectPendingServiceBookings (static helper)
|
|
||||||
Description: Allows selection of a pending service booking by index.
|
|
||||||
Parameters:
|
|
||||||
- serviceBookingsMap: util::Map<int, const ServiceBooking*>&, map of indexed bookings
|
|
||||||
Returns:
|
|
||||||
- const ServiceBooking*: Pointer to the selected booking, or nullptr if invalid
|
|
||||||
*/
|
|
||||||
static const ServiceBooking* selectPendingServiceBookings(util::Map<int, const ServiceBooking*>& serviceBookingsMap)
|
|
||||||
{
|
|
||||||
int userInputIndex;
|
|
||||||
std::cout << "Enter a valid service index: ";
|
|
||||||
util::read(userInputIndex);
|
|
||||||
if (serviceBookingsMap.find(userInputIndex) != -1)
|
|
||||||
{
|
|
||||||
return serviceBookingsMap.getValueAt(userInputIndex);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Enter a valid index.";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: listAvailableTechnicians (static helper)
|
|
||||||
Description: Lists all available technicians and maps them to indices for selection.
|
|
||||||
Parameters:
|
|
||||||
- currentAvailableTechnicians: util::Map<std::string, const User*>, available technicians
|
|
||||||
- numberOfTechnicians: int, number of technicians
|
|
||||||
- currentAvailableTechniciansMap: util::Map<int, const User*>&, map of indexed technicians
|
|
||||||
Returns:
|
|
||||||
- void
|
|
||||||
*/
|
|
||||||
static void listAvailableTechnicians( util::Map<std::string, const User*> currentAvailableTechnicians, int numberOfTechnicians, util::Map<int, const User*>& currentAvailableTechniciansMap)
|
|
||||||
{
|
|
||||||
bool hasTechnicians = false;
|
|
||||||
int currentIndex = 1;
|
|
||||||
std::cout << std::left
|
|
||||||
<< std::setw(6) << "Index"
|
|
||||||
<< std::setw(15) << "Technician ID"
|
|
||||||
<< std::setw(20) << "Name"
|
|
||||||
<< std::endl;
|
|
||||||
for (int iterator = 0; iterator < numberOfTechnicians; iterator++)
|
|
||||||
{
|
|
||||||
const User* currentTechnician = currentAvailableTechnicians.getValueAt(iterator);
|
|
||||||
if (currentTechnician->getState() == util::State::INACTIVE)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
hasTechnicians = true;
|
|
||||||
std::cout << std::left
|
|
||||||
<< std::setw(6) << currentIndex
|
|
||||||
<< std::setw(15) << currentTechnician->getId()
|
|
||||||
<< std::setw(20) << currentTechnician->getName()
|
|
||||||
<< std::endl;
|
|
||||||
currentAvailableTechniciansMap.insert(currentIndex++, currentTechnician);
|
|
||||||
}
|
|
||||||
if (!hasTechnicians)
|
|
||||||
{
|
|
||||||
std::cout << "No technicians currently available.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: selectTechnician (static helper)
|
|
||||||
Description: Allows selection of a technician by index.
|
|
||||||
Parameters:
|
|
||||||
- currentAvailableTechniciansMap: util::Map<int, const User*>&, map of indexed technicians
|
|
||||||
Returns:
|
|
||||||
- const User*: Pointer to the selected technician, or nullptr if invalid
|
|
||||||
*/
|
|
||||||
static const User* selectTechnician(util::Map<int, const User*>& currentAvailableTechniciansMap)
|
|
||||||
{
|
|
||||||
int userInputIndex;
|
|
||||||
util::read(userInputIndex);
|
|
||||||
if (currentAvailableTechniciansMap.find(userInputIndex) != -1)
|
|
||||||
{
|
|
||||||
return currentAvailableTechniciansMap.getValueAt(userInputIndex);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Enter a valid index.";
|
|
||||||
return nullptr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: assignJob
|
|
||||||
Description: Allows the admin to assign pending service bookings to available technicians.
|
|
||||||
Creates job cards for selected services.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- void
|
|
||||||
*/
|
|
||||||
void AdminMenu::assignJob()
|
void AdminMenu::assignJob()
|
||||||
{
|
{
|
||||||
util::clear();
|
|
||||||
std::string selectedService;
|
|
||||||
bool hasPendingService = false;
|
|
||||||
auto currentBookings = m_controller.getServiceBookings();
|
|
||||||
auto availableTechnicians = m_controller.getUsers(util::UserType::TECHNICIAN);
|
|
||||||
int bookingsSize = currentBookings.getSize();
|
|
||||||
util::Map<int, const ServiceBooking*> serviceBookingsMap;
|
|
||||||
util::Map<int, const User*> currentAvailableTechniciansMap;
|
|
||||||
if (listServiceBookings(currentBookings, bookingsSize, serviceBookingsMap))
|
|
||||||
{
|
|
||||||
const ServiceBooking* selectedService = selectPendingServiceBookings(serviceBookingsMap);
|
|
||||||
if (selectedService)
|
|
||||||
{
|
|
||||||
if (availableTechnicians.getSize() != 0)
|
|
||||||
{
|
|
||||||
listAvailableTechnicians(availableTechnicians, availableTechnicians.getSize(), currentAvailableTechniciansMap);
|
|
||||||
const User* selectedTechnician = selectTechnician(currentAvailableTechniciansMap);
|
|
||||||
if (selectedTechnician)
|
|
||||||
{
|
|
||||||
auto& servicesInBooking = selectedService->getServices();
|
|
||||||
for (int iterator = 0; iterator < servicesInBooking.getSize(); iterator++)
|
|
||||||
{
|
|
||||||
m_controller.createJobCard(selectedService->getId(), selectedTechnician->getId(), servicesInBooking.getValueAt(iterator)->getId());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "No technicians are currently available.";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Function: selectInventoryItems (static helper)
|
|
||||||
Description: Allows selection of inventory items by index for creating a service.
|
|
||||||
Parameters:
|
|
||||||
- currentInventoryItems: util::Map<std::string, const InventoryItem*>&, available inventory items
|
|
||||||
- selectedInventoryItems: util::Vector<std::string>&, vector to store selected item IDs
|
|
||||||
Returns:
|
|
||||||
- void
|
|
||||||
*/
|
|
||||||
static void selectInventoryItems(util::Map<std::string, const InventoryItem*>& currentInventoryItems, util::Vector<std::string>& selectedInventoryItems)
|
|
||||||
{
|
|
||||||
bool doRun = true, hasInventoryItems = false;
|
|
||||||
util::Map<int, const InventoryItem*> currentInventoryMap;
|
|
||||||
int currentIndex = 1;
|
|
||||||
int choice;
|
|
||||||
if (currentInventoryItems.getSize() == 0)
|
|
||||||
{
|
|
||||||
std::cout << "Inventory empty.";
|
|
||||||
}
|
|
||||||
while (doRun)
|
|
||||||
{
|
|
||||||
bool hasInventoryItems = false;
|
|
||||||
int currentIndex = 1;
|
|
||||||
currentInventoryMap.clear();
|
|
||||||
std::cout << std::left
|
|
||||||
<< std::setw(6) << "Index"
|
|
||||||
<< std::setw(12) << "Item ID"
|
|
||||||
<< std::setw(20) << "Part Name"
|
|
||||||
<< std::setw(10) << "Price"
|
|
||||||
<< std::setw(10) << "Quantity"
|
|
||||||
<< std::endl;
|
|
||||||
for (int iterator = 0; iterator < currentInventoryItems.getSize(); iterator++)
|
|
||||||
{
|
|
||||||
const InventoryItem* currentInventoryItem = currentInventoryItems.getValueAt(iterator);
|
|
||||||
if (currentInventoryItem->getState() == util::State::INACTIVE)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
std::cout << std::left
|
|
||||||
<< std::setw(6) << currentIndex
|
|
||||||
<< std::setw(12) << currentInventoryItem->getId()
|
|
||||||
<< std::setw(20) << currentInventoryItem->getPartName()
|
|
||||||
<< std::setw(10) << currentInventoryItem->getPrice()
|
|
||||||
<< std::setw(10) << currentInventoryItem->getQuantity()
|
|
||||||
<< std::endl;
|
|
||||||
|
|
||||||
hasInventoryItems = true;
|
|
||||||
currentInventoryMap.insert(currentIndex++, currentInventoryItem);
|
|
||||||
}
|
|
||||||
if (!hasInventoryItems)
|
|
||||||
{
|
|
||||||
std::cout << "No items present in the inventory." << std::endl;
|
|
||||||
doRun = false;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
std::cout << "Select the item (Index) or enter -1 to exit: ";
|
|
||||||
util::read(choice);
|
|
||||||
|
|
||||||
if (choice == -1)
|
|
||||||
{
|
|
||||||
doRun = false;
|
|
||||||
}
|
|
||||||
else if (currentInventoryMap.find(choice) != -1)
|
|
||||||
{
|
|
||||||
selectedInventoryItems.push_back(currentInventoryMap.getValueAt(choice)->getId());
|
|
||||||
std::cout << "Item added successfully." << std::endl;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Enter a valid integer." << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: createService
|
|
||||||
Description: Allows the admin to create a new service by selecting inventory items and specifying labor cost.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- void
|
|
||||||
*/
|
|
||||||
void AdminMenu::createService()
|
void AdminMenu::createService()
|
||||||
{
|
{
|
||||||
util::clear();
|
|
||||||
std::string serviceName;
|
|
||||||
double labourCost;
|
|
||||||
std::cout << "Enter the service name: ";
|
|
||||||
util::read(serviceName);
|
|
||||||
util::Map<std::string, const InventoryItem*> currentInventoryItems = m_controller.getInventoryItems();
|
|
||||||
util::Vector<std::string> selectedInventoryItems;
|
|
||||||
selectInventoryItems(currentInventoryItems,selectedInventoryItems);
|
|
||||||
std::cout << "Enter the labour cost: ";
|
|
||||||
util::read(labourCost);
|
|
||||||
m_controller.createService(serviceName, selectedInventoryItems, labourCost);
|
|
||||||
std::cout << "Service created sucessfully.\n";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Function: selectServicesToRemove (static helper)
|
|
||||||
Description: Allows selection of a service to remove by index.
|
|
||||||
Parameters:
|
|
||||||
- currentServices: util::Map<std::string, const Service*>, available services
|
|
||||||
Returns:
|
|
||||||
- std::string: ID of the selected service, or empty string if invalid
|
|
||||||
*/
|
|
||||||
static std::string selectServicesToRemove(util::Map<std::string, const Service*> currentServices)
|
|
||||||
{
|
|
||||||
util::Map<int, const Service*> currentServicesMap;
|
|
||||||
bool hasServices = false;
|
|
||||||
int currentIndex = 1, choice;
|
|
||||||
std::cout << std::left
|
|
||||||
<< std::setw(6) << "Index"
|
|
||||||
<< std::setw(12) << "Service ID"
|
|
||||||
<< std::setw(20) << "Name"
|
|
||||||
<< std::setw(10) << "Labor Cost"
|
|
||||||
<< std::endl;
|
|
||||||
for (int iterator = 0; iterator < currentServices.getSize(); iterator++)
|
|
||||||
{
|
|
||||||
const Service* currentService = currentServices.getValueAt(iterator);
|
|
||||||
if (currentService->getState() == util::State::INACTIVE)
|
|
||||||
{
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
std::cout << std::left
|
|
||||||
<< std::setw(6) << currentIndex
|
|
||||||
<< std::setw(12) << currentService->getId()
|
|
||||||
<< std::setw(20) << currentService->getName()
|
|
||||||
<< std::setw(10) << currentService->getLaborCost()
|
|
||||||
<< std::endl;
|
|
||||||
hasServices = true;
|
|
||||||
currentServicesMap.insert(currentIndex++, currentService);
|
|
||||||
}
|
|
||||||
if (!hasServices)
|
|
||||||
{
|
|
||||||
std::cout << "No services currently available." << std::endl;
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
std::cout << "Enter your choice: ";
|
|
||||||
util::read(choice);
|
|
||||||
if (currentServicesMap.find(choice) != -1)
|
|
||||||
{
|
|
||||||
return currentServicesMap.getValueAt(currentServicesMap.find(choice))->getId();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Invalid choice." << std::endl;
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: removeService
|
|
||||||
Description: Allows the admin to remove an existing service by selecting from available services.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- void
|
|
||||||
*/
|
|
||||||
void AdminMenu::removeService()
|
void AdminMenu::removeService()
|
||||||
{
|
{
|
||||||
util::clear();
|
|
||||||
std::string selectedServiceID;
|
|
||||||
util::Map<std::string, const Service*> currentServices = m_controller.getServices();
|
|
||||||
selectedServiceID = selectServicesToRemove(currentServices);
|
|
||||||
if (selectedServiceID != "")
|
|
||||||
{
|
|
||||||
m_controller.removeService(selectedServiceID);
|
|
||||||
std::cout << "Service removed sucessfully.";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Failed to remove service.";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void AdminMenu::addTechnician()
|
void AdminMenu::addTechnician()
|
||||||
|
|||||||
@@ -1,10 +1,15 @@
|
|||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <iostream>
|
||||||
#include "CustomerMenu.h"
|
#include "CustomerMenu.h"
|
||||||
#include "InputHelper.h"
|
#include "InputHelper.h"
|
||||||
#include "OutputHelper.h"
|
#include "OutputHelper.h"
|
||||||
#include "User.h"
|
#include "Invoice.h"
|
||||||
#include "ServiceBooking.h"
|
|
||||||
#include "Enums.h"
|
#include "Enums.h"
|
||||||
|
#include "ServiceBooking.h"
|
||||||
|
#include "User.h"
|
||||||
|
#include "Timestamp.h"
|
||||||
|
#include "Service.h"
|
||||||
|
#include "InventoryItem.h"
|
||||||
|
|
||||||
void CustomerMenu::showMenu()
|
void CustomerMenu::showMenu()
|
||||||
{
|
{
|
||||||
@@ -55,63 +60,201 @@ void CustomerMenu::selectComboPackage()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void CustomerMenu::viewServiceHistory()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
Function: viewServiceHistory
|
Function: selectInvoiceFromUserForPayment (static helper)
|
||||||
Description: Displays the customer’s past service bookings in tabular format,
|
Description: Lists all pending invoices for the customer and allows selection by index.
|
||||||
including booking ID, technician, vehicle details, discount percentage, and status.
|
Parameters:
|
||||||
|
- currentInvoices: util::Map<std::string, const Invoice*>&, 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<std::string, const Invoice*>& currentInvoices)
|
||||||
|
{
|
||||||
|
int currentIndex = 1, choice;
|
||||||
|
util::Map<int, const Invoice*> 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 "";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: selectPaymentMode (static helper)
|
||||||
|
Description: Allows the customer to select a payment mode (ONLINE or OFFLINE).
|
||||||
|
Parameters:
|
||||||
|
- None
|
||||||
|
Returns:
|
||||||
|
- util::PaymentMode: Selected payment mode
|
||||||
|
*/
|
||||||
|
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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: completePayments
|
||||||
|
Description: Allows the customer to complete pending payments for invoices.
|
||||||
|
Validates invoice selection and payment mode before completing payment.
|
||||||
Parameters:
|
Parameters:
|
||||||
- None
|
- None
|
||||||
Returns:
|
Returns:
|
||||||
- void
|
- void
|
||||||
*/
|
*/
|
||||||
void CustomerMenu::viewServiceHistory()
|
|
||||||
{
|
|
||||||
util::clear();
|
|
||||||
bool hasServiceHistory = false;
|
|
||||||
const User* currentUser = m_controller.getAuthenticatedUser();
|
|
||||||
std::string currentUserID = currentUser->getId();
|
|
||||||
util::Map<std::string, const ServiceBooking*> serviceBookingsByCurrentUser = m_controller.getServiceBookingsByUser(currentUserID);
|
|
||||||
if (serviceBookingsByCurrentUser.getSize() != 0)
|
|
||||||
{
|
|
||||||
std::cout << std::left
|
|
||||||
<< std::setw(12) << "Booking ID"
|
|
||||||
<< std::setw(20) << "Technician"
|
|
||||||
<< std::setw(15) << "Vehicle Brand"
|
|
||||||
<< std::setw(15) << "Vehicle Number"
|
|
||||||
<< std::setw(15) << "Vehicle Model"
|
|
||||||
<< std::setw(10) << "Discount %"
|
|
||||||
<< std::setw(12) << "Status"
|
|
||||||
<< std::endl;
|
|
||||||
for (int iterator = 0; iterator < serviceBookingsByCurrentUser.getSize(); iterator++)
|
|
||||||
{
|
|
||||||
const ServiceBooking* currentBooking = serviceBookingsByCurrentUser.getValueAt(iterator);
|
|
||||||
std::string technicianName = currentBooking->getAssignedTechnician() == nullptr
|
|
||||||
? "Not Assigned"
|
|
||||||
: currentBooking->getAssignedTechnician()->getName();
|
|
||||||
std::cout << std::left
|
|
||||||
<< std::setw(12) << currentBooking->getId()
|
|
||||||
<< std::setw(20) << technicianName
|
|
||||||
<< std::setw(15) << currentBooking->getVehicleBrand()
|
|
||||||
<< std::setw(15) << currentBooking->getVehicleNumber()
|
|
||||||
<< std::setw(15) << currentBooking->getVehicleModel()
|
|
||||||
<< std::setw(10) << currentBooking->getDiscountPercentage()
|
|
||||||
<< std::setw(12) << util::getServiceJobStatusString(currentBooking->getStatus())
|
|
||||||
<< std::endl;
|
|
||||||
hasServiceHistory = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!hasServiceHistory)
|
|
||||||
{
|
|
||||||
std::cout << "No history available." << std::endl;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void CustomerMenu::completePayments()
|
void CustomerMenu::completePayments()
|
||||||
{
|
{
|
||||||
|
util::clear();
|
||||||
|
util::Map<std::string, const Invoice*> 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";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: displayInvoices (static helper)
|
||||||
|
Description: Displays detailed information for all invoices associated with the customer,
|
||||||
|
including booking details, technician, discount, total amount, payment status, and items used.
|
||||||
|
Parameters:
|
||||||
|
- currentUserInvoices: util::Map<std::string, const Invoice*>, customer’s invoices
|
||||||
|
Returns:
|
||||||
|
- void
|
||||||
|
Throws:
|
||||||
|
- std::runtime_error if a null invoice is encountered
|
||||||
|
*/
|
||||||
|
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.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: viewInvoices
|
||||||
|
Description: Displays invoices associated with the customer by calling displayInvoices.
|
||||||
|
Parameters:
|
||||||
|
- None
|
||||||
|
Returns:
|
||||||
|
- void
|
||||||
|
*/
|
||||||
void CustomerMenu::viewInvoices()
|
void CustomerMenu::viewInvoices()
|
||||||
{
|
{
|
||||||
|
util::clear();
|
||||||
|
util::Map<std::string, const Invoice*> currentUserInvoices = m_controller.getInvoicesByUser();
|
||||||
|
displayInvoices(currentUserInvoices);
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomerMenu::viewNotifications()
|
void CustomerMenu::viewNotifications()
|
||||||
|
|||||||
@@ -1,10 +1,6 @@
|
|||||||
#include <iomanip>
|
|
||||||
#include "TechnicianMenu.h"
|
#include "TechnicianMenu.h"
|
||||||
#include "InputHelper.h"
|
#include "InputHelper.h"
|
||||||
#include "OutputHelper.h"
|
#include "OutputHelper.h"
|
||||||
#include "JobCard.h"
|
|
||||||
#include "Enums.h"
|
|
||||||
#include "Service.h"
|
|
||||||
|
|
||||||
void TechnicianMenu::showMenu()
|
void TechnicianMenu::showMenu()
|
||||||
{
|
{
|
||||||
@@ -35,86 +31,8 @@ bool TechnicianMenu::handleOperation(int choice)
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
|
||||||
Function: selectJobCardToComplete (static helper)
|
|
||||||
Description: Lists all incomplete job cards assigned to the technician and allows selection by index.
|
|
||||||
Parameters:
|
|
||||||
- assignedJobCards: util::Map<std::string, const JobCard*>&, job cards assigned to the technician
|
|
||||||
- incompleteJobCards: util::Map<int, const JobCard*>&, map of incomplete job cards indexed for selection
|
|
||||||
Returns:
|
|
||||||
- std::string: ID of the selected job card, or empty string if none selected
|
|
||||||
*/
|
|
||||||
static std::string selectJobCardToComplete(util::Map<std::string, const JobCard*>& assignedJobCards, util::Map<int, const JobCard*>& incompleteJobCards)
|
|
||||||
{
|
|
||||||
int currentIndex = 1;
|
|
||||||
int choice;
|
|
||||||
bool hasIncompleteJobCard = false;
|
|
||||||
std::cout << std::left
|
|
||||||
<< std::setw(6) << "Index"
|
|
||||||
<< std::setw(12) << "BookingID"
|
|
||||||
<< std::setw(12) << "JobID"
|
|
||||||
<< std::setw(20) << "ServiceName"
|
|
||||||
<< std::setw(12) << "ServiceID"
|
|
||||||
<< std::endl;
|
|
||||||
for (int iterator = 0; iterator < assignedJobCards.getSize(); iterator++)
|
|
||||||
{
|
|
||||||
const JobCard* currentJobCard = assignedJobCards.getValueAt(iterator);
|
|
||||||
if (currentJobCard && (currentJobCard->getStatus() == util::ServiceJobStatus::STARTED))
|
|
||||||
{
|
|
||||||
std::cout << std::left << std::setw(6) << currentIndex
|
|
||||||
<< std::setw(12) << currentJobCard->getBookingId()
|
|
||||||
<< std::setw(12) << currentJobCard->getId()
|
|
||||||
<< std::setw(20) << currentJobCard->getService()->getName()
|
|
||||||
<< std::setw(12) << currentJobCard->getServiceId()
|
|
||||||
<< std::endl;
|
|
||||||
hasIncompleteJobCard = true;
|
|
||||||
incompleteJobCards.insert(currentIndex++, currentJobCard);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if (!hasIncompleteJobCard)
|
|
||||||
{
|
|
||||||
std::cout << "No pending jobs are present.\n";
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
std::cout << "Select the Job Card to complete (Index): ";
|
|
||||||
util::read(choice);
|
|
||||||
int selectedJobCardIndex = incompleteJobCards.find(choice);
|
|
||||||
if (selectedJobCardIndex != -1)
|
|
||||||
{
|
|
||||||
const JobCard* selectedJobCard = incompleteJobCards.getValueAt(selectedJobCardIndex);
|
|
||||||
return selectedJobCard->getId();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
std::cout << "Invalid choice.\n";
|
|
||||||
return "";
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/*
|
|
||||||
Function: completeJob
|
|
||||||
Description: Allows the technician to mark a selected job card as completed.
|
|
||||||
Validates selection and updates job status through the controller.
|
|
||||||
Parameters:
|
|
||||||
- None
|
|
||||||
Returns:
|
|
||||||
- void
|
|
||||||
*/
|
|
||||||
void TechnicianMenu::completeJob()
|
void TechnicianMenu::completeJob()
|
||||||
{
|
{
|
||||||
util::Map<std::string, const JobCard*> assignedJobCards = m_controller.getJobCardsByUser();
|
|
||||||
util::Map<int, const JobCard*> incompleteJobCards;
|
|
||||||
std::cout << "Jobs to be completed.\n";
|
|
||||||
std::string selectedJobID = selectJobCardToComplete(assignedJobCards, incompleteJobCards);
|
|
||||||
if (selectedJobID == "")
|
|
||||||
{
|
|
||||||
std::cout << "Failed to complete the job.\n";
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
m_controller.completeJob(selectedJobID);
|
|
||||||
std::cout << "Job marked as completed.\n";
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void TechnicianMenu::viewNotifications()
|
void TechnicianMenu::viewNotifications()
|
||||||
|
|||||||
Reference in New Issue
Block a user