Merge branch 'feature-inventory-management' into feature-1552-1560
This commit is contained in:
@@ -2,13 +2,14 @@
|
||||
File: AdminMenu.cpp
|
||||
Description: Implementation file containing the method definitions of the
|
||||
AdminMenu class, including menu handling, inventory operations,
|
||||
user management, and combo package management functions.
|
||||
user management , stock management, and combo package management functions.
|
||||
Author: Trenser
|
||||
Date:19-May-2026
|
||||
*/
|
||||
#include <iostream>
|
||||
#include <iomanip>
|
||||
#include "AdminMenu.h"
|
||||
#include "InventoryItem.h"
|
||||
#include "InputHelper.h"
|
||||
#include "OutputHelper.h"
|
||||
#include "User.h"
|
||||
@@ -158,20 +159,252 @@ void AdminMenu::changePassword()
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: viewStockLevels
|
||||
Description: Displays all active inventory items with their details
|
||||
including ID, part name, quantity, and price.
|
||||
Parameter: None
|
||||
Return type: void
|
||||
*/
|
||||
void AdminMenu::viewStockLevels()
|
||||
{
|
||||
auto inventoryItems = m_controller.getInventoryItems();
|
||||
std::cout << std::left << std::setw(15) << "Item ID"
|
||||
<< std::setw(25) << "Part Name"
|
||||
<< std::setw(10) << "Quantity"
|
||||
<< std::setw(10) << "Price"
|
||||
<< std::endl;
|
||||
for (int iterator = 0; iterator < inventoryItems.getSize(); ++iterator)
|
||||
{
|
||||
const InventoryItem* item = inventoryItems.getValueAt(iterator);
|
||||
if (item != nullptr)
|
||||
{
|
||||
if (item->getState() != util::State::INACTIVE)
|
||||
{
|
||||
std::cout << std::left << std::setw(15) << item->getId()
|
||||
<< std::setw(25) << item->getPartName()
|
||||
<< std::setw(10) << item->getQuantity()
|
||||
<< std::setw(10) << item->getPrice()
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: filterActiveItems
|
||||
Description: Filters out inactive inventory items and returns a map
|
||||
containing only active items.
|
||||
Parameter: const util::Map<std::string, const InventoryItem*>& inventoryItems -
|
||||
map of all inventory items
|
||||
Return type: util::Map<std::string, const InventoryItem*>
|
||||
*/
|
||||
static util::Map<std::string, const InventoryItem*>
|
||||
filterActiveItems(const util::Map<std::string, const InventoryItem*>& inventoryItems)
|
||||
{
|
||||
util::Map<std::string, const InventoryItem*> activeItems;
|
||||
int inventorySize = inventoryItems.getSize();
|
||||
for (int index = 0; index < inventorySize; index++)
|
||||
{
|
||||
const InventoryItem* item = inventoryItems.getValueAt(index);
|
||||
if (item != nullptr && item->getState() != util::State::INACTIVE)
|
||||
{
|
||||
activeItems.insert(item->getId(), item);
|
||||
}
|
||||
}
|
||||
return activeItems;
|
||||
}
|
||||
|
||||
/*
|
||||
Function: displayInventoryWithItems
|
||||
Description: Displays inventory items in a tabular format with index, ID,
|
||||
part name, quantity, and price.
|
||||
Parameter: util::Map<std::string, const InventoryItem*>& inventoryItems -
|
||||
map of inventory items to display
|
||||
Return type: void
|
||||
*/
|
||||
static void displayInventoryWithItems(util::Map<std::string, const InventoryItem*>& inventoryItems)
|
||||
{
|
||||
int inventorySize = inventoryItems.getSize();
|
||||
std::cout << std::left << std::setw(10) << "Index"
|
||||
<< std::setw(15) << "Item ID"
|
||||
<< std::setw(25) << "Part Name"
|
||||
<< std::setw(10) << "Quantity"
|
||||
<< std::setw(10) << "Price"
|
||||
<< std::endl;
|
||||
for (int iterator = 0; iterator < inventorySize; iterator++)
|
||||
{
|
||||
const InventoryItem* item = inventoryItems.getValueAt(iterator);
|
||||
if (item != nullptr)
|
||||
{
|
||||
std::cout << std::left << std::setw(10) << (iterator + 1)
|
||||
<< std::setw(15) << item->getId()
|
||||
<< std::setw(25) << item->getPartName()
|
||||
<< std::setw(10) << item->getQuantity()
|
||||
<< std::setw(10) << item->getPrice()
|
||||
<< std::endl;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: addQuantityToItem
|
||||
Description: Allows the admin to select an active inventory item and
|
||||
increase its stock quantity.
|
||||
Parameter: util::Map<std::string, const InventoryItem*>& inventoryItems -
|
||||
map of inventory items
|
||||
Controller& m_controller - controller instance to update stock
|
||||
Return type: void
|
||||
*/
|
||||
static void addQuantityToItem(util::Map<std::string, const InventoryItem*>& inventoryItems, Controller& m_controller)
|
||||
{
|
||||
int itemIndex;
|
||||
int quantity;
|
||||
auto activeItems = filterActiveItems(inventoryItems);
|
||||
int activeSize = activeItems.getSize();
|
||||
if (activeSize == 0)
|
||||
{
|
||||
std::cout << "No active items available in Inventory" << std::endl;
|
||||
return;
|
||||
}
|
||||
displayInventoryWithItems(activeItems);
|
||||
std::cout << "Enter the index of the item to update: ";
|
||||
util::read(itemIndex);
|
||||
if (itemIndex < 1 || itemIndex > activeSize)
|
||||
{
|
||||
std::cout << "Invalid index selected." << std::endl;
|
||||
return;
|
||||
}
|
||||
std::cout << "Enter quantity to add: ";
|
||||
util::read(quantity);
|
||||
if (quantity < 0)
|
||||
{
|
||||
std::cout << "The quantity should be Greater than 0." << std::endl;
|
||||
return;
|
||||
}
|
||||
const InventoryItem* selectedItem = activeItems.getValueAt(itemIndex - 1);
|
||||
if (selectedItem != nullptr)
|
||||
{
|
||||
std::string selectedItemId = selectedItem->getId();
|
||||
m_controller.addInventoryItemStock(selectedItemId, quantity);
|
||||
std::cout << "Updated " << selectedItem->getPartName()
|
||||
<< " stock. New quantity: " << selectedItem->getQuantity()
|
||||
<< std::endl;
|
||||
}
|
||||
else
|
||||
{
|
||||
std::cout << "Error: Selected item could not be found." << std::endl;
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
Function: addInventoryItem
|
||||
Description: Allows the admin to either add a new inventory item
|
||||
or increase the quantity of an existing item.
|
||||
Parameter: None
|
||||
Return type: void
|
||||
*/
|
||||
void AdminMenu::addInventoryItem()
|
||||
{
|
||||
util::clear();
|
||||
int choice, quantity;
|
||||
double price;
|
||||
std::string partName;
|
||||
std::cout << "1. Add new item \n2. Add Quantity\nEnter your choice : ";
|
||||
util::read(choice);
|
||||
switch (choice)
|
||||
{
|
||||
case 1:
|
||||
{
|
||||
std::cout << "--------Enter Item Details----------\n";
|
||||
std::cout << "Part Name : ";
|
||||
util::read(partName);
|
||||
std::cout << "Quantity : ";
|
||||
util::read(quantity);
|
||||
std::cout << "Price : ";
|
||||
util::read(price);
|
||||
m_controller.addInventoryItem(partName, quantity, price);
|
||||
std::cout << "New Item " << partName << " added to the Inventory.\n";
|
||||
break;
|
||||
}
|
||||
case 2:
|
||||
{
|
||||
auto inventoryItems = m_controller.getInventoryItems();
|
||||
addQuantityToItem(inventoryItems, m_controller);
|
||||
break;
|
||||
}
|
||||
}
|
||||
util::pressEnter();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: removeInventoryItem
|
||||
Description: Removes an active inventory item by marking it inactive
|
||||
after user selection.
|
||||
Parameter: None
|
||||
Return type: void
|
||||
*/
|
||||
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();
|
||||
}
|
||||
|
||||
/*
|
||||
Function: checkStockAvailability
|
||||
Description: Checks if a specific inventory item is available
|
||||
and displays its details if active.
|
||||
Parameter: None
|
||||
Return type: void
|
||||
*/
|
||||
void AdminMenu::checkStockAvailability()
|
||||
{
|
||||
util::clear();
|
||||
std::string itemId;
|
||||
std::cout << "Enter the Item Id : ";
|
||||
util::read(itemId);
|
||||
const InventoryItem* selectedItem = m_controller.getInventoryItem(itemId);
|
||||
if (selectedItem != nullptr)
|
||||
{
|
||||
if (selectedItem->getState() != util::State::INACTIVE)
|
||||
{
|
||||
std::cout << "Item Details\n";
|
||||
std::cout << "---------------------------------------------\n";
|
||||
std::cout << "Item ID : " << selectedItem->getId() << "\n";
|
||||
std::cout << "Part Name : " << selectedItem->getPartName() << "\n";
|
||||
std::cout << "Quantity : " << selectedItem->getQuantity() << "\n";
|
||||
}
|
||||
}
|
||||
util::pressEnter();
|
||||
}
|
||||
|
||||
void AdminMenu::assignJob()
|
||||
|
||||
Reference in New Issue
Block a user