-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmenu.py
More file actions
176 lines (145 loc) · 5.76 KB
/
menu.py
File metadata and controls
176 lines (145 loc) · 5.76 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
import datetime
from enum import Enum
import database
class MainMenuOption(Enum):
LOGIN = 1
REGISTER = 2
QUIT = 3
class MemberMenuOption(Enum):
BROWSESUBJECT = 1
BROWSEAUHTORANDTITLE = 2
CHECKOUT = 3
LOGOUT = 4
def printMainMenu():
print("----------- MAIN MENU ------------")
print("1. Login")
print("2. Register New Member")
print("3. Quit")
# Get user menu option
while True:
try:
option = int(input("Select an option: "))
break
except ValueError:
print("Invalid input. Please enter a valid integer.")
if option == MainMenuOption.LOGIN.value:
return MainMenuOption.LOGIN
elif option == MainMenuOption.REGISTER.value:
return MainMenuOption.REGISTER
elif option == MainMenuOption.QUIT.value:
print("Goodbye!")
exit()
else:
print("Invalid option")
def printMemberMenu():
print("----------- MEMBER MENU ------------")
print("1. Browse by Subject")
print("2. Browse by Author/Title")
print("3. Check Out")
print("4. Log Out")
# Get user menu option
while True:
try:
option = int(input("Select an option: "))
break
except ValueError:
print("Invalid input. Please enter a valid integer.")
if option == MemberMenuOption.BROWSESUBJECT.value:
return MemberMenuOption.BROWSESUBJECT
elif option == MemberMenuOption.BROWSEAUHTORANDTITLE.value:
return MemberMenuOption.BROWSEAUHTORANDTITLE
elif option == MemberMenuOption.CHECKOUT.value:
return MemberMenuOption.CHECKOUT
elif option == MemberMenuOption.LOGOUT.value:
return MemberMenuOption.LOGOUT
def printCartInfo(cartInfo):
totalPriceCart = 0
if cartInfo is None or len(cartInfo) == 0:
print("Cart seems to be empty, might be due to invalid user ID")
return False
else:
print("---------- CURRENT CART CONTENTS: ------------")
# Print table header
print("+------------+----------------------------------------------------+-----+---------+")
print("| ISBN | Title | Qty | Total |")
print("+------------+----------------------------------------------------+-----+---------+")
# Print table rows
for item in cartInfo:
total = item['quantity'] * item['price']
totalPriceCart += total
print("| {isbn:<10} | {title:<50} | {quantity:>3} | {total:>7.2f} |".format(
isbn=item['isbn'],
title=item['title'][:50],
quantity=item['quantity'],
total=total
))
print("+------------+----------------------------------------------------+-----+---------+")
# Print table footer with total price
print("| {totalPriceCart:<72} ".format(totalPriceCart=f"Total Price: {totalPriceCart:.2f}"))
print("+---------------------------------------------------------------------------------+")
return True
def printOrderInfo(orderNumber):
# Connect to database
connection = database.getDatabaseConnection()
cursor = connection.cursor()
# Define the SQL query
query = """
SELECT members.fname, members.lname, members.address, members.city, members.zip,
odetails.isbn, books.title, odetails.qty, odetails.qty * books.price AS total
FROM members
JOIN (
SELECT odetails.ono, odetails.isbn, odetails.qty, books.price
FROM odetails
JOIN books ON odetails.isbn = books.isbn
) AS odetails ON members.userid = (
SELECT orders.userid
FROM orders
WHERE orders.ono = odetails.ono
)
JOIN books ON odetails.isbn = books.isbn
WHERE odetails.ono = %s
"""
params = (orderNumber,)
# Execute the query and fetch the results
cursor.execute(query, params)
results = cursor.fetchall()
# Get today's date
today = datetime.date.today()
# Add one week to today's date
oneWeek = datetime.timedelta(days=7)
estDeliveryDate = today + oneWeek
# Print the output header
print(f"Invoice for order number: {orderNumber}\n")
print(f"Estimated delivery date: {estDeliveryDate}\n")
print("Shipping Address: ")
print(f"Name: {results[0][0]} {results[0][1]}")
print(f"Address: {results[0][2]}\n {results[0][3]}\n {results[0][4]}\n")
print("+------------+----------------------------------------------------+-----+---------+")
print("| ISBN | Title | Qty | Total |")
print("+------------+----------------------------------------------------+-----+---------+")
# Print the table data
grandTotal = 0
for row in results:
grandTotal += row[8]
print("| {isbn:<10} | {title:<50} | {qty:>3} | {total:>7.2f} |".format(
isbn=row[5], title=row[6][:50], qty=row[7], total=row[8]))
# Print the table footer with grand total price
print("+------------+----------------------------------------------------+-----+---------+")
print("| {grandTotal:<64} ".format(grandTotal=f"Grand Total: {grandTotal:.2f}"))
print("+-----------------------------------------------------------------+-----+---------+")
# Close database connection
connection.close()
def printUserIdPrompt():
while True:
try:
userid = int(input("Enter your user ID: "))
break
except ValueError:
print("Invalid input. Please enter a valid integer.")
return userid
def printCheckOutPrompt():
wantsToCheckOut = input("Proceed to checkout? Y/N: ")
if wantsToCheckOut.lower() == "y":
return True
else:
return False