-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSourceCode.py
More file actions
350 lines (298 loc) · 12.3 KB
/
SourceCode.py
File metadata and controls
350 lines (298 loc) · 12.3 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
import csv
import pickle
import datetime
# File paths
MENU_FILE = 'menu.csv' # CSV file for menu
ORDER_FILE = 'orders.dat' # Binary file for storing orders
SALES_FILE = 'sales.csv' # CSV file for sales
FEEDBACK_FILE='feedback.txt' # Text file for storing feedbacks
#1. Pre-storing some menu data into 'menu.csv'
def initialize_menu():
menu_data = [
['1', 'Salad', '100'],
['2', 'Smoothie', '150'],
['3', 'Grilled Sandwich', '200'],['4','Coffee','120'],['5','Pasta','180'],
['6','Pizza','475'],['7','French Fries','180']]
# Writing the menu data to the CSV file
with open(MENU_FILE, 'w', newline='') as file:
writer = csv.writer(file)
writer.writerows(menu_data)
#2. Displaying the menu from 'menu.csv'
def display_menu():
print("\n\t\t*****--MENU--*****\n")
with open(MENU_FILE, 'r') as file:
reader = csv.reader(file)
for row in reader:
print("\t--------------------------------------------------------")
print(f"\t|Code: {row[0]} | Item: {row[1]} | Price: Rs.{row[2]}/- |")
print("\t-------------------------------------------------------")
# Function to get feedback from the customer
def get_feedback():
ch=input("Could you please provide us with your feedback? (sure/skip): ").lower().strip()
if ch=="sure":
feedback = input("\nPlease provide your valuable feedback: ")
# Save the feedback to a text file
with open('feedback.txt', 'a') as file:
file.write(f"Feedback: {feedback}\n")
print("\nThank you for your time & feedback!\n")
elif ch=="skip":
pass
else:
print("Please enter valid input")
# Modify the place_order function to include feedback after payment
def place_order():
total_amount = 0
while True:
order = []
display_menu()
while True:
item_code = input("Enter Item Code to order( type 'Done' to finish): ").strip()
if item_code.lower() == 'done':
print("Thanks for ordering")
break
quantity = int(input("Enter Quantity: "))
item = get_item_from_menu(item_code)
if item:
item_name, item_price = item
order.append([item_name, quantity, int(item_price) * quantity])
total_amount += int(item_price) * quantity
else:
print("Invalid item code. Try again.")
if order:
print("\n--- Order Summary ---")
for item in order:
print(f"\t\t{item[0]} x {item[1]} = Rs.{item[2]}")
print(f"\t\tTotal Amount: Rs.{total_amount}")
confirm = input("Do you want to confirm the order? (yes/no): ").strip().lower()
if confirm == 'yes' or confirm=="y":
order_number = save_order(order, total_amount)
generate_bill(order_number, order, total_amount)
print(f"\nYour Order Number is: {order_number}")
payment_mode = input("Select payment mode (cash/card/UPI): ").strip().lower()
if payment_mode == 'cash':
print("Please pay the amount at the counter.")
elif payment_mode == 'upi':
print("Please pay using UPI.{ UPI ID: 1800111000}")
elif payment_mode == "card":
print("Please ask for the swipe machine at the counter to pay")
else:
print("Invalid payment mode selected.")
get_feedback() # Get feedback from the customer after payment
more_orders = input("Do you want to order more? (yes/no): ").strip().lower()
if more_orders == 'yes':
continue
else:
print("Your order will be ready at the counter soon!\nThank you for visiting ONE8 COMMUNE!")
break
else:
print("Order cancelled. Please re-order.")
else:
print("No items ordered.")
main()
# Function for the manager to view feedbacks
def view_feedback():
print("\n--- Customer Feedbacks ---\n")
try:
with open('feedback.txt', 'r') as file:
feedbacks = file.read()
if feedbacks:
print(feedbacks)
else:
print("No feedbacks found.")
except FileNotFoundError:
print("No feedback file found.")
print("\n")
# Function to clear all feedback from the feedback file
def clear_feedback():
confirm = input("Are you sure you want to clear all feedbacks? (yes/no): ").strip().lower()
if confirm == 'yes':
with open('feedback.txt', 'w') as file:
file.write('') # Overwrite the file with an empty string to clear its contents
print("All feedbacks have been cleared.")
else:
print("Operation cancelled.")
#4. Getting item details from the menu
def get_item_from_menu(item_code):
with open(MENU_FILE, 'r') as file:
reader = csv.reader(file)
for row in reader:
if row[0] == item_code:
return row[1], row[2] # Return item name and price
return None # Return None if item code is invalid
#5. Generating a bill after placing an order
def generate_bill(order_number, order, total_amount):
print("\n--- BILL ---")
print(f"Order Number: {order_number}")
for item in order:
print(f"{item[0]} x {item[1]} = Rs.{item[2]}/-")
print(f"Total Amount: Rs.{total_amount}/-")
#6. Saving the order to the binary file
def save_order(order, total_amount):
order_data = {
'order_number': get_next_order_number(),
'date': str(datetime.date.today()),
'order': order,
'total_amount': total_amount
}
# Write the order to a binary file
with open(ORDER_FILE, 'ab') as file:
pickle.dump(order_data, file)
# Save to sales report as well
save_sales(order_data)
return order_data['order_number'] # Return the order number
#7.Getting the next order number
def get_next_order_number():
try:
with open(ORDER_FILE, 'rb') as file:
orders = []
while True:
try:
orders.append(pickle.load(file))
except EOFError:
break
if orders:
return orders[-1]['order_number'] + 1 # Increment last order number
else:
return 1 # Start with 1 if no orders exist
except FileNotFoundError:
return 1 # Start with 1 if file does not exist
#8. Save order details to sales CSV file for report generation
def save_sales(order_data):
with open(SALES_FILE, 'a', newline='') as file:
writer = csv.writer(file)
for item in order_data['order']:
writer.writerow([order_data['date'], item[0], item[1], item[2]])
#9. Deleting an order by order number (Manager Functionality)
def delete_order():
order_number = int(input("Enter Order Number to delete: ")) # Ask for the order number
orders = [] # List to store all existing orders
order_found = False # Flag to check if the order exists
try:
# Read orders from the file
with open(ORDER_FILE, 'rb') as file:
while True:
try:
orders.append(pickle.load(file)) # Add each order to the list
except EOFError:
break # Stop when the file ends
except FileNotFoundError:
print("No orders found.") # If there is no file, show a message
return
# Create a new list without the order to delete
new_orders = []
for order in orders:
if order['order_number'] == order_number:
order_found = True # Mark that we found the order to delete
else:
new_orders.append(order) # Add other orders to the new list
if order_found:
# Save the new list back to the file
with open(ORDER_FILE, 'wb') as file:
for order in new_orders:
pickle.dump(order, file)
print(f"\t\tOrder No. {order_number} deleted.")
else:
print("\t\tPlease enter a valid order number.") # Show if the order doesn't exist
#10. Generating a sales report for a given date
def generate_sales_report():
report_date = input("Enter date (YYYY-MM-DD) for sales report: ")
print(f"\n\t\t\t--- Sales Report for {report_date} ---\n")
total_sales = 0
with open(SALES_FILE, 'r') as file:
reader = csv.reader(file)
for row in reader:
if row[0] == report_date:
print(f" Item: {row[1]}, Quantity: {row[2]}, Total: Rs.{row[3]}/-")
total_sales += int(row[3])
print(f"\n Total Sales for {report_date}: Rs.{total_sales}/-\n")
#11. Customer login function to place an order
def customer_login():
print("\n\t\tPlease Order Your Happy Meal From The Menu!!")
place_order()
#12. Manager login function to perform managerial tasks
def manager_login():
password = "manager123" # Predefined manager password
entered_password = input("Please Enter Login Password: ")
if entered_password == password:
print("\n--- MANAGER MENU ---")
while True:
print("1. Display Menu")
print("2. Add Menu Item")
print("3. Remove Menu Item")
print("4. Delete Order")
print("5. Generate Sales Report")
print("6. View Customer Feedback")
print("7. Clear Feedback File")
print("8. Logout")
choice = input("Enter your choice: ")
if choice == '1':
display_menu() # Display the menu
elif choice == '2':
add_menu_item()
elif choice == '3':
remove_menu_item()
elif choice == '4':
delete_order()
elif choice == '5':
generate_sales_report()
elif choice == '6':
view_feedback()
elif choice=='7':
clear_feedback()
elif choice=="8":
print("\t\t\tLogin window ended")
break
else:
print("Invalid choice. Try again.")
else:
print("Invalid password. Access denied.")
#13. Add a new item to the menu (Manager Functionality)
def add_menu_item():
item_code = input("Enter Item Code: ")
item_name = input("Enter Item Name: ")
item_price = input("Enter Item Price: ")
with open(MENU_FILE, 'a', newline='') as file:
writer = csv.writer(file)
writer.writerow([item_code, item_name, item_price])
print(f"Item {item_name} added to menu.")
#14. Remove an item from the menu (Manager Functionality)
def remove_menu_item():
item_code = input("Enter Item Code to remove: ")
menu_items = []
found = False
with open(MENU_FILE, 'r') as file:
reader = csv.reader(file)
menu_items = [row for row in reader]
# Remove the item with the specified code
for item in menu_items:
if item[0] == item_code:
menu_items.remove(item)
found = True
break
if found:
# Rewrite the menu file with the updated items
with open(MENU_FILE, 'w', newline='') as file:
writer = csv.writer(file)
writer.writerows(menu_items)
print(f"Item with code {item_code} removed from the menu.")
else:
print("Item code not found.")
#15. Main function to start the program
def main():
initialize_menu() # Pre-store some menu data for simplicity
print("\t || WELCOME TO ONE8 COMMUNE ||")
print ("\t\t=====================")
print("\t\tPress 1 For Customer Login")
print("\t\tPress 2 For Manager Login")
print("\t\t=====================")
choice = input("Enter your choice: ")
if choice == '1':
customer_login()
elif choice == '2':
manager_login()
else:
print("Invalid option. Please re-enter.")
main()
if __name__ == "__main__": # This ensures the main() function only runs if the file is executed directly,
#not when it's imported into another file.
main()