Implement Remove Stock Functionality
<UserStory> INV003: Remove Stock </UserStory>
<Changes>
1. Integrated InventoryManagementService into Controller to handle removal of inventory items.
2. Implemented InventoryManagementService::removeInventoryItem to mark items as INACTIVE in the datastore.
3. Enhanced AdminMenu with removeInventoryItem workflow:
- Displays inventory list with index, ID, part name, quantity, and price.
- Allows admin to select item by index for removal.
- Provides confirmation message after successful deletion.
4. Added static helper function displayInventoryWithItems in AdminMenu for modularized inventory display.
</Changes>
<Test>
Precondition:
1. Admin user is logged into the system.
2. Inventory contains multiple items with unique IDs.
3. DataStore is initialized and accessible.
Steps:
1. Navigate to Admin Menu and select "Remove Inventory Item".
- Verify that the system displays all inventory items with ID, part name, quantity, and price.
2. Select an item by entering its index.
- Verify that the system removes the item and displays a confirmation message.
3. Attempt to remove an item with an invalid index.
- Verify that the system rejects the input and shows an error message.
4. Navigate to "View Stock Levels".
- Verify that the removed item no longer appears in the inventory list.
</Test>
<Review>
Sreeja Reghukumar
</Review>
This commit is contained in:
@@ -64,6 +64,7 @@ void Controller::addInventoryItem(const std::string& partName, int quantity, dou
|
||||
|
||||
void Controller::removeInventoryItem(const std::string& inventoryItemID)
|
||||
{
|
||||
m_inventoryManagementService.removeInventoryItem(inventoryItemID);
|
||||
}
|
||||
|
||||
util::Map<std::string, const ServiceBooking*> Controller::getServiceBookings()
|
||||
|
||||
@@ -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();
|
||||
|
||||
+14
@@ -1 +1,15 @@
|
||||
#include "InventoryManagementService.h"
|
||||
#include "InventoryItem.h"
|
||||
|
||||
void InventoryManagementService::removeInventoryItem(const std::string& inventoryItemID)
|
||||
{
|
||||
int index = m_dataStore.getInventoryItems().find(inventoryItemID);
|
||||
if (index != -1)
|
||||
{
|
||||
InventoryItem* item = m_dataStore.getInventoryItems().getValueAt(index);
|
||||
if (item != nullptr)
|
||||
{
|
||||
item->setState(util::State::INACTIVE);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,8 @@
|
||||
#include <iomanip>
|
||||
#include "AdminMenu.h"
|
||||
#include "InputHelper.h"
|
||||
#include "OutputHelper.h"
|
||||
#include "InventoryItem.h"
|
||||
|
||||
void AdminMenu::showMenu()
|
||||
{
|
||||
@@ -48,8 +50,47 @@ void AdminMenu::addInventoryItem()
|
||||
{
|
||||
}
|
||||
|
||||
static util::Map<std::string, const InventoryItem*>
|
||||
filterActiveItems(const util::Map<std::string, const InventoryItem*>& inventoryItems)
|
||||
{ }
|
||||
|
||||
static void displayInventoryWithItems(util::Map<std::string, const InventoryItem*>& inventoryItems)
|
||||
{
|
||||
}
|
||||
|
||||
void AdminMenu::removeInventoryItem()
|
||||
{
|
||||
util::clear();
|
||||
auto inventoryItems = m_controller.getInventoryItems();
|
||||
auto activeItems = filterActiveItems(inventoryItems);
|
||||
int activeItemsSize = activeItems.getSize();
|
||||
if (activeItemsSize == 0)
|
||||
{
|
||||
std::cout << "No items available in Inventory." << std::endl;
|
||||
util::pressEnter();
|
||||
return;
|
||||
}
|
||||
displayInventoryWithItems(activeItems);
|
||||
int itemIndex;
|
||||
std::cout << "Enter the index of the item to remove: ";
|
||||
util::read(itemIndex);
|
||||
if (itemIndex < 1 || itemIndex > activeItemsSize)
|
||||
{
|
||||
std::cout << "Invalid index selected." << std::endl;
|
||||
util::pressEnter();
|
||||
return;
|
||||
}
|
||||
const InventoryItem* selectedItem = inventoryItems.getValueAt(itemIndex - 1);
|
||||
if (selectedItem != nullptr)
|
||||
{
|
||||
if(selectedItem->getState() != util::State::INACTIVE)
|
||||
{
|
||||
std::string selectedItemId = selectedItem->getId();
|
||||
m_controller.removeInventoryItem(selectedItemId);
|
||||
std::cout << "Item " << selectedItem->getPartName() << " removed successfully." << std::endl;
|
||||
}
|
||||
}
|
||||
util::pressEnter();
|
||||
}
|
||||
|
||||
void AdminMenu::checkStockAvailability()
|
||||
|
||||
Reference in New Issue
Block a user