-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
211 lines (125 loc) · 5.01 KB
/
main.py
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
import pymysql
from prettytable import PrettyTable
import datetime
from menu_functions import add_menu_to_database, edit_menu_item_in_database, delete_menu_item_from_database
from order_functions import add_order_details_to_database, get_user_details_from_database
# function to get current date
def date_now():
now = datetime.datetime.now()
date_format = now.strftime("%d-%m-%Y")
return date_format
# function to get current time
def time_now():
now = datetime.datetime.now()
time_format = now.strftime("%I:%M %p")
return time_format
# function for admin account
def admin_account():
print("Command List => Press '1' for add dish to menu,")
print("\t\tPress '2' for edit price,")
print("\t\tPress '3' for delete item from menu")
print("\t\tPress 'q' to exit")
admin_input = input("Enter command : ")
if admin_input == '1':
dish = input("Enter new dish : ")
price = int(input("Enter price for new dish : "))
add_menu_to_database(dish, price)
elif admin_input == '2':
dish = input("Enter dish name for which you want to change price : ")
price = int(input("Enter new price for dish : "))
edit_menu_item_in_database(dish, price)
elif admin_input == '3':
dish = input("Enter dish name which you want to delete : ")
delete_menu_item_from_database(dish)
elif admin_input == 'q':
select_input(command=)
# function to take user input
def select_input(my_input):
if my_input == '1':
output = view_menu()
elif my_input == '2':
output = add_order()
elif my_input == '3':
name = input("Enter name of the person : ")
print()
output = get_user_details_from_database(name)
else:
output = "Error : Please Enter Correct Command"
return output
# function for adding order details
def add_order():
name = input("Name of the person : ")
date = date_now()
time = time_now()
total_price = get_total_price()
bill = f"-----------------\nYour Bill {name}\n------------------\nTotal = {total_price}\nDate : {date}\nTime : {time}\n\n"
date_time = f"{date}, {time}"
add_order_details_to_database(name, date_time, total_price)
print(bill)
# function to view menu
def view_menu():
db = pymysql.connect("localhost", "root", "uttu8449", "DISHES_PRICES")
cursor = db.cursor()
table2 = PrettyTable()
table2.field_names = ["Dish", "Price"]
sql = "SELECT * FROM PRICE_LIST"
try:
cursor.execute(sql)
results = cursor.fetchall()
for row in results:
dish = row[0]
price = row[1]
table2.add_row([dish, price])
print(table2)
except:
print("Error Can't show menu")
db.close()
# function to get price from database
def get_price_from_database(dish):
db = pymysql.connect("localhost", "root", "uttu8449", "DISHES_PRICES")
cursor = db.cursor()
sql = f"SELECT PRICE FROM PRICE_LIST WHERE DISHES = '{dish}'"
cursor.execute(sql)
result = cursor.fetchall()
for row in result:
price = row[0]
return price
# fuction to add total price
def get_total_price():
price_list = []
print()
dish = input("What you want to eat ? : ")
while dish != "":
dish_price = get_price_from_database(dish)
price_list.append(dish_price)
print()
dish = input("Anything else ? : ")
print()
total_price = sum(price_list)
return total_price
if __name__ == "__main__":
print("---------------------------------------------------------------------CAFETERIA MANAGEMENT SYSTEM---------------------------------------------------------------------")
print()
print("===============================================")
print("Command List => Press '1' for menu,")
print("\t\tPress '2' to add order,")
print("\t\tPress '3' to view order")
print("\t\tPress 'q' to exit")
print("===============================================")
print()
# take input from user
command = input("Enter command : ")
print()
# loop to get command
while command != "q":
if command == '0':
admin_account()
elif command == '1' or '2' or '3':
select_input(command)
else:
print("Error : Please enter correct command")
print("------------------------------------------------------------------------------------------------------")
print()
command = input("Enter command : ")
# exit message
print("Thank you for using this project | This project is created by => Shashwat Dubey, Subrat Rathore")