Merge branch 'feature' into feature-1552-1560
This commit is contained in:
@@ -7,7 +7,12 @@ Author: Trenser
|
||||
Date:19-May-2026
|
||||
*/
|
||||
|
||||
#include <sstream>
|
||||
#include <stdexcept>
|
||||
#include "JobCard.h"
|
||||
#include "Factory.h"
|
||||
#include "StringHelper.h"
|
||||
#include "Enums.h"
|
||||
|
||||
int JobCard::m_uid = 0;
|
||||
|
||||
@@ -27,18 +32,19 @@ JobCard::JobCard()
|
||||
|
||||
/*
|
||||
Function: JobCard
|
||||
Description: Parameterized constructor that initializes a job card with
|
||||
booking, service, technician, and status details.
|
||||
Parameter: const std::string& bookingId - ID of the booking
|
||||
ServiceBooking* booking - pointer to the booking object
|
||||
Service* service - pointer to the service object
|
||||
const std::string& serviceId - ID of the service
|
||||
const std::string& technicianId - ID of the technician
|
||||
User* technician - pointer to the technician object
|
||||
const util::Timestamp& assignedDate - date when job was assigned
|
||||
util::ServiceJobStatus status - current status of the job
|
||||
const util::Timestamp& completionDate - date when job was completed
|
||||
Return type: Constructor
|
||||
Description: Parameterized constructor that initializes a new job card with a unique ID and specified details.
|
||||
Parameters:
|
||||
- bookingId: ID of the associated service booking.
|
||||
- booking: Pointer to the ServiceBooking object.
|
||||
- service: Pointer to the Service object.
|
||||
- serviceId: ID of the associated service.
|
||||
- technicianId: ID of the assigned technician.
|
||||
- technician: Pointer to the User object representing the technician.
|
||||
- assignedDate: Timestamp of when the job was assigned.
|
||||
- status: Current status of the job (STARTED/COMPLETED).
|
||||
- completionDate: Timestamp of when the job was completed.
|
||||
Returns:
|
||||
- A new JobCard object.
|
||||
*/
|
||||
JobCard::JobCard(const std::string& bookingId,
|
||||
ServiceBooking* booking,
|
||||
@@ -61,11 +67,53 @@ JobCard::JobCard(const std::string& bookingId,
|
||||
m_status(status),
|
||||
m_completionDate(completionDate) {}
|
||||
|
||||
/*
|
||||
Function: JobCard (parameterized constructor with ID)
|
||||
Description: Initializes a job card with an existing ID, booking ID, service ID,
|
||||
technician ID, assignment date, completion date, and status.
|
||||
Updates UID tracking based on ID.
|
||||
Parameters:
|
||||
- id: const std::string&, unique job card ID
|
||||
- bookingId: const std::string&, ID of the booking
|
||||
- serviceId: const std::string&, ID of the service
|
||||
- technicianId: const std::string&, ID of the technician
|
||||
- assignedDate: const util::Timestamp&, date of assignment
|
||||
- status: util::ServiceJobStatus, job status
|
||||
- completionDate: const util::Timestamp&, date of completion
|
||||
Returns:
|
||||
- A new JobCard object
|
||||
*/
|
||||
JobCard::JobCard(const std::string& id,
|
||||
const std::string& bookingId,
|
||||
const std::string& serviceId,
|
||||
const std::string& technicianId,
|
||||
const util::Timestamp& assignedDate,
|
||||
util::ServiceJobStatus status,
|
||||
const util::Timestamp& completionDate
|
||||
)
|
||||
: m_id(id),
|
||||
m_bookingId(bookingId),
|
||||
m_booking(nullptr),
|
||||
m_service(nullptr),
|
||||
m_serviceId(serviceId),
|
||||
m_technicianId(technicianId),
|
||||
m_technician(nullptr),
|
||||
m_assignedDate(assignedDate),
|
||||
m_status(status),
|
||||
m_completionDate(completionDate)
|
||||
{
|
||||
int idNumber = util::extractNumber(m_id);
|
||||
if (idNumber > m_uid)
|
||||
{
|
||||
m_uid = idNumber;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getId
|
||||
Description: Retrieves the unique identifier of the job card.
|
||||
Parameter: None
|
||||
Return type: const std::string&
|
||||
Description: Retrieves the unique ID of the job card.
|
||||
Returns:
|
||||
- const std::string& representing the job card ID.
|
||||
*/
|
||||
const std::string& JobCard::getId() const
|
||||
{
|
||||
@@ -75,8 +123,8 @@ const std::string& JobCard::getId() const
|
||||
/*
|
||||
Function: getBookingId
|
||||
Description: Retrieves the booking ID associated with the job card.
|
||||
Parameter: None
|
||||
Return type: const std::string&
|
||||
Returns:
|
||||
- const std::string& representing the booking ID.
|
||||
*/
|
||||
const std::string& JobCard::getBookingId() const
|
||||
{
|
||||
@@ -85,9 +133,9 @@ const std::string& JobCard::getBookingId() const
|
||||
|
||||
/*
|
||||
Function: getBooking
|
||||
Description: Retrieves the booking object associated with the job card.
|
||||
Parameter: None
|
||||
Return type: ServiceBooking*
|
||||
Description: Retrieves the pointer to the associated ServiceBooking.
|
||||
Returns:
|
||||
- ServiceBooking* representing the booking.
|
||||
*/
|
||||
ServiceBooking* JobCard::getBooking() const
|
||||
{
|
||||
@@ -96,9 +144,9 @@ ServiceBooking* JobCard::getBooking() const
|
||||
|
||||
/*
|
||||
Function: getService
|
||||
Description: Retrieves the service object associated with the job card.
|
||||
Parameter: None
|
||||
Return type: Service*
|
||||
Description: Retrieves the pointer to the associated Service.
|
||||
Returns:
|
||||
- Service* representing the service.
|
||||
*/
|
||||
Service* JobCard::getService() const
|
||||
{
|
||||
@@ -108,8 +156,8 @@ Service* JobCard::getService() const
|
||||
/*
|
||||
Function: getServiceId
|
||||
Description: Retrieves the service ID associated with the job card.
|
||||
Parameter: None
|
||||
Return type: const std::string&
|
||||
Returns:
|
||||
- const std::string& representing the service ID.
|
||||
*/
|
||||
const std::string& JobCard::getServiceId() const
|
||||
{
|
||||
@@ -118,9 +166,9 @@ const std::string& JobCard::getServiceId() const
|
||||
|
||||
/*
|
||||
Function: getTechnicianId
|
||||
Description: Retrieves the technician ID assigned to the job card.
|
||||
Parameter: None
|
||||
Return type: const std::string&
|
||||
Description: Retrieves the technician ID associated with the job card.
|
||||
Returns:
|
||||
- const std::string& representing the technician ID.
|
||||
*/
|
||||
const std::string& JobCard::getTechnicianId() const
|
||||
{
|
||||
@@ -129,9 +177,9 @@ const std::string& JobCard::getTechnicianId() const
|
||||
|
||||
/*
|
||||
Function: getTechnician
|
||||
Description: Retrieves the technician object assigned to the job card.
|
||||
Parameter: None
|
||||
Return type: User*
|
||||
Description: Retrieves the pointer to the assigned technician.
|
||||
Returns:
|
||||
- User* representing the technician.
|
||||
*/
|
||||
User* JobCard::getTechnician() const
|
||||
{
|
||||
@@ -140,9 +188,9 @@ User* JobCard::getTechnician() const
|
||||
|
||||
/*
|
||||
Function: getAssignedDate
|
||||
Description: Retrieves the date when the job was assigned.
|
||||
Parameter: None
|
||||
Return type: const util::Timestamp&
|
||||
Description: Retrieves the timestamp of when the job was assigned.
|
||||
Returns:
|
||||
- const util::Timestamp& representing the assigned date.
|
||||
*/
|
||||
const util::Timestamp& JobCard::getAssignedDate() const
|
||||
{
|
||||
@@ -151,9 +199,9 @@ const util::Timestamp& JobCard::getAssignedDate() const
|
||||
|
||||
/*
|
||||
Function: getStatus
|
||||
Description: Retrieves the current status of the job card.
|
||||
Parameter: None
|
||||
Return type: util::ServiceJobStatus
|
||||
Description: Retrieves the current status of the job.
|
||||
Returns:
|
||||
- ServiceJobStatus representing the job status.
|
||||
*/
|
||||
util::ServiceJobStatus JobCard::getStatus() const
|
||||
{
|
||||
@@ -162,9 +210,9 @@ util::ServiceJobStatus JobCard::getStatus() const
|
||||
|
||||
/*
|
||||
Function: getCompletionDate
|
||||
Description: Retrieves the completion date of the job card.
|
||||
Parameter: None
|
||||
Return type: const util::Timestamp&
|
||||
Description: Retrieves the timestamp of when the job was completed.
|
||||
Returns:
|
||||
- const util::Timestamp& representing the completion date.
|
||||
*/
|
||||
const util::Timestamp& JobCard::getCompletionDate() const
|
||||
{
|
||||
@@ -173,9 +221,11 @@ const util::Timestamp& JobCard::getCompletionDate() const
|
||||
|
||||
/*
|
||||
Function: setId
|
||||
Description: Sets the unique identifier of the job card.
|
||||
Parameter: const std::string& id - new job card ID
|
||||
Return type: void
|
||||
Description: Sets the unique ID of the job card.
|
||||
Parameters:
|
||||
- id: New job card ID string.
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void JobCard::setId(const std::string& id)
|
||||
{
|
||||
@@ -184,9 +234,11 @@ void JobCard::setId(const std::string& id)
|
||||
|
||||
/*
|
||||
Function: setBookingId
|
||||
Description: Sets the booking ID for the job card.
|
||||
Parameter: const std::string& bookingId - new booking ID
|
||||
Return type: void
|
||||
Description: Sets the booking ID associated with the job card.
|
||||
Parameters:
|
||||
- bookingId: New booking ID string.
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void JobCard::setBookingId(const std::string& bookingId)
|
||||
{
|
||||
@@ -195,9 +247,11 @@ void JobCard::setBookingId(const std::string& bookingId)
|
||||
|
||||
/*
|
||||
Function: setBooking
|
||||
Description: Sets the booking object for the job card.
|
||||
Parameter: ServiceBooking* booking - pointer to the booking object
|
||||
Return type: void
|
||||
Description: Sets the associated ServiceBooking pointer.
|
||||
Parameters:
|
||||
- booking: Pointer to the ServiceBooking object.
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void JobCard::setBooking(ServiceBooking* booking)
|
||||
{
|
||||
@@ -206,9 +260,11 @@ void JobCard::setBooking(ServiceBooking* booking)
|
||||
|
||||
/*
|
||||
Function: setService
|
||||
Description: Sets the service object for the job card.
|
||||
Parameter: Service* service - pointer to the service object
|
||||
Return type: void
|
||||
Description: Sets the associated Service pointer.
|
||||
Parameters:
|
||||
- service: Pointer to the Service object.
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void JobCard::setService(Service* service)
|
||||
{
|
||||
@@ -217,9 +273,11 @@ void JobCard::setService(Service* service)
|
||||
|
||||
/*
|
||||
Function: setServiceId
|
||||
Description: Sets the service ID for the job card.
|
||||
Parameter: const std::string& serviceId - new service ID
|
||||
Return type: void
|
||||
Description: Sets the service ID associated with the job card.
|
||||
Parameters:
|
||||
- serviceId: New service ID string.
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void JobCard::setServiceId(const std::string& serviceId)
|
||||
{
|
||||
@@ -228,9 +286,11 @@ void JobCard::setServiceId(const std::string& serviceId)
|
||||
|
||||
/*
|
||||
Function: setTechnicianId
|
||||
Description: Sets the technician ID for the job card.
|
||||
Parameter: const std::string& technicianId - new technician ID
|
||||
Return type: void
|
||||
Description: Sets the technician ID associated with the job card.
|
||||
Parameters:
|
||||
- technicianId: New technician ID string.
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void JobCard::setTechnicianId(const std::string& technicianId)
|
||||
{
|
||||
@@ -239,9 +299,11 @@ void JobCard::setTechnicianId(const std::string& technicianId)
|
||||
|
||||
/*
|
||||
Function: setTechnician
|
||||
Description: Sets the technician object for the job card.
|
||||
Parameter: User* technician - pointer to the technician object
|
||||
Return type: void
|
||||
Description: Sets the pointer to the assigned technician.
|
||||
Parameters:
|
||||
- technician: Pointer to the User object.
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void JobCard::setTechnician(User* technician)
|
||||
{
|
||||
@@ -250,9 +312,11 @@ void JobCard::setTechnician(User* technician)
|
||||
|
||||
/*
|
||||
Function: setAssignedDate
|
||||
Description: Sets the assigned date for the job card.
|
||||
Parameter: const util::Timestamp& assignedDate - new assigned date
|
||||
Return type: void
|
||||
Description: Sets the timestamp of when the job was assigned.
|
||||
Parameters:
|
||||
- assignedDate: New timestamp for the assigned date.
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void JobCard::setAssignedDate(const util::Timestamp& assignedDate)
|
||||
{
|
||||
@@ -261,9 +325,11 @@ void JobCard::setAssignedDate(const util::Timestamp& assignedDate)
|
||||
|
||||
/*
|
||||
Function: setStatus
|
||||
Description: Sets the status of the job card.
|
||||
Parameter: util::ServiceJobStatus status - new job status
|
||||
Return type: void
|
||||
Description: Sets the current status of the job.
|
||||
Parameters:
|
||||
- status: New job status value.
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void JobCard::setStatus(util::ServiceJobStatus status)
|
||||
{
|
||||
@@ -272,11 +338,92 @@ void JobCard::setStatus(util::ServiceJobStatus status)
|
||||
|
||||
/*
|
||||
Function: setCompletionDate
|
||||
Description: Sets the completion date for the job card.
|
||||
Parameter: const util::Timestamp& completionDate - new completion date
|
||||
Return type: void
|
||||
Description: Sets the timestamp of when the job was completed.
|
||||
Parameters:
|
||||
- completionDate: New timestamp for the completion date.
|
||||
Returns:
|
||||
- void
|
||||
*/
|
||||
void JobCard::setCompletionDate(const util::Timestamp& completionDate)
|
||||
{
|
||||
m_completionDate = completionDate;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: serialize
|
||||
Description: Serializes the job card into a CSV-formatted string.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- std::string: Serialized job card record
|
||||
*/
|
||||
std::string JobCard::serialize() const
|
||||
{
|
||||
std::ostringstream serializedJobCard;
|
||||
serializedJobCard << m_id << ','
|
||||
<< m_bookingId << ','
|
||||
<< m_serviceId << ','
|
||||
<< m_technicianId << ','
|
||||
<< m_assignedDate.toString() << ','
|
||||
<< util::getServiceJobStatusString(m_status) << ','
|
||||
<< m_completionDate.toString();
|
||||
return serializedJobCard.str();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: deserialize
|
||||
Description: Deserializes a CSV-formatted string into a JobCard object.
|
||||
Parameters:
|
||||
- record: const std::string&, serialized job card record
|
||||
Returns:
|
||||
- JobCard*: Pointer to the deserialized JobCard object
|
||||
Throws:
|
||||
- std::runtime_error if timestamp parsing fails
|
||||
*/
|
||||
JobCard* JobCard::deserialize(const std::string& record)
|
||||
{
|
||||
std::string id, bookingId, serviceId, technicianId;
|
||||
std::string assignedDateString, statusString, completionDateString;
|
||||
std::istringstream serializedJobCard(record);
|
||||
getline(serializedJobCard, id, ',');
|
||||
getline(serializedJobCard, bookingId, ',');
|
||||
getline(serializedJobCard, serviceId, ',');
|
||||
getline(serializedJobCard, technicianId, ',');
|
||||
getline(serializedJobCard, assignedDateString, ',');
|
||||
getline(serializedJobCard, statusString, ',');
|
||||
getline(serializedJobCard, completionDateString, ',');
|
||||
util::Timestamp assignedDate;
|
||||
util::Timestamp completionDate;
|
||||
try
|
||||
{
|
||||
assignedDate = util::Timestamp::fromString(assignedDateString);
|
||||
completionDate = util::Timestamp::fromString(completionDateString);
|
||||
}
|
||||
catch (...)
|
||||
{
|
||||
throw std::runtime_error("Invalid timestamp");
|
||||
}
|
||||
util::ServiceJobStatus status = util::getServiceJobStatus(statusString);
|
||||
return Factory::getObject<JobCard>(
|
||||
id,
|
||||
bookingId,
|
||||
serviceId,
|
||||
technicianId,
|
||||
assignedDate,
|
||||
status,
|
||||
completionDate
|
||||
);
|
||||
}
|
||||
|
||||
/*
|
||||
Function: getHeaders
|
||||
Description: Retrieves the CSV headers for job card serialization.
|
||||
Parameters:
|
||||
- None
|
||||
Returns:
|
||||
- std::string: Header string ("ID,BookingID,ServiceID,TechnicianID,AssignedDate,Status,CompletionDate")
|
||||
*/
|
||||
std::string JobCard::getHeaders()
|
||||
{
|
||||
return "ID,BookingID,ServiceID,TechnicianID,AssignedDate,Status,CompletionDate";
|
||||
}
|
||||
Reference in New Issue
Block a user