/* File: JobCard.cpp Description: Implementation file containing the method definitions of the JobCard class, including constructors, getters, and setters for job card attributes. Author: Trenser Date:19-May-2026 */ #include #include #include "SerializedRecords.h" #include "JobCard.h" #include "Factory.h" #include "StringHelper.h" #include "Enums.h" int JobCard::m_uid = 0; /* Function: JobCard Description: Default constructor that initializes a new job card with a unique ID and default values. Parameter: None Return type: Constructor */ JobCard::JobCard() : m_id("JC" + std::to_string(++m_uid)), m_booking(nullptr), m_service(nullptr), m_technician(nullptr), m_status(util::ServiceJobStatus()) { } /* Function: JobCard 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, Service* service, const std::string& serviceId, const std::string& technicianId, User* technician, const util::Timestamp& assignedDate, util::ServiceJobStatus status, const util::Timestamp& completionDate ) : m_id("JC" + std::to_string(++m_uid)), m_bookingId(bookingId), m_booking(booking), m_service(service), m_serviceId(serviceId), m_technicianId(technicianId), m_technician(technician), m_assignedDate(assignedDate), 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 ID of the job card. Returns: - const std::string& representing the job card ID. */ const std::string& JobCard::getId() const { return m_id; } /* Function: getBookingId Description: Retrieves the booking ID associated with the job card. Returns: - const std::string& representing the booking ID. */ const std::string& JobCard::getBookingId() const { return m_bookingId; } /* Function: getBooking Description: Retrieves the pointer to the associated ServiceBooking. Returns: - ServiceBooking* representing the booking. */ ServiceBooking* JobCard::getBooking() const { return m_booking; } /* Function: getService Description: Retrieves the pointer to the associated Service. Returns: - Service* representing the service. */ Service* JobCard::getService() const { return m_service; } /* Function: getServiceId Description: Retrieves the service ID associated with the job card. Returns: - const std::string& representing the service ID. */ const std::string& JobCard::getServiceId() const { return m_serviceId; } /* Function: getTechnicianId Description: Retrieves the technician ID associated with the job card. Returns: - const std::string& representing the technician ID. */ const std::string& JobCard::getTechnicianId() const { return m_technicianId; } /* Function: getTechnician Description: Retrieves the pointer to the assigned technician. Returns: - User* representing the technician. */ User* JobCard::getTechnician() const { return m_technician; } /* Function: getAssignedDate Description: Retrieves the timestamp of when the job was assigned. Returns: - const util::Timestamp& representing the assigned date. */ const util::Timestamp& JobCard::getAssignedDate() const { return m_assignedDate; } /* Function: getStatus Description: Retrieves the current status of the job. Returns: - ServiceJobStatus representing the job status. */ util::ServiceJobStatus JobCard::getStatus() const { return m_status; } /* Function: getCompletionDate Description: Retrieves the timestamp of when the job was completed. Returns: - const util::Timestamp& representing the completion date. */ const util::Timestamp& JobCard::getCompletionDate() const { return m_completionDate; } /* Function: setId 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) { m_id = id; } /* Function: setBookingId 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) { m_bookingId = bookingId; } /* Function: setBooking Description: Sets the associated ServiceBooking pointer. Parameters: - booking: Pointer to the ServiceBooking object. Returns: - void */ void JobCard::setBooking(ServiceBooking* booking) { m_booking = booking; } /* Function: setService Description: Sets the associated Service pointer. Parameters: - service: Pointer to the Service object. Returns: - void */ void JobCard::setService(Service* service) { m_service = service; } /* Function: setServiceId 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) { m_serviceId = serviceId; } /* Function: setTechnicianId 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) { m_technicianId = technicianId; } /* Function: setTechnician Description: Sets the pointer to the assigned technician. Parameters: - technician: Pointer to the User object. Returns: - void */ void JobCard::setTechnician(User* technician) { m_technician = technician; } /* Function: setAssignedDate 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) { m_assignedDate = assignedDate; } /* Function: setStatus Description: Sets the current status of the job. Parameters: - status: New job status value. Returns: - void */ void JobCard::setStatus(util::ServiceJobStatus status) { m_status = status; } /* Function: setCompletionDate 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 JobCard object into a SerializedJobCard record. Parameters: - None Returns: - SerializedJobCard: Serialized representation of the job card */ SerializedJobCard JobCard::serialize() const { SerializedJobCard serialized = {}; strcpy_s(serialized.id, sizeof(serialized.id), m_id.c_str()); strcpy_s(serialized.bookingId, sizeof(serialized.bookingId), m_bookingId.c_str()); strcpy_s(serialized.serviceId, sizeof(serialized.serviceId), m_serviceId.c_str()); strcpy_s(serialized.technicianId, sizeof(serialized.technicianId), m_technicianId.c_str()); serialized.assignedDate = m_assignedDate; serialized.status = m_status; serialized.completionDate = m_completionDate; return serialized; } /* Function: deserialize Description: Deserializes a SerializedJobCard record into a JobCard object. Parameters: - serializedJobCard: const SerializedJobCard&, serialized job card record Returns: - JobCard*: Pointer to the deserialized JobCard object */ JobCard* JobCard::deserialize(const SerializedJobCard& serializedJobCard) { return Factory::getObject( serializedJobCard.id, serializedJobCard.bookingId, serializedJobCard.serviceId, serializedJobCard.technicianId, serializedJobCard.assignedDate, serializedJobCard.status, serializedJobCard.completionDate); }