-
Notifications
You must be signed in to change notification settings - Fork 4
/
Python code.py
2763 lines (2261 loc) · 89.2 KB
/
Python code.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
# LAI KAI YONG TP059040
# LIM WYE YEE TP059371
# Section A: General code functionalities
# 1. decoration style of the system section block
def decoration():
# pattern design
return '*' * 10
# 2. convert the line users want to modified to index value.
def index_converter(a):
return a - 1
# Section B: Headers
# 1. Car data header
def car_header():
# Headers
car_headers = ['Car ID', 'Car Brand', 'Car Model',
'Car Plate', 'Year', 'Status', 'Price']
# Setting / Display format of displaying all headers
format_row = "{} " * (len(car_headers) + 1)
print("\n", format_row.format("", *car_headers))
# 2. Customer booking statement data header
def cus_book_header():
# Headers
cus_book = ['Username', 'Car ID', 'Price', 'Days',
'Total Amount', 'Status', 'Reservation', 'Requested Rent Date']
# Setting / Display format of displaying all headers
format_row = "{} " * (len(cus_book) + 1)
print("\n", format_row.format("", *cus_book))
# 3. Customer payment statement data header
def cus_pay_header():
# Headers
cus_pay = ['Username', 'Car ID', 'Price', 'Days',
'Total Amount', 'Status', 'Payment Method', 'Requested Rent Date']
# Setting / Display format of displaying all headers
format_row = "{} " * (len(cus_pay) + 1)
print("\n", format_row.format("", *cus_pay))
# 4. Customer statement data header
def cus_statement_header():
# Headers
cus_stmnt = ['Username', 'Car ID', 'Price', 'Days',
'Total Amount', 'Status', 'Reservation', 'Payment Method', 'Requested Rent Date']
# Setting / Display format of displaying all headers
format_row = "{} " * (len(cus_stmnt) + 1)
print("\n", format_row.format("", *cus_stmnt))
# 5. Customer registration page header
def cus_reg_header():
print("\n", decoration(), "Welcome to the registration page", decoration(), "\n")
# Direct to customer registration page
customer_registration()
# 6. Customer top up page header
def top_up_header():
print("\n", decoration(), "Welcome to the top up system.", decoration())
# Direct to customer balance top up page
top_up()
# Section C: Database/ Text File Data Management
# Read file
# 1. car database
def car_database_read():
# Extract car data to a list
try:
index = 0
cars = []
index_collector = []
with open("carDatabase.txt", 'r') as car_file:
for line in car_file:
index_collector.append(index)
row = line.strip().split(" | ")
cars.append(row)
index += 1
except:
print("\nDatabase is corrupted..")
all_car_details = [cars, index_collector]
return all_car_details
# 2. customer details
def customer_details_read():
# Extract customer information to a list
try:
customers = []
with open("customerDetails.txt", 'r') as customers_file:
for line in customers_file:
row = line.strip().split(" | ")
customers.append(row)
except:
print("\nDatabase is corrupted..")
return customers
# 3. customer booking / payment statement
def bookpay_stmnt_read():
# Extract customer booking / payment statement to a list
try:
statements = []
with open("customerBookingPayment.txt", 'r') as statement_file:
for line in statement_file:
row = line.strip().split(" | ")
statements.append(row)
for statement in statements:
total = int(statement[2]) * int(statement[3])
statement.append(total)
except:
print("\nDatabase is corrupted..")
return statements
# Section D: General Users Interface
# 1. Welcome page with text display.
def welcome():
print("\n", decoration(), "Welcome to the Online Car Rental System(OCRS) by Super Car Rental Services(SCRS)",
decoration())
# Menu
print("""
Enter the number that best describe you.
Admin : 1
Customer : 2
""")
login_system()
# 2. Role definition pass
def login_system():
# Ask for users' role
def role_validation():
try:
role = int(input("Role => "))
return role
# Exclude non numeric value
except ValueError:
print("\nInvalid input, please insert a numeric value..\n")
return role_validation()
role = role_validation()
# Administrator pass
if role == 1:
administrator_login()
# Customer pass
elif role == 2:
customer_interface()
# Error if neither 1 nor 2 are entered
else:
print("\nInvalid choice, please choose again.\n")
return login_system()
# 3. Exit system
def exit_system():
# Menu
print("""
Are you sure you want to exit the Online Car Rental System?
[YES] or [NO]
Note: Selecting [NO] will navigate you back to the welcome page.""")
# Asking for exit confirmation
confirmation = input("Option => ").upper()
# Terminate the program
if confirmation == "YES":
print("\n", decoration(), "Exit", decoration(), "\n")
exit()
# Direct to the welcome page
elif confirmation == "NO":
print("You will be redirect to the welcome page shortly...\n")
welcome()
# Error when either "YES" or "NO" are not selected
else:
print("Invalid input, please enter YES or NO.")
return exit_system()
# Section E: Administrator
# Additional: When database corrupted and required to recreate one.
def maintenance_database_access():
# Accessing database by verifying username and password
maintenance_username = "SCRSLL001"
maintenance_password = "SCRSOCRSLaiLim"
username = input("Enter username: ")
password = input("Enter password: ")
# Validation of username and password
if username == maintenance_username and password == maintenance_password:
print(f"\n{decoration()} Welcome administrator {decoration()}\n")
def admin_create_file():
# Options on new database if it is not created
try:
# Menu
print("""What database you would like to create
1: Car Database
2: Customer information Database
3: Customer Booking / Payment Database
""")
create_file = int(input("Option => "))
# Execute based on the choices entered
if create_file == 1:
create_car = open("carDatabase.txt", "w")
print(
"\nDatabase created, you will be redirected to the add car functionalities.")
create_car.close()
admin_add_car()
elif create_file == 2:
create_user = open("customerDetails.txt", "w")
print(
"\nDatabase created, you will be redirected to the administrator main screen.")
create_user.close()
administrator_system()
elif create_file == 3:
create_booking = open("customerBookingPayment.txt", "w")
print(
"\nDatabase created, you will be redirected to the administrator main screen.")
create_booking.close()
administrator_system()
# Error message on inputing the shown value
else:
print(
"Please insert a number from 1 to 3.\n")
return admin_create_file()
# Exclude non numeric value
except ValueError:
print("\nPlease insert a numeric value.\n")
return admin_create_file()
admin_create_file()
# Error message after selecting a non existent choice
else:
print("\nPlease try again.\n")
return maintenance_database_access()
# 1. Administrator login page
def administrator_login():
# request for admins username and password
administrator_username = "SCRSLL001"
administrator_password = "SCRSOCRSLaiLim"
username = input("\nEnter your username: ")
password = input("Enter your password: ")
# username and password validation
if username == administrator_username and password == administrator_password:
administrator_system()
else:
print("Invalid credential, please check your username and password.")
return administrator_login()
# 2. Administrator access system
def administrator_system():
# Admins welcome line
print("\n", decoration(), "Welcome, administrator!", decoration())
# Admins functionalities menu
def admin_function_validation():
try:
# Menu
print("""
Choose the action you want to perform:
1: Add cars to be rented out.
2: Modify car details.
3: Display records.
4: Search specific record.
5: Return a rented car.
6: Mark a car as Ready upon customer's booking confirmation.
7: OCRS Data Analytics Dashboard
8: Exit the system.
""")
option = int(input("Select your action: "))
# Execute system based on option
if option == 1:
admin_add_car()
elif option == 2:
admin_modify()
elif option == 3:
admin_display()
elif option == 4:
admin_search()
elif option == 5:
admin_return_rent()
elif option == 6:
admin_mark_ready()
elif option == 7:
analytics_dashboard()
elif option == 8:
exit_system()
# Error for invalid input
else:
print("Invalid input, please choose options in range of 1 to 8.")
# request for input again
return admin_function_validation()
# Exclude non numeric value
except ValueError:
print("\nInvalid input, please insert a numeric value..\n")
return admin_function_validation()
admin_function_validation()
# Section E01: Administrator functionalities
# 1. Add car
def admin_add_car():
# Extract car data to a database that store a list
try:
cars = car_database_read()[0]
# No file identified
except:
print("Access the database system to check database progress\n")
maintenance_database_access()
# Menu
print("""
Insert car data:
[YES] to continue
[NO] to stop and display all data. then redirected to admin main screen.
""")
# Add car choice
add_or_not = input("Option => ").upper()
# Auto generate the new car id
last_car_id = cars[-1][0].split("R")
new_car_id_num = int(last_car_id[1]) + 1
# Add car while admins choose 'yes'
if add_or_not == "YES":
new_car_details = []
new_car_id = 'R' + f'{new_car_id_num:03d}'
print("Car ID: ", new_car_id)
new_car_brand = input("Enter car brand: ")
new_car_model = input("Enter car model: ")
new_car_plate = input("Enter car plate: ")
new_year = input("Enter car manufacture year: ")
def new_status_validation():
new_status = input(
"Enter status [Open / Rented / X / Booked]: ").capitalize()
status = ['Open', 'Rented', 'X', 'Booked']
if new_status not in status:
print("Invalid status, Please enter a valid status.\n")
return new_status_validation()
else:
return new_status
new_status = new_status_validation()
def new_price_validation():
try:
new_price = int(
input("Enter price per day (Only numeric data): "))
return new_price
# Exclude non numeric value
except ValueError:
print("\nInvalid input, please insert a numeric value..\n")
return new_price_validation()
new_price = new_price_validation()
new_car_details.extend([new_car_id, new_car_brand,
new_car_model, new_car_plate, new_year, new_status, str(new_price)])
# Append the new car data into carDatabase text file
try:
count = 1
with open('carDatabase.txt', "a") as admin_add_details:
admin_add_details.write("\n")
for detail in new_car_details:
if count < len(new_car_details):
count += 1
admin_add_details.write(f"{detail} | ")
else:
admin_add_details.write(detail)
print("\nInsert completed... Processing...\n")
# No file identified
except:
print("Access the database system to check database progress.\n")
maintenance_database_access()
# Ask for admins choice on inserting more cars or stop adding
return admin_add_car()
# Stop adding car and display all cars
elif add_or_not == "NO":
print("\nDisplaying all data...")
view_cars()
print("\n", decoration(),
" Back to administrator main screen. ", decoration())
administrator_system()
# Invalid choice and ask for choice again
else:
print("Invalid input, please try again.")
return admin_add_car()
# 2. Modify car
def admin_modify():
# Display all cars data
view_cars()
# Extract car data to a variable that hold a list
try:
cars = car_database_read()[0]
cars_index = car_database_read()[1]
# No file identified
except:
print("Access the database system to check database issue.\n")
maintenance_database_access()
# Ask for modification required details
def modify_line_validation():
try:
data_line = int(
input("\nWhich line of data you want to perform the modification: "))
car_index_convert = index_converter(data_line)
car_index = cars_index[car_index_convert]
if data_line <= 0:
print("Invalid input, please try again.")
return modify_line_validation()
else:
return car_index
# Exclude non numeric value
except ValueError:
print("\nInvalid input, please insert a numeric value..")
return modify_line_validation()
# Exclude non existent records
except IndexError:
print("\nCar line is out of range.")
return modify_line_validation()
car_index = modify_line_validation()
print("\nIMPORTANT!!! Note that uniqueID can't be modified. "
"\nIf the car had been removed from the system place X in rent status.\n")
def modify_type_validation():
# Ask for desired data type
item = input("Modify data type (e.g. Car Model, Price): ").replace(
" ", '_').lower()
if item == "car_brand":
index = 1
origin_word = cars[car_index][index]
elif item == "car_model":
index = 2
origin_word = cars[car_index][index]
elif item == "car_plate":
index = 3
origin_word = cars[car_index][index]
elif item == "year":
index = 4
origin_word = cars[car_index][index]
elif item == "status":
index = 5
origin_word = cars[car_index][index]
elif item == "price":
index = 6
origin_word = cars[car_index][index]
elif item == "car_id":
print("\nInvalid choice, car id is immutable.\n")
return modify_type_validation()
else:
print(
"\nInvalid data type, please choose according to the data headers displayed other than car id.\n")
return modify_type_validation()
word_and_index = [origin_word, index]
return word_and_index
# Extract and display original data
word_and_index = modify_type_validation()
origin_word = word_and_index[0]
replace_index = word_and_index[1]
print("Origin data: ", origin_word)
# Replace data
replace_word = input("Replaced by: ")
cars[car_index][replace_index] = replace_word
# Display updated data
print("\nDisplaying updated data.\n")
car_header()
print(" {:<8}{:<11}{:<11}{:<10}{:<7}{:<9}{:<6}"
.format(cars[car_index][0], cars[car_index][1], cars[car_index][2], cars[car_index][3], cars[car_index][4], cars[car_index][5], cars[car_index][6]))
# Transfer new data to the text file
with open('carDatabase.txt', 'w') as modified:
car_count = 1
for car in cars:
if car_count < len(cars):
count = 1
for details in car:
if count < len(car):
modified.write(f"{details} | ")
count += 1
else:
modified.write(details)
modified.write("\n")
car_count += 1
else:
count = 1
for details in car:
if count < len(car):
modified.write(f"{details} | ")
count += 1
else:
modified.write(details)
# Ask for admins' preferences on continue editing / modify data
def cont_or_no():
print("""
Continue modifying?
[YES] or [NO]
Note: Selecting [NO] will redirect you back to the administrator main menu.""")
continue_or_not = input("Option => ").upper()
# Continue modification
if continue_or_not == 'YES':
print("\nContinue modification based on new data.")
return admin_modify()
# Stop modification and return to administrator functionalities menu
elif continue_or_not == 'NO':
print("\nYou will be redirected to the administrator main screen...")
return administrator_system()
# Invalid input and ask for admins' choice again
else:
print("\nInvalid input, only [YES] or [NO] allowed.\n")
return cont_or_no()
# call function to execute in admin_modify() function
cont_or_no()
# 3. Display all data
def admin_display():
# data display menu
def display_validation():
try:
# Menu
print("""
Display data choice:
1. All Cars
2: Cars Availability
3: Customer Bookings
4: Customer Payment for a specific time duration
5: Registered customers' username in the system
6: Exit to administrator main screen.
""")
dis_option = int(input("Option => "))
return dis_option
# Exclude non numeric value
except ValueError:
print("\nInvalid input, please insert a numeric value..\n")
return display_validation()
dis_option = display_validation()
# Read option
if dis_option == 1:
view_cars()
display_redirect()
if dis_option == 2:
dis_rent_car()
elif dis_option == 3:
dis_cus_booking()
elif dis_option == 4:
dis_cus_pay()
elif dis_option == 5:
dis_cus_username()
elif dis_option == 6:
administrator_system()
# Invalid input, ask for display choice again
else:
print("Invalid input. Please select choices in range 1 to 6.")
return admin_display()
# 3.1 Continue to display menu or administrator page.
def display_redirect():
# Ask for admins' preference in redirection
def redirect_validation():
try:
print("""
Do you wish to return to the display menu or administrator's main screen?
1: Display Menu
2: Administrator Main Screen
""")
option = int(input("Option=> "))
return option
# Exclude non numeric value
except ValueError:
print("\nInvalid input, please insert a numeric value..")
return redirect_validation()
option = redirect_validation()
# Return to the display menu
if option == 1:
print("\nYou will be redirected to the display menu...")
admin_display()
# Return to administrator functionalities main screen
elif option == 2:
print("\nYou are returning to the administrator main screen....")
administrator_system()
# Invalid input, ask for redirection option again
else:
print("\nInvalid input, please key in 1 or 2.\n")
return display_redirect()
# 3.2 All display dataset
# 1. View all car data
def view_cars():
# Extract car data to a list
try:
cars = car_database_read()[0]
# No file identified
except:
print("Access the database system to check database issue.\n")
maintenance_database_access()
# Display all car data
car_header()
line_num = 1
for car in cars:
print("{:<4}{:<7}{:<12}{:<11}{:<10}{:<6}{:<8}{:<5}"
.format(line_num, car[0], car[1], car[2], car[3], car[4], car[5], car[6]))
line_num += 1
# 2. Display car with different status
def dis_rent_car():
# Extract car data to in list
try:
cars = car_database_read()[0]
# No file identified
except:
print("Access the database system to check database issue.\n")
maintenance_database_access()
# Menu
print("\nCategories available [Open] [Rented] [X] [Booked]\n")
# Request status
status = input(
"Status => ").capitalize()
available_status = ["Open", "Rented", "X", "Booked"]
# Display cars with matching status
if status in available_status:
index = 0
emp_spotter = []
line_number = 1
car_header()
for car in cars:
if status == car[5]:
emp_spotter.append(index)
print("{:<4}{:<7}{:<12}{:<11}{:<10}{:<6}{:<8}{:<5}"
.format(line_number, car[0], car[1], car[2], car[3], car[4], car[5], car[6]))
index += 1
line_number += 1
else:
index += 1
continue
else:
print("\nInvalid type of status, please choose again.")
return dis_rent_car()
# No data spotted
if not emp_spotter:
print(
"\nThere is no relevant data for records of cars on that particular status.\n")
# Admins' option on redirection
display_redirect()
# Admins' option on redirection
display_redirect()
# 3. Display customer booking statement
def dis_cus_booking():
# Extract customer booking / payment statement to a list
try:
statements = bookpay_stmnt_read()
# No file identified
except:
print("Access the database system to check database issue.\n")
maintenance_database_access()
# Set reservation only specify on booking status
reservation = ['In Queue', 'Ready']
# Display matching customer booking statement
index = 0
line_number = 1
emp_spotter = []
cus_book_header()
for statement in statements:
if reservation[0] == statement[5] or reservation[1] == statement[5]:
emp_spotter.append(index)
print("{:<4}{:<11}{:<8}{:<7}{:<8}RM{:<9}{:<8}{:<12}{:<10}"
.format(line_number, statement[0], statement[1], statement[2], statement[3], statement[8], statement[4], statement[5], statement[7]))
index += 1
line_number += 1
else:
index += 1
continue
# No data spotted
if not emp_spotter:
print("\nThere is no relevant data for records of customer booking statement.\n")
# Admins' option on redirection
display_redirect()
# Admins' option on redirection
display_redirect()
# 4. Display customer payment statement
def dis_cus_pay():
# Extract customer booking / payment statement to a list
try:
statements = bookpay_stmnt_read()
# No file identified
except:
print("Access the database system to check database issue.\n")
maintenance_database_access()
def date_request_validation():
# Menu instruction
print("\nDisplay rent car between the start date and end date.\n")
try:
# request start date
start_date = input(
"Insert the start date in DD/MM/YYYY Format: ").split("/")
start_day, start_month, start_year = int(
start_date[0]), int(start_date[1]), int(start_date[2])
start_date = [start_year, start_month, start_day]
# request end date
end_date = input(
"Insert the end date in DD/MM/YYYY Format: ").split("/")
end_day, end_month, end_year = int(
end_date[0]), int(end_date[1]), int(end_date[2])
end_date = [end_year, end_month, end_day]
if start_month not in range(1, 13) or end_month not in range(1, 13):
print("\nInvalid date input, please insert a valid date.\n")
return date_request_validation()
else:
dates = [start_date, end_date]
return dates
except:
print("\nInvalid input, please insert a date in DD/MM/YYYY Format.")
return date_request_validation()
dates = date_request_validation()
start_date = dates[0]
end_date = dates[1]
# Set statement status only specify on 'Paid'
status = 'Paid'
# Display matching customer payment statement
index = 0
line_number = 1
emp_spotter = []
cus_pay_header()
for statement in statements:
# make a valid date
try:
date = statement[7].split("/")
date_year, date_month, date_day = int(date[2]), int(
date[1]), int(date[0])
date = [date_year, date_month, date_day]
# Skip N/A value
except:
pass
if status == statement[4] and start_date <= date <= end_date:
emp_spotter.append(index)
print("{:<4}{:<11}{:<8}{:<7}{:<8}RM{:<9}{:<8}{:<16}{:<10}"
.format(line_number, statement[0], statement[1], statement[2], statement[3], statement[8], statement[4], statement[6], statement[7]))
index += 1
line_number += 1
else:
index += 1
continue
# No data spotted
if not emp_spotter:
print("\nThere is no relevant data for records of customer payment statement.\n")
# Admins' option on redirection
display_redirect()
# Admins' option on redirection
display_redirect()
# 5. Display all registered customer username
def dis_cus_username():
# Extract customer details to variable that store a list
try:
customers = customer_details_read()
# No file identified
except:
print("Access the database system to check database issue.\n")
maintenance_database_access()
# Store all customers' username in a list
customers_names = []
for customer in customers:
customers_names.append(customer[0])
# Arrange customers' username alphabetically
customers_names.sort()
# Display all customers' username
line_num = 1
print('\n\tUsername')
for name in customers_names:
print(f"{line_num}\t{name}", end='\n')
line_num += 1
print("\nThis is all of the registered customers' username.")
# Admins' option on redirection
display_redirect()
# 4. Search Record
def admin_search():
# Admin's option database search
def search_choice_validation():
try:
print("""
Choose database that you want to inspect / search:
1: Customer Booking
2: Customer Payment
""")
file_choose = int(input("Option => "))
return file_choose
# Exclude non numeric value
except ValueError:
print("\nInvalid input, please insert a numeric value..\n")
return search_choice_validation()
file_choose = search_choice_validation()
# Booking statement search
if file_choose == 1:
cus_book_search()
# Payment statement search
elif file_choose == 2:
cus_pay_search()
# Invalid input, ask for database option again
else:
print("Invalid input, choose only 1 or 2.\n")
return admin_search()
# 4.1 Continue at search menu or back to administrator main screen.
def search_redirect():
# Ask for admins' preference in redirection
def menu_direct_validation():
try:
# Menu
print("""
Do you want to return to the search menu or administrator main screen?
1: Search menu
2: Administrator Main screen
""")
option = int(input("Option => "))
return option
# Exclude non numeric value
except ValueError:
print("\nInvalid input, please insert a numeric value..\n")
return menu_direct_validation()
option = menu_direct_validation()
# Return back to the search menu
if option == 1:
print("\nYou will be redirected to the search menu shortly....\n")
admin_search()
# Return to the administrator main screen
elif option == 2:
print('\nYou will be redirected to the administrator main screen shortly...\n')
administrator_system()
# Invalid input, ask for input again
else:
print("\nInvalid input, please select 1 or 2.\n")
return search_redirect()
# 4.2 Search data
# 1. Search on customer booking data
def cus_book_search():
# Extract customer booking / payment statement to a variable that store a list
try:
statements = bookpay_stmnt_read()
# No file identified
except:
print("Access the database system to check database issue.\n")