-
Notifications
You must be signed in to change notification settings - Fork 0
/
Restaurant.cpp
303 lines (252 loc) · 8.51 KB
/
Restaurant.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
#include "Restaurant.h"
Restaurant::Restaurant(int capacity) : _tables(capacity), _total_account(0), _monthly_account(0),
_daily_account(0), _best_selling(nullptr) {}
int Restaurant::getNumberOfEmployees() const {
return _employees.size();
}
unsigned int Restaurant::getEmployeeId(string &name) const {
auto it = _employees.find(name);
if (it != _employees.end()) {
return it->second.getId();
}
return -1;
}
double Restaurant::calculateMonthlySalary(string &name) const {
auto it = _employees.find(name);
if (it != _employees.end()) {
return it->second.calculateMonthlySalary();
}
return -1;
}
void Restaurant::printScheduleForOne(string &name) const {
auto it = _employees.find(name);
if (it != _employees.end()) {
it->second.printSchedule(name);
}
}
void Restaurant::printScheduleForAll() const {
for (auto &it : _employees){
it.second.printSchedule(it.first);
std::cout << std::endl;
}
}
void Restaurant::markEntrance(string &name) {
auto it = _employees.find(name);
if (it != _employees.end()) {
it->second.markEntrance();
}
}
void Restaurant::markQuit(string &name) {
auto it = _employees.find(name);
if (it != _employees.end()) {
it->second.markQuit();
}
}
void Restaurant::resetWorkTimeForOne(string &name) {
auto it = _employees.find(name);
if (it != _employees.end()) {
it->second.resetWorkTime();
}
}
void Restaurant::resetWorkTimeForAll() {
for (auto &it : _employees){
it.second.resetWorkTime();
std::cout << std::endl;
}
}
void Restaurant::addNewEmployee(string &name, Role role, double salary) {
_employees.insert({std::move(name), Employee(_employees.size()+1, role, salary)});
}
void Restaurant::removeEmployee(string &name) {
std::remove((std::to_string(this->getEmployeeId(name))+"entrance.txt").c_str());
std::remove((std::to_string(this->getEmployeeId(name))+".txt").c_str());
_employees.erase(name);
}
void Restaurant::setSalary(string &name, double salary) {
auto it = _employees.find(name);
if (it != _employees.end()){
it->second.setSalary(salary);
}
}
void Restaurant::setRole(string &name, Role role) {
auto it = _employees.find(name);
if (it != _employees.end()){
it->second.setRole(role);
}
}
void Restaurant::addNewCategory(string &name) {
_menu.insert({std::move(name), Category()});
}
void Restaurant::removeCategory(string &name) {
_menu.erase(name);
}
void Restaurant::addDish(string &category, string &dish, string &description, int rank, double price) {
auto i = _menu.find(category);
if (i != _menu.end())
i->second.addDish(dish, description, rank, price);
}
void Restaurant::addDishWithProducts(string &category, string &dish, string &description,
std::unordered_set<Product> &products, int rank, double price) {
auto i = _menu.find(category);
if (i != _menu.end())
i->second.addDishWithProducts(dish, description, products, rank, price);
}
void Restaurant::removeDish(string &category, string &dish) {
auto i = _menu.find(category);
if (i != _menu.end())
i->second.removeDish(dish);
}
void Restaurant::addProductToDish(string &category, string &dish, Product product) {
auto i = _menu.find(category);
if (i != _menu.end())
i->second.addProductToDish(dish, product);
}
void Restaurant::removeProductFromDish(string &category, string &dish, Product product) {
auto i = _menu.find(category);
if (i != _menu.end())
i->second.removeProductFromDish(dish, product);
}
void Restaurant::changeDishName(string &category, string &dish, string &name) {
auto i = _menu.find(category);
if (i != _menu.end())
i->second.changeDishName(dish, name);
}
void Restaurant::changeDishDescription(string &category, string &dish, string &description) {
auto i = _menu.find(category);
if (i != _menu.end())
i->second.changeDishDescription(dish, description);
}
void Restaurant::outOfVariety(string &category, string &dish) {
auto i = _menu.find(category);
if (i != _menu.end())
i->second.outOfVariety(dish);
}
void Restaurant::putInVariety(string &category, string &dish) {
auto i = _menu.find(category);
if (i != _menu.end())
i->second.putInVariety(dish);
}
void Restaurant::setDishPrice(string &category, string &dish, double price) {
auto i = _menu.find(category);
if (i != _menu.end())
i->second.setDishPrice(dish, price);
}
void Restaurant::setDishRank(string &category, string &dish, int rank) {
auto i = _menu.find(category);
if (i != _menu.end())
i->second.setDishRank(dish, rank);
}
void Restaurant::printMenu() const {
for (auto& it : _menu) {
it.second.printCategory(it.first);
}
}
void Restaurant::printDishProduct(string &category, string &dish) const {
auto i = _menu.find(category);
if (i != _menu.end())
i->second.printProductsDish(dish);
}
void Restaurant::printBestDishes(string &category, int k) {
auto i = _menu.find(category);
if (i != _menu.end())
i->second.printBestDishes(k);
}
int Restaurant::getDishRank(string &category, string &dish) const {
auto i = _menu.find(category);
if (i != _menu.end())
return i->second.getDishRank(dish);
else
return -1;
}
double Restaurant::getDishPrice(string &category, string &dish) const {
auto i = _menu.find(category);
if (i != _menu.end())
return i->second.getDishPrice(dish);
else
return -1;
}
void Restaurant::increaseCapacity(int factor) {
_tables.increaseCapacity(factor);
}
unsigned int Restaurant::getNumOfCustomer() const {
return _tables.getNumOfCustomer();
}
unsigned int Restaurant::getNumOfAvailableTables() const {
return _tables.getNumOfAvailableTables();
}
unsigned int Restaurant::seatCustomer() {
return _tables.seatCustomer();
}
double Restaurant::getFinalBill(unsigned int num) {
if (num < 1 || num > _tables.getCapacity()) return -1;
std::cout << "============== Bill ==============" << std::endl;
double bill = _tables.getFinalBill(num);
std::cout << std::endl << "============== Total to pay: " << bill << " ==============" << std::endl << std::endl;
_daily_account += bill;
return bill;
}
double Restaurant::getCurrentBill(int num) const {
return _tables.getCurrentBill(num);
}
int Restaurant::getNumOfOrders() const {
return _orders.size();
}
void Restaurant::giveCredit(int num, double credit) {
_tables.giveCredit(num, credit);
}
void Restaurant::orderDish(int num, string &category, string &dish) {
auto cat = _menu.find(category);
if (cat == _menu.end()) return;
Dish* ordered = cat->second.getDish(dish);
if (!ordered || !ordered->isAvailable()) return;
if (_tables.orderDish(num, ordered)) {
ordered->orderDish();
if (!_best_selling || ordered->getNumberOfSales() > _best_selling->getNumberOfSales())
_best_selling = ordered;
_orders.push(ordered);
}
}
void Restaurant::supplyDish() {
if (!_orders.empty())
_orders.pop();
}
void Restaurant::endDay() {
_monthly_account += _daily_account;
_daily_account = 0;
}
void Restaurant::endMonth() {
std::cout << "============== Employees Report ==============" << std::endl;
double total = 0;
for (auto &it : _employees){
double monthly_salary = it.second.endMonth();
total += monthly_salary;
std::cout << "Name: " << it.first << " | Salary: " << monthly_salary << std::endl << std::endl;
}
std::cout << "============== Monthly Report ==============" << std::endl;
std::cout << "Total salaries: " << total << std::endl;
std::cout << "Total costumers: " << _monthly_account << std::endl;
_monthly_account -= total;
std::cout << "Total this month: " << _monthly_account << std::endl;
_total_account += _monthly_account;
_monthly_account = 0;
}
double Restaurant::getDailyAccount() const {
return _daily_account;
}
double Restaurant::getMonthlyAccount() const {
return _monthly_account;
}
double Restaurant::getTotalAccount() const {
return _total_account;
}
string Restaurant::getBestSellingDish() const {
if (_best_selling)
return _best_selling->getName();
return "The menu is empty";
}
unsigned int Restaurant::getTotalNumberOfCustomers() const {
return _tables.getTotalNumberOfCustomers();
}
double Restaurant::getMostExpensiveBill() const {
return _tables.getMostExpensiveBill();
}