Inventaory Explain
Inventaory Explain
The
program allows an admin to manage an inventory of items by performing actions like
adding items, viewing items, editing items, selling items, and viewing purchase and
sales records. Below is a detailed explanation of the code:
These constants define the admin's username and password for login.
### Classes
- **`class Item`**: Represents an item in the inventory.
- **Attributes**:
- `int id`: Item ID.
- `string name`: Item name.
- `double price`: Item price.
- `int quantity`: Item quantity.
- `double totalPrice`: Total price (price * quantity).
- `string supplierName`: Supplier name.
- **Methods**:
- `void inputItemDetails()`: Prompts user to input item details and calculates
the total price.
- `void displayItem()`: Displays item details (excluding `totalPrice`).
- `void displayItemWithTotal()`: Displays item details including `totalPrice`.
### Functions
- **`bool login()`**: Prompts the user to enter a username and password, returns
`true` if they match the admin credentials.
- **`void addItem()`**: Clears the screen, prompts the user to enter item details,
and saves the item to both `Inventorydashboard.txt` and `Purchasebook.txt`.
- **`void viewItems()`**: Clears the screen, reads and displays all items from
`Inventorydashboard.txt`.
- **`void displayAvailableItems()`**: Displays available items (without supplier
details) from `Inventorydashboard.txt`.
- **`void editItem()`**: Allows the user to edit an existing item's details by its
ID and updates `Inventorydashboard.txt`.
- **`void sellItem()`**: Handles the sale of an item by updating its quantity in
`Inventorydashboard.txt` and recording the sale in `Salesbook.txt`.
- **`void viewPurchaseBook()`**: Clears the screen, reads and displays all purchase
records from `Purchasebook.txt`.
- **`void viewSalesBook()`**: Clears the screen, reads and displays all sale
records from `Salesbook.txt`.
- **`void resetInventory()`**: Prompts for confirmation and, if confirmed, clears
the contents of `Inventorydashboard.txt`, `Purchasebook.txt`, and `Salesbook.txt`.
The use of file I/O operations (`ifstream` for reading, `ofstream` for writing)
ensures data persistence across sessions. The program relies on formatted input and
output operations (`cin` and `cout`), and the `<iomanip>` library for aligned table
display. The inclusion of error handling (e.g., `cin.clear()` and `cin.ignore()`)
ensures robust input validation.