-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommand_Line_Interface.py
1099 lines (1014 loc) · 43.3 KB
/
command_Line_Interface.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
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
import mysql.connector
from mysql.connector import Error
import sys
try:
connection = mysql.connector.connect(host='localhost',
database='Online_Retail_Store',
user='root',
password='Vidurg@1102')
cursor = connection.cursor()
def start():
print("Welcome to the Vidur Online Retail Store")
print("Choose the option from the given below menu: ")
print("1. Enter as Admin")
print("2. Enter as Customer")
print("3. Enter as Dealer")
print("4. Enter as Delivery Boy")
print("5. Exit the Application")
ans=int(input("Enter the choice: "))
print()
if(ans==1):
admin()
elif(ans==2):
customer()
elif(ans==3):
dealer()
elif(ans==4):
delivery_boy()
elif(ans==5):
sys.exit(0)
else:
print("Sorry, wrong input has been given try again...")
start()
return
def customer():
print("Enter the choice from given below: ")
print("1. Login")
print("2. Go Back")
num=int(input("Enter: "))
if(num==1):
print()
print("Enter the credentials: ")
usrname=input("Enter your username: ")
pwd=input("Enter your password: ")
mySql_sql_select_Query ="""
SELECT customer_username, customer_password,customer_id,customer_name FROM Online_Retail_Store.customer
"""
cursor.execute(mySql_sql_select_Query)
result = cursor.fetchall()
for row in result:
if(row[0]==usrname and row[1]==pwd):
# print(row[0],row[1])
print(f'Welcome {row[3]}')
id=int(row[2])
customer_query(id)
customer()
return
print("Sorry, Wrong Credentials,try again!!!")
customer()
elif(num==2):
start()
else:
print("Sorry, wrong input has been given try again...")
customer()
return
def customer_query(id):
print("1. View Cart")
print("2. Browse Products")
print("3. Add/Edit quantity of product to cart")
print("4. View Coupons")
print("5. Empty Cart")
print("6. Checkout Cart")
print("7. Log out")
ans=int(input("Enter the choice: "))
if(ans==1):
mySql_sql_select_Query ="""
SELECT product.product_name, product.product_cost, cart_prod.quantity,product.product_cost*cart_prod.quantity as Total_cost
FROM product
JOIN cart_prod ON product.product_id = cart_prod.prod_id
WHERE cart_prod.cart_id = """+str(id)+";"
cursor.execute(mySql_sql_select_Query)
result = cursor.fetchall()
print()
print(f'There are currently {len(result)} products in the cart')
print(f'Product name Product Cost Quantity Total_cost')
grand_total=0
for row in result:
print(f'{row[0]} {row[1]} {row[2]} {row[3]}')
grand_total+=int(row[3])
print()
print(f'Grand Total : {grand_total}')
print()
customer_query(id)
elif(ans==2):
mySql_sql_select_Query ="""
SELECT product.product_name,product.Brand_name,product.product_cost FROM Online_Retail_Store.product;"""
cursor.execute(mySql_sql_select_Query)
result = cursor.fetchall()
print()
print(f'Product name Brand Name Product Cost')
for row in result:
print(f'{row[0]} {row[1]} {row[2]}')
print()
customer_query(id)
elif(ans==3):
pr_name=input("Enter the product name: ")
quantity=int(input("Enter the quantity of product: "))
mySql_sql_select_Query ="""
SELECT product.product_id,Quantity,product.product_cost
FROM product
WHERE product.product_name = '"""+pr_name+"';"
#print(mySql_sql_select_Query)
mySql_sql_select_Query2="""
SELECT prod_id,cart_id,quantity FROM Online_Retail_Store.cart_prod;
"""
#print(mySql_sql_select_Query2)
cursor.execute(mySql_sql_select_Query)
result = cursor.fetchall()
#print(1)
cursor.execute(mySql_sql_select_Query2)
result2 = cursor.fetchall()
#print(2)
#print(len(result))
if(len(result)==0):
print("Sorry, no such product name exists, try again with correct product name..")
customer_query(id)
return
cost_of_product=int(result[0][2])
#print(cost_of_product)
flag=0
qty=0
#print(len(result2))
for ro in result2:
#print(ro)
if(int(result[0][0])==int(ro[0]) and id==int(ro[1])):
print(result[0][0],ro[0])
print(id,ro[1])
flag=1
qty=int(ro[2])
break
#print(3)
if(flag==0):
#print(4)
if(int(result[0][1])>=quantity):
my_query="""
insert into cart_prod (prod_id,cart_id,quantity) values
('"""
#print(my_query)
my_query=my_query+str(result[0][0])
#print(my_query)
my_query=my_query+"',"+str(id)+",'"+str(quantity)+"');"
#print(my_query)
try:
cursor.execute(my_query)
connection.commit()
print()
print(f'Your cart has been updated succesfully.')
print()
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
else:
print("Sorry, product you have requested is out of stock")
else:
#print(5)
if(int(result[0][1])>=quantity):
my_query2="""
SELECT total_cost FROM Online_Retail_Store.cart
WHERE cart_id="""+str(id)+";"
cursor.execute(my_query2)
answer=cursor.fetchall()
calcu=int(answer[0][0])-cost_of_product*qty+cost_of_product*quantity
my_query="""
UPDATE cart_prod
SET quantity="""+str(quantity)+"""
WHERE cart_id="""+str(id)+""" and prod_id="""+str(result[0][0])+""";"""
try:
cursor.execute(my_query)
connection.commit()
print()
print(f'Your quantity of product has been updated succesfully.')
print()
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
my_query="""
UPDATE cart
SET total_cost="""+str(calcu)+"""
WHERE cart_id="""+str(id)+""";"""
try:
cursor.execute(my_query)
connection.commit()
print()
print(f'Your cart has been updated succesfully.')
print()
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
else:
print("Sorry, product you have requested is out of stock")
customer_query(id)
elif(ans==5):
empty_cart(id)
customer_query(id)
elif(ans==4):
mySql_sql_select_Query ="""
SELECT coupon.coupon_code,coupon.percentage_discount
FROM coupon
INNER JOIN customer_coupon ON coupon.coupon_id = customer_coupon.coupon_id
WHERE customer_coupon.customer_id = """+str(id)+""";"""
cursor.execute(mySql_sql_select_Query)
result=cursor.fetchall()
print(f'There are currently {len(result)} coupons allocated to you.')
print("Coupon_Code Percentage_discount")
for row in result:
print(f'{row[0]} {row[1]}')
customer_query(id)
elif(ans==6):
my_query2="""
SELECT total_cost FROM Online_Retail_Store.cart
WHERE cart_id="""+str(id)+";"
cursor.execute(my_query2)
answer=cursor.fetchall()
if(int(answer[0][0])==0):
print("Sorry nothing to checkout your cart is alreaady empty.")
else:
cost=int(answer[0][0])
percent=0
asku=input("Do you want to apply the coupon code on the order(YES/NO):")
if(asku=='NO'):
percent=0
else:
coupon_code=input("Enter the coupon code:")
mySql_sql_select_Query ="""
SELECT coupon.percentage_discount,coupon.coupon_id
FROM coupon
INNER JOIN customer_coupon ON coupon.coupon_id = customer_coupon.coupon_id
WHERE coupon.coupon_code= '"""+coupon_code+"""' and customer_coupon.customer_id = """+str(id)+""";"""
cursor.execute(mySql_sql_select_Query)
res=cursor.fetchall()
if(len(res)==0):
print("No such coupon code is available.")
else:
percent=int(res[0][0])
cost=cost-cost*(percent)/100
print("Coupon Applied Successfully")
coupon_id=res[0][1]
mySql_sql_select_Query="""
DELETE FROM customer_coupon
WHERE customer_coupon.customer_id="""+str(id)+""" and customer_coupon.coupon_id= """+str(coupon_id)+""";
"""
try:
cursor.execute(mySql_sql_select_Query)
connection.commit()
print()
print("Coupon Applied Successfully")
print()
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
customer_query(id)
date=input("Enter the date: ")
expected_date=input("Enter the date upto which you can expect delivery(make it atleast 7 days later than the date at which you placed the order): ")
address=input("Enter the delivery address: ")
order_status='Not delivered'
empty_cart_with_checkout(id)
my_query="""
insert into orders (delivery_boy_id, total_cost, delivery_address, order_status, order_placed_date, expected_delivery_time, customer_id) values
(6, '"""+str(cost)+"""', '"""+str(address)+"""', '"""+str(order_status)+"""', '"""+str(date)+"""', '"""+str(expected_date)+"""', '"""+str(id)+"""');
"""
print(2)
try:
cursor.execute(my_query)
connection.commit()
print()
print(f'Your order has been placed succesfully.')
print()
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
customer_query(id)
elif(ans==7):
customer()
else:
print("Sorry, wrong input has been given try again...")
customer_query(id)
return
def empty_cart(id):
if(True):
mySql_sql_select_Query ="""
DELETE FROM cart_prod
WHERE cart_prod.cart_id= """+str(id)+""";"""
try:
cursor.execute(mySql_sql_select_Query)
connection.commit()
print()
print(f'Your cart has been emptied succesfully.')
print()
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
my_query="""
UPDATE cart
SET total_cost=0
WHERE cart_id="""+str(id)+""";"""
try:
cursor.execute(my_query)
connection.commit()
print()
print(f'Your cart has been updated succesfully.')
print()
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
def empty_cart_with_checkout(id):
if(True):
mySql_sql_select_Query ="""
SELECT cart_prod.prod_id,cart_prod.quantity
FROM cart_prod
WHERE cart_prod.cart_id="""+str(id)+""";"""
cursor.execute(mySql_sql_select_Query)
result=cursor.fetchall()
flag=0
for row in result:
my_query="""
SELECT product.Quantity
FROM product
WHERE product.product_id= """+str(row[0])+""";"""
cursor.execute(my_query)
armer=cursor.fetchall()
if(int(row[1])>int(armer[0][0])):
flag=1
if(flag==1):
print("Sorry unable to checkout due to insufficient amount of product in inventory.")
customer_query(id)
mySql_sql_select_Query ="""
SELECT cart_prod.prod_id,cart_prod.quantity
FROM cart_prod
WHERE cart_prod.cart_id="""+str(id)+""";"""
cursor.execute(mySql_sql_select_Query)
result=cursor.fetchall()
for row in result:
my_query=="""
SELECT product.Quantity
FROM cart_prod
WHERE product.product_id= """+str(row[0])+""";"""
cursor.execute(my_query)
armer=cursor.fetchall()
my_query="""
UPDATE product
SET Quantity="""+str(int(armer[0][0])-int(row[1]))+"""
WHERE product_id="""+str(row[0])+""";"""
try:
cursor.execute(my_query)
connection.commit()
print()
print(f'Your cart has been updated succesfully.')
print()
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
mySql_sql_select_Query ="""
DELETE FROM cart_prod
WHERE cart_prod.cart_id= """+str(id)+""";"""
try:
cursor.execute(mySql_sql_select_Query)
connection.commit()
print()
print(f'Your cart has been emptied succesfully.')
print()
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
my_query="""
UPDATE cart
SET total_cost=0
WHERE cart_id="""+str(id)+""";"""
try:
cursor.execute(my_query)
connection.commit()
print()
print(f'Your cart has been updated succesfully.')
print()
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
def dealer():
print("Enter the choice from given below: ")
print("1. Login")
print("2. Go Back")
num=int(input("Enter: "))
if(num==1):
print()
print("Enter the credentials: ")
usrname=input("Enter your username: ")
pwd=input("Enter your password: ")
mySql_sql_select_Query ="""
SELECT dealer_username, dealer_password,dealer_id FROM Online_Retail_Store.dealer
"""
cursor.execute(mySql_sql_select_Query)
result = cursor.fetchall()
for row in result:
if(row[0]==usrname and row[1]==pwd):
print(f'Welcome {row[0]}')
id=int(row[2])
dealer_query(id)
dealer()
print("Sorry, Wrong Credentials,try again!!!")
dealer()
elif(num==2):
start()
else:
print("Sorry, wrong input has been given try again...")
dealer()
return
def dealer_query(id):
print("1. View Products currently being sold")
print("2. Log out")
ans=int(input("Enter the choice: "))
if(ans==1):
mySql_sql_select_Query ="""
SELECT product.product_id,product.product_name
FROM product
JOIN deal_prod ON product.product_id = deal_prod.prod_id
WHERE deal_prod.deal_id = """+str(id)+";"
cursor.execute(mySql_sql_select_Query)
result = cursor.fetchall()
print()
print(f'There are currently {len(result)} products sold by you')
print(f'Product_id Product_name')
for row in result:
print(row[0],row[1])
print()
dealer_query(id)
elif(ans==2):
dealer()
else:
print("Sorry, wrong input has been given try again...")
dealer_query(id)
return
def delivery_boy():
print("Enter the choice from given below: ")
print("1. Login")
print("2. Go Back")
num=int(input("Enter: "))
if(num==1):
print("Enter the credentials: ")
usrname=input("Enter your username: ")
pwd=input("Enter your password: ")
mySql_sql_select_Query ="""
SELECT delivery_boy_username, delivery_boy_password ,delivery_boy_id FROM Online_Retail_Store.delivery_boy
"""
cursor.execute(mySql_sql_select_Query)
result = cursor.fetchall()
for row in result:
if(row[0]==usrname and row[1]==pwd):
print(row[0],row[1])
id=int(row[2])
delivery_boy_query(id)
delivery_boy()
print("Sorry, Wrong Credentials,try again!!!")
delivery_boy()
elif(num==2):
start()
else:
print("Sorry, wrong input has been given try again...")
delivery_boy()
return
def delivery_boy_query(id):
print("1. View Orders")
print("2. Mark Order Delivered")
print("3. Log out")
ans=int(input("Enter the choice: "))
if(ans==1):
mySql_sql_select_Query ="""
SELECT customer.customer_username,orders.order_id, orders.delivery_address
FROM orders
JOIN delivery_boy ON orders.delivery_boy_id = delivery_boy.delivery_boy_id
JOIN customer ON customer.customer_id = orders.customer_id
WHERE orders.order_status='Not delivered' and delivery_boy.delivery_boy_id = """+str(id)+";"
cursor.execute(mySql_sql_select_Query)
result = cursor.fetchall()
print()
print(f'There are currently {len(result)} orders to be delivered')
print(f'Customer name Order_id Delivery Address')
for row in result:
print(row[0],row[1],row[2])
print()
delivery_boy_query(id)
elif(ans==2):
ord_id=input("Enter the order id: ")
my_query="""
UPDATE orders
SET orders.order_status='Delivered'
WHERE orders.order_status='Not delivered' and orders.delivery_boy_id= """+str(id)+""" and orders.order_id= """+str(ord_id)+""";
"""
try:
cursor.execute(my_query)
connection.commit()
print()
print(f'Order status has been updated succesfully.')
print()
delivery_boy_query(id)
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
delivery_boy_query(id)
elif(ans==3):
delivery_boy()
else:
print("Sorry, wrong input has been given try again...")
delivery_boy_query(id)
return
def admin():
print("Enter the choice from given below: ")
print("1. Login")
print("2. Quit")
num=int(input("Enter: "))
if(num==1):
print()
print("Enter the credentials: ")
usrname=input("Enter your username: ")
pwd=input("Enter your password: ")
mySql_sql_select_Query ="""
SELECT admin_username,admin_password,admin_id FROM Online_Retail_Store.admins
"""
cursor.execute(mySql_sql_select_Query)
result = cursor.fetchall()
for row in result:
if(row[0]==usrname and row[1]==pwd):
print()
print(f'Welcome, {usrname}')
print()
id=int(row[2])
admin_query(id)
admin()
print("Sorry, Wrong Credentials,try again!!!")
admin()
else:
start()
return
def admin_query(id):
print("1. Add Product")
print("2. View products")
print("3. Add Category")
print("4. View Categories")
print("5. Assign category to a product")
print("6. Add Customer")
print("7. View Customers")
print("8. Add Coupon")
print("9. View Coupons")
print("10. Assign a coupon to a customer")
print("11. Add Dealer")
print("12. Add Delivery Boy")
print("13. Analyse Data")
print("14. Delete Product")
print("15. Log out.")
ans=int(input("Enter the choice: "))
print()
if(ans==15):
admin()
elif(ans==14):
name=input("Enter product_id: ")
my_query="""
DELETE FROM product
WHERE product.product_id= """+str(name)+""";
"""
# print(my_query)
try:
cursor.execute(my_query)
connection.commit()
print()
print(f'Product has been deleted succesfully.')
print()
admin_query(id)
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
admin_query(id)
elif(ans==13):
admin_data_analysis(id)
elif(ans==12):
name=input("Enter name: ")
usrname=input("Enter username: ")
pwd=input("Enter password: ")
contact_number=input("Enter phone number: ")
emid=input("Enter email-id: ")
my_query="""
insert into delivery_boy (delivery_boy_name, delivery_boy_username, delivery_boy_password, delivery_boy_average_rating, contact_number, email_id, admin_id) values
('"""+name+"""','"""+usrname+"""','"""+pwd+"""', 0,'"""+contact_number+"""','"""+emid+"""','"""+str(id)+"""');
"""
# print(my_query)
try:
cursor.execute(my_query)
connection.commit()
print()
print(f'{name} has been added succesfully.')
print()
admin_query(id)
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
admin_query(id)
elif(ans==11):
name=input("Enter name: ")
usrname=input("Enter username: ")
pwd=input("Enter password: ")
address=input("Enter address_of_operations: ")
contact_number=input("Enter phone number: ")
emid=input("Enter email-id: ")
my_query="""
insert into dealer (dealer_name, dealer_username, dealer_password, address_of_operations, contact_number, email_id, admin_id) values
('"""+name+"""','"""+usrname+"""','"""+pwd+"""','"""+address+"""','"""+contact_number+"""','"""+emid+"""','"""+str(id)+"""');
"""
try:
cursor.execute(my_query)
connection.commit()
print()
print(f'{name} has been added succesfully.')
print()
admin_query(id)
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
admin_query(id)
elif(ans==10):
name=input("Enter coupon_id: ")
usrname=input("Enter customer_id: ")
my_query="""
insert into customer_coupon (coupon_id, customer_id) values
("""+name+""","""+usrname+""");
"""
try:
cursor.execute(my_query)
connection.commit()
print()
print(f'Coupon has been assigned to the customer succesfully.')
print()
admin_query(id)
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
admin_query(id)
elif(ans==9):
my_query="""
SELECT * FROM Online_Retail_Store.coupon;
"""
cursor.execute(my_query)
result=cursor.fetchall()
print(f'There are currently {len(result)} coupons present in the database.')
print("Coupon_id Coupon_Code Percentage_discount")
for row in result:
print(f'{row[0]} {row[2]} {row[1]}')
admin_query(id)
elif(ans==8):
name=input("Enter coupon_code: ")
usrname=input("Enter percentage_discount: ")
my_query="""
insert into coupon (percentage_discount, coupon_code, admin_id) values
('"""+usrname+"""','"""+name+"""','"""+str(id)+"""');
"""
try:
cursor.execute(my_query)
connection.commit()
print()
print(f'Coupon has been added succesfully.')
print()
admin_query(id)
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
admin_query(id)
elif(ans==7):
my_query="""
SELECT * FROM Online_Retail_Store.customer;
"""
cursor.execute(my_query)
result=cursor.fetchall()
print(f'There are currently {len(result)} customers present in the database.')
print("Customer_id Customer_name Contact_number Customer_username Email_id Customer_address")
for row in result:
print(f'{row[0]} {row[1]} {row[2]} {row[3]} {row[5]} {row[6]}')
admin_query(id)
elif(ans==6):
name=input("Enter name: ")
usrname=input("Enter username: ")
pwd=input("Enter password: ")
address=input("Enter address: ")
contact_number=input("Enter phone number: ")
emid=input("Enter email-id: ")
my_query="""
insert into customer(customer_name, customer_username, customer_password,customer_address, contact_number, email_id, admin_id) values
('"""+name+"""','"""+usrname+"""','"""+pwd+"""','"""+address+"""','"""+contact_number+"""','"""+emid+"""','"""+str(id)+"""');
"""
try:
cursor.execute(my_query)
connection.commit()
print()
print(f'Customer has been added succesfully.')
helper="""
SELECT customer_id FROM Online_Retail_Store.customer
WHERE customer_username= '"""+usrname+"""';"""
cursor.execute(helper)
rey=cursor.fetchall()
cart_id=rey[0][0]
my_quer="""
insert into cart (cart_id,total_cost, description_info) values
('"""
my_quer=my_quer+str(cart_id)
my_quer=my_quer+"""',0,'jvrenvjnvjnrvnkj vrnwvjn wrvjw vbntv tjb vjthjkv krj vj vfrv');"""
try:
cursor.execute(my_quer)
connection.commit()
print()
print(f'Cart of customer has also been added succesfully.')
print()
admin_query(id)
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
query="""DELETE FROM customer
WHERE customer_id="""+str(cart_id)+""";"""
cursor.execute(query)
connection.commit()
print()
admin_query(id)
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
admin_query(id)
elif(ans==5):
name=input("Enter category_id: ")
usrname=input("Enter product_id: ")
my_query="""
insert into categ_prod (prod_id,categ_id) values
("""+usrname+""","""+name+""");
"""
try:
cursor.execute(my_query)
connection.commit()
print()
print(f'Category has been assigned to the given product succesfully.')
print()
admin_query(id)
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
admin_query(id)
elif(ans==4):
my_query="""
SELECT * FROM Online_Retail_Store.category;
"""
cursor.execute(my_query)
result=cursor.fetchall()
print(f'There are currently {len(result)} categories present in the database.')
print("Category_id Category_name Category_info")
for row in result:
print(f'{row[0]} {row[1]} {row[2]}')
admin_query(id)
elif(ans==3):
name=input("Enter category_name: ")
usrname=input("Enter category_info: ")
my_query="""
insert into category (category_name, category_info, admin_id) values
('"""+name+"""','"""+usrname+"""','"""+str(id)+"""');
"""
try:
cursor.execute(my_query)
connection.commit()
print()
print(f'Category has been added succesfully.')
print()
admin_query(id)
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
admin_query(id)
elif(ans==2):
my_query="""
SELECT * FROM Online_Retail_Store.product;
"""
cursor.execute(my_query)
result=cursor.fetchall()
print(f'There are currently {len(result)} products present in the database.')
print("Product_id Product_name Product_cost Brand_Name Quantity")
for row in result:
print(f'{row[0]} {row[1]} {row[2]} {row[3]} {row[4]}')
admin_query(id)
elif(ans==1):
name=input("Enter product_name: ")
cost=input("Enter product_cost: ")
brand=input("Enter brand_name: ")
quantity=input("Enter quantity: ")
my_query="""
insert into product (product_name, product_cost, Brand_name, Quantity, admin_id) values
('"""+name+"""','"""+cost+"""','"""+brand+"""','"""+quantity+"""','"""+str(id)+"""');
"""
try:
cursor.execute(my_query)
connection.commit()
print()
print(f'Product has been added succesfully.')
print()
admin_query(id)
except:
connection.rollback()
print()
print(f'Sorry due to some error/wrong input information is not been able to be saved try again.')
print()
admin_query(id)
else:
print("Sorry, wrong input has been given try again...")
admin_query(id)
return
def admin_data_analysis(id):
print("1. Displaying customer id,customer name,order id of the customers who have placed order having total cost>= the given cost")
print("2. Displaying delivery boy id,date at which order placed,order status,delivery boy name,average rating of the delivery boy in all those orders in which toal cost>= the given cost")
print("3. Displaying number of products sold by each brand for a given year.")
print("4. Displaying product-wise order and sales count for a given month and year.")
print("5. Displaying total Sales by the product category and month.")
print("6. Top given number of customers by total order value.")
print("7. Go Back")
num=int(input("Now choose which query do you want to see: "))
if(num==1):
cost=input("Enter the cost:")
mySql_sql_select_Query ="""
SELECT c.customer_id, c.customer_name,o.order_id
FROM Online_Retail_Store.customer as c
LEFT JOIN Online_Retail_Store.orders as o ON c.customer_id = o.customer_id
WHERE o.total_cost>="""
mySql_sql_select_Query=mySql_sql_select_Query+cost
mySql_sql_select_Query=mySql_sql_select_Query+""" ORDER BY c.customer_id """
cursor.execute(mySql_sql_select_Query)
result = cursor.fetchall()
print(f'Total number of tuples fetched for the above query: {cursor.rowcount}')
print()
for row in result:
print(f'customer_id: {row[0]}', end =" ")
print(f'customer_name: {row[1]}', end =" ")
print(f'order_id: {row[2]}')
print()
admin_data_analysis(id)
elif(num==2):
cost=input("Enter the cost:")
mySql_sql_select_Query ="""
select Online_Retail_Store.orders.delivery_boy_id,Online_Retail_Store.orders.order_placed_date,Online_Retail_Store.orders.order_status,Online_Retail_Store.delivery_boy.delivery_boy_name,Online_Retail_Store.delivery_boy.delivery_boy_average_rating
from Online_Retail_Store.orders
left join Online_Retail_Store.delivery_boy
on Online_Retail_Store.orders.delivery_boy_id = Online_Retail_Store.delivery_boy.delivery_boy_id
where Online_Retail_Store.orders.total_cost>="""
mySql_sql_select_Query=mySql_sql_select_Query+cost
mySql_sql_select_Query=mySql_sql_select_Query+""" ORDER BY Online_Retail_Store.delivery_boy.delivery_boy_id"""
cursor.execute(mySql_sql_select_Query)
result = cursor.fetchall()
print(f'Total number of tuples fetched for the query: {cursor.rowcount}')
print()
for row in result:
print(f'-> ', end=" ")
print(f'Delivery Boy Id: {row[0]}', end =" ")
print(f'Order placed Date: {row[1]}', end =" ")
print(f'Status of Order: {row[2]}', end =" ")
print(f'Delivery Boy Name: {row[3]}', end =" ")
print(f'Average rating: {row[4]}')
print()
admin_data_analysis(id)
elif(num==3):
year=input("Enter the year:")
mySql_sql_select_Query ="""
SELECT p.Brand_name, COUNT(cp.prod_id) as total_products_sold
FROM orders o
JOIN cart c ON o.customer_id = c.cart_id
JOIN cart_prod cp ON c.cart_id = cp.cart_id
JOIN product p ON cp.prod_id = p.product_id
WHERE YEAR(order_placed_date) = """
mySql_sql_select_Query=mySql_sql_select_Query+year
mySql_sql_select_Query=mySql_sql_select_Query+""" GROUP BY p.Brand_name WITH ROLLUP"""
cursor.execute(mySql_sql_select_Query)
result = cursor.fetchall()
print(f'Total number of tuples fetched for the query: {cursor.rowcount}')
print()
for row in result:
print(f'-> ', end=" ")
print(f'Brand name: {row[0]}', end =" ")
print(f'Total Products sold: {row[1]}')
print()
admin_data_analysis(id)
elif(num==4):
year=input("Enter the year:")
month=input("Enter the month number:")
mySql_sql_select_Query ="""
SELECT p.product_name, COUNT(o.order_id) as total_orders, SUM(o.total_cost) as total_sales
FROM orders o
JOIN cart c ON o.customer_id = c.cart_id
JOIN cart_prod cp ON c.cart_id = cp.cart_id
JOIN product p ON cp.prod_id = p.product_id
WHERE MONTH(order_placed_date) = """
mySql_sql_select_Query=mySql_sql_select_Query+month
mySql_sql_select_Query=mySql_sql_select_Query+""" AND YEAR(order_placed_date) = """