-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp_a.py
573 lines (491 loc) · 26.8 KB
/
app_a.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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
from app import *
@app.route('/login_a')
def login_a():
return render_template('login_a.html')
#Define route for register
@app.route('/register_a')
def register_a():
return render_template('register_a.html')
#Authenticates the login
@app.route('/loginAuth_a', methods=['GET', 'POST'])
def loginAuth_a():
email = request.form['email']
password = request.form['password']
booking_agent_id = request.form['booking_agent_id']
cursor = conn.cursor()
query = 'SELECT password FROM booking_agent WHERE email = %s'
cursor.execute(query, (email))
data = cursor.fetchone()
cursor.close()
error = None
if(data):
result= check_password_hash(data['password'],password)
if result==False:
error = 'Invalid login or username'
return render_template('login_a.html', error=error)
else:
session['email'] = email
session['booking_agent_id'] = booking_agent_id
return redirect(url_for('home_a'))
else:
error = 'Invalid login or username'
return render_template('login_a.html', error=error)
#Authenticates the register
@app.route('/registerAuth_a', methods=['GET', 'POST'])
def registerAuth_a():
#grabs information from the forms
email = request.form['email']
password = request. form['password']
booking_agent_id= request.form['booking_agent_id']
cursor = conn.cursor()
#executes query
query = 'SELECT * FROM booking_agent WHERE email = %s'
cursor.execute(query, (email))
#stores the results in a variable
data = cursor.fetchone()
#use fetchall() if you are expecting more than 1 data row
error = None
if(data):
error = "This user already exists"
return render_template('register_a.html', error = error)
else:
password = generate_password_hash(password)
ins = 'INSERT INTO booking_agent(email, password, booking_agent_id) VALUES(%s, %s, %s)'
cursor.execute(ins, (email, password, booking_agent_id))
conn.commit()
cursor.close()
return render_template('login_a.html')
#
@app.route('/home_a')
def home_a():
# global search
email= session['email']
if email==None:
error = "Please login first"
return render_template('login_a.html', error = error)
return render_template('home_a.html',email=email, data=[{'temp':1}])
@app.route('/search_a', methods=['GET', 'POST'])
def search_a():
src_airport = request.form['src_airport']
des_airport = request.form['des_airport']
departure_d = request.form['departure_d']
departure_m = request.form['departure_m']
departure_y = request.form['departure_y']
round_trip = request.form['round_trip']
arrival_d = request.form['arrival_d']
arrival_m = request.form['arrival_m']
arrival_y = request.form['arrival_y']
cursor = conn.cursor()
if round_trip=='No':
query = 'SELECT flight_num, flight.airline_name, departure_airport, departure_hour, departure_min, departure_day, departure_month, departure_year, arrival_airport, arrival_hour, arrival_min, arrival_day, arrival_month, arrival_year, status FROM flight join airplane on (airplane.id = flight.airplane_id) and (flight.airline_name = airplane.airline_name) WHERE departure_airport = %s and arrival_airport = %s and departure_day = %s and departure_month = %s and departure_year = %s'
cursor.execute(query, (src_airport, des_airport, departure_d, departure_m, departure_y))
data = cursor.fetchall()
error = None
print(data)
if(data):
for d in data:
querycount = 'SELECT count(ticket_id) as c from ticket where flight_num= %s and airline_name= %s'
cursor.execute(querycount, (d['flight_num'], d['airline_name']))
count = cursor.fetchone()
print(count)
queryprice = 'SELECT base_price from flight where flight_num= %s and airline_name= %s'
cursor.execute(queryprice, (d['flight_num'], d['airline_name']))
price = cursor.fetchone()
print(price)
queryseats = 'SELECT num_of_seats from flight, airplane where airplane_id=id and flight_num= %s and flight.airline_name= %s'
cursor.execute(queryseats, (d['flight_num'], d['airline_name']))
seats = cursor.fetchone()
print(seats)
if count['c']/seats['num_of_seats'] >= .7:
d['price']= price['base_price']*1.20
else:
d['price']= price['base_price']
return render_template('home_a.html', error='', flights_departure=data, flights_arrival=[])
else:
message = 'No Tickets available'
return render_template('home_a.html', error=message)
else:
query = 'SELECT flight_num, flight.airline_name, departure_airport, departure_hour, departure_min, departure_day, departure_month, departure_year, arrival_airport, arrival_hour, arrival_min, arrival_day, arrival_month, arrival_year, status FROM flight join airplane on (airplane.id = flight.airplane_id) and (flight.airline_name = airplane.airline_name) WHERE departure_airport = %s and arrival_airport = %s and departure_day = %s and departure_month = %s and departure_year = %s'
cursor.execute(query, (src_airport, des_airport, departure_d, departure_m, departure_y ))
data_deparature = cursor.fetchall()
for d in data_deparature:
querycount = 'SELECT count(ticket_id) as c from ticket where flight_num= %s and airline_name= %s'
cursor.execute(querycount, (d['flight_num'], d['airline_name']))
count = cursor.fetchone()
print(count)
queryprice = 'SELECT base_price from flight where flight_num= %s and airline_name= %s'
cursor.execute(queryprice, (d['flight_num'], d['airline_name']))
price = cursor.fetchone()
print(price)
queryseats = 'SELECT num_of_seats from flight, airplane where airplane_id=id and flight_num= %s and flight.airline_name= %s'
cursor.execute(queryseats, (d['flight_num'], d['airline_name']))
seats = cursor.fetchone()
print(seats)
if count['c']/seats['num_of_seats'] >= .7:
d['price']= price['base_price']*1.20
else:
d['price']= price['base_price']
query = 'SELECT flight_num, flight.airline_name, departure_airport, departure_hour, departure_min, departure_day, departure_month, departure_year, arrival_airport, arrival_hour, arrival_min, arrival_day, arrival_month, arrival_year, status, num_of_seats FROM flight join airplane on (airplane.id = flight.airplane_id) and (flight.airline_name = airplane.airline_name) WHERE departure_airport = %s and arrival_airport = %s and departure_day = %s and departure_month = %s and departure_year = %s'
cursor.execute(query, (des_airport, src_airport, arrival_d, arrival_m, arrival_y ))
data_arrival = cursor.fetchall()
for d2 in data_arrival:
querycount = 'SELECT count(ticket_id) as c from ticket where flight_num= %s and airline_name= %s'
cursor.execute(querycount, (d2['flight_num'], d2['airline_name']))
count = cursor.fetchone()
print(count)
queryprice = 'SELECT base_price from flight where flight_num= %s and airline_name= %s'
cursor.execute(queryprice, (d2['flight_num'], d2['airline_name']))
price = cursor.fetchone()
print(price)
queryseats = 'SELECT num_of_seats from flight, airplane where airplane_id=id and flight_num= %s and flight.airline_name= %s'
cursor.execute(queryseats, (d2['flight_num'], d2['airline_name']))
seats = cursor.fetchone()
print(seats)
if count['c']/seats['num_of_seats'] >= .7:
print("1")
d2['price']= price['base_price']*1.20
else:
print("2")
d2['price']= price['base_price']
cursor.close()
error = None
if(data_deparature):
return render_template('home_a.html', error='', flights_departure=data_deparature, flights_arrival=data_arrival)
else:
message = 'No Tickets available'
return render_template('home_a.html', error=message, flighs=[])
@app.route('/purchase_ticket_a', methods=['GET', 'POST'])
def purchase_ticket_a():
email = session['email']
if email==None:
return render_template('login_a.html')
flight_num_dep = request.form['flight_num_dep']
airline_name_dep = request.form["airline_name_dep"]
round='no'
try:
flight_num_arr = request.form['flight_num_arr']
airline_name_arr = request.form["airline_name_arr"]
round='yes'
except:
round='no'
cursor = conn.cursor()
if round=='yes':
flight_num_arr = request.form['flight_num_arr']
query = 'SELECT flight_num, flight.airline_name, departure_airport, departure_hour, departure_min, departure_day, departure_month, departure_year, arrival_airport, arrival_hour, arrival_min, arrival_day, arrival_month, arrival_year, base_price FROM flight join airplane on (airplane.id = flight.airplane_id) and (flight.airline_name = airplane.airline_name) WHERE flight_num = %s and flight.airline_name = %s'
cursor.execute(query, (flight_num_dep, airline_name_dep))
dep_data = cursor.fetchone()
querycount = 'SELECT count(ticket_id) as c from ticket where flight_num= %s and airline_name= %s'
cursor.execute(querycount, (dep_data['flight_num'], dep_data['airline_name']))
count = cursor.fetchone()
print(count)
queryprice = 'SELECT base_price from flight where flight_num= %s and airline_name= %s'
cursor.execute(queryprice, (dep_data['flight_num'], dep_data['airline_name']))
price = cursor.fetchone()
print(price)
queryseats = 'SELECT num_of_seats from flight, airplane where airplane_id=id and flight_num= %s and flight.airline_name= %s'
cursor.execute(queryseats, (dep_data['flight_num'], dep_data['airline_name']))
seats = cursor.fetchone()
print(seats)
if count['c']/seats['num_of_seats'] >= .7:
print("1")
dep_data['base_price']= price['base_price']*1.20
else:
print("2")
dep_data['base_price']= price['base_price']
query = 'SELECT flight_num, flight.airline_name, departure_airport, departure_hour, departure_min, departure_day, departure_month, departure_year, arrival_airport, arrival_hour, arrival_min, arrival_day, arrival_month, arrival_year, base_price FROM flight join airplane on (airplane.id = flight.airplane_id) and (flight.airline_name = airplane.airline_name) WHERE flight_num = %s and flight.airline_name = %s'
cursor.execute(query, (flight_num_arr, airline_name_arr))
#stores the results in a variable
arr_data = cursor.fetchone()
querycount = 'SELECT count(ticket_id) as c from ticket where flight_num= %s and airline_name= %s'
cursor.execute(querycount, (arr_data['flight_num'], arr_data['airline_name']))
count = cursor.fetchone()
print(count)
queryprice = 'SELECT base_price from flight where flight_num= %s and airline_name= %s'
cursor.execute(queryprice, (arr_data['flight_num'], arr_data['airline_name']))
price = cursor.fetchone()
print(price)
queryseats = 'SELECT num_of_seats from flight, airplane where airplane_id=id and flight_num= %s and flight.airline_name= %s'
cursor.execute(queryseats, (arr_data['flight_num'], arr_data['airline_name']))
seats = cursor.fetchone()
print(seats)
if count['c']/seats['num_of_seats'] >= .7:
print("1")
arr_data['base_price']= price['base_price']*1.20
else:
print("2")
arr_data['base_price']= price['base_price']
cursor.close()
#save the flight number in the session
session['flight_num_dep'] = flight_num_dep
session['airline_name_dep'] = airline_name_dep
session['round_trip'] = round
session['flight_num_arr'] = flight_num_arr
session['airline_name_arr'] = airline_name_arr
# get information of the flight and send to the payment page to ask for credit card information
cursor = conn.cursor();
# print(dep_data)
price=float(arr_data['base_price']) + float(dep_data['base_price'])
print("price", price, arr_data['base_price'], dep_data['base_price'])
#session['price'] = price
return render_template('purchase_ticket_a.html', flight_dep=[dep_data], flight_arr=[arr_data], price=price)
else:
query = 'SELECT flight_num, flight.airline_name, departure_airport, departure_hour, departure_min, departure_day, departure_month, departure_year, arrival_airport, arrival_hour, arrival_min, arrival_day, arrival_month, arrival_year, base_price FROM flight join airplane on (airplane.id = flight.airplane_id) and (flight.airline_name = airplane.airline_name) WHERE flight_num = %s and flight.airline_name = %s'
cursor.execute(query, (flight_num_dep, airline_name_dep))
#stores the results in a variable
#use fetchall() if you are expecting more than 1 data row
dep_data = cursor.fetchone()
querycount = 'SELECT count(ticket_id) as c from ticket where flight_num= %s and airline_name= %s'
cursor.execute(querycount, (dep_data['flight_num'], dep_data['airline_name']))
count = cursor.fetchone()
print(count)
queryprice = 'SELECT base_price from flight where flight_num= %s and airline_name= %s'
cursor.execute(queryprice, (dep_data['flight_num'], dep_data['airline_name']))
price = cursor.fetchone()
print(price)
queryseats = 'SELECT num_of_seats from flight, airplane where airplane_id=id and flight_num= %s and flight.airline_name= %s'
cursor.execute(queryseats, (dep_data['flight_num'], dep_data['airline_name']))
seats = cursor.fetchone()
print(seats)
if count['c']/seats['num_of_seats'] >= .7:
print("1")
dep_data['base_price']= price['base_price']*1.20
else:
print("2")
dep_data['base_price']= price['base_price']
cursor.close()
#save the flight number in the session
session['flight_num_dep'] = flight_num_dep
session['airline_name_dep'] = airline_name_dep
session['round_trip'] = round
session['flight_num_arr'] = 'None'
session['airline_name_arr'] = 'None'
# get information of the flight and send to the payment page to ask for credit card information
cursor = conn.cursor();
price=float(dep_data['base_price'])
#session['price'] = price
return render_template('purchase_ticket_a.html', flight_dep=[dep_data], flight_arr=[], price=price)
@app.route('/payment_a', methods=['GET', 'POST'])
def payment_a():
email = session['email']
booking_agent_id = session['booking_agent_id']
if email==None:
print('Please login first to pay')
return render_template('login.html')
#get credit card information from the form
name = request.form['card_name']
card_number = request.form['card_number']
card_type = request.form['card_type']
security_code = request.form['security_code']
exp_month = request.form['exp_month']
exp_year = request.form['exp_year']
customer_email = request.form['email']
first_name = request.form['first_name']
last_name = request.form['last_name']
building_number = request.form['building_number']
street = request.form['street']
city = request.form['city']
state = request.form['state']
passport_num = request.form['passport_num']
passport_exp_d = request.form['passport_exp_d']
passport_exp_m = request.form['passport_exp_m']
passport_exp_y = request.form['passport_exp_y']
passport_country = request.form['passport_country']
dob_d = request.form['dob_d']
dob_m = request.form['dob_m']
dob_y = request.form['dob_y']
#get details of the flight saved in the session
flight_num_dep= session['flight_num_dep']
airline_name_dep= session['airline_name_dep']
round= session['round_trip']
flight_num_arr= session['flight_num_arr']
airline_name_arr= session['airline_name_arr']
#price=session['price']
cursor = conn.cursor();
#card information
query0 = 'select email from customer where email = %s'
cursor.execute(query0, (customer_email))
data = cursor.fetchone()
if data == None:
ins = 'INSERT INTO customer(email, first_name, last_name, building_number, street, city, state, passport_number, passport_ex_day, passport_ex_month, passport_ex_year, passport_country, dob_day, dob_month, dob_year) VALUES(%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)'
cursor.execute(ins, (customer_email, first_name, last_name, building_number, street, city, state, passport_num, passport_exp_d, passport_exp_m, passport_exp_y, passport_country, dob_d, dob_m, dob_y))
conn.commit()
# use information to process the payment and purchase the flight
if round=='no':
from random import randint
ticket_number= str(randint(10000, 99999))
payment_number = str(randint(10000000, 99999999))
# query = 'SELECT base_price FROM flight WHERE flight_num = %s and airline_name = %s'
# cursor.execute(query, (flight_num_dep, airline_name_dep))
# price = cursor.fetchone()['base_price']
querycount = 'SELECT count(ticket_id) as c from ticket where flight_num= %s and airline_name= %s'
cursor.execute(querycount, (flight_num_dep, airline_name_dep))
count = cursor.fetchone()
print(count)
queryprice = 'SELECT base_price from flight where flight_num= %s and airline_name= %s'
cursor.execute(queryprice, (flight_num_dep, airline_name_dep))
price = cursor.fetchone()
print(price)
queryseats = 'SELECT num_of_seats from flight, airplane where airplane_id=id and flight_num= %s and flight.airline_name= %s'
cursor.execute(queryseats, (flight_num_dep, airline_name_dep))
seats = cursor.fetchone()
print(seats)
if count['c']/seats['num_of_seats'] >= .7:
print("1")
price= price['base_price']*1.20
else:
print("2")
price= price['base_price']
price_a = float(price) * 0.9
query1 = 'insert into ticket(ticket_id, flight_num, airline_name) values (%s, %s, %s)'
cursor.execute(query1, (ticket_number, flight_num_dep, airline_name_dep))
query2 = 'insert into buys(ticket_id, customer_email, booking_agent_id) values (%s, %s, %s)'
cursor.execute(query2, (ticket_number, customer_email, booking_agent_id))
query3 = 'insert into payment(payment_num, card_type, card_number, card_name, security_code, expiration_month, expiration_year, sold_price) values(%s, %s, %s, %s, %s, %s, %s, %s)'
cursor.execute(query3, (payment_number, card_type, card_number, name, security_code, exp_month, exp_year, price))
query4 = 'insert into paid(ticket_id, payment_num) values (%s, %s)'
cursor.execute(query4, (ticket_number, payment_number))
conn.commit()
cursor.close()
return redirect(url_for('home_a'))
else:
cursor = conn.cursor();
from random import randint
ticket_number= str(randint(10000, 99999))
payment_number = str(randint(10000000, 99999999))
# query = 'SELECT base_price FROM flight WHERE flight_num = %s and airline_name = %s'
# cursor.execute(query, (flight_num_dep, airline_name_dep))
# price_dep = cursor.fetchone()['base_price']
querycount = 'SELECT count(ticket_id) as c from ticket where flight_num= %s and airline_name= %s'
cursor.execute(querycount, (flight_num_dep, airline_name_dep))
count = cursor.fetchone()
print(count)
queryprice = 'SELECT base_price from flight where flight_num= %s and airline_name= %s'
cursor.execute(queryprice, (flight_num_dep, airline_name_dep))
price = cursor.fetchone()
print(price)
queryseats = 'SELECT num_of_seats from flight, airplane where airplane_id=id and flight_num= %s and flight.airline_name= %s'
cursor.execute(queryseats, (flight_num_dep, airline_name_dep))
seats = cursor.fetchone()
print(seats)
if count['c']/seats['num_of_seats'] >= .7:
print("1")
price_dep= price['base_price']*1.20
else:
print("2")
price_dep= price['base_price']
price_dep_a = float(price_dep) * 0.9
# query6 = 'SELECT base_price FROM flight WHERE flight_num = %s and airline_name = %s'
# cursor.execute(query6, (flight_num_arr, airline_name_arr))
# price_arr = cursor.fetchone()['base_price']
querycount = 'SELECT count(ticket_id) as c from ticket where flight_num= %s and airline_name= %s'
cursor.execute(querycount, (flight_num_arr, airline_name_arr))
count = cursor.fetchone()
print(count)
queryprice = 'SELECT base_price from flight where flight_num= %s and airline_name= %s'
cursor.execute(queryprice, (flight_num_arr, airline_name_arr))
price = cursor.fetchone()
print(price)
queryseats = 'SELECT num_of_seats from flight, airplane where airplane_id=id and flight_num= %s and flight.airline_name= %s'
cursor.execute(queryseats, (flight_num_arr, airline_name_arr))
seats = cursor.fetchone()
print(seats)
if count['c']/seats['num_of_seats'] >= .7:
print("1")
price_arr= price['base_price']*1.20
else:
print("2")
price_arr= price['base_price']
price_arr_a = float(price_arr)*0.9
price = price_dep + price_arr
price_a = price_dep_a + price_arr_a
query1 = 'insert into ticket(ticket_id, flight_num, airline_name) values (%s, %s, %s)'
cursor.execute(query1, (ticket_number, flight_num_dep, airline_name_dep))
query2 = 'insert into buys(ticket_id, customer_email, booking_agent_id) values (%s, %s, %s)'
cursor.execute(query2, (ticket_number, customer_email, booking_agent_id))
query3 = 'insert into payment(payment_num, card_type, card_number, card_name, security_code, expiration_month, expiration_year, sold_price) values(%s, %s, %s, %s, %s, %s, %s, %s)'
cursor.execute(query3, (payment_number, card_type, card_number, name, security_code, exp_month, exp_year, price))
query4 = 'insert into paid(ticket_id, payment_num) values (%s, %s)'
cursor.execute(query4, (ticket_number, payment_number))
conn.commit()
return redirect(url_for('home_a'))
@app.route('/view_my_commissions_a', methods=['GET', 'POST'])
def view_my_commissions_a():
email = session['email']
booking_agent_id = session['booking_agent_id']
cursor = conn.cursor()
try:
print("Try")
start_date = request.form['start_date']
end_date = request.form['end_date']
start_date= start_date+' 00:00:00'
end_date= end_date+' 23:59:00'
#total amount of commissions last 30 days
query0 = 'SELECT sum(sold_price*0.1) as sum FROM buys natural join paid natural join payment where payment_time between %s and %s and booking_agent_id = %s'
cursor.execute(query0, (start_date, end_date, booking_agent_id))
total_com = cursor.fetchone()['sum']
print(total_com)
#average commission last 30 days
query1 = 'SELECT avg(sold_price*0.1) as average FROM buys natural join paid natural join payment where payment_time between %s and %s and booking_agent_id = %s'
cursor.execute(query1, (start_date, end_date, booking_agent_id))
avg_com = cursor.fetchone()['average']
#total number of tickets sold last 30 days
query2 = 'SELECT count(ticket_id) as count FROM buys natural join paid natural join payment where payment_time between %s and %s and booking_agent_id = %s'
cursor.execute(query2, (start_date, end_date, booking_agent_id))
count = cursor.fetchone()['count']
except:
#total amount of commissions last 30 days
query0 = 'SELECT sum(sold_price*0.1) as sum FROM buys natural join paid natural join payment where payment_time >= date_sub(now(), interval 1 month) and booking_agent_id = %s'
cursor.execute(query0, (booking_agent_id))
total_com = cursor.fetchone()['sum']
#average commission last 30 days
query1 = 'SELECT avg(sold_price*0.1) as average FROM buys natural join paid natural join payment where payment_time >= date_sub(now(), interval 1 month) and booking_agent_id = %s'
cursor.execute(query1, (booking_agent_id))
avg_com = cursor.fetchone()['average']
#total number of tickets sold last 30 days
query2 = 'SELECT count(ticket_id) as count FROM buys natural join paid natural join payment where payment_time >= date_sub(now(), interval 1 month) and booking_agent_id = %s'
cursor.execute(query2, (booking_agent_id))
count = cursor.fetchone()['count']
cursor.close()
return render_template('view_my_commissions_a.html', username=email, total_com=total_com, avg_com = avg_com, count=count)
@app.route('/view_top_customers_a', methods=['GET', 'POST'])
def view_top_customers_a():
email = session['email']
booking_agent_id = session['booking_agent_id']
cursor = conn.cursor()
#view top customers based on number of tickets
query = 'SELECT customer_email, count(customer_email) as count FROM buys natural join paid natural join payment where payment_time >= date_sub(now(), interval 6 month) and booking_agent_id = %s Group by customer_email order by count desc limit 5'
cursor.execute(query, (booking_agent_id))
top5 = cursor.fetchall()
#top5y = cursor.fetchall()['count']
top5x=[]
top5y=[]
for i in top5:
top5x.append(i['customer_email'])
top5y.append(i['count'])
#view top customers based on amount of commissions
query = 'SELECT customer_email, sum(sold_price*0.1) as sum FROM buys natural join paid natural join payment where payment_time >= date_sub(now(), interval 12 month) and booking_agent_id = %s group by customer_email order by sum desc limit 5'
cursor.execute(query, (booking_agent_id))
top5comm = cursor.fetchall()
top5commx=[]
top5commy=[]
print(top5comm)
for k in top5comm:
top5commx.append(k['customer_email'])
top5commy.append(float(k['sum']))
return render_template('view_top_customers_a.html', username=email, top5x=top5x, top5y=top5y, top5commx= top5commx, top5commy= top5commy)
@app.route('/view_my_flights_a', methods=['GET', 'POST'])
def view_my_flights_a():
email = session['email']
booking_agent_id = session['booking_agent_id']
cursor = conn.cursor()
query = 'SELECT email FROM booking_agent where email = %s'
cursor.execute(query, (email))
data = cursor.fetchone()
if data==None:
error = "Please login first"
return render_template('login_a.html', error = error)
query = 'SELECT flight_num, status, customer_email, airline_name, departure_airport, departure_hour, departure_min, departure_day, departure_month, departure_year, arrival_airport, arrival_hour, arrival_min, arrival_day, arrival_month, arrival_year, base_price FROM buys natural join ticket natural join flight where booking_agent_id = %s'
cursor.execute(query, (booking_agent_id))
flights = cursor.fetchall()
cursor.close()
return render_template('view_my_flights_a.html', username=email, flights=flights)