From aef0f4146e675337f018774fab29217e1f0961a1 Mon Sep 17 00:00:00 2001 From: Joel Thomas Date: Wed, 20 May 2026 17:32:13 +0530 Subject: [PATCH] Implement Low Stock Alert functionality NOT004: Low Stock Alert 1. Added low stock alert check in Controller::runSystemChecks() to trigger inventory notification processing during system startup. 2. Implemented InventoryManagementService::sendLowStockAlerts() to detect inventory items below threshold, identify admin users, and send low stock alert notifications with item details. 3. Added helper logic to notify all admins when low stock inventory is detected. Precondition: 1. System has at least one admin user. 2. Inventory item exists with quantity below the configured low stock threshold. 3. Application is started and system checks execute. Steps: 1. Start the application. 2. Allow system checks to run during startup. 3. Navigate to Inventory Menu / View Notifications. - Verify that a low stock alert notification is displayed. 4. Open the generated notification. - Verify that the notification includes the part name and remaining quantity. 5. Confirm notification content. - Verify that the alert was triggered only for inventory items with stock below the threshold. Sreeja Reghukumar, please review --- .../Trenser.VehicleServiceSystem.vcxproj | 2 + .../controllers/Controller.cpp | 1 + .../controllers/Controller.h | 3 ++ .../services/InventoryManagementService.cpp | 49 +++++++++++++++++++ .../utilities/Config.h | 9 ++++ .../utilities/Utility.h | 1 + .../views/UserInterface.cpp | 1 + 7 files changed, 66 insertions(+) create mode 100644 Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Config.h create mode 100644 Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Utility.h diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj index a65c46d..0cb9d3f 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem.vcxproj @@ -171,11 +171,13 @@ + + diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp index d536e8a..b91450c 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp @@ -143,5 +143,6 @@ void Controller::configureNotifications(const std::string& userID, bool paymentN void Controller::runSystemChecks() { + m_inventoryManagementService.sendLowStockAlerts(); } diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h index 3aabb58..d1b73a8 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.h @@ -2,6 +2,7 @@ #include "Map.h" #include #include "Enums.h" +#include "InventoryManagementService.h" class Service; class ComboPackage; @@ -14,6 +15,8 @@ class Notification; class Controller { +private: + InventoryManagementService m_inventoryManagementService; public: bool login(const std::string& username, const std::string& password); void logout(); diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.cpp index 39ef719..aa15ae8 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.cpp @@ -1 +1,50 @@ +#include #include "InventoryManagementService.h" +#include "Vector.h" +#include "Enums.h" +#include "InventoryItem.h" +#include "Config.h" + +static void sendLowStockAlertsToAdmins(InventoryManagementService& inventoryManagementService, const InventoryItem* inventoryItem, const util::Vector& adminUsers) +{ + int adminUsersSize = adminUsers.getSize(); + for (int index = 0; index < adminUsersSize; index++) + { + inventoryManagementService.sendNotification( + adminUsers[index], + "Low Stock Alert", + "The inventory item with ID " + inventoryItem->getId() + + " has very low quantity in the inventory" + ); + } +} + +void InventoryManagementService::sendLowStockAlerts() +{ + auto& inventoryItems = m_dataStore.getInventoryItems(); + int inventoryItemsSize = inventoryItems.getSize(); + auto& usersMap = m_dataStore.getUsers(); + int usersMapSize = usersMap.getSize(); + util::Vector adminUsers; + for (int index = 0; index < usersMapSize; index++) + { + User* user = usersMap.getValueAt(index); + if (user->getUserType() == util::UserType::ADMIN) + { + adminUsers.push_back(user); + } + } + int adminUsersSize = adminUsers.getSize(); + if (adminUsersSize < 1) + { + throw std::runtime_error("The system has no admins present!"); + } + for (int index = 0; index <= inventoryItemsSize; index++) + { + InventoryItem* inventoryItem = inventoryItems.getValueAt(index); + if (inventoryItem && inventoryItem->getQuantity() < config::threshold::INVENTORY_LOW_STOCK_THRESHOLD) + { + sendLowStockAlertsToAdmins(*this, inventoryItem, adminUsers); + } + } +} diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Config.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Config.h new file mode 100644 index 0000000..7a96ed6 --- /dev/null +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Config.h @@ -0,0 +1,9 @@ +#pragma once + +namespace config +{ + namespace threshold + { + constexpr int INVENTORY_LOW_STOCK_THRESHOLD = 5; + } +} diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Utility.h b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Utility.h new file mode 100644 index 0000000..6f70f09 --- /dev/null +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/utilities/Utility.h @@ -0,0 +1 @@ +#pragma once diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/UserInterface.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/UserInterface.cpp index 122f9a8..cc47e47 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/UserInterface.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/UserInterface.cpp @@ -4,6 +4,7 @@ void UserInterface::run() { + m_controller.runSystemChecks(); bool isMenuActive = true; while (isMenuActive) {