Fix Add Inventory Item Issues

- Added heading "Add Inventory Item" to submenu for clearer user guidance.
- Updated option text from "Add Quantity" to "Restock Item".
- Ensured console clearing (util::clear) before add item and restock operations.
- Reformatted prompts with consistent spacing and line breaks (e.g., "Enter Item Details", "Select Item to Restock").
- Added default case handling in AdminMenu for invalid choices.
- Enhanced MenuHelper output:
  - Extra line breaks for readability.
  - Improved error messages ("Invalid index selected", "No active items available").
  - Clearer success message when updating stock with new quantity.

Fixes #1740
This commit is contained in:
Jissin Mathew
2026-05-26 12:23:23 +05:30
committed by Joel Thomas
parent f63e4056f2
commit 937ba2e7cf
2 changed files with 18 additions and 8 deletions
@@ -218,13 +218,15 @@ void AdminMenu::addInventoryItem()
int choice, quantity;
double price;
std::string partName;
std::cout << "1. Add new item \n2. Add Quantity\nEnter your choice : ";
std::cout << "Add Inventory Item\n";
std::cout << "1. Add new item \n2. Restock Item\n\nEnter your choice : ";
util::read(choice);
switch (choice)
{
case 1:
case 1:
{
std::cout << "--------Enter Item Details----------\n";
util::clear();
std::cout << "Enter Item Details\n";
std::cout << "Part Name : ";
util::read(partName);
std::cout << "Quantity : ";
@@ -232,15 +234,21 @@ void AdminMenu::addInventoryItem()
std::cout << "Price : ";
util::read(price);
m_controller.addInventoryItem(partName, quantity, price);
std::cout << "New Item " << partName << " added to the Inventory.\n";
std::cout << "\nNew Item " << partName << " added to the Inventory.\n\n";
break;
}
case 2:
{
util::clear();
std::cout << "Select Item to Restock\n";
auto inventoryItems = m_controller.getInventoryItems();
addQuantityToItem(inventoryItems, m_controller);
break;
}
default:
{
std::cout << "\nEnter a valid choice.\n\n";
}
}
util::pressEnter();
}
@@ -908,6 +908,7 @@ inline void displayInventoryWithItems(util::Map<std::string, const InventoryItem
<< std::endl;
}
}
std::cout << std::endl;
}
/*
@@ -927,7 +928,7 @@ inline void addQuantityToItem(util::Map<std::string, const InventoryItem*>& inve
int activeSize = activeItems.getSize();
if (activeSize == 0)
{
std::cout << "No active items available in Inventory" << std::endl;
std::cout << "\nNo active items available in Inventory" << std::endl << std::endl;
return;
}
displayInventoryWithItems(activeItems);
@@ -935,7 +936,7 @@ inline void addQuantityToItem(util::Map<std::string, const InventoryItem*>& inve
util::read(itemIndex);
if (itemIndex < 1 || itemIndex > activeSize)
{
std::cout << "Invalid index selected." << std::endl;
std::cout << "\nInvalid index selected." << std::endl << std::endl;
return;
}
std::cout << "Enter quantity to add: ";
@@ -950,13 +951,14 @@ inline void addQuantityToItem(util::Map<std::string, const InventoryItem*>& inve
{
std::string selectedItemId = selectedItem->getId();
m_controller.addInventoryItemStock(selectedItemId, quantity);
std::cout << "Updated " << selectedItem->getPartName()
std::cout << "\nUpdated " << selectedItem->getPartName()
<< " stock. New quantity: " << selectedItem->getQuantity()
<< std::endl
<< std::endl;
}
else
{
std::cout << "Error: Selected item could not be found." << std::endl;
std::cout << "\nError: Selected item could not be found." << std::endl << std::endl;
}
}