Fix Admin Inventory Management UI Issues and Workflow Enhancements

- Added heading output to Remove Inventory Item submenu for clearer user context.
- Prevented service creation with empty inventory selection by adding validation and early return.
- Improved combo package creation by simplifying null checks with modern idioms.
- Enhanced inventory selection flow:
  - Clear screen and context header for better UX.
  - Prevent duplicate item selection by checking already chosen items.
  - Changed exit option from -1 to 0 for consistency.
  - Added pressEnter prompt after successful item addition.
- Simplified pointer checks using concise conditions (e.g., if (item)).

Fixes #1778
This commit is contained in:
Avinash Rajesh
2026-05-27 16:16:28 +05:30
committed by Joel Thomas
parent 859f7bbeaa
commit c1bd2a6ef1
2 changed files with 27 additions and 6 deletions
@@ -263,6 +263,7 @@ Return type: void
void AdminMenu::removeInventoryItem()
{
util::clear();
std::cout << "Remove Inventory Item\n";
auto inventoryItems = m_controller.getInventoryItems();
auto activeItems = filterActiveItems(inventoryItems);
int activeItemsSize = activeItems.getSize();
@@ -402,6 +403,11 @@ void AdminMenu::createService()
util::Map<std::string, const InventoryItem*> activeInventoryItems = filterActiveItems(currentInventoryItems);
util::Vector<std::string> selectedInventoryItems;
selectInventoryItems(activeInventoryItems,selectedInventoryItems);
if (selectedInventoryItems.isEmpty())
{
util::pressEnter();
return;
}
std::cout << "\nEnter the labour cost: ";
util::read(labourCost);
m_controller.createService(serviceName, selectedInventoryItems, labourCost);
@@ -541,7 +547,7 @@ void AdminMenu::createComboPackages()
while (true)
{
chosenService = selectServiceFromServices(activeServices);
if (chosenService == nullptr)
if (!chosenService)
{
std::cout << "Failed to create combo package!\n\n";
util::pressEnter();
@@ -94,13 +94,15 @@ inline void selectInventoryItems(util::Map<std::string, const InventoryItem*>& c
bool doRun = true;
util::Map<int, const InventoryItem*> currentInventoryMap;
int choice;
if (currentInventoryItems.getSize() == 0)
if (currentInventoryItems.isEmpty())
{
std::cout << "No Items Present, Inventory empty.\n";
return;
}
while (doRun)
{
util::clear();
std::cout << "Create Service\n";
std::cout << "\nSelect Required Items\n";
bool hasInventoryItems = false;
int currentIndex = 1;
@@ -119,6 +121,19 @@ inline void selectInventoryItems(util::Map<std::string, const InventoryItem*>& c
{
continue;
}
bool alreadySelected = false;
for (int iteratorOne = 0; iteratorOne < selectedInventoryItems.getSize(); iteratorOne++)
{
if (selectedInventoryItems[iteratorOne] == currentInventoryItem->getId())
{
alreadySelected = true;
break;
}
}
if (alreadySelected)
{
continue;
}
std::cout << std::left
<< std::setw(6) << currentIndex
<< std::setw(12) << currentInventoryItem->getId()
@@ -133,10 +148,9 @@ inline void selectInventoryItems(util::Map<std::string, const InventoryItem*>& c
{
break;
}
std::cout << "Select the item (Index) or enter -1 to exit: ";
std::cout << "Select the item (Index) or enter 0 to exit: ";
util::read(choice);
if (choice == -1)
if (choice == 0)
{
doRun = false;
}
@@ -144,6 +158,7 @@ inline void selectInventoryItems(util::Map<std::string, const InventoryItem*>& c
{
selectedInventoryItems.push_back(currentInventoryMap.getValueAt(currentInventoryMap.find(choice))->getId());
std::cout << "Item added successfully.\n" << std::endl;
util::pressEnter();
}
else
{
@@ -1066,7 +1081,7 @@ inline util::Map<std::string, const InventoryItem*> filterActiveItems(const util
for (int index = 0; index < inventorySize; index++)
{
const InventoryItem* item = inventoryItems.getValueAt(index);
if (item != nullptr && item->getState() != util::State::INACTIVE)
if (item && item->getState() != util::State::INACTIVE)
{
activeItems.insert(item->getId(), item);
}