diff --git a/Src/Invoice_Generator_System/InvoiceGenerator.cpp b/Src/Invoice_Generator_System/InvoiceGenerator.cpp new file mode 100644 index 0000000..ca52aa2 --- /dev/null +++ b/Src/Invoice_Generator_System/InvoiceGenerator.cpp @@ -0,0 +1,322 @@ +// InvoiceGenerator.cpp +// Works on Dev-C++, Old MinGW, Linux, Windows +// Compile: g++ InvoiceGenerator.cpp -o InvoiceGenerator + +#include +#include +#include +#include +#include +#include + +#ifdef _WIN32 +#include // for _mkdir +#else +#include // for mkdir +#endif + +using namespace std; + +// ----------- Utility: Create Directory ------------- +void makeDirectory(const string &dirName) +{ +#ifdef _WIN32 + _mkdir(dirName.c_str()); // Windows +#else + mkdir(dirName.c_str(), 0777); // Linux +#endif +} + +// Check if file exists +bool fileExists(const string &filename) +{ + ifstream f(filename.c_str()); + return f.good(); +} + +// ----------- Item Class ------------- +class Item +{ +public: + string name; + int quantity; + double price; + + Item() : quantity(0), price(0) {} + + Item(string n, int q, double p) + : name(n), quantity(q), price(p) {} + + double getTotal() const + { + return quantity * price; + } +}; + +// ----------- Invoice Class ------------- +class Invoice +{ +public: + int invoiceID; + string customerName; + vector items; + double subtotal, tax, total; + double taxRate; // NEW: user-entered tax rate % + + Invoice(int id, string cname, double tr) + : invoiceID(id), customerName(cname), subtotal(0), + tax(0), total(0), taxRate(tr) {} + + void addItem(const Item &it) + { + items.push_back(it); + } + + void calculateTotals() + { + subtotal = 0; + for (auto &it : items) + subtotal += it.getTotal(); + + tax = subtotal * (taxRate / 100.0); + total = subtotal + tax; + } + + string filename() const + { + return "invoices/invoice_" + to_string(invoiceID) + ".txt"; + } + + void saveToFile() + { + makeDirectory("invoices"); + + ofstream out(filename().c_str()); + if (!out) + { + cout << "Error saving invoice file!\n"; + return; + } + + out << "----------------------------------------\n"; + out << "Invoice ID: " << invoiceID << "\n"; + out << "Customer Name: " << customerName << "\n"; + out << "----------------------------------------\n\n"; + + out << left << setw(20) << "Item Name" + << setw(10) << "Qty" + << setw(10) << "Price" + << setw(10) << "Total" << "\n"; + out << "--------------------------------------------------\n"; + + for (auto &it : items) + { + out << left << setw(20) << it.name + << setw(10) << it.quantity + << setw(10) << fixed << setprecision(2) << it.price + << setw(10) << fixed << setprecision(2) << it.getTotal() + << "\n"; + } + + out << "--------------------------------------------------\n\n"; + out << "Subtotal: " << subtotal << "\n"; + out << "Tax (" << taxRate << "%): " << tax << "\n"; + out << "Total: " << total << "\n"; + out << "----------------------------------------\n"; + + out.close(); + } +}; + +// ----------- Invoice Manager ------------- +class InvoiceManager +{ +public: + string indexFile; + + InvoiceManager() + { + indexFile = "invoices/index.txt"; + makeDirectory("invoices"); + + if (!fileExists(indexFile)) + { + ofstream make(indexFile.c_str()); + make.close(); + } + } + + int generateID() + { + ifstream f(indexFile.c_str()); + string line; + int maxID = 1000; + + while (getline(f, line)) + { + if (line.empty()) + continue; + + stringstream ss(line); + string idStr; + getline(ss, idStr, '|'); + + int id = stoi(idStr); + if (id > maxID) + maxID = id; + } + return maxID + 1; + } + + void saveToIndex(int id, string cname, string fname) + { + ofstream f(indexFile.c_str(), ios::app); + f << id << "|" << cname << "|" << fname << "\n"; + f.close(); + } + + void createInvoice() + { + cin.ignore(); + cout << "Enter customer name: "; + string cname; + getline(cin, cname); + + cout << "Enter tax percentage (%): "; + double taxPercent; + cin >> taxPercent; + cin.ignore(); + + int id = generateID(); + Invoice inv(id, cname, taxPercent); + + while (true) + { + cout << "\nEnter item name (leave blank to finish): "; + string iname; + getline(cin, iname); + + if (iname.empty()) + break; + + cout << "Quantity: "; + int qty; + cin >> qty; + + cout << "Price: "; + double price; + cin >> price; + cin.ignore(); + + inv.addItem(Item(iname, qty, price)); + } + + if (inv.items.empty()) + { + cout << "No items added. Invoice cancelled.\n"; + return; + } + + inv.calculateTotals(); + inv.saveToFile(); + + saveToIndex(inv.invoiceID, inv.customerName, inv.filename()); + + cout << "\nInvoice created and saved successfully!\n"; + } + + void viewInvoiceByID() + { + cout << "Enter Invoice ID: "; + int id; + cin >> id; + + ifstream f(indexFile.c_str()); + string line; + + while (getline(f, line)) + { + stringstream ss(line); + string idStr, cname, fname; + + getline(ss, idStr, '|'); + getline(ss, cname, '|'); + getline(ss, fname, '|'); + + if (stoi(idStr) == id) + { + ifstream invFile(fname.c_str()); + cout << "\n----- Invoice Content -----\n\n"; + string ln; + while (getline(invFile, ln)) + cout << ln << "\n"; + return; + } + } + + cout << "Invoice not found!\n"; + } + + void showAllInvoices() + { + ifstream f(indexFile.c_str()); + string line; + + cout << "\nStored Invoices:\n"; + cout << "-------------------------------------------\n"; + + while (getline(f, line)) + { + if (line.empty()) + continue; + + stringstream ss(line); + string id, cname, fname; + getline(ss, id, '|'); + getline(ss, cname, '|'); + getline(ss, fname, '|'); + + cout << "ID: " << id << " | Name: " << cname + << " | File: " << fname << "\n"; + } + } +}; + +// ----------- MAIN MENU ------------- +int main() +{ + InvoiceManager manager; + + while (true) + { + cout << "\n----------------------------------------\n"; + cout << " INVOICE GENERATOR SYSTEM \n"; + cout << "----------------------------------------\n"; + cout << "1. Create Invoice\n"; + cout << "2. View Invoice by ID\n"; + cout << "3. Show All Invoices\n"; + cout << "4. Exit\n"; + cout << "Enter choice: "; + + int choice; + cin >> choice; + + switch (choice) + { + case 1: + manager.createInvoice(); + break; + case 2: + manager.viewInvoiceByID(); + break; + case 3: + manager.showAllInvoices(); + break; + case 4: + cout << "Exiting...\n"; + return 0; + default: + cout << "Invalid choice!\n"; + } + } +} diff --git a/Src/Invoice_Generator_System/InvoiceGenerator.exe b/Src/Invoice_Generator_System/InvoiceGenerator.exe new file mode 100644 index 0000000..fcae9fb Binary files /dev/null and b/Src/Invoice_Generator_System/InvoiceGenerator.exe differ diff --git a/Src/Invoice_Generator_System/README.md b/Src/Invoice_Generator_System/README.md new file mode 100644 index 0000000..448735e --- /dev/null +++ b/Src/Invoice_Generator_System/README.md @@ -0,0 +1,78 @@ +# Invoice Generator --- User Guide + +This document explains how to run and use the Invoice Generator System. + +------------------------------------------------------------------------ + +## Menu Options + + 1. Create Invoice + 2. View Invoice by ID + 3. Show All Invoices + 4. Exit + Enter choice: + +------------------------------------------------------------------------ + +## 1. Create Invoice + +### Steps: + +1. Enter customer name\ +2. Add items one by one: + - Enter item name\ + - Enter quantity\ + - Enter price\ +3. To finish adding items, **press ENTER on an empty item name** + +### Example: + + Enter customer name: Aditya Gupta + + Enter item name (leave blank to finish): Biscuits + Quantity: 3 + Price: 300 + + Enter item name (leave blank to finish): + +After this, the invoice is saved automatically. + +------------------------------------------------------------------------ + +## 2. View Invoice by ID + +Enter: + + Enter invoice ID: 1001 + +------------------------------------------------------------------------ + +## 🗂 3. Show All Invoices + +Displays all invoice IDs stored in `index.txt`. + +------------------------------------------------------------------------ + +## Project Structure + + project/ + InvoiceGenerator.cpp + index.txt + invoices/ + invoice_1001.txt + invoice_1002.txt + +------------------------------------------------------------------------ + +## ✔ Adding Sample Data + +Place sample invoices in the `invoices/` folder and update `index.txt`. + +------------------------------------------------------------------------ + +## You're Ready! + +- Create invoices\ +- View invoices\ +- Store invoices\ +- List all saved invoices diff --git a/Src/Invoice_Generator_System/invoices/index.txt b/Src/Invoice_Generator_System/invoices/index.txt new file mode 100644 index 0000000..89e5161 --- /dev/null +++ b/Src/Invoice_Generator_System/invoices/index.txt @@ -0,0 +1,5 @@ +1001|Test Customer|invoices/invoice_1001.txt +1002|Rohan Sharma|invoices/invoice_1002.txt +1003|Priya Verma|invoices/invoice_1003.txt +1004|Aditya Gupta|invoices/invoice_1004.txt +1005|Rakshesh Singh Rajput|invoices/invoice_1005.txt diff --git a/Src/Invoice_Generator_System/invoices/invoice_1001.txt b/Src/Invoice_Generator_System/invoices/invoice_1001.txt new file mode 100644 index 0000000..c8d1449 --- /dev/null +++ b/Src/Invoice_Generator_System/invoices/invoice_1001.txt @@ -0,0 +1,18 @@ +---------------------------------------- +Invoice ID: 1001 +Customer Name: Test Customer +Date: 2025-11-14 12:00:00 +---------------------------------------- + +Item Name Qty Price Total +-------------------------------------------------------------- +Pen 2 10.00 20.00 +Notebook 1 50.00 50.00 +Pencil 5 5.00 25.00 +-------------------------------------------------------------- + +Subtotal: 95.00 +Tax (18%): 17.10 +Total: 112.10 + +---------------------------------------- diff --git a/Src/Invoice_Generator_System/invoices/invoice_1002.txt b/Src/Invoice_Generator_System/invoices/invoice_1002.txt new file mode 100644 index 0000000..dbb9a97 --- /dev/null +++ b/Src/Invoice_Generator_System/invoices/invoice_1002.txt @@ -0,0 +1,18 @@ +---------------------------------------- +Invoice ID: 1002 +Customer Name: Rohan Sharma +Date: 2025-11-14 12:30:00 +---------------------------------------- + +Item Name Qty Price Total +-------------------------------------------------------------- +USB Cable 1 150.00 150.00 +Charger 1 350.00 350.00 +Earphones 2 200.00 400.00 +-------------------------------------------------------------- + +Subtotal: 900.00 +Tax (18%): 162.00 +Total: 1062.00 + +---------------------------------------- diff --git a/Src/Invoice_Generator_System/invoices/invoice_1003.txt b/Src/Invoice_Generator_System/invoices/invoice_1003.txt new file mode 100644 index 0000000..28fd0a3 --- /dev/null +++ b/Src/Invoice_Generator_System/invoices/invoice_1003.txt @@ -0,0 +1,18 @@ +---------------------------------------- +Invoice ID: 1003 +Customer Name: Priya Verma +Date: 2025-11-14 13:15:00 +---------------------------------------- + +Item Name Qty Price Total +-------------------------------------------------------------- +Shampoo 1 120.00 120.00 +Soap 4 25.00 100.00 +Face Wash 1 180.00 180.00 +-------------------------------------------------------------- + +Subtotal: 400.00 +Tax (18%): 72.00 +Total: 472.00 + +---------------------------------------- diff --git a/Src/Invoice_Generator_System/invoices/invoice_1004.txt b/Src/Invoice_Generator_System/invoices/invoice_1004.txt new file mode 100644 index 0000000..8479837 --- /dev/null +++ b/Src/Invoice_Generator_System/invoices/invoice_1004.txt @@ -0,0 +1,14 @@ +---------------------------------------- +Invoice ID: 1004 +Customer Name: Aditya Gupta +---------------------------------------- + +Item Name Qty Price Total +-------------------------------------------------- +Biscuits 3 300.00 900.00 +-------------------------------------------------- + +Subtotal: 900.00 +Tax (18%): 162.00 +Total: 1062.00 +---------------------------------------- diff --git a/Src/Invoice_Generator_System/invoices/invoice_1005.txt b/Src/Invoice_Generator_System/invoices/invoice_1005.txt new file mode 100644 index 0000000..e6d0b03 --- /dev/null +++ b/Src/Invoice_Generator_System/invoices/invoice_1005.txt @@ -0,0 +1,14 @@ +---------------------------------------- +Invoice ID: 1005 +Customer Name: Rakshesh Singh Rajput +---------------------------------------- + +Item Name Qty Price Total +-------------------------------------------------- +Wine 2 3000.00 6000.00 +-------------------------------------------------- + +Subtotal: 6000.00 +Tax (40.00%): 2400.00 +Total: 8400.00 +----------------------------------------