-
Notifications
You must be signed in to change notification settings - Fork 0
/
Customer.py
354 lines (303 loc) · 11.2 KB
/
Customer.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
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
351
352
353
354
# Author: Oluwakemi Toluwalase Obadeyi
# Date: 03/10/2023
# Import Libraries
import sqlite3
import time
import datetime
from datetime import datetime
from Data import create_connection, cancel_previous_booking, get_bookings, get_drivers
# Indicating the Database Connection File
database = "tbs.db3"
# Creating database connection to the SQLite database
conn = create_connection(database)
if not conn:
print("Error! cannot create the database connection.")
exit()
existing_customer = None
print("Welcome to RydeEasy")
# Defining function for customer sign in data entry
def signin_customer():
check_customer = input("Have you previously signed up with us? (yes/no): ")
if check_customer in ("y", "Y", "yes", "Yes"):
current_customer()
elif check_customer in ("n", "N", "no", "No"):
new_customer()
else:
print("Invalid email address or password. please enter y for yes or n for no")
signin_customer()
# Defining function for new customer data entry and writing to database
def new_customer():
global existing_customer
print("Sign Up")
found = 0
while found == 0:
email = input("Please enter your email address: ")
with sqlite3.connect("tbs.db3") as db:
cursor = db.cursor()
find_customer = "SELECT * FROM customers WHERE email = ?"
cursor.execute(find_customer, [email])
if cursor.fetchall():
try_again_or_signin = input(
"An account has already been created using this email address., "
"enter t to try again or enter s to signin: "
)
if try_again_or_signin in ("t", "T"):
new_customer()
elif try_again_or_signin in ("s", "S"):
print()
current_customer()
else:
print("Invalid email address or password. Redirecting...")
signin_customer()
else:
found = 1
title = input("Enter your title: ")
firstname = input("Enter your first name: ")
lastname = input("Enter your last name: ")
phone_number = input("Enter your phone number: ")
address = input("Enter your address: ")
town = input("Enter your town: ")
county = input("Enter your county: ")
postcode = input("Enter your postcode: ")
payment_method = input("Enter your payment method: ")
password = input("Create password (Case Sensitive): ")
cpassword = input("Confirm your password: ")
while password != cpassword:
print("Passwords does not match!")
password = input("Create password (Case Sensitive): ")
cpassword = input("Confirm your password: ")
input_data = """INSERT INTO Customers(title, firstname, lastname, phone_number,
email, password, address, town, county, postcode, payment_method)
VALUES(?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)"""
cursor.execute(
input_data,
[
title,
firstname,
lastname,
phone_number,
email,
password,
address,
town,
county,
postcode,
payment_method,
],
)
db.commit()
sql = """ SELECT * FROM Customers WHERE email=? AND password=?"""
cursor.execute(sql, (email, password))
first = cursor.fetchall()[0]
# Current customer ID
existing_customer = first[0]
print("You have successfully created an account")
time.sleep(1)
customer_menu()
# Reading from database, existing Customer Sign In function
while True:
def current_customer():
global existing_customer
print("Please Sign In")
email = input("Enter your email address: ")
password = input("Enter your password: ")
with sqlite3.connect("tbs.db3") as db:
cursor = db.cursor()
find_signin = "SELECT * FROM Customers WHERE email = ? AND password = ?"
cursor.execute(find_signin, [email, password])
results = cursor.fetchall()
if results:
for i in results:
print("Successfully signed in! Welcome " + i[2])
# current customer ID for later use
existing_customer = i[0]
customer_menu()
break
else:
print("Invalid email or password!")
retry = input("Would you like to try again? yes/no: ")
if retry in ("y", "Y", "yes", "Yes"):
current_customer()
elif retry in ("n", "N", "no", "No"):
print("Goodbye!")
break
# Defining function to view customer menu after signup or signin
def customer_menu():
print("Main Menu")
global existing_customer
print("1. Book RydeEasy")
print("2. View Previous Bookings")
print("3. Cancel Booking")
print("4. Sign Out")
menu_input = input("Please indicate: ")
if menu_input == "1":
book_new_taxi()
if menu_input == "2":
previous_bookings(existing_customer)
if menu_input == "3":
cancel_booking()
if menu_input == "4":
exit()
# Taxi Booking form function
def book_new_taxi():
global existing_customer
print("\n")
print("RydeEasy Booking Menu")
drivers = get_drivers(conn)
print("Available Drivers:")
for i, driver in enumerate(drivers):
print(str(i) + "." + str(driver[1]) + " " + str(driver[3]))
# UniqueID for entities
_input = input("Select option: ")
index = int(_input)
driver = drivers[index]
driverid = driver[0]
customerid = existing_customer
# Date and time when the booking was made.
print("Enter the date booked: ")
now = datetime.now() # Current date and time
datebooked = now.strftime("%d/%m/%Y, %H:%M:%S")
print("Date and time when the booking was made:", datebooked)
# Addresses and postcodes
print("Your current address is")
start_address = input("Enter your pick-up address: ")
start_postcode = input("Enter your pick-up postcode: ")
print("Your destination address is")
destination_address = input("Enter your drop-off address: ")
destination_postcode = input("Enter your drop-off postcode: ")
# Date of Pick-up
print("Enter the pick-up date: ")
date = input("DD/MM/YYYY: ")
# Time of pick-up
print("Time: ")
time1 = int(time.time())
print(time1)
# Confirmation of booking status
print("Booking status: Approved/Pending/Cancelled")
status = input("Enter your booking status: ")
# Confirmation of payment status
print("Payment status confirmation ")
paid = input("Yes/No: ")
print("Thank you for choosing RydeEasy!")
print(
"Your pick-up address is: number "
+ start_address
+ ", postcode "
+ start_postcode
+ ""
)
print(
"Booking RydeEasy to: number "
+ destination_address
+ ", postcode "
+ destination_postcode
+ ""
)
# Customer Information Verification
while True:
answer = input("Verify if this information is correct? y/n: ")
if answer in ("n", "N", "no", "No"):
print("Please start again")
print("__________________")
customer_menu()
elif answer in ("y", "Y", "yes", "Yes"):
# Adding Booking to Database
with sqlite3.connect("tbs.db3") as db:
cursor = db.cursor()
sql = """INSERT INTO Bookings (driverid, customerid, datebooked, start_address, start_postcode,
destination_address, destination_postcode, date, time1, status, paid) VALUES(?,?,?,?,?,?,?,?,?,?,?) """
data = (
driverid,
customerid,
datebooked,
start_address,
start_postcode,
destination_address,
destination_postcode,
date,
time1,
status,
paid,
)
cursor.execute(sql, data)
db.commit()
print(
"Your ride has been successfully booked. Have a great experience with RydeEasy!"
)
time.sleep(3)
print("Redirecting to RydeEasy Customer main menu")
customer_menu()
# Defining function to view available booking(s)
def previous_bookings(customerid):
print("\n")
print("Previous Bookings")
with sqlite3.connect("tbs.db3") as db:
cursor = db.cursor()
# Bookings which belong to the current customer
sql = """ SELECT * FROM Bookings WHERE customerid=?"""
cursor.execute(sql, (customerid,))
bookings = cursor.fetchall()
if not bookings:
print("No bookings available, Redirecting to RydeEasy Customer main menu")
time.sleep(2)
customer_menu()
else:
# Show available booking function
for i, b in enumerate(bookings, 1):
print(
str(i) + ") "
"Start Address: "
"" + str(b[4]) + " Postcode: "
"" + str(b[5]) + " Time: "
"" + str(b[6]),
""" -> Destination Address: """ + str(b[7]) + " Postcode: "
"" + str(b[8]) + " Date: "
"" + str(b[9]),
)
# Previous menu function
print("\n")
return_menu = input(
" Enter r to return to the main menu or enter c to cancel booking: "
)
if return_menu in ("r", "R", "return", "Return"):
print("\n")
customer_menu()
elif return_menu in ("c", "C", "cancel", "Cancel"):
print("\n")
cancel_booking()
else:
print(
"Invalid email address or password. Redirecting to RydeEasy Customer main menu"
)
customer_menu()
# Defining function to cancel or delete booking(s)
def cancel_booking():
print("Cancel a booking")
bookings = get_bookings(conn) # connection to database
if not bookings:
print("There is no booking yet, redirecting to Admin Menu...")
time.sleep(2)
customer_menu()
else:
# Show all available bookings
for i, b in enumerate(bookings, 0):
print(
str(i) + ") "
"Start Address: "
"" + str(b[4]) + " Postcode: "
"" + str(b[5]) + " Time: "
"" + str(b[6]),
""" -> Destination Address: """ + str(b[7]) + " Postcode: "
"" + str(b[8]) + " Date: "
"" + str(b[9]),
)
_input = input("Select which booking you would like to cancel: ")
index = int(_input)
b = bookings[index]
bookingid = b[0]
cancel_previous_booking(conn, bookingid)
print("Your booking has been cancelled successfully.")
print("Redirecting to RydeEasy Customer main menu")
time.sleep(3)
customer_menu()
signin_customer()