From 4243f4e43f4d84ac02d1d5c9a19c3d1225a87a8b Mon Sep 17 00:00:00 2001 From: Jissin Mathew Date: Wed, 17 Jun 2026 15:29:46 +0530 Subject: [PATCH] Fix Inventory Quantity Is Not Decremented When Job Card Is Created Changes: - Added retrieval of tracked service bookings and inventory items in ServiceManagementService::createJobCard(). - Validated service booking ID and inventory item indices before proceeding with job card creation. - Decremented inventory item quantities when job cards are created and marked corresponding tracked inventory records as MODIFIED. - Updated tracked service booking state to MODIFIED when technician is assigned and job status changes. - Persisted changes by saving job cards, service bookings, and inventory items to the datastore. Fixes #2075 --- .../services/ServiceManagementService.cpp | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp index 2949778..f20c3d6 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/ServiceManagementService.cpp @@ -596,6 +596,14 @@ void ServiceManagementService::createJobCard(const std::string& bookingID, const UserManagementService m_userManagementService; ServiceBooking* currentBooking = getServiceBooking(bookingID); auto& currentTrackedJobCards = m_dataStore.getJobCards(); + auto& currentTrackedInventoryItems = m_dataStore.getInventoryItems(); + auto& currentTrackedServiceBookings = m_dataStore.getServiceBookings(); + int currentTrackedServiceBookingIndex = currentTrackedServiceBookings.find(bookingID); + if (currentTrackedServiceBookingIndex == -1) + { + throw std::runtime_error("Invalid service booking id."); + } + auto& currentTrackedServiceBooking = currentTrackedServiceBookings.getValueAt(currentTrackedServiceBookingIndex); if (currentBooking == nullptr) { throw std::runtime_error("Service Booking not available"); @@ -624,10 +632,18 @@ void ServiceManagementService::createJobCard(const std::string& bookingID, const for (int iterator = 0; iterator < inventoryItems.getSize(); iterator++) { InventoryItem* currentInventoryItem = inventoryItems.getValueAt(iterator); + const std::string& currentInventoryItemId = inventoryItems.getKeyAt(iterator); if (currentInventoryItem) { + int trackedCurrentInventoryItemIndex = currentTrackedInventoryItems.find(currentInventoryItemId); + if (trackedCurrentInventoryItemIndex == -1) + { + throw std::runtime_error("Invalid inventory item index."); + } + auto& trackedCurrentInventoryItem = currentTrackedInventoryItems.getValueAt(trackedCurrentInventoryItemIndex); int currentStockQuantity = currentInventoryItem->getQuantity(); currentInventoryItem->setQuantity(currentStockQuantity - 1); + trackedCurrentInventoryItem.state = RecordState::MODIFIED; } } currentBooking->setAssignedTechnician(selectedTechnician); @@ -636,6 +652,7 @@ void ServiceManagementService::createJobCard(const std::string& bookingID, const { currentBooking->setStatus(util::ServiceJobStatus::STARTED); } + 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(bookingID, currentBooking, currentService, serviceID, technicianID, selectedTechnician, util::Timestamp(), util::ServiceJobStatus::STARTED, util::Timestamp()); @@ -652,6 +669,8 @@ void ServiceManagementService::createJobCard(const std::string& bookingID, const message = "A technician has been assigned to your Service Booking with ID " + bookingID; sendNotification(currentBooking->getCustomer(), title, message); m_dataStore.saveJobCards(); + m_dataStore.saveServiceBookings(); + m_dataStore.saveInventoryItems(); } /*