-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathOrder.cpp
More file actions
204 lines (115 loc) · 4.13 KB
/
Order.cpp
File metadata and controls
204 lines (115 loc) · 4.13 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
#include "Order.h"
#include <iostream>
#include <string>
Order::Order(string type, Date planned, Customer* client , Company* office)
: event(type), customer(client), from(office), DateRequest(planned) {
time_t currentTime = time(nullptr);
tm* localTime = localtime(¤tTime);
DateMade = Date(*localTime);
receipt.bill = this->calculate_bill();
receipt.IsCovered = false;
receipt.DueDate = (Date(*localTime) += 30);
}
double Order::get_bill() const{
return receipt.bill;
}
bool Order::get_covered() const{
return receipt.IsCovered;
}
Date Order::get_DueDate() const{
return receipt.DueDate;
}
Date Order::get_DateMade() const{
return DateMade;
}
Date Order::get_DateRequest() const{
return DateRequest;
}
std::string Order::get_event() const{
return event;
}
Customer* Order::get_customer() const{
return customer;
}
Company* Order::get_from() const{
return from;
}
void Order::set_bill(const double& payment){
receipt.bill = payment;
}
void Order::set_IsCovered(const bool& covered){
receipt.IsCovered = covered;
}
void Order::set_customer(Customer* new_customer){
customer = new_customer;
}
void Order::set_from(Company* new_from){
from = new_from;
}
void Order::set_DateRequest(const Date& planned){
DateRequest = planned;
}
void Order::setItemPrice(const string& name, const double& price){
for (auto& menuItem : menu) {
if (menuItem.name == name) {
menuItem.price = price;
break;
}
}
}
void Order::set_event(const string& new_event){
event = new_event;
}
int Order::getMenuSize() const{
return menu.size();
}
double Order::calculate_bill() const{
double total = 0.0;
for (auto menuItem : menu) {
total += menuItem.price;
}
return total;
}
int Order::find_index(string name) const{
for (size_t i = 0; i < menu.size(); ++i){
if (menu[i].name == name) {
return i;
}
}
return -1;
}
void Order::add_item(item new_item){
menu.push_back(new_item);
receipt.bill = this->calculate_bill();
}
void Order::remove_item(string name){
int index = find_index(name);
if (index != -1) {
menu.erase(menu.begin() + index);
}
receipt.bill = this->calculate_bill();
}
void Order::print() const{
std::cout << "------------------------" << std::endl;
std::cout << " ORDER RECEIPT " << std::endl;
std::cout << "------------------------" << std::endl;
std::cout << "Event: " << event << std::endl;
std::cout << "Date Made: ";
DateMade.print();
std::cout << "Date Request: ";
DateRequest.print();
std::cout << "------------------------" << std::endl;
std::cout << "Menu Items:" << std::endl;
for (auto menuItem : menu) std::cout << "- " << menuItem.name << " $" << menuItem.price << std::endl;
std::cout << "------------------------" << std::endl;
std::cout << "Subtotal: $" << receipt.bill << std::endl;
std::cout << "Tax: $" << receipt.bill * 0.1 << std::endl;
std::cout << "------------------------" << std::endl;
std::cout << "Total: $" << receipt.bill * 1.1 << std::endl;
std::cout << "------------------------" << std::endl;
std::cout << "Customer: ";
if(customer) cout << customer->getName() << std::endl;
std::cout << "------------------------" << std::endl;
std::cout << "Thank you for your order!" << std::endl;
std::cout << "------------------------" << std::endl;
}