-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathInventoryManagementSystem.cpp
734 lines (685 loc) · 21 KB
/
InventoryManagementSystem.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
using namespace std;
void
clearTerminal ()
{
#ifdef _WIN32
system ("cls");
#else
system ("clear");
#endif
}
class Product
{
public:
string name;
int id;
int quantity;
double price;
string category;
public:
Product (string name, int id, int quantity, double price, string category)
{
this->name = name;
this->id = id;
this->quantity = quantity;
this->price = price;
this->category = category;
}
void
display ()
{
cout << "\n====================================================\n";
cout << "| Product Details | \n";
cout << "| ID: " << setw (38) << id << " |\n";
cout << "| Name: " << setw (38) << name << " |\n";
cout << "| Category: " << setw (38) << category << " |\n";
cout << "| Quantity: " << setw (38) << quantity << " |\n";
cout << "| Price: " << setw (38) << fixed << setprecision (2) << price
<< " |\n";
cout << "====================================================\n\n";
}
};
class Category
{
public:
string name;
string description;
public:
Category (string name, string description)
{
this->name = name;
this->description = description;
}
void
display ()
{
cout << "\n====================================================\n";
cout << "| Category Details |\n";
cout << "| Name: " << setw (42) << name << " |\n";
cout << "| Description: " << setw (32) << fixed << setprecision (2)
<< description << " |\n";
cout << "====================================================\n\n";
}
};
class Supplier
{
public:
string name;
string contactInfo;
Supplier (string name, string contactInfo)
{
this->name = name;
this->contactInfo = contactInfo;
}
void
display ()
{
cout << "\n====================================================\n";
cout << "| Supplier Details |\n";
cout << "| Name: " << setw (42) << name << " |\n";
cout << "| Contact Info: " << setw (32) << fixed << setprecision (2)
<< contactInfo << " |\n";
cout << "====================================================\n\n";
}
};
class Invoice
{
public:
vector<Product> products;
vector<int> quantities;
double total;
public:
Invoice () { total = 0; }
void
addItem (Product &product, int quantity)
{
products.push_back (product);
quantities.push_back (quantity);
total += product.price * quantity;
}
void
display ()
{
clearTerminal ();
cout << "\n====================================================\n";
cout << "| Invoice |\n";
cout << "====================================================\n";
cout << "| ID Name Quantity Price |\n";
cout << "====================================================\n";
for (size_t i = 0; i < products.size (); ++i)
{
cout << "| " << setw (1) << products[i].id << " " << setw (10)
<< products[i].name << " " << setw (12) << quantities[i] << " "
<< setw (19) << fixed << setprecision (2) << products[i].price
<< " |\n";
}
cout << "====================================================\n";
cout << "| Total: " << setw (41) << fixed << setprecision (2) << total
<< " |\n";
cout << "====================================================\n\n";
}
};
class Inventory
{
vector<Product> products;
vector<Category> categories;
vector<Supplier> suppliers;
public:
void
addSampleProducts ()
{
products.push_back (Product ("Bags", 1, 10, 19.99, "Children"));
products.push_back (Product ("Toys", 2, 10, 19.99, "Children"));
products.push_back (Product ("Laptop", 3, 15, 29.99, "Electronics"));
products.push_back (Product ("Charger", 4, 15, 29.99, "Electronics"));
}
void
addSampleCategories ()
{
categories.push_back (
Category ("Children", "This Category is for Children"));
categories.push_back (
Category ("Electronics", "This Category is for Electronics"));
}
void
addSampleSuppliers ()
{
suppliers.push_back (Supplier ("Supplier1", "ContactInfo1"));
suppliers.push_back (Supplier ("Supplier2", "ContactInfo2"));
}
void
addProduct (Product &product)
{
products.push_back (product);
clearTerminal ();
cout << "\n====================================================\n";
cout << "| Product Added Successfully |\n";
cout << "====================================================\n\n";
}
void
updateProduct (int id, Product &updatedProduct)
{
bool found = false;
for (int i = 0; i < products.size (); ++i)
{
if (products[i].id == id)
{
products[i] = updatedProduct;
clearTerminal ();
cout << "\n====================================================\n";
cout << "| Product Updated Successfully |\n";
cout << "====================================================\n\n";
found = true;
break;
}
}
if (found == false)
{
clearTerminal ();
cout << "\n====================================================\n";
cout << "| Product Not Found!! |\n";
cout << "====================================================\n\n";
}
}
void
queryProduct (int id)
{
bool found = false;
for (int i = 0; i < products.size (); ++i)
{
if (products[i].id == id)
{
clearTerminal ();
products[i].display ();
found = true;
break;
}
}
if (found == false)
{
clearTerminal ();
cout << "\n====================================================\n";
cout << "| Product Not Found!! |\n";
cout << "====================================================\n\n";
}
}
void
removeProduct (int id)
{
for (int i = 0; i < products.size (); ++i)
{
if (products[i].id == id)
{
products.erase (products.begin () + i);
clearTerminal ();
cout << "\n====================================================\n";
cout << "| Product Removed Successfully |\n";
cout << "====================================================\n\n";
return;
}
}
clearTerminal ();
cout << "\n====================================================\n";
cout << "| Product Not Found!! |\n";
cout << "====================================================\n\n";
}
void
buyProduct (string name, int quantity)
{
Invoice invoice;
for (int i = 0; i < products.size (); ++i)
{
if (products[i].name == name)
{
if (products[i].quantity >= quantity)
{
products[i].quantity -= quantity;
invoice.addItem (products[i], quantity);
clearTerminal ();
invoice.display ();
return;
}
else
{
clearTerminal ();
cout << "\n==================================================="
"=\n";
cout << "| Insufficient quantity available. "
"|\n";
cout << "==================================================="
"=\n\n";
return;
}
}
}
cout << "\n====================================================\n";
cout << "| Product Not Found!! |\n";
cout << "====================================================\n\n";
}
void
displayAllProducts ()
{
clearTerminal ();
for (int i = 0; i < products.size (); ++i)
{
products[i].display ();
}
}
void
addCategory (Category &category)
{
categories.push_back (category);
clearTerminal ();
cout << "\n====================================================\n";
cout << "| Category Added Successfully |\n";
cout << "====================================================\n\n";
}
void
updateCategory (string name, Category &updatedCategory)
{
bool found = false;
for (int i = 0; i < categories.size (); ++i)
{
if (categories[i].name == name)
{
categories[i] = updatedCategory;
clearTerminal ();
cout << "\n====================================================\n";
cout << "| Category Updated Successfully |\n";
cout << "====================================================\n\n";
found = true;
break;
}
}
if (found == false)
{
clearTerminal ();
cout << "\n====================================================\n";
cout << "| Category Not Found!! |\n";
cout << "====================================================\n\n";
}
}
void
queryCategory (string name)
{
bool found = false;
for (int i = 0; i < categories.size (); ++i)
{
if (categories[i].name == name)
{
clearTerminal ();
categories[i].display ();
found = true;
break;
}
}
if (!found)
{
clearTerminal ();
cout << "\n====================================================\n";
cout << "| Category Not Found!! |\n";
cout << "====================================================\n\n";
}
}
void
removeCategory (string name)
{
for (int i = 0; i < categories.size (); ++i)
{
if (categories[i].name == name)
{
categories.erase (categories.begin () + i);
clearTerminal ();
cout << "\n====================================================\n";
cout << "| Category Removed Successfully |\n";
cout << "====================================================\n\n";
return;
}
}
}
void
displayAllCategories ()
{
clearTerminal ();
for (int i = 0; i < categories.size (); ++i)
{
categories[i].display ();
}
}
void
displayProductByCategory (string &category)
{
bool found = false;
clearTerminal ();
for (int i = 0; i < products.size (); i++)
{
if (products[i].category == category)
{
products[i].display ();
found = true;
}
}
if (!found)
{
clearTerminal ();
cout << "\n====================================================\n";
cout << "| No products found in this category |\n";
cout << "====================================================\n\n";
}
}
void
addSupplier (Supplier &supplier)
{
suppliers.push_back (supplier);
clearTerminal ();
cout << "\n====================================================\n";
cout << "| Supplier Added Successfully |\n";
cout << "====================================================\n\n";
}
void
updateSupplier (string name, Supplier &updatedSupplier)
{
bool found = false;
for (int i = 0; i < suppliers.size (); ++i)
{
if (suppliers[i].name == name)
{
suppliers[i] = updatedSupplier;
clearTerminal ();
cout << "\n====================================================\n";
cout << "| Supplier Updated Successfully |\n";
cout << "====================================================\n\n";
found = true;
break;
}
}
if (!found)
{
clearTerminal ();
cout << "\n====================================================\n";
cout << "| Supplier Not Found!! |\n";
cout << "====================================================\n\n";
}
}
void
querySupplier (string name)
{
bool found = false;
for (int i = 0; i < suppliers.size (); ++i)
{
if (suppliers[i].name == name)
{
clearTerminal ();
suppliers[i].display ();
found = true;
break;
}
}
if (!found)
{
clearTerminal ();
cout << "\n====================================================\n";
cout << "| Supplier Not Found!! |\n";
cout << "====================================================\n\n";
}
}
void
removeSupplier (string name)
{
for (int i = 0; i < suppliers.size (); ++i)
{
if (suppliers[i].name == name)
{
suppliers.erase (suppliers.begin () + i);
clearTerminal ();
cout << "\n====================================================\n";
cout << "| Supplier Removed Successfully |\n";
cout << "====================================================\n\n";
return;
}
}
}
void
displayAllSuppliers ()
{
clearTerminal ();
for (int i = 0; i < suppliers.size (); ++i)
{
suppliers[i].display ();
}
}
};
int
main ()
{
Inventory inventory;
inventory.addSampleCategories ();
inventory.addSampleProducts ();
inventory.addSampleSuppliers ();
int choice;
do
{
cout << "====================================================\n";
cout << "| |\n";
cout << "| Inventory Management System |\n";
cout << "| |\n";
cout << "====================================================\n";
cout << "| --Product Options-- |\n";
cout << "| 1. Add Product |\n";
cout << "| 2. Update Product |\n";
cout << "| 3. Query Product |\n";
cout << "| 4. Remove Product |\n";
cout << "| 5. Display All Product |\n";
cout << "| 6. Buy Product |\n";
cout << "| 7. Display Products by Category |\n";
cout << "====================================================\n";
cout << "| --Category Options-- |\n";
cout << "| 8. Add Category |\n";
cout << "| 9. Update Category |\n";
cout << "| 10. Query Category |\n";
cout << "| 11. Display All Category |\n";
cout << "| 12. Remove Category |\n";
cout << "====================================================\n";
cout << "| --Supplier Options-- |\n";
cout << "| 13. Add Supplier |\n";
cout << "| 14. Update Supplier |\n";
cout << "| 15. Query Supplier |\n";
cout << "| 16. Display All Supplier |\n";
cout << "| 17. Remove Supplier |\n";
cout << "====================================================\n";
cout << "| 0. Exit |\n";
cout << "====================================================\n";
cout << "Enter your choice: ";
cin >> choice;
switch (choice)
{
case 1:
{
string name;
int id, quantity;
double price;
string category;
cout << "Enter the product name: ";
cin >> name;
cout << "Enter product ID: ";
cin >> id;
cout << "Enter the Category name: ";
cin >> category;
cout << "Enter product quantity: ";
cin >> quantity;
cout << "Enter product price: ";
cin >> price;
Product product (name, id, quantity, price, category);
inventory.addProduct (product);
break;
}
case 2:
{
int id;
string name;
int quantity;
double price;
string category;
cout << "Enter product ID to update: ";
cin >> id;
cout << "Enter new product name: ";
cin >> name;
cout << "Enter the new category name: ";
cin >> category;
cout << "Enter new product quantity: ";
cin >> quantity;
cout << "Enter new product price: ";
cin >> price;
Product updatedProduct (name, id, quantity, price, category);
inventory.updateProduct (id, updatedProduct);
break;
}
case 3:
{
int id;
cout << "Enter product ID to query: ";
cin >> id;
inventory.queryProduct (id);
break;
}
case 4:
{
int id;
cout << "Enter product ID to remove: ";
cin >> id;
inventory.removeProduct (id);
break;
}
case 5:
{
inventory.displayAllProducts ();
break;
}
case 6:
{
string name;
int quantity;
cout << "Enter product name to buy: ";
cin.ignore ();
getline (cin, name);
cout << "Enter quantity to buy: ";
cin >> quantity;
inventory.buyProduct (name, quantity);
break;
}
case 7:
{
{
string categoryName;
cout << "Enter category name: ";
cin >> categoryName;
inventory.displayProductByCategory (categoryName);
break;
}
}
case 8:
{
string name, description;
cout << "Enter category name: ";
cin >> name;
cin.ignore ();
cout << "Enter category description: ";
getline (cin, description);
Category category (name, description);
inventory.addCategory (category);
break;
}
case 9:
{
string name, description;
cout << "Enter category name to update: ";
cin >> name;
cin.ignore ();
cout << "Enter new category description: ";
getline (cin, description);
Category updatedCategory (name, description);
inventory.updateCategory (name, updatedCategory);
break;
}
case 10:
{
string name;
cout << "Enter category name to query: ";
cin >> name;
inventory.queryCategory (name);
break;
}
case 11:
{
inventory.displayAllCategories ();
break;
}
case 12:
{
string name;
cout << "Enter category name to remove: ";
cin >> name;
inventory.removeCategory (name);
break;
}
case 13:
{
string name, contactInfo;
cout << "Enter supplier name: ";
cin >> name;
cout << "Enter supplier contact information: ";
cin >> contactInfo;
Supplier supplier (name, contactInfo);
inventory.addSupplier (supplier);
break;
}
case 14:
{
string name, contactInfo;
cout << "Enter supplier name to update: ";
cin >> name;
cout << "Enter new supplier contact information: ";
cin >> contactInfo;
Supplier updatedSupplier (name, contactInfo);
inventory.updateSupplier (name, updatedSupplier);
break;
}
case 15:
{
string name;
cout << "Enter supplier name to query: ";
cin >> name;
inventory.querySupplier (name);
break;
}
case 16:
{
inventory.displayAllSuppliers ();
break;
}
case 17:
{
string name;
cout << "Enter supplier name to remove : ";
cin >> name;
inventory.removeSupplier (name);
break;
}
case 0:
cout << "Exiting program. Goodbye!" << endl;
break;
default:
{
clearTerminal ();
cout << "Invalid choice. Please try again." << endl;
break;
}
}
}
while (choice != 0);
return 0;
}