Professional Documents
Culture Documents
IMS FINAL COPY
IMS FINAL COPY
IMS FINAL COPY
#include <fstream>
#include <sstream>
#include <vector>
#include <iomanip>
#include <limits> // for std::numeric_limits
void clearScreen() {
#ifdef _WIN32
system("cls");
#else
system("clear");
#endif
}
class Item {
public:
int id;
string name;
double price;
int quantity;
double totalPrice;
string supplierName;
void inputItemDetails() {
cout << endl;
cout << "Enter item ID=> ";
while (!(cin >> id)) {
cout << "Invalid input. Please enter a valid item ID=> ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
cout << "Enter item name=> ";
cin.ignore();
getline(cin, name);
cout << "Enter item price=> ";
while (!(cin >> price)) {
cout << "Invalid input. Please enter a valid item price=> ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
cout << "Enter item quantity=> ";
while (!(cin >> quantity)) {
cout << "Invalid input. Please enter a valid item quantity=> ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
cout << "Enter supplier name=> ";
cin.ignore();
getline(cin, supplierName);
void displayItemWithTotal() {
cout << left << setw(10) << id << setw(20) << name << setw(10) << price <<
setw(20) << quantity << setw(10) << totalPrice << setw(20) << supplierName << endl;
}
};
class Sale {
public:
int id;
string name;
double price;
int quantity;
double totalPrice;
string customerName;
void displaySale() {
cout << left << setw(20) << id << setw(30) << name << setw(20) << price <<
setw(20) << quantity << setw(20) << totalPrice << setw(30) << customerName << endl;
}
};
bool login() {
string username, password;
cout << "WELCOME TO INVENTORY MANAGEMENT SYSTEM :)" << endl;
cout << "Enter username=> ";
cin >> username;
cout << "Enter password=> ";
cin >> password;
return (username == ADMIN_USERNAME && password == ADMIN_PASSWORD);
}
void addItem() {
clearScreen();
ofstream inventoryFile("Inventorydashboard.txt", ios::app);
ofstream purchaseFile("Purchasebook.txt", ios::app);
Item item;
cout << "CREATING A PURCHASE" << endl;
item.inputItemDetails();
inventoryFile << item.id << " " << item.name << " " << item.price << " " <<
item.quantity << " " << item.totalPrice << " " << item.supplierName << endl;
purchaseFile << item.id << " " << item.name << " " << item.price << " " <<
item.quantity << " " << item.totalPrice << " " << item.supplierName << endl;
inventoryFile.close();
purchaseFile.close();
cout << "Purchase successful from " << item.supplierName << " with quantity "
<< item.quantity << " at price Rs " << item.price << " for a total of Rs. " <<
item.totalPrice << "." << endl;
}
void viewItems() {
clearScreen();
cout << "INVENTORY ITEMS" << endl;
ifstream inventoryFile("Inventorydashboard.txt");
Item item;
string line;
cout << left << setw(20) << "ID" << setw(30) << "Name" << setw(20) << "Price"
<< setw(20) << "Quantity" << setw(30) << "Supplier" << endl;
while (getline(inventoryFile, line)) {
stringstream ss(line);
ss >> item.id >> item.name >> item.price >> item.quantity >>
item.totalPrice >> item.supplierName;
item.displayItem();
}
inventoryFile.close();
}
void displayAvailableItems() {
ifstream inventoryFile("Inventorydashboard.txt");
Item item;
string line;
cout << left << setw(20) << "ID" << setw(30) << "Name" << setw(20) << "Price"
<< setw(20) << "Quantity" << endl;
while (getline(inventoryFile, line)) {
stringstream ss(line);
ss >> item.id >> item.name >> item.price >> item.quantity >>
item.totalPrice;
item.displayItem();
}
inventoryFile.close();
}
void editItem() {
clearScreen();
viewItems();
vector<Item> items;
ifstream inventoryFile("Inventorydashboard.txt");
ofstream tempFile("temp.txt");
Item item;
string line;
int editId;
cout << "Enter the ID of the item to edit: ";
while (!(cin >> editId)) {
cout << "Invalid input. Please enter a valid item ID: ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
remove("Inventorydashboard.txt");
rename("temp.txt", "Inventorydashboard.txt");
}
void sellItem() {
clearScreen();
vector<Item> items;
ifstream inventoryFile("Inventorydashboard.txt");
ofstream tempFile("temp.txt");
ofstream salesFile("Salesbook.txt", ios::app);
Item item;
string line;
remove("Inventorydashboard.txt");
rename("temp.txt", "Inventorydashboard.txt");
}
void viewPurchaseBook() {
clearScreen();
ifstream purchaseFile("Purchasebook.txt");
Item item;
string line;
cout << left << setw(10) << "ID" << setw(20) << "Name" << setw(10) << "Price"
<< setw(10) << "Quantity" << setw(20) << "Total" << setw(20) << "Supplier" << endl;
while (getline(purchaseFile, line)) {
stringstream ss(line);
ss >> item.id >> item.name >> item.price >> item.quantity >>
item.totalPrice >> item.supplierName;
item.displayItemWithTotal();
}
purchaseFile.close();
}
void viewSalesBook() {
clearScreen();
ifstream salesFile("Salesbook.txt");
Sale sale;
string line;
cout << left << setw(20) << "ID" << setw(30) << "Name" << setw(20) << "Price"
<< setw(20) << "Quantity" << setw(20) << "Total" << setw(30) << "Customer" << endl;
while (getline(salesFile, line)) {
stringstream ss(line);
ss >> sale.id >> sale.name >> sale.price >> sale.quantity >>
sale.totalPrice >> sale.customerName;
sale.displaySale();
}
salesFile.close();
}
int main() {
bool loggedIn = false;
do {
if (!login()) {
clearScreen();
cout << "Login failed. Incorrect username or password." << endl;
cout << "Press 1 to try again or any other key to exit: ";
char choice;
cin >> choice;
if (choice != '1') {
cout << "Exiting program." << endl;
return 1;
}
clearScreen();
}
else {
loggedIn = true;
}
} while (!loggedIn);
int choice;
do {
clearScreen();
cout << "---------------------------------------------INVENTORY MANAGEMENT
SYSTEM------------------------------------------------" << endl;
cout << "1. Add Item" << endl;
cout << "2. View Items" << endl;
cout << "3. Edit Item" << endl;
cout << "4. Sell Item" << endl;
cout << "5. View Purchase Book" << endl;
cout << "6. View Sales Book" << endl;
cout << "7. Exit" << endl;
cout << "Enter your choice: ";
while (!(cin >> choice)) {
cout << "Invalid input. Please enter a valid choice: ";
cin.clear();
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
switch (choice) {
case 1:
addItem();
cout << "Press Enter to continue...";
cin.ignore();
cin.get();
break;
case 2:
viewItems();
cout << "Press Enter to continue...";
cin.ignore();
cin.get();
break;
case 3:
editItem();
cout << "Press Enter to continue...";
cin.ignore();
cin.get();
break;
case 4:
sellItem();
cout << "Press Enter to continue...";
cin.ignore();
cin.get();
break;
case 5:
viewPurchaseBook();
cout << "Press Enter to continue...";
cin.ignore();
cin.get();
break;
case 6:
viewSalesBook();
cout << "Press Enter to continue...";
cin.ignore();
cin.get();
break;
case 7:
cout << "Exiting program." << endl;
break;
default:
cout << "Invalid choice. Please try again." << endl;
cout << "Press Enter to continue...";
cin.ignore();
cin.get();
break;
}
} while (choice != 7);
return 0;
}