-
Notifications
You must be signed in to change notification settings - Fork 1
/
reservation.cpp
775 lines (615 loc) · 19.6 KB
/
reservation.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
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
/*
File Name : reservation.cpp
Description :
Author : Garly Nugraha & Nazwa Fitriyani Zahra
Date : 08/12/2001
*/
/* ========== Header File ========== */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <conio.h>
#include <ctype.h>
#include <time.h>
#include "concierge.h"
#include "room.h"
#include "reservation.h"
#include "compare.h"
#include "validation.h"
/* ======= End of Header File ====== */
int ReservationMenu()
{
int menu;
system("cls");
printf("|==================================|\n");
printf("| Reservation Menu |\n");
printf("|==================================|\n");
printf("|1. Create |\n");
printf("|2. Read |\n");
printf("|3. Update |\n");
printf("|4. Delete |\n");
printf("|5. Back |\n");
printf("|==================================|\n");
printf("\n\n");
printf("Select Menu : ");
scanf("%d", &menu);
system("cls");
switch (menu) {
case 1:
/* Call Modul Create Data Reservation */
ReservationCreate();
break;
case 2:
/* Call Modul Read Data Reservation */
ReservationRead();
break;
case 3:
/* Call Modul Update Data Reservation */
ReservationUpdate();
break;
case 4:
/* Call Modul Delete Data Reservation */
ReservationDelete();
break;
case 5:
/* Call Modul Menu Concierge Menu */
ConciergeMenu();
break;
default:
printf("ERROR : Sorry I don't know the answer to this one!!!");
getch();
system("cls");
/* Call Modul Menu Reservation */
ReservationMenu();
break;
}
}
void ReservationCreate()
{
FILE *f_reservation, *f_room, *f_temproom;
Reservation ReservationData;
room roomdata, temproomdata;
int roomcode, checkreservation, checkroom, more, checklongstay, checkage;
time_t t;
struct tm now;
t = time(NULL);
now = *localtime(&t);
system("cls");
/* Open File */
f_reservation = fopen("Reservation.DAT", "ab+");
/* Error Handle About Open File */
if (!f_reservation)
{
printf ("ERROR : Sorry file cannot be open!!!\n");
getch();
system("cls");
/* Call Modul Menu Reservation */
ReservationMenu();
}
do {
printf("Reservation Code : ");
fflush(stdin);
scanf("%d", &ReservationData.ReservationCode);
checkreservation = CheckReservationCode(ReservationData, ReservationData.ReservationCode);
if(checkreservation != 0)
{
system("cls");
printf("ERROR : Reservation Code has been used, please enter another code!!!\n");
printf("Press Any Key to continue . . .");
getch();
system("cls");
/* Call Modul Create Data Reservation */
ReservationCreate();
}
printf("Nasional Identity Number : ");
fflush(stdin);
gets(ReservationData.NIN);
printf("Full Name : ");
fflush(stdin);
scanf("%[^\n]",&ReservationData.FullName);
printf("Email : ");
fflush(stdin);
gets(ReservationData.Email);
printf("Gender (Male/Female) : ");
fflush(stdin);
gets(ReservationData.Gender);
printf("Age : ");
fflush(stdin);
scanf("%d", &ReservationData.Age);
checkage = ValidationNumbers(ReservationData.Age);
if(checkage != 1){
system("cls");
printf("ERROR : Please Input The Valid age");
printf("\n");
printf("Press Any Key to continue . . .");
getch();
system("cls");
/* Call Modul Create Data Reservation */
ReservationCreate();
}
printf("Room code : ");
fflush(stdin);
scanf("%d", &roomcode);
printf("Number of rooms booked : ");
fflush(stdin);
scanf("%d", &ReservationData.RentRoomData.Quantity);
checkroom = CheckRoomCode(roomdata, roomcode);
if(checkroom != 0)
{
ReservationData.RentRoomData.Code = roomcode;
/* Open File */
f_room = fopen("Room.DAT","rb");
f_temproom = fopen("TempRoom.DAT", "wb");
while(fread(&roomdata, sizeof(roomdata), 1, f_room)){
if(roomcode == roomdata.code){
strcpy(ReservationData.RentRoomData.Name,roomdata.name);
ReservationData.RentRoomData.Price = roomdata.price;
temproomdata.code = roomdata.code;
strcpy(temproomdata.name,roomdata.name);
strcpy(temproomdata.type,roomdata.type);
if(ReservationData.RentRoomData.Quantity > roomdata.total){
system("cls");
printf("ERROR : The number of rooms available is only %d rooms!!!\n", roomdata.total);
printf("Press Any Key to continue . . .");
getch();
system("cls");
/* Call Function Create Data Reservation */
ReservationCreate();
}
temproomdata.total = roomdata.total - ReservationData.RentRoomData.Quantity;
temproomdata.price = roomdata.price;
fwrite(&temproomdata, sizeof(temproomdata),1,f_temproom);
} else {
fwrite(&roomdata, sizeof(roomdata),1,f_temproom);
}
}
/* Close File */
fclose(f_room);
fclose(f_temproom);
/* Remove File */
remove("Room.DAT");
/* Rename File */
rename("TempRoom.DAT", "Room.DAT");
} else {
system("cls");
printf("ERROR : The room code you entered is not available!!!\n");
printf("Press Any Key to continue . . .");
getch();
system("cls");
/* Call Modul Create Data Reservation */
ReservationCreate();
}
printf("Type of the room : %s \n", ReservationData.RentRoomData.Name);
printf("The price of the room : %li \n", ReservationData.RentRoomData.Price);
printf("Check In Day (*Ex : 1 - 31) : ");
fflush(stdin);
scanf("%d", &ReservationData.CheckInDate.Day);
printf("Check In Month (*Ex : 1 - 12) : ");
fflush(stdin);
scanf("%d", &ReservationData.CheckInDate.Month);
printf("Check In Year (*Ex : 2022) : ");
fflush(stdin);
scanf("%d", &ReservationData.CheckInDate.Year);
printf("Check Out Day (*Ex : 1 - 31) : ");
fflush(stdin);
scanf("%d", &ReservationData.CheckOutDate.Day);
printf("Check Out Month (*Ex : 1 - 12) : ");
fflush(stdin);
scanf("%d", &ReservationData.CheckOutDate.Month);
printf("Check Out Year (*Ex : 2022) : ");
fflush(stdin);
scanf("%d", &ReservationData.CheckOutDate.Year);
ReservationData.LongStay = ((ReservationData.CheckOutDate.Year - ReservationData.CheckInDate.Year) * 365) + ((ReservationData.CheckOutDate.Month - ReservationData.CheckInDate.Month) * 30) + (ReservationData.CheckOutDate.Day - ReservationData.CheckInDate.Day);
checklongstay = ValidationNumbers(ReservationData.LongStay);
if(checklongstay != 1){
system("cls");
printf("ERROR : Input Valid Check-In or Check-Out Date");
printf("\n");
printf("Press Any Key to continue . . .");
getch();
system("cls");
/* Call Modul Create Data Reservation */
ReservationCreate();
}
printf("\n\n");
printf("Long Stay : %i\n", ReservationData.LongStay);
ReservationData.Total = ReservationData.RentRoomData.Price * ReservationData.RentRoomData.Quantity * ReservationData.LongStay;
printf("\n");
printf("Total : Rp.%li",ReservationData.Total);
if(ReservationData.Total >= 7500000)
{
ReservationData.Discount = 0.1 * ReservationData.Total;
printf("\n");
printf("Discount 10% : Rp. %d\n", ReservationData.Discount);
} else {
ReservationData.Discount = 0;
}
printf("\n\n");
ReservationData.GrandTotal = ReservationData.Total - ReservationData.Discount;
printf("Grand Total : Rp. %li\n", ReservationData.GrandTotal);
ReservationData.ReservationDate.Day = now.tm_mday;
ReservationData.ReservationDate.Month = now.tm_mon + 1;
ReservationData.ReservationDate.Year = now.tm_year + 1900;
strcpy(ReservationData.Status,"Reservation");
fwrite(&ReservationData, sizeof(ReservationData), 1, f_reservation);
printf("Do you want to create more data? (Y/N) ");
fflush(stdin);
more = getche();
} while (more == 'Y' || more == 'y');
/* Close File */
fclose(f_reservation);
system("cls");
printf("The data is already stored in the file!!!\n");
printf("Press Any Key to continue . . .");
getche();
system("cls");
/* Call Modul Menu Reservation */
ReservationMenu();
}
void CountReservationData()
{
FILE *f_reservation;
char line[255];
int count = 0;
/* Open File */
f_reservation = fopen("Reservation.DAT", "rt");
/* Error Handle About Open File */
if (!f_reservation)
{
printf ("ERROR : Sorry file cannot be open!!!\n");
getch();
system("cls");
/* Call Modul Menu Reservation */
ReservationMenu();
}
while(fgets(line, 255, f_reservation))
{
count++;
}
printf("The amount of data available is %d", count);
printf("\n\n");
/* Close File */
fclose(f_reservation);
}
void ReservationData()
{
FILE *f_reservation;
Reservation ReservationData;
/* Call Modul Count Data Reservation */
CountReservationData();
printf("|===================================================================================|\n");
printf("| Reservation Data |\n");
printf("|===================================================================================|\n");
printf("| ID Guest Name Type Total Price |\n");
printf("|===================================================================================|\n");
/* Open File */
f_reservation = fopen("Reservation.DAT", "rt");
/* Error Handle About Open File */
if (!f_reservation)
{
printf ("ERROR : Sorry file cannot be open!!!\n");
getch();
system("cls");
ReservationMenu();
}
while ((fread(&ReservationData, sizeof(ReservationData), JUM_BLOK, f_reservation)) == JUM_BLOK)
{
printf(" %-7d %-20s %d %-15s %-12li %-20li\n", ReservationData.ReservationCode, ReservationData.FullName, ReservationData.RentRoomData.Code, ReservationData.RentRoomData.Name, ReservationData.RentRoomData.Price, ReservationData.GrandTotal);
}
printf("\n\n\n");
/* Close File */
fclose(f_reservation);
}
void ReservationRead(){
/* Call Modul Data Reservation */
ReservationData();
printf("Press Any Key to continue . . .");
getche();
system("cls");
/* Call Modul Menu Reservation */
ReservationMenu();
}
int CheckReservationCode(Reservation ReservationData, int id)
{
FILE *f_reservation;
/* Open File */
f_reservation = fopen("Reservation.DAT","rb");
while(fread(&ReservationData, sizeof(ReservationData), 1, f_reservation))
{
if(id == ReservationData.ReservationCode)
{
/* Close File */
fclose(f_reservation);
return 1;
}
}
}
void ReservationUpdate()
{
int MenuUpdate;
system("cls");
/* Call Modul Show Data Reservation */
ReservationData();
printf("|==================================|\n");
printf("| Reservation Update |\n");
printf("|==================================|\n");
printf("|1. Update Status |\n");
printf("|2. Back |\n");
printf("|==================================|\n");
printf("\n");
printf("Select Menu : ");
scanf("%d", &MenuUpdate);
system("cls");
switch (MenuUpdate) {
case 1:
/* Call Modul Update Data Status Reservation */
UpdateReservationStatus();
break;
case 2:
/* Call Modul Menu Reservation */
ReservationMenu();
break;
default:
printf("ERROR : Sorry I don't know the answer to this one!!!\n");
printf("Press Any Key to continue . . .");
getch();
system("cls");
/* Call Modul Update Data Reservation */
ReservationUpdate();
break;
}
}
void UpdateReservationStatus()
{
int Code, Compare;
char Status[15], StatusCheckOut[15];
room roomdata, temproomdata;
Reservation ReservationData, TempReservationData;
FILE *f_reservation, *f_room, *f_tempreservation, *f_temproom;
printf("Enter the Reservation Code to be updated : ");
fflush(stdin);
scanf("%d", &Code);
printf("Status (Reservation/Check In/Check Out) : ");
fflush(stdin);
scanf("%[^\n]",&Status);
/* Open File */
f_reservation = fopen("Reservation.DAT", "rb");
f_room = fopen("Room.DAT", "rb");
f_tempreservation = fopen("TempReservation.DAT", "wb");
f_temproom = fopen("TempRoom.DAT", "wb");
/* Error Handle About Open File */
if (!f_reservation)
{
printf ("ERROR : Sorry file cannot be open!!!\n");
getch();
system("cls");
/* Call Modul Update Data Reservation */
ReservationUpdate();
}
/* Error Handle About Open File */
if (!f_room)
{
printf ("ERROR : Sorry file cannot be open!!!\n");
getch();
system("cls");
/* Call Modul Update Data Reservation */
ReservationUpdate();
}
/* Error Handle About Open File */
if (!f_temproom)
{
printf ("ERROR : Sorry file cannot be open!!!\n");
getch();
system("cls");
/* Call Modul Update Data Reservation */
ReservationUpdate();
}
/* Error Handle About Open File */
if (!f_tempreservation)
{
printf ("ERROR : Sorry file cannot be open!!!\n");
getch();
system("cls");
/* Call Modul Update Data Reservation */
ReservationUpdate();
}
while (fread(&ReservationData, sizeof(ReservationData),1, f_reservation))
{
if(Code == ReservationData.ReservationCode){
TempReservationData.ReservationCode = ReservationData.ReservationCode;
strcpy(TempReservationData.FullName,ReservationData.FullName);
strcpy(TempReservationData.Email,ReservationData.Email);
strcpy(TempReservationData.Email,ReservationData.Email);
TempReservationData.Age = ReservationData.Age;
TempReservationData.RentRoomData.Code = ReservationData.RentRoomData.Code;
strcpy(TempReservationData.RentRoomData.Name,ReservationData.RentRoomData.Name);
TempReservationData.RentRoomData.Quantity = ReservationData.RentRoomData.Quantity;
TempReservationData.RentRoomData.Price = ReservationData.RentRoomData.Price;
TempReservationData.LongStay = ReservationData.LongStay;
TempReservationData.CheckInDate.Day = ReservationData.CheckInDate.Day;
TempReservationData.CheckInDate.Month = ReservationData.CheckInDate.Month;
TempReservationData.CheckInDate.Year = ReservationData.CheckInDate.Year;
TempReservationData.CheckOutDate.Day = ReservationData.CheckOutDate.Day;
TempReservationData.CheckOutDate.Month = ReservationData.CheckOutDate.Month;
TempReservationData.CheckOutDate.Year = ReservationData.CheckOutDate.Year;
TempReservationData.Total = ReservationData.Total;
TempReservationData.Discount = ReservationData.Discount;
TempReservationData.GrandTotal = ReservationData.GrandTotal;
TempReservationData.ReservationDate.Day = ReservationData.ReservationDate.Day;
TempReservationData.ReservationDate.Month = ReservationData.ReservationDate.Month;
TempReservationData.ReservationDate.Year = ReservationData.ReservationDate.Year;
strcpy(TempReservationData.Status,Status);
fwrite(&TempReservationData, sizeof(TempReservationData), 1, f_tempreservation);
} else {
fwrite(&ReservationData, sizeof(ReservationData), 1, f_tempreservation);
}
}
while (fread(&roomdata, sizeof(roomdata), 1, f_room))
{
if(TempReservationData.RentRoomData.Code == roomdata.code){
temproomdata.code = roomdata.code;
strcpy(temproomdata.name,roomdata.name);
strcpy(temproomdata.type,roomdata.type);
strcpy(StatusCheckOut, "Check Out");
Compare = StringCompare(Status,StatusCheckOut);
if (Compare == 0){
temproomdata.total = roomdata.total + TempReservationData.RentRoomData.Quantity;
} else {
temproomdata.total = roomdata.total;
}
temproomdata.price = roomdata.price;
fwrite(&temproomdata, sizeof(temproomdata), 1, f_temproom);
} else {
fwrite(&roomdata, sizeof(roomdata), 1, f_temproom);
}
}
/* Close File */
fclose(f_reservation);
fclose(f_room);
fclose(f_tempreservation);
fclose(f_temproom);
/* Remove File */
remove("Reservation.DAT");
remove("Room.DAT");
/* Rename File */
rename("TempReservation.DAT", "Reservation.DAT");
rename("TempRoom.DAT", "Room.DAT");
system("cls");
printf("Data successfully updated!!!\n");
printf("Press Any Key to continue . . .");
getch();
system("cls");
/* Call Modul Update Data Reservation */
ReservationUpdate();
}
void ReservationDelete()
{
int menudelete;
system("cls");
/* Call Modul Show Data Reservation */
ReservationData();
printf("|==================================|\n");
printf("| Reservation Delete |\n");
printf("|==================================|\n");
printf("|1. One Record |\n");
printf("|2. All |\n");
printf("|3. Back |\n");
printf("|==================================|\n");
printf("\n");
printf("Select Menu : ");
scanf("%d", &menudelete);
system("cls");
switch (menudelete) {
case 1:
/* Call Modul Alert Delete One Record Data Reservation */
AlertDeleteOneReservationData();
break;
case 2:
/* Call Modul Alert Delete All Data Reservation */
AlertDeleteAllReservationData();
break;
case 3:
/* Call Modul Menu Reservation */
ReservationMenu();
break;
default:
printf("ERROR : Sorry I don't know the answer to this one!!!\n");
printf("Press Any Key to continue . . .");
getch();
system("cls");
/* Call Modul Delete Reservation */
ReservationDelete();
break;
}
}
void AlertDeleteOneReservationData()
{
Reservation ReservationData;
char Answer;
int Code;
printf("\n");
printf("Enter the Reservation Code to be deleted : ");
scanf("%d", &Code);
fflush(stdin);
printf("\n");
printf("Are you sure? (Y/N)");
Answer = getche();
if (Answer == 'Y' || Answer == 'y')
{
system("cls");
/* Call Modul Delete One Data Reservation */
DeleteOneReservationData(ReservationData, Code);
printf("Data successfully deleted!!!\n");
printf("Press Any Key to continue . . .");
getch();
system("cls");
/* Call Modul Delete Data Reservation */
ReservationDelete();
}
system("cls");
/* Call Modul Delete Data Reservation */
ReservationDelete();
}
void DeleteOneReservationData(Reservation ReservationData, int ID)
{
FILE *f_reservation, *f_tempreservation;
int Code, Check;
Check = CheckReservationCode(ReservationData, ID);
if(Check != 0)
{
/* Open File */
f_reservation = fopen("Reservation.DAT", "rb");
f_tempreservation = fopen("TempReservation.DAT", "wb");
while (fread(&ReservationData, sizeof(ReservationData), 1, f_reservation))
{
Code = ReservationData.ReservationCode;
if (Code != ID){
fwrite(&ReservationData, sizeof(ReservationData), 1, f_tempreservation);
}
}
/* Close File */
fclose(f_reservation);
fclose(f_tempreservation);
/* Remove File */
remove("Reservation.DAT");
/* Rename File */
rename("TempReservation.DAT", "Reservation.DAT");
} else{
system("cls");
printf("ERROR : Reservation data with code %d not found!!!\n", ID);
printf("Press Any Key to continue . . .");
getch();
system("cls");
/* Call Modul Delete Data Reservation */
ReservationDelete();
}
}
void AlertDeleteAllReservationData()
{
char Answer;
printf("Are you sure? (Y/N)");
Answer = getche();
if (Answer == 'Y' || Answer == 'y')
{
system("cls");
/* Call Modul Delete All Data Reservation */
DeleteAllReservationData();
}
system("cls");
/* Call Modul Delete Data Reservation */
ReservationDelete();
}
void DeleteAllReservationData()
{
FILE *f_reservation;
/* Open File */
f_reservation = fopen("Reservation.DAT","wb");
/* Close File */
fclose(f_reservation);
printf("All data was deleted!!!\n");
printf("Press Any Key to continue . . .");
getch();
system("cls");
/* Call Modul Delete Data Reservation */
ReservationDelete();
}