Implement Low Stock Alert functionality
<UserStory> NOT004: Low Stock Alert </UserStory>
<Changes>
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.
</Changes>
<Test>
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.
</Test>
<Review>
Sreeja Reghukumar, please review
</Review>
This commit is contained in:
+2
@@ -171,11 +171,13 @@
|
||||
<ClInclude Include="services\PaymentManagementService.h" />
|
||||
<ClInclude Include="services\ServiceManagementService.h" />
|
||||
<ClInclude Include="services\UserManagementService.h" />
|
||||
<ClInclude Include="utilities\Config.h" />
|
||||
<ClInclude Include="utilities\Enums.h" />
|
||||
<ClInclude Include="utilities\InputHelper.h" />
|
||||
<ClInclude Include="utilities\Map.h" />
|
||||
<ClInclude Include="utilities\OutputHelper.h" />
|
||||
<ClInclude Include="utilities\Timestamp.h" />
|
||||
<ClInclude Include="utilities\Utility.h" />
|
||||
<ClInclude Include="utilities\Validator.h" />
|
||||
<ClInclude Include="utilities\Vector.h" />
|
||||
<ClInclude Include="views\AdminMenu.h" />
|
||||
|
||||
@@ -143,5 +143,6 @@ void Controller::configureNotifications(const std::string& userID, bool paymentN
|
||||
|
||||
void Controller::runSystemChecks()
|
||||
{
|
||||
m_inventoryManagementService.sendLowStockAlerts();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
#include "Map.h"
|
||||
#include <string>
|
||||
#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();
|
||||
|
||||
+49
@@ -1 +1,50 @@
|
||||
#include <stdexcept>
|
||||
#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<User*>& 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<User*> 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,9 @@
|
||||
#pragma once
|
||||
|
||||
namespace config
|
||||
{
|
||||
namespace threshold
|
||||
{
|
||||
constexpr int INVENTORY_LOW_STOCK_THRESHOLD = 5;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1 @@
|
||||
#pragma once
|
||||
@@ -4,6 +4,7 @@
|
||||
|
||||
void UserInterface::run()
|
||||
{
|
||||
m_controller.runSystemChecks();
|
||||
bool isMenuActive = true;
|
||||
while (isMenuActive)
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user