-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmanagement_system.cpp
More file actions
580 lines (540 loc) · 17.7 KB
/
Copy pathmanagement_system.cpp
File metadata and controls
580 lines (540 loc) · 17.7 KB
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
#include <iostream>
#include <string.h>
using namespace std;
struct item
{
int id_item, banyak, harga;
string nama, placeholder;
item *next;
item *prev;
};
struct customer
{
int id_customer, harga;
string nama, tanggal, waktu;
customer *next;
customer *prev;
};
struct customer *customer_init = NULL;
struct item *init = NULL;
// inisiasi node baru
item *node_baru()
{
item *baru = new item;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "Silakan input ID Item : " << endl;
cin >> baru->id_item;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "Silakan input Nama Item : " << endl;
cin >> baru->nama;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "Silakan input Kuantitas Item : " << endl;
cin >> baru->banyak;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "Silakan input Harga Item : " << endl;
cin >> baru->harga;
baru->next = NULL;
baru->prev = NULL;
}
customer *new_node()
{
customer *customer_baru = new customer;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "Silakan input id anda : " << endl;
cin >> customer_baru->id_customer;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "Silakan input nama anda : " << endl;
cin >> customer_baru->nama;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "Silakan input tanggal kedatangan anda (contoh: 19_Agustus)" << endl;
cin >> customer_baru->tanggal;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "Silakan input waktu kedatangan anda : " << endl;
cin >> customer_baru->waktu;
customer_baru->next = NULL;
}
void bubbleSort()
{
if (init == nullptr || init->next == nullptr)
return;
bool swapped;
item *current;
item *last = nullptr;
do
{
swapped = false;
current = init;
while (current->next != last)
{
if (current->id_item > current->next->id_item)
{
// Swap the items
swap(current->id_item, current->next->id_item);
swap(current->banyak, current->next->banyak);
swap(current->harga, current->next->harga);
swap(current->nama, current->next->nama);
swap(current->placeholder, current->next->placeholder);
swapped = true;
}
current = current->next;
}
last = current;
} while (swapped);
}
// addItem
void addItem()
{
item *add;
add = node_baru();
if (init == NULL)
{
init = add;
}
else
{
item *traverse;
traverse = init;
while (traverse->next != NULL)
{
traverse = traverse->next;
}
traverse->next = add;
add->prev = traverse;
}
bubbleSort();
}
// addCustomer
void addCustomer()
{
customer *add_customer;
add_customer = new_node();
if (customer_init == NULL)
{
customer_init = add_customer;
}
else
{
customer *traverse;
traverse = customer_init;
while (traverse->next != NULL)
{
traverse = traverse->next;
}
traverse->next = add_customer;
add_customer->prev = traverse;
}
}
// deleteItem
void deleteItem()
{
item *deleteItem;
deleteItem = init;
if (deleteItem != NULL)
{
init = init->next;
cout << "---------------------------------" << endl;
cout << "Data berhasil dihapus" << endl;
cout << "---------------------------------" << endl;
free(deleteItem);
}
else
{
cout << "---------------------------------" << endl;
cout << "Item masih kosong" << endl;
cout << "---------------------------------" << endl;
}
}
void deleteByID()
{
int ID;
item *deleteitemID;
deleteitemID = init;
if (deleteitemID != NULL)
{
cout << "Input ID Item yang akan dihapus: ";
cin >> ID;
if (deleteitemID->id_item == ID)
{
init = init->next;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "Data berhasil dihapus" << endl;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
free(deleteitemID);
}
}
else
{
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "Item masih kosong" << endl;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
}
}
// database produk
int database()
{
int temp = 0;
item *database = init;
while (database != NULL)
{
database = database->next;
temp++;
}
return temp;
}
int traverseID(int id)
{
int count = 1;
item *idItem = init;
while (idItem != NULL)
{
// cek idItem pada node
if (idItem->id_item == id)
{
break;
}
else
{
count++;
}
idItem = idItem->next;
}
return count;
}
// BeliItem
void beliItem()
{
string produk[32];
int temp = 0;
int bayar, posisi = 0;
int total[32] = {0}; // initialize the array to 0
int count = 0; // to keep track of the number of items bought
int opr, id, banyak, harga;
int i = 1;
item *show;
item *now = init;
item *traverse = init;
customer *totalHarga = customer_init;
if (init == NULL)
{
cout << "MAAF STOK SEDANG KOSONG" << endl;
}
else
{
cout << "Mau beli berapa barang?" << endl; // basic looping
cin >> opr;
int data = database(); // cek banyak barang di database
while (i <= opr)
{
if (traverse != NULL)
{
cout << "\t\t----------------- DATABASE ITEM ---------------------\t\t" << endl;
while (traverse != NULL)
{
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "Product ID: " << traverse->id_item << endl;
cout << "Product Name: " << traverse->nama << endl;
cout << "Quantity: " << traverse->banyak << endl;
cout << "Price: " << traverse->harga << endl;
traverse = traverse->next;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
}
}
else
{
cout << "\t\t----------------- SELAMAT DATANG DI AGRISTORE ---------------------\t\t" << endl;
}
cout << "pilih ID Item:" << endl;
cin >> id;
posisi = traverseID(id); // buat cek ID yang dipilih ada di db
// cek posisi tidak melebihi banyak barang
if (posisi <= data)
{
while (now->id_item != id)
{
now = now->next;
}
cout << "Beli berapa banyak?" << endl;
cin >> banyak;
produk[temp] = now->nama;
temp++;
total[count] = now->harga * banyak;
count++;
// hitung harga total
now->banyak = now->banyak - banyak; // operasi perkurangan kuantitas barang
i++;
}
else
{
cout << "Item tidak tersedia di database" << endl;
}
}
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "Barang yang anda beli adalah: " << endl;
for (int i = 0; i < opr; i++)
{
cout << produk[i] << endl;
}
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
for (int i = 0; i < opr; i++)
{
cout << "Total Harga Semua Item adalah : Rp." << total[i] << endl;
}
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
}
}
// katalog item
void showItem()
{
item *traverse;
traverse = init;
if (traverse != NULL)
{
cout << "\t\t----------------- DATABASE ITEM ---------------------\t\t" << endl;
while (traverse != NULL)
{
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "\nPRODUCT ID\t"
<< "PRODUCT NAME\t"
<< "QUANTITY\t"
<< "PRICE" << endl;
cout << traverse->id_item << "\t\t";
cout << traverse->nama << "\t\t";
cout << traverse->banyak << "\t\t";
cout << traverse->harga << endl;
traverse = traverse->next;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << endl;
}
}
else
{
cout << "\t\t----------------- TIDAK ADA ITEM DI DATABASE ---------------------\t\t" << endl;
cout << endl;
}
}
void showCustomer()
{
customer *traverse = customer_init;
if (traverse == NULL)
{
cout << "\t\t----------------- BELUM ADA PENGUNJUNG ---------------------\t\t" << endl;
}
else
{
cout << "\t\t----------------- DATA PENGUNJUNG ---------------------\t\t" << endl;
while (traverse != NULL)
{
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "\nCustomer ID\t"
<< "Customer Name\t"
<< "Tanggal" << "\t"
<< "Jam" << endl;
cout << traverse->id_customer << "\t\t";
cout << traverse->nama << "\t\t";
cout << traverse->tanggal << "\t\t";
cout << traverse->waktu << endl;
traverse = traverse->next;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
}
}
}
void showHarga()
{
customer *traverseHarga = customer_init;
if (traverseHarga == NULL)
{
cout << "\t\t----------------- BELUM ADA PEMBELI ---------------------\t\t" << endl;
}
else
{
while (traverseHarga != NULL)
{
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "Customer ID: " << traverseHarga->harga << endl;
cout << "Total Beli: " << traverseHarga->harga << endl;
traverseHarga = traverseHarga->next;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
}
}
}
void searchItem()
{
string nama;
int temp = 0;
struct item *src = init;
if (src == NULL)
{
cout << "\t\t----------------- TIDAK ADA ITEM DI DATABASE ---------------------\t\t" << endl;
}
else
{
while (src != NULL)
{
cout << "Silakan cari produk yang anda inginkan di sini: " << endl;
cin >> nama;
if (nama == src->nama)
{
temp = 1;
break;
}
src = src->next;
}
if (temp == 1)
{
cout << "Produk tersedia di katalog" << endl;
}
else
{
cout << "Produk tidak tersedia saat ini" << endl;
}
}
}
int main()
{
int option;
int role;
do
{
cout << endl;
cout << "\t\t----------------- SELAMAT DATANG DI AGRISTORE ---------------------\t\t" << endl;
menu_choice:
cout << "1. ADMIN" << endl;
cout << "2. EMPLOYEE" << endl;
cout << "3. CUSTOMER" << endl;
cout << "4. Exit" << endl;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "choice: ";
cin >> role;
switch (role)
{
case 1:
admin_choice:
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "1. Tambah Item Ke Database" << endl;
cout << "2. Cetak Total Beli" << endl;
cout << "3. Cetak Item yang tersedia pada Database" << endl;
cout << "4. Cetak Data Customer" << endl;
cout << "5. Cari Item pada Database" << endl;
cout << "6. Hapus item" << endl;
cout << "7. Return" << endl;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "choice: ";
cin >> option;
switch (option)
{
case 1:
cout << endl;
addItem();
goto admin_choice;
break;
case 2:
cout << endl;
showHarga();
goto admin_choice;
break;
case 3:
cout << endl;
showItem();
goto admin_choice;
break;
case 4:
cout << endl;
showCustomer();
goto admin_choice;
break;
case 5:
searchItem();
goto admin_choice;
break;
case 6:
deleteByID();
goto admin_choice;
break;
case 7:
goto menu_choice;
break;
}
case 2:
employee_choice:
cout << endl;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "1. Cetak item pada database" << endl;
cout << "2. Return" << endl;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "choice: ";
cin >> option;
switch (option)
{
case 1:
cout << endl;
showItem();
goto employee_choice;
break;
case 2:
cout << endl;
goto menu_choice;
break;
}
case 3:
customer_choice:
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "1. Tambah ID Customer" << endl;
cout << "2. Beli barang" << endl;
cout << "3. Return" << endl;
cout << "------------------------------------------------";
cout << "-----------------------------------------------------\t\t" << endl;
cout << "choice: ";
cin >> option;
switch (option)
{
case 1:
cout << endl;
addCustomer();
goto customer_choice;
break;
case 2:
cout << endl;
beliItem();
goto customer_choice;
break;
case 3:
cout << endl;
goto menu_choice;
break;
default:
goto menu_choice;
}
break;
}
} while (role != 4);
return 0;
}