Compare commits
9 Commits
b983337630
...
develop
| Author | SHA1 | Date | |
|---|---|---|---|
| 05b9fc7962 | |||
| 956ef58c79 | |||
| 32f1fa33ce | |||
| 684d6d3860 | |||
| 976547e7d1 | |||
| 4fa143946e | |||
| bdb8431773 | |||
| 2eaa719aca | |||
| 931913fa30 |
@@ -358,7 +358,7 @@ util::Map<std::string, TrackedRecord<ServiceBooking>>& DataStore::getServiceBook
|
|||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid service index.");
|
throw std::runtime_error("Invalid service index.");
|
||||||
}
|
}
|
||||||
auto currentService = services.getValueAt(serviceIndex);
|
auto& currentService = services.getValueAt(serviceIndex);
|
||||||
servicesInBooking[currentServiceId] = currentService.data;
|
servicesInBooking[currentServiceId] = currentService.data;
|
||||||
}
|
}
|
||||||
serviceBooking->setServices(servicesInBooking);
|
serviceBooking->setServices(servicesInBooking);
|
||||||
@@ -369,7 +369,7 @@ util::Map<std::string, TrackedRecord<ServiceBooking>>& DataStore::getServiceBook
|
|||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid user index.");
|
throw std::runtime_error("Invalid user index.");
|
||||||
}
|
}
|
||||||
auto customer = users.getValueAt(userIndex);
|
auto& customer = users.getValueAt(userIndex);
|
||||||
serviceBooking->setCustomer(customer.data);
|
serviceBooking->setCustomer(customer.data);
|
||||||
}
|
}
|
||||||
if (!serviceBooking->getAssignedTechnicianId().empty())
|
if (!serviceBooking->getAssignedTechnicianId().empty())
|
||||||
@@ -379,7 +379,7 @@ util::Map<std::string, TrackedRecord<ServiceBooking>>& DataStore::getServiceBook
|
|||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid technician index.");
|
throw std::runtime_error("Invalid technician index.");
|
||||||
}
|
}
|
||||||
auto technician = users.getValueAt(technicianIndex);
|
auto& technician = users.getValueAt(technicianIndex);
|
||||||
serviceBooking->setAssignedTechnician(technician.data);
|
serviceBooking->setAssignedTechnician(technician.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -423,7 +423,7 @@ util::Map<std::string, TrackedRecord<JobCard>>& DataStore::getJobCards()
|
|||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid service ID: " + serviceId);
|
throw std::runtime_error("Invalid service ID: " + serviceId);
|
||||||
}
|
}
|
||||||
auto trackedService = services.getValueAt(serviceIndex);
|
auto& trackedService = services.getValueAt(serviceIndex);
|
||||||
jobCard->setService(trackedService.data);
|
jobCard->setService(trackedService.data);
|
||||||
const std::string& technicianId = jobCard->getTechnicianId();
|
const std::string& technicianId = jobCard->getTechnicianId();
|
||||||
if (!technicianId.empty())
|
if (!technicianId.empty())
|
||||||
@@ -433,7 +433,7 @@ util::Map<std::string, TrackedRecord<JobCard>>& DataStore::getJobCards()
|
|||||||
{
|
{
|
||||||
throw std::runtime_error("Invalid technician ID: " + technicianId);
|
throw std::runtime_error("Invalid technician ID: " + technicianId);
|
||||||
}
|
}
|
||||||
auto trackedTechnician = users.getValueAt(technicianIndex);
|
auto& trackedTechnician = users.getValueAt(technicianIndex);
|
||||||
jobCard->setTechnician(trackedTechnician.data);
|
jobCard->setTechnician(trackedTechnician.data);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -691,7 +691,7 @@ void DataStore::saveObservers(MappingInfo& mapping, util::Map<std::string, User*
|
|||||||
SharedMemory::setRecordCount(mapping, observerCount);
|
SharedMemory::setRecordCount(mapping, observerCount);
|
||||||
for (size_t index = 0; index < observerCount; index++)
|
for (size_t index = 0; index < observerCount; index++)
|
||||||
{
|
{
|
||||||
SerializedObserver serializedObserver;
|
SerializedObserver serializedObserver{};
|
||||||
User* user = observers.getValueAt(static_cast<int>(index));
|
User* user = observers.getValueAt(static_cast<int>(index));
|
||||||
strcpy_s(serializedObserver.id, sizeof(serializedObserver.id), user->getId().c_str());
|
strcpy_s(serializedObserver.id, sizeof(serializedObserver.id), user->getId().c_str());
|
||||||
SerializedObserver* destination = static_cast<SerializedObserver*>(SharedMemory::getRecordAddress(mapping, index));
|
SerializedObserver* destination = static_cast<SerializedObserver*>(SharedMemory::getRecordAddress(mapping, index));
|
||||||
|
|||||||
+21
-11
@@ -629,6 +629,7 @@ void ServiceManagementService::createJobCard(const std::string& bookingID, const
|
|||||||
DataStoreLockGuard lock(m_dataStore);
|
DataStoreLockGuard lock(m_dataStore);
|
||||||
UserManagementService m_userManagementService;
|
UserManagementService m_userManagementService;
|
||||||
ServiceBooking* currentBooking = getServiceBooking(bookingID);
|
ServiceBooking* currentBooking = getServiceBooking(bookingID);
|
||||||
|
std::string title, message;
|
||||||
if (currentBooking == nullptr)
|
if (currentBooking == nullptr)
|
||||||
{
|
{
|
||||||
throw std::runtime_error("Service Booking not available");
|
throw std::runtime_error("Service Booking not available");
|
||||||
@@ -684,18 +685,30 @@ void ServiceManagementService::createJobCard(const std::string& bookingID, const
|
|||||||
trackedCurrentInventoryItem.state = RecordState::MODIFIED;
|
trackedCurrentInventoryItem.state = RecordState::MODIFIED;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
currentBooking->setAssignedTechnician(selectedTechnician);
|
const User* currentAssignedTechnician = currentBooking->getAssignedTechnician();
|
||||||
currentBooking->setAssignedTechnicianId(selectedTechnician->getId());
|
const std::string& currentAssignedTechnicianId = currentBooking->getAssignedTechnicianId();
|
||||||
|
if (!currentAssignedTechnician && currentAssignedTechnicianId.empty())
|
||||||
|
{
|
||||||
|
currentBooking->setAssignedTechnician(selectedTechnician);
|
||||||
|
currentBooking->setAssignedTechnicianId(selectedTechnician->getId());
|
||||||
|
title = "Technician assigned";
|
||||||
|
message = "A technician has been assigned to your Service Booking with ID " + bookingID;
|
||||||
|
sendNotification(currentBooking->getCustomer(), title, message);
|
||||||
|
}
|
||||||
|
|
||||||
if (currentBooking->getStatus() == util::ServiceJobStatus::PENDING)
|
if (currentBooking->getStatus() == util::ServiceJobStatus::PENDING)
|
||||||
{
|
{
|
||||||
currentBooking->setStatus(util::ServiceJobStatus::STARTED);
|
currentBooking->setStatus(util::ServiceJobStatus::STARTED);
|
||||||
}
|
}
|
||||||
currentTrackedServiceBooking.state = RecordState::MODIFIED;
|
currentTrackedServiceBooking.state = RecordState::MODIFIED;
|
||||||
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());
|
JobCard* jobCard = Factory::getObject<JobCard>(bookingID, currentBooking, currentService, serviceID, technicianID, selectedTechnician, util::Timestamp(), util::ServiceJobStatus::STARTED, util::Timestamp());
|
||||||
if (jobCard)
|
if (jobCard)
|
||||||
{
|
{
|
||||||
|
title = "Job Card Assigned";
|
||||||
|
message = "A new Job Card (ID: " + jobCard->getId() +
|
||||||
|
") has been created for Service " + serviceID +
|
||||||
|
" in Booking " + bookingID +
|
||||||
|
". You have been assigned to this job.";
|
||||||
currentTrackedJobCards.insert(jobCard->getId(), util::createNewRecord(jobCard));
|
currentTrackedJobCards.insert(jobCard->getId(), util::createNewRecord(jobCard));
|
||||||
sendNotification(selectedTechnician, title, message);
|
sendNotification(selectedTechnician, title, message);
|
||||||
}
|
}
|
||||||
@@ -703,9 +716,6 @@ void ServiceManagementService::createJobCard(const std::string& bookingID, const
|
|||||||
{
|
{
|
||||||
throw std::runtime_error("Failed to create job card.");
|
throw std::runtime_error("Failed to create job card.");
|
||||||
}
|
}
|
||||||
title = "Technician assigned";
|
|
||||||
message = "A technician has been assigned to your Service Booking with ID " + bookingID;
|
|
||||||
sendNotification(currentBooking->getCustomer(), title, message);
|
|
||||||
m_dataStore.saveJobCards();
|
m_dataStore.saveJobCards();
|
||||||
m_dataStore.saveServiceBookings();
|
m_dataStore.saveServiceBookings();
|
||||||
m_dataStore.saveInventoryItems();
|
m_dataStore.saveInventoryItems();
|
||||||
@@ -852,8 +862,8 @@ void ServiceManagementService::removeServiceBooking(const std::string& bookingID
|
|||||||
{
|
{
|
||||||
if (currentServiceBooking->getStatus() == util::ServiceJobStatus::PENDING)
|
if (currentServiceBooking->getStatus() == util::ServiceJobStatus::PENDING)
|
||||||
{
|
{
|
||||||
const std::string title = "Service Booking cancelled.";
|
const std::string title = "Service Booking Cancelled";
|
||||||
const std::string message = "Service Booking of id " + bookingID + " successfully cancelled.";
|
const std::string message = "Service Booking (ID: " + bookingID + ") has been successfully cancelled";
|
||||||
currentServiceBooking->setStatus(util::ServiceJobStatus::CANCELLED);
|
currentServiceBooking->setStatus(util::ServiceJobStatus::CANCELLED);
|
||||||
currentTrackedServiceBooking.state = RecordState::MODIFIED;
|
currentTrackedServiceBooking.state = RecordState::MODIFIED;
|
||||||
serviceBookingRemoved = true;
|
serviceBookingRemoved = true;
|
||||||
@@ -1025,8 +1035,8 @@ void ServiceManagementService::updateJobStatus(const std::string& jobID)
|
|||||||
currentJob->getBooking()->setStatus(util::ServiceJobStatus::COMPLETED);
|
currentJob->getBooking()->setStatus(util::ServiceJobStatus::COMPLETED);
|
||||||
trackedServiceBookings.getValueAt(trackedServiceBookings.find(bookingId)).state = RecordState::MODIFIED;
|
trackedServiceBookings.getValueAt(trackedServiceBookings.find(bookingId)).state = RecordState::MODIFIED;
|
||||||
paymentManagementService.generateInvoice(currentJob->getBooking());
|
paymentManagementService.generateInvoice(currentJob->getBooking());
|
||||||
std::string title = "Service Booking completed. Invoice Generated.";
|
std::string title = "Service Booking Completed";
|
||||||
std::string message = "Services completed for the booking and invoice generated.";
|
std::string message = "Service Booking (ID: " + bookingId + ") has been completed successfully. An invoice has been generated.";
|
||||||
sendNotification(currentJob->getBooking()->getCustomer(), title, message);
|
sendNotification(currentJob->getBooking()->getCustomer(), title, message);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -220,6 +220,13 @@ void CustomerMenu::selectService()
|
|||||||
util::pressEnter();
|
util::pressEnter();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!verifyAllPaymentsCompleted(m_controller))
|
||||||
|
{
|
||||||
|
std::cout << "Your booking cannot be processed because you have pending payments for previous services. Please complete all outstanding invoices before booking a new service."
|
||||||
|
<< std::endl;
|
||||||
|
util::pressEnter();
|
||||||
|
return;
|
||||||
|
}
|
||||||
util::Vector<std::string> selectedServices;
|
util::Vector<std::string> selectedServices;
|
||||||
const Service* selectedService = selectServiceFromServices(services);
|
const Service* selectedService = selectServiceFromServices(services);
|
||||||
if (selectedService == nullptr)
|
if (selectedService == nullptr)
|
||||||
@@ -262,6 +269,13 @@ void CustomerMenu::selectComboPackage()
|
|||||||
util::pressEnter();
|
util::pressEnter();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
if (!verifyAllPaymentsCompleted(m_controller))
|
||||||
|
{
|
||||||
|
std::cout << "Your booking cannot be processed because you have pending payments for previous services. Please complete all outstanding invoices before booking a new combo package."
|
||||||
|
<< std::endl;
|
||||||
|
util::pressEnter();
|
||||||
|
return;
|
||||||
|
}
|
||||||
const ComboPackage* selectedComboPackage = selectComboPackageFromPackages(activeComboPackages);
|
const ComboPackage* selectedComboPackage = selectComboPackageFromPackages(activeComboPackages);
|
||||||
if (selectedComboPackage == nullptr)
|
if (selectedComboPackage == nullptr)
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -67,7 +67,7 @@ Return type: void
|
|||||||
*/
|
*/
|
||||||
void Menu::eventListenerLoop()
|
void Menu::eventListenerLoop()
|
||||||
{
|
{
|
||||||
HANDLE handles[3];
|
HANDLE handles[3] = { NULL, NULL, NULL };
|
||||||
handles[0] = m_accountDisabledEvent;
|
handles[0] = m_accountDisabledEvent;
|
||||||
handles[1] = m_notificationAvailableEvent;
|
handles[1] = m_notificationAvailableEvent;
|
||||||
handles[2] = m_shutdownEvent;
|
handles[2] = m_shutdownEvent;
|
||||||
|
|||||||
@@ -588,7 +588,7 @@ inline void displayInvoices(util::Map<std::string, const Invoice*> currentUserIn
|
|||||||
<< util::getPaymentStatusString(selectedInvoice->getStatus()) << std::endl;
|
<< util::getPaymentStatusString(selectedInvoice->getStatus()) << std::endl;
|
||||||
std::cout << std::left << std::setw(20) << "Payment Mode:"
|
std::cout << std::left << std::setw(20) << "Payment Mode:"
|
||||||
<< util::getPaymentModeString(selectedInvoice->getPaymentMethod()) << std::endl;
|
<< util::getPaymentModeString(selectedInvoice->getPaymentMethod()) << std::endl;
|
||||||
auto inventoryItemsInInvoice = selectedInvoice->getParts();
|
auto& inventoryItemsInInvoice = selectedInvoice->getParts();
|
||||||
if (inventoryItemsInInvoice.isEmpty())
|
if (inventoryItemsInInvoice.isEmpty())
|
||||||
{
|
{
|
||||||
std::cout << "No inventory items used.\n\n";
|
std::cout << "No inventory items used.\n\n";
|
||||||
@@ -597,7 +597,6 @@ inline void displayInvoices(util::Map<std::string, const Invoice*> currentUserIn
|
|||||||
std::cout << "\nItems Used:\n";
|
std::cout << "\nItems Used:\n";
|
||||||
std::cout << std::left
|
std::cout << std::left
|
||||||
<< std::setw(20) << "ItemName"
|
<< std::setw(20) << "ItemName"
|
||||||
<< std::setw(10) << "Quantity"
|
|
||||||
<< std::setw(10) << "Price"
|
<< std::setw(10) << "Price"
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
std::cout << std::string(40, '-') << std::endl;
|
std::cout << std::string(40, '-') << std::endl;
|
||||||
@@ -606,7 +605,6 @@ inline void displayInvoices(util::Map<std::string, const Invoice*> currentUserIn
|
|||||||
InventoryItem* currentItem = inventoryItemsInInvoice.getValueAt(iterator);
|
InventoryItem* currentItem = inventoryItemsInInvoice.getValueAt(iterator);
|
||||||
std::cout << std::left
|
std::cout << std::left
|
||||||
<< std::setw(20) << currentItem->getPartName()
|
<< std::setw(20) << currentItem->getPartName()
|
||||||
<< std::setw(10) << currentItem->getQuantity()
|
|
||||||
<< std::setw(10) << currentItem->getPrice()
|
<< std::setw(10) << currentItem->getPrice()
|
||||||
<< std::endl;
|
<< std::endl;
|
||||||
}
|
}
|
||||||
@@ -1146,15 +1144,18 @@ inline void displayAllComboPackages(util::Map<std::string, const ComboPackage*>
|
|||||||
for (int index = 0; index < comboPackages.getSize(); index++)
|
for (int index = 0; index < comboPackages.getSize(); index++)
|
||||||
{
|
{
|
||||||
const ComboPackage* currentComboPackage = comboPackages.getValueAt(index);
|
const ComboPackage* currentComboPackage = comboPackages.getValueAt(index);
|
||||||
if (currentComboPackage && currentComboPackage->getState() != util::State::ACTIVE)
|
if (currentComboPackage)
|
||||||
{
|
{
|
||||||
continue;
|
if (currentComboPackage->getState() != util::State::ACTIVE)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
std::cout << std::left
|
||||||
|
<< std::setw(15) << currentComboPackage->getId()
|
||||||
|
<< std::setw(35) << util::truncateString(currentComboPackage->getPackageName(), 30)
|
||||||
|
<< std::setw(15) << util::calculateComboServiceEstimatedCost(currentComboPackage)
|
||||||
|
<< std::endl;
|
||||||
}
|
}
|
||||||
std::cout << std::left
|
|
||||||
<< std::setw(15) << currentComboPackage->getId()
|
|
||||||
<< std::setw(35) << util::truncateString(currentComboPackage->getPackageName(), 30)
|
|
||||||
<< std::setw(15) << util::calculateComboServiceEstimatedCost(currentComboPackage)
|
|
||||||
<< std::endl;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -1180,18 +1181,21 @@ inline const ComboPackage* selectComboPackageFromPackages(const util::Map<std::s
|
|||||||
for (int index = 0; index < comboPackages.getSize(); index++)
|
for (int index = 0; index < comboPackages.getSize(); index++)
|
||||||
{
|
{
|
||||||
const ComboPackage* currentComboPackage = comboPackages.getValueAt(index);
|
const ComboPackage* currentComboPackage = comboPackages.getValueAt(index);
|
||||||
if (currentComboPackage && currentComboPackage->getState() != util::State::ACTIVE)
|
if (currentComboPackage)
|
||||||
{
|
{
|
||||||
continue;
|
if (currentComboPackage->getState() != util::State::ACTIVE)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
activeComboPackages.insert(currentIndex, currentComboPackage);
|
||||||
|
std::cout << std::left
|
||||||
|
<< std::setw(10) << currentIndex
|
||||||
|
<< std::setw(15) << currentComboPackage->getId()
|
||||||
|
<< std::setw(35) << util::truncateString(currentComboPackage->getPackageName(), 30)
|
||||||
|
<< std::setw(15) << util::calculateComboServiceEstimatedCost(currentComboPackage)
|
||||||
|
<< std::endl;
|
||||||
|
currentIndex++;
|
||||||
}
|
}
|
||||||
activeComboPackages.insert(currentIndex, currentComboPackage);
|
|
||||||
std::cout << std::left
|
|
||||||
<< std::setw(10) << currentIndex
|
|
||||||
<< std::setw(15) << currentComboPackage->getId()
|
|
||||||
<< std::setw(35) << util::truncateString(currentComboPackage->getPackageName(), 30)
|
|
||||||
<< std::setw(15) << util::calculateComboServiceEstimatedCost(currentComboPackage)
|
|
||||||
<< std::endl;
|
|
||||||
currentIndex++;
|
|
||||||
}
|
}
|
||||||
if (activeComboPackages.getSize() == 0)
|
if (activeComboPackages.getSize() == 0)
|
||||||
{
|
{
|
||||||
@@ -1467,3 +1471,45 @@ inline void displayNewNotification(util::Vector<const Notification*> notificatio
|
|||||||
MB_ICONINFORMATION);
|
MB_ICONINFORMATION);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
Function: verifyAllPaymentsCompleted
|
||||||
|
Description: Checks whether the authenticated customer has completed
|
||||||
|
all payments for their invoices. Iterates through all
|
||||||
|
invoices belonging to the customer and verifies that
|
||||||
|
each invoice has a payment status of COMPLETED.
|
||||||
|
Parameters: Controller& m_controller -
|
||||||
|
reference to the Controller object used to access
|
||||||
|
authenticated user and invoice data
|
||||||
|
Return type: bool
|
||||||
|
true if all invoices for the authenticated customer
|
||||||
|
are completed, false if any invoice is pending or not completed
|
||||||
|
Throws: std::runtime_error if no authenticated user is found
|
||||||
|
*/
|
||||||
|
inline bool verifyAllPaymentsCompleted(Controller& m_controller)
|
||||||
|
{
|
||||||
|
const User* authenticatedUser = m_controller.getAuthenticatedUser();
|
||||||
|
if (!authenticatedUser)
|
||||||
|
{
|
||||||
|
throw std::runtime_error("No authenticated user found.");
|
||||||
|
}
|
||||||
|
const std::string& authenticatedUserId = authenticatedUser->getId();
|
||||||
|
util::Map<std::string, const Invoice*> listOfInvoices = m_controller.getAllInvoices();
|
||||||
|
for (int invoiceIndex = 0; invoiceIndex < listOfInvoices.getSize(); ++invoiceIndex)
|
||||||
|
{
|
||||||
|
const Invoice* invoice = listOfInvoices.getValueAt(invoiceIndex);
|
||||||
|
if (!invoice)
|
||||||
|
{
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
const std::string& customerId = invoice->getBooking()->getCustomerId();
|
||||||
|
if (customerId == authenticatedUserId)
|
||||||
|
{
|
||||||
|
if (invoice->getStatus() != util::PaymentStatus::COMPLETED)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user