-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathStore Management System.cpp
435 lines (430 loc) · 8.81 KB
/
Store Management System.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
#include<iostream>
#include<string.h>
#include<conio.h>
#include<math.h>
#include<fstream>
#include<chrono>
#define ll long long int
using namespace std;
ll i,n;
ifstream fin;
ofstream fout,fout1;
fstream fio;
void disp();
class stock
{
public:
string name;//pass[15];
float pr; ll quant;
void get();
void get2();
void show();
ll stchk(string nm);
void withd(ll qty);
void refil(ll qty);
}st;
void stock::withd(ll qty)
{
if(quant>=qty)
{
auto timenow1 = chrono::system_clock::to_time_t(chrono::system_clock::now());
fout1.open("sales.csv",ios::out|ios::app|ios::ate);
fout1 << endl;
string temp(ctime(&timenow1));
fout1 << st.name << " , " << qty << " , " << st.pr << " , " << qty*st.pr << " , " << temp.substr(0,temp.length()-1);
quant-=qty;
fout1.close();
cout << "\n\nStock updated.\n";
cout << "\n\nTotal price to be paid:" << pr*qty;
}
else
cout << "\n\nInsufficient stock";
getch();
}
void stock::refil(ll qty)
{
quant+=qty;
cout << "\n\nStock updated.";
getch();
}
ll stock::stchk(string nm)
{
if(nm==name)
return 0;
else
return 1;
}
void stock::get()
{
cin >> name >> pr >> quant;
}
void stock::get2()
{
cin >> name >> quant;
}
void stock::show()
{
ll a = name.length();
cout << "\n" << name ;
for(ll i=0;i<25-a;i++)
cout << " ";
cout << quant;
ll b = to_string(quant).length();
for(ll i=0;i<25-b;i++)
cout << " ";
cout << pr;
}
void addnew()
{
system("cls");
disp();
getch();
system("cls");
cout << "\nEnter the No. of Products that you wish to add: ";
cin >> n;
if (n!=0)
{
ll j,l,sum=0;
fout.open("project.csv",ios::out|ios::app|ios::ate);
fout << endl;
for(i=0;i<n;i++)
{
cout << "\n\nInput the name, price and the quantity of item respectively\n\n";
st.get();
fout << st.name << " , " << st.quant << " , " << st.pr;
if(i!=n-1)
fout << endl;
cout << "\n\nitem updated";
cin.get();
}
cout << "\n\nStock Updated!!";
fout.close();
cin.get();
system("cls");
disp();
}
else
{
fout.close();
cin.get();
system("cls");
cout << "\n\nNo items to be added";
}
}
void withdraw()
{
system("cls");
string temp;ll qty;
ll i=0;
disp();
cout << "\n\nEnter the product's name \n" << endl;
cin >> temp;
cout << "\n\nEnter quantity: \n" << endl;
cin >> qty;
char ch;
fin.open("project.csv",ios::in);
fout.open("temp.csv",ios::out);
string a,b,c;
fin >> a;
// fin >> a >> ch >> b >> ch >> c;
// fout << a << " , " << b << " , " << c;
fout << a;
if(fin.tellg()!=-1)
fout << endl;
while(!fin.eof())
{
fin >> st.name >> ch >> st.quant >> ch >> st.pr;
if(st.stchk(temp)==0)
{
st.withd(qty);
fout << st.name << " , " << st.quant << " , " << st.pr;
if(fin.tellg()!=-1)
fout << endl;
i++;continue;
}
fout << st.name << " , " << st.quant << " , " << st.pr;
if(fin.tellg()!=-1)
fout << endl;
}
if(i==0)
cout << "\n\n!!Record not found!!";
fin.close();
fout.close();
remove("project.csv");
rename("temp.csv","project.csv");
cin.get();
system("cls");
disp();
getch();
}
void disp()
{
ll i=0;
cout << "\n==================================================================";
cout << "\n\n=================\tTHE STOCK ITEMS ARE\t==================";
cout << "\n\n==================================================================\n";
cout << "\n\nPARTICULARS\tSTOCK AVAILABLE\t\t\t PRICE";
cout << "\n\n============================================================\n";
fin.open("project.csv",ios::in);
string a;
fin >> a;
ll count = 0 ;
char ch;
while(!fin.eof())
{
if(fin.tellg()<0)
break;
fin >> st.name >> ch >> st.quant >> ch >> st.pr;
count++;
st.show();
}
if(count==0)
{
cout << "\n\n\t\t\t!!Empty record room!!";
getch();
}
fin.close();
}
void refill()
{
system("cls");
string temp;ll qty;
ll i=0;
disp();
cout << "\n\nEnter the products name \n" << endl;
cin >> temp;
cout << "\n\nEnter quantity: \n" << endl;
cin >> qty;
char ch;
fin.open("project.csv",ios::in);
fout.open("temp.csv",ios::out);
string a,b,c;
fin >> a;
// fin >> a >> ch >> b >> ch >> c;
// fout << a << " , " << b << " , " << c;
fout << a;
if(fin.tellg()!=-1)
fout << endl;
while(!fin.eof())
{
fin >> st.name >> ch >> st.quant >> ch >> st.pr;
if(st.stchk(temp)==0)
{
st.refil(qty);
fout << st.name << " , " << st.quant << " , " << st.pr;
if(fin.tellg()!=-1)
fout << endl;
i++;
continue;
}
fout << st.name << " , " << st.quant << " , " << st.pr;
if(fin.tellg()!=-1)
fout << endl;
}
if(i!=1)
cout << "\n\n!!Record not found!!";
fin.close();
fout.close();
remove("project.csv");
rename("temp.csv","project.csv");
system("cls");
cin.get();
disp();
cin.get();
}
void remove()
{
system("cls");
ll i=0;
string temp;
cout << "\n\t\t\t\tDelete Record";
cout << "\n\nEnter the name of the product:";
char ch;
cin >> temp;
fin.open("project.csv",ios::in);
fout.open("temp.csv",ios::out);
string a,b,c;
// fin >> a >> ch >> b >> ch >> c;
fin >> a;
// fout << a << "," << b << "," << c;
fout << a;
if(fin.tellg()!=-1)
fout << endl;
while(!fin.eof())
{
fin >> st.name >> ch >> st.quant >> ch >> st.pr;
if(st.stchk(temp)==0)
{
st.show();
cout << "\n\n\t\tRecord deleted";
i++;
}
else
{
fout << st.name << " , " << st.quant << " , " << st.pr;
if(fin.tellg()!=-1)
fout << endl;
}
}
if(i==0)
cout << "\n\n!!Record not found!!";
fin.close();
fout.close();
remove("project.csv");
rename("temp.csv","project.csv");
}
int main()
{
ll i,j;
cout << "\n\n\n\n\n\n\n\n\n\n\n \t\t\t|============ WELCOME TO STORE MANAGEMENT SYSTEM ============|";
getch();
system("cls");
mainmenu:
string pass,pass2;
system("cls");
cout << "\n\t\t STORE MANAGEMENT SYSTEM\n";
cout << "=============================================================";
cout << "\n\n\t\t 1. Dealer Menu\n\n\t\t 2. Customer Menu\n\n\t\t 3. Employee Menu";
cout << "\n\n=============================================================\n";
cout << "\n\nEnter Your Choice:";
cin >> j;
if(j==1)
{
system("cls");
system("cls");
cout << "\n\n\n\n\n\n\n\t\t\t\t\tPlease enter the password: ";
for(ll z=0;z<7;z++)
{
pass.push_back(getch());
system("cls");
cout << "\n\n\n\n\n\n\n\t\t\t\t\tPlease enter the password: ";
for(i=1;i<=(z+1);i++)
{
cout << "*";
}
}
if(pass=="ironman")
{
system("cls");
dealermenu:
system("cls");
cout << "=================================================================";
cout << "\n\n\t\t\t DEALER MENU\n1. Add new product\n2. Display stock\n3. Refill\n4. Remove an item\n5. Exit:";
cout << "\n\n\n==========================END OF MENU=============================";
cout << "\n\n Enter your Choice :\t";
cin >> i;
if(i==1)
{
addnew();getch();
goto dealermenu;
}
else if(i==2)
{
system("cls");
disp();
getch();
goto dealermenu;
}
else if(i==3)
{
refill();
goto dealermenu;
}
else if(i==4)
{
remove();
getch();
goto dealermenu;
}
else
{
goto mainmenu;
}
}
else
{
cout << "\n\n\nINPUT CORRECT PASSWORD!!!\n\n";
getch();
goto mainmenu;
}
}
if(j==2)
{
custmenu:
system("cls");
cout << "=================================================================";
cout << "\n\n\t\t\t CUSTOMER MENU\n1. Purchase\n2. Display stock\n3. Exit:";
cout << "\n\n\n==========================END OF MENU=============================";
cout << "\n\n Enter your Choice :\t";
cin >> i;
if (i==1)
{
withdraw();
getch();
goto custmenu;
}
else if(i==2)
{
system("cls");
disp();
getch();
goto custmenu;
}
else
{
system("cls");
goto mainmenu;
}
}
if(j==3)
{
system("cls");
cout << "\n\n\n\n\n\n\n\t\t\t\t\tPlease enter the password: ";
for(ll z=0;z<7;z++)
{
pass2.push_back(getch());
system("cls");
cout << "\n\n\n\n\n\n\n\t\t\t\t\tPlease enter the password : ";
for(i=1;i<=(z+1);i++)
{
cout << "*";
}
}
if(pass2=="ironman")
{
empmenu:
system("cls");
cout << "=================================================================";
cout << "\n\n\t\t\tEMPLOYEE MENU\n1. Display stock\n2. Refill\n3. Exit";
cout << "\n\n\n==========================END OF MENU=============================";
cout << "\n\n Enter your Choice :\t";
cin >> i;
if(i==1)
{
system("cls");
disp();
getch();
goto empmenu;
}
else if(i==2)
{
refill();
goto empmenu;
}
else
{
system("cls");
cout << "\n\n\n\t\t\tThank You!!";
getch();
goto mainmenu;
}
}
else
{
cout << "\n\nSorry!! Please Provide Valid Password..\n\n";
getch();
goto mainmenu;
}
}
getch();
}