From 3594fa4f26c4bea119fefe9534b47a0115b83d46 Mon Sep 17 00:00:00 2001 From: Avinash Rajesh Date: Tue, 19 May 2026 20:37:52 +0530 Subject: [PATCH] Implement Remove Stock Functionality INV003: Remove Stock 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. 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. Sreeja Reghukumar --- .../controllers/Controller.cpp | 1 + .../controllers/Controller.h | 3 ++ .../services/InventoryManagementService.cpp | 14 +++++++ .../views/AdminMenu.cpp | 41 +++++++++++++++++++ 4 files changed, 59 insertions(+) diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp index d536e8a..bd85497 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/controllers/Controller.cpp @@ -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 Controller::getServiceBookings() 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..2b6f7cb 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/services/InventoryManagementService.cpp @@ -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); + } + } +} \ No newline at end of file diff --git a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp index 0432f3c..30425c1 100644 --- a/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp +++ b/Trenser.VehicleServiceSystem/Trenser.VehicleServiceSystem/views/AdminMenu.cpp @@ -1,6 +1,8 @@ +#include #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 +filterActiveItems(const util::Map& inventoryItems) +{ } + +static void displayInventoryWithItems(util::Map& 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()