-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAdminDashboard.cpp
More file actions
216 lines (187 loc) · 6.87 KB
/
Copy pathAdminDashboard.cpp
File metadata and controls
216 lines (187 loc) · 6.87 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
#include "AdminDashboard.h"
#include <iostream>
using namespace std;
void AdminDashboard::displayHeader(Staff& staff) {
cout << "********************************************************\n";
cout << "* ADMIN DASHBOARD *\n";
cout << "********************************************************\n";
cout << " Logged in as: " << staff.getFName() << " " << staff.getLName()
<< " (" << staff.getRole() << ")\n";
cout << "********************************************************\n";
}
void AdminDashboard::displayMenu() {
cout << "\nPlease select an option:\n";
cout << " 1) View Reservations\n";
cout << " 2) Modify Reservation (basic)\n";
cout << " 3) Cancel Reservation\n";
cout << " 4) View Rooms (counts)\n";
cout << " 5) Check In Guest (by name)\n";
cout << " 6) Check Out Guest (by name)\n";
cout << " 0) Logout\n";
cout << "--------------------------------------------------------\n";
cout << "Enter a choice: ";
}
AdminDashboardChoice AdminDashboard::getUserChoice() {
int choice;
while (true) {
if (!(cin >> choice)) {
cout << "Invalid input. Please enter a number.\n";
cin.clear();
cin.ignore(100, '\n');
cout << "Enter a choice: ";
continue;
}
cin.ignore(100, '\n');
switch (choice) {
case 0: return AdminDashboardChoice::LOGOUT;
case 1: return AdminDashboardChoice::VIEW_RESERVATIONS;
case 2: return AdminDashboardChoice::MODIFY_RESERVATION;
case 3: return AdminDashboardChoice::CANCEL_RESERVATION;
case 4: return AdminDashboardChoice::VIEW_ROOMS;
case 5: return AdminDashboardChoice::CHECK_IN;
case 6: return AdminDashboardChoice::CHECK_OUT;
default:
cout << "Invalid option. Please entera number from 0 to 6.\n";
cout << "Enter a choice: ";
}
}
}
int AdminDashboard::selectReservationByName(
const std::vector<Reservation>& reservations,
std::vector<Guest>& guests)
{
string firstName, lastName;
cout << "Enter guest first name: ";
getline(cin, firstName);
cout << "Enter guest last name: ";
getline(cin, lastName);
vector<int> matchingIndices;
for (size_t i = 0; i < reservations.size(); ++i) {
int resGuestID = reservations[i].getGuestID();
for (auto& g : guests) {
if (g.getID() == resGuestID &&
g.getFName() == firstName &&
g.getLName() == lastName)
{
matchingIndices.push_back(static_cast<int>(i));
break;
}
}
}
if (matchingIndices.empty()) {
cout << "No reservations found for " << firstName << " " << lastName << ".\n";
return -1;
}
cout << "\nMatching reservations:\n";
for (size_t i = 0; i < matchingIndices.size(); ++i) {
const Reservation& r = reservations[matchingIndices[i]];
cout << " (" << i << ") "
<< "ResID=" << r.getReservationID()
<< ", RoomID=" << r.getRoomID()
<< ", CheckIn=" << r.getCheckInDate()
<< ", CheckOut=" << r.getCheckOutDate()
<< ", Status=" << r.getStatus()
<< "\n";
}
cout << "Select reservation index: ";
int choice;
if (!(cin >> choice)) {
cin.clear();
cin.ignore(100, '\n');
cout << "Invalid input.\n";
return -1;
}
cin.ignore(100, '\n');
if (choice < 0 || static_cast<size_t>(choice) >= matchingIndices.size()) {
cout << "Invalid selection.\n";
return -1;
}
return matchingIndices[choice];
}
void AdminDashboard::listAllReservations(const std::vector<Reservation>& reservations)
{
if (reservations.empty()) {
cout << "No reservations found.\n";
return;
}
cout << "\n=== ALL RESERVATIONS ===\n";
for (const auto& r : reservations) {
cout << "ResID=" << r.getReservationID()
<< ", GuestID=" << r.getGuestID()
<< ", RoomID=" << r.getRoomID()
<< ", CheckIn=" << r.getCheckInDate()
<< ", CheckOut=" << r.getCheckOutDate()
<< ", Status=" << r.getStatus()
<< "\n";
}
}
void AdminDashboard::dashboard(Staff& loggedInStaff,
std::vector<Reservation>& reservations,
std::vector<Guest>& guests,
AvailableRooms& roomsAvailable,
ReservationManager& manager)
{
bool keepRunning = true;
while (keepRunning) {
displayHeader(loggedInStaff);
displayMenu();
AdminDashboardChoice choice = getUserChoice();
switch (choice) {
case AdminDashboardChoice::VIEW_RESERVATIONS:
listAllReservations(reservations);
break;
case AdminDashboardChoice::MODIFY_RESERVATION: {
int idx = selectReservationByName(reservations, guests);
if (idx >= 0) {
Reservation& r = reservations[idx];
cout << "Current status: " << r.getStatus() << "\n";
cout << "Enter new status: ";
string newStatus;
getline(cin, newStatus);
manager.modifyStay(r, "new_status", newStatus);
cout << "Reservation updated.\n";
}
break;
}
case AdminDashboardChoice::CANCEL_RESERVATION: {
int idx = selectReservationByName(reservations, guests);
if (idx >= 0) {
Reservation& r = reservations[idx];
Room& room = AvailableRooms::lookup(r.getRoomID());
manager.cancelStay(r, room, roomsAvailable);
cout << "Reservation cancelled.\n";
}
break;
}
case AdminDashboardChoice::VIEW_ROOMS: {
cout << "\n=== ROOM COUNTS ===\n";
cout << "Available rooms: " << AvailableRooms::getAvailableCount() << "\n";
cout << "Occupied rooms: " << AvailableRooms::getOccupiedCount() << "\n";
cout << "Total rooms: " << AvailableRooms::getTotalCount() << "\n";
break;
}
case AdminDashboardChoice::CHECK_IN: {
int idx = selectReservationByName(reservations, guests);
if (idx >= 0) {
Reservation& r = reservations[idx];
manager.checkIn(r, roomsAvailable);
cout << "Guest checked in.\n";
}
break;
}
case AdminDashboardChoice::CHECK_OUT: {
int idx = selectReservationByName(reservations, guests);
if (idx >= 0) {
Reservation& r = reservations[idx];
manager.checkOut(r, roomsAvailable);
cout << "Guest checked out.\n";
}
break;
}
case AdminDashboardChoice::LOGOUT:
keepRunning = false;
break;
}
cout << "\n";
}
}