-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathRe_cafe_function.py
872 lines (707 loc) · 28.7 KB
/
Re_cafe_function.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
#!/usr/bin/env python
# coding: utf-8
# In[1]:
"""
This Module have all The Functions which are used in the Main Page of the Re: Cafe!
Arguments:
No argument Taken
global variable:
login_value : variable is use to conform whether the user has successfully login or not.
menu_changed : variable is use to conform whether the menu has successfully Changed or not.
"""
# **Funtion to get data from the file into a list!!**
# In[2]:
def retrieve_data(path):
"""
This Function is use to get the data from the File,
which contains the data in comma seprated form and
convert it into a nested list and return that list.
Arguments:
path : The path of the .txt file to read in string format.
Returns:
Returns a nested list, in which data in each line is converted into a list.
In the case of an error, it returns None.
Raises:
FileNotFoundError: Raises an exception when the file is not found in the specified path.
"""
try:
file_data = open(path , mode = "rt" , encoding = "utf-8" )
list_data = []
for data in file_data:
if data != '\n' :
raw_data = data.strip()
final_data = raw_data.split(",")
list_data.append(final_data)
else:
pass
file_data.close()
return list_data
except FileNotFoundError :
print("Please Make Sure That The Path You Have Provided Is Correct!")
return
except Exception as e :
print("An Error Occured!")
print("ERROR :",e,"\n")
return
# **Funtion to enter data in the file from a list!!**
# In[3]:
def data_entry(path,entry):
"""
This Function is use to enter the data from the Nested List,
Into the file in a comma seprated form.
Each line in the file contains the data of a list(element).
Arguments:
path : The path of the .txt file is to write in string format.
entry : The Nested List(Which means a List inside a List).
Returns:
returns True, if executed succesfully.
In the case of an error it returns False.
Raises:
UnknownError: Raises an exception when a error is found.
"""
try:
file_open = open(path , mode = "wt" , encoding = "utf-8" )
data = ""
for list_data in entry:
data = ",".join(list_data)
final_data = data + "\n"
file_open.write(final_data)
file_open.close()
except Exception as e:
print("An Error Occured!")
print("ERROR :",e)
print("Please Enter A Valid Input!\n")
# **Funtion to Display the menu!!**
# In[4]:
def menu_display():
"""
This Function is use to retrieve the data from the file cafe_menu.txt,
into the function using retrieve_data function.
Then, Print the current Menu Page.
Arguments:
No Argument Taken
Returns:
returns the Menu in a Tabular form.
Raises:
UnknownError: Raises an exception when a error is found.
"""
try :
print()
print("." * 46)
print(": Item I.D : Item : Price :")
menu_list = retrieve_data("cafe_menu.txt")
for i in menu_list:
print("." * 46)
print(":" , " " , i[0] , " " , ":" , " " , i[1] , " " * (15 - len(i[1])) , ":" , " " , i[2] , " "*(6 - len(i[2])),":")
print("." * 46,"\n")
except Exception as e:
print("An Error Occured!")
print("ERROR :",e,"\n")
# **Get The Menu Data in the form of dictionary**
# In[5]:
def menu_data():
"""
This Function is use to retrieve the data from the file cafe_menu.txt,
into the function using retrieve_data function.
Then, convert it into a dictonary with Key as Item_Id and Value as a tuple of name and price.
Arguments:
No Argument Taken
Returns:
returns a dictonary with Key as Item_Id and Value as a tuple of name and price.
Raises:
UnknownError: Raises an exception when a error is found.
"""
try :
menu_dictionary = {}
menu_list = retrieve_data("cafe_menu.txt")
for item in menu_list :
item_id = item[0]
item_name = item[1]
item_price = float(item[2])
menu_dictionary[item_id] = item_name , item_price
return menu_dictionary
except Exception as e :
print("An Error Occured!")
print("ERROR :",e,"\n")
# **Get The User Data in the form of dictionary**
# In[6]:
def user_data():
"""
This Function is use to retrieve the data from the file Admin_info.txt,
into the function using retrieve_data function.
Then convert it into a dictonary with Key as admin name and Value as the password.
Arguments:
No Argument Taken
Returns:
returns a dictonary with Key as admin name and Value as the password.
Raises:
UnknownError: Raises an exception when a error is found.
"""
try :
user_dictionary = {}
user_list = retrieve_data("Admin_info.txt")
for info in user_list :
user_name = info[1]
password = info[2]
user_dictionary[user_name] = password
return user_dictionary
except Exception as e :
print("An Error Occured!")
print("ERROR :",e,"\n")
# **Funtion to print Greeting!**
# In[7]:
def greeting():
"""
This Function is use to print the greeting at the start of the program.
Arguments:
No Argument Taken
Returns:
print greeting message.
"""
print(r" _")
print(r" __ __ _______ _____ _ _______ | |")
print(r" \ \ / / |__ __| | _ \ |_| | ______| | |")
print(r" \ \ __ / / | | | |_| / | | | |")
print(r" \ \ /__\ / / __ _ _ _ _ _ | | _ | __ \ __ | | _ __ __ |_|")
print(r" \ \_// \\_/ / |_ | | | | | \_/ | |_ | | | | | | \ \ |_ _ | |_____ /_\ |_ |_ _ ")
print(r" \__/ \__/ |__ |_ |_ |_| | | |_ |_| |_| |_| \_\ |__ |_| |_______| / \ | |__ |_|")
# **Funtion to check Item Details From the Menu**
# In[8]:
def check_item_details(item_id , item_name = None):
"""
This Function is use to check whether the Item_Id and Item_Name
provided matches with that in the DataBase(cafe_menu.txt) File.
And Returns a tuple with 2 boolean values.
For Example : if item_id is correct and item_name is wrong
output : (True,False)
Arguments:
item_id : The Item ID is written in string format.
item_name : The Item Name is written in string format and it is not necessary to include(optional argument).
Default Value is None.
Returns:
Returns a tuple with 2 boolean values.
For Example : if item_id is correct and item_name is wrong
output : (True,False)
Raises:
UnknownError: Raises an exception when a error is found.
"""
try :
menu = menu_data()
for value in menu:
if value == item_id :
if menu[value][0] == item_name :
return True , True
else :
return True , False
elif value != item_id :
if menu[value][0] == item_name :
return False , True
else :
pass
return False , False
except Exception as e :
print("An Error Occured!")
print("ERROR :",e,"\n")
# **Storing the order details**
# In[9]:
def add_menu_item():
"""
This Function is use to Add New Menu Items into the File cafe_menu.txt,
By Using the data_entry function.
To verify that the Item_Id provided does not exists in the menu to avoid Duplication of the Item_Id,
check_item_details function is used (as Item_Id is a unique Key/Primary Key).
After updating the quantity it stores the order back into the cart.txt File.
Arguments:
No Argument Taken.
Inputs:
Take the Unique Item Id and Item Name as an input from the user.
Returns:
returns True, if it is is executed succesfully.
In case of any error, it returns False.
Raises:
UnknownError: Raises an exception when a error is found.
"""
try :
old_menu = retrieve_data("cafe_menu.txt")
print(" *** The Current Menu Details ***")
menu_display()
print("Please Enter the Following Detail's!\n")
item_id = input("Unique Item Id : ",)
item_name = input("Item Name : ",)
try :
item_price = float(input("Item Price :",))
except:
print()
print("Please Enter a valid Item Price!\n")
return False
validity = check_item_details(item_id , item_name)
if validity == (False , False) and item_name != "" :
item_detail = item_id , item_name , str(item_price)
item_detail = list(item_detail)
old_menu.append(item_detail)
data_entry("cafe_menu.txt",old_menu)
return True
else :
print()
print("Please Enter a valid Input!")
print("ERROR : Duplication of Input was Found!\n")
return False
except Exception as e :
print()
print("An Error Occured!")
print("ERROR :",e)
print("Please Enter a valid Input!\n")
return False
# **Function To Store Order in Cart.txt ; Cart.txt : A Temporary txt file to have the order details**
# In[10]:
def cart(order_list):
"""
This Function is use to enter(append) the data from the Nested List,
into the file cart.txt in a comma seperated form.
Each line in the file contains the data of a list(element).
Arguments:
order_list : The Nested List.(A List Inside A List)
Returns:
returns nothing(None).
Raises:
UnknownError: Raises an exception when a error is found.
"""
try :
file_cart = open("cart.txt" , mode = "at" , encoding = "utf-8" )
order = ",".join(order_list)
final_order = order + "\n"
file_cart.write(final_order)
file_cart.close()
return
except Exception as e :
print("An Error Occured!")
print("ERROR :",e,"\n")
return
# **Taking the Order and Storing it in the Cart.txt File**
# In[11]:
def take_order(item_id , quantity = 1):
"""
This Function is use to Take Order with the Item_Id and quantity as the inputs.
And uses check_item_details function to check with that in the DataBase(cafe_menu.txt) File.
And uses cart function to add the item into the cart.txt File.
Arguments:
item_id : The Item ID is written in string format.
Quentity : The Item Quantity is written in integer format.( Default value is 1)
Returns:
returns True, if it is is executed succesfully.
In case of any error, it returns False.
Raises:
UnknownError: Raises an exception when a error is found.
"""
try :
check = check_item_details(item_id)
if check == (True , False) :
order_list = [item_id,]
menu_dict = menu_data()
order_list.append(menu_dict[item_id][0])
order_list.append(str(menu_dict[item_id][1]))
order_list.append(str(quantity))
cart(order_list)
return True
else :
return False
except Exception as e :
print("An Error Occured!")
print("ERROR :",e)
print("Please Enter a valid Input!\n")
return False
# **Function to Generate a Bill**
# In[12]:
def generate_bill(order_list):
"""
This Function is use to generate the bill from the data in the order_list.
Then generate the bill and also the total amount to be payed.
Arguments:
order_list : The Nested List.(A List Inside A List)
Returns:
returns True, if it is is executed succesfully.
In case of any error, it returns False.
Raises:
UnknownError: Raises an exception when a error is found.
"""
print()
print()
print(" *** BILL *** ")
print("." * 106)
print(": S.No : ITEM ID : ITEM NAME : PRICE : QUANTITY : TOTAL AMOUNT :")
s_no = 1
total_amount = 0.0
try :
for item in order_list:
print("." * 106)
print(": " , s_no , " " * (5 - len(str(s_no))) , ": " , item[0] , " " * (8 - len(item[0])) , ": " , item[1] ,
" " * (16 - len(item[1])) , ": " , item[2] , " " * (8 - len(str(item[2]))) , ": " , item[3] ,
" " * (6 - len(str(item[3]))) , ": " , item[3]*item[2] , " " * (11 - len(str(item[3]*item[2]))) , ":")
s_no += 1
total_amount += item[3]*item[2]
print("." * 106)
print()
print()
print("." * 55)
print(": TOTAL AMOUNT TO PAY IN RUPEES : " , total_amount , " " * (8 - len(str(total_amount))) , ":")
print("." * 55)
return True
except Exception as e :
print("An Error Occured!")
print("ERROR :",e,"\n")
return False
# **Updating The Order Quantity and Stoing it in The Cart.txt File**
# In[13]:
def update_order(item_id , update_qty):
"""
This Function is use to Update the Item Quentity present in the cart.txt File.
To verify that the Item_Id provided exists check_item_details funcion is used.
After updating the quantity it stores the order back into the cart.txt File.
Arguments:
item_id : The Item ID is written in string format.
update_qty : The Updated Quantity of the item in the string format.
Returns:
returns True, if it is is executed succesfully.
In case of any error, it returns False.
Raises:
UnknownError: Raises an exception when a error is found.
"""
try :
check = check_item_details(item_id)
if check == (True , False) and update_qty != "":
order = retrieve_data("cart.txt")
for value in order:
if value[0] == item_id :
value[3] = update_qty
data_entry("cart.txt",order)
return True
print("ERROR : The Item does not exit in the cart!")
print("Please enter a valid Input\n")
return False
else :
print("Please enter a valid Item ID\n")
return False
except Exception as e :
print("An Error Occured!")
print("ERROR :",e,"\n")
return False
# **Function to Log-in into the Admin system and with a global variable to check**
# In[14]:
def log_in(attempts = 3):
"""
This is a login Function for the Admin, It takes the Admin Name and Admin Password and
Check the input from the Admin_info.txt File(Data Base).
The password is taken using getpass method.
login_value variable is use to confirm whether the user has successfully login or not.
login_value variable is define globally, so that it can be used outside the function also.
Argumentss:
Attempts : Number of attempts provided to login.
Default value is 3.
Inputs:
Take the Admin Name and Password as the input.
Returns:
returns True, if it is is executed succesfully.
In case of any error, it returns False.
But after first try function returns None value (Thats why to check use login_value).
Raises:
UnknownError: Raises an exception when a error is found.
"""
try :
global login_value
login_value = False
if attempts != 0 :
from getpass import getpass
print("Please Enter the following details!\n")
user_name = input("User Name :",)
user_name = user_name.lower()
password = getpass("Password :",)
print()
user_list = user_data()
for user in user_list :
if user_name == user and password == user_list[user]:
login_value = True
print("~~~ Log-in successfully!! ~~~\n")
print("Welcome" , user_name , "!")
return True
if attempts == 3 or attempts == 2 :
print("This is not a valid Username/Password, input Username and Password again please!\n")
log_in(attempts - 1)
elif attempts == 1 :
print("This is not a valid Username/Password!")
print("This was your last attempt!")
print("Please try later!\n")
login_value = False
return False
else :
login_value = False
return False
except Exception as e :
print("An Error Occured!")
print("ERROR :",e,"\n")
return False
# **Function to Update Menu by the admin!!**
# In[15]:
def update_menu(item_id):
"""
This Function is use to update the item information present in the cafe_menu.txt file.
To verify that the Item_Id provided exists in the menu, check_item_details funcion is used.
After checking, the user can update the Item Name or Item Price or can update both.
Then, the Function updates the cafe_menu.txt File.
Also, this Function takes the input, according to the requirment to update the provided fields.
Arguments:
item_id : The Item ID is written in the string format.
Inputs:
Taking Update field Name, Item Name and Item Price as the input.
Returns:
rreturns True, if it is is executed succesfully.
In case of any error, it returns False.
But, after first try function, it returns None value.
Raises:
UnknownError: Raises an exception when a error is found.
"""
try :
global menu_changed
menu_changed = False
check = check_item_details(item_id)
if check == (True, False) :
print("Help! {Input : Name/price (if you only want to update one field) or Name,Price (if you want to update both)}")
update = input("What you want to update [Available field are : Name and Price] : ",)
update = update.lower()
update_list = update.split(",")
menu_list = retrieve_data("cafe_menu.txt")
for value_list in menu_list:
if value_list[0] == item_id :
new_name = value_list[1]
new_price = value_list[2]
break
if len(update_list) == 1 :
if update_list[0] == "name" or update_list[0] == "item name" :
new_name = input("Enter the updated Item name: ",)
menu_changed = True
elif update_list[0] == "price" or update_list[0] == "item price" :
test_price = input("Enter the updated item price: ",)
try :
new_price = float(test_price)
menu_changed = True
except Exception as e:
print()
print("Please Enter a valid Price!{Hint : enter a integer or decimal value as a input}")
print("Error :",e,"\n")
menu_changed = False
update_menu(item_id)
else :
print()
print("Please Enter a Vaild Input!\n")
menu_changed = False
update_menu(item_id)
elif len(update_list) == 2 :
if (update_list[0] == "name" or update_list[0] == "item name") and (update_list[1] == "price" or update_list[1] == "item price"):
test_name = input("Enter the updated Item name: ",)
test_price = input("Enter the updated item price: ",)
try :
new_price = float(test_price)
new_name = test_name
menu_changed = True
except Exception as e:
print()
print("Please Enter a valid Price!{Hint : enter a integer or decimal value as a input}")
print("Error :",e,"\n")
menu_changed = False
update_menu(item_id)
elif (update_list[0] == "price" or update_list[0] == "item price") and (update_list[1] == "name" or update_list[1] == "item name"):
test_name = input("Enter the updated Item name: ",)
test_price = input("Enter the updated item price: ",)
try :
new_price = float(test_price)
new_name = test_name
menu_changed = True
except Exception as e:
print()
print("Please Enter a valid Price!{Hint : enter a integer or decimal value as a input}")
print("Error :",e,"\n")
menu_changed = False
update_menu(item_id)
else :
print()
print("Please Enter a Vaild Input!\n")
menu_changed = False
update_menu(item_id)
else :
print()
print("Please Enter a Vaild Input!\n")
menu_changed = False
return False
else :
menu_changed = False
return False
if menu_changed == True :
for value_list in menu_list:
if value_list[0] == item_id :
value_list[1] = new_name
value_list[2] = str(new_price)
data_entry("cafe_menu.txt", menu_list)
return True
except Exception as e :
print("An Error Occured!")
print("ERROR :",e,"\n")
return False
# **Function to Transfer the Order Information into the order_history.txt File**
# In[16]:
def cart_to_order(customer_name):
"""
This Function is use to enter the data from the cart.txt File into order_history.txt File,
Data is stored in the order_history.txt file in a comma seprated form with
additional customer name added at the last of each line.
Arguments:
customer_name : The Name of the Customer is written in the string format.
Returns:
returns True, if it is executed succesfully.
In case of any error, it returns False.
Raises:
UnknownError: Raises an exception, when a error is found.
"""
try :
final_order = retrieve_data("cart.txt")
file_open = open("order_history.txt" , mode = "at" , encoding = "utf-8" )
data = ""
for list_data in final_order:
list_data.append(customer_name)
data = ",".join(list_data)
final_data = data + "\n"
file_open.write(final_data)
file_open.close()
return True
except Exception as e :
print("An Error Occured!")
print("ERROR :",e,"\n")
return False
# **Function to Empty the Current Item in the Cart.txt File**
# In[17]:
def empty_cart():
"""
This Function is used to empty the data from the cart.txt File.
Arguments:
No Argument Taken.
Returns:
returns True, if it is executed succesfully.
In case of any error, it returns False.
Raises:
UnknownError: Raises an exception when a error is found.
"""
try :
file_open = open("cart.txt" , mode = "wt" , encoding = "utf-8" )
file_open.write("")
file_open.close()
return True
except Exception as e :
print("An Error Occured!")
print("ERROR :",e,"\n")
return False
# **Function to Remove an Item From the Menu and Update the cafe_menu.txt File**
# In[18]:
def item_remove_menu(item_id):
"""
This Function is use to remove items from the information present in the cafe_menu.txt File.
To verify that the Item_Id provided exists in the menu, check_item_details function is used.
After checking, The Item's information is removed from the File.
The,n the Function update the cafe_menu.txt File.
Arguments:
item_id : The Item ID is written in string format.
Returns:
returns True, if it is is executed succesfully.
In case of any error, it returns False.
Raises:
UnknownError: Raises an exception when a error is found.
"""
try:
check = check_item_details(item_id)
if check == (True, False):
menu_list = retrieve_data("cafe_menu.txt")
new_menu = []
for value in menu_list:
if value[0] != item_id:
new_menu.append(value)
data_entry("cafe_menu.txt",new_menu)
return True
else:
print("Entered Item id was wrong. Please Enter A Valid ID!\n")
return False
except Exception as e :
print("An Error Occured!")
print("ERROR :",e,"\n")
return False
# **Function to Remove an Item From the Order as well as From the cart.txt File**
# In[19]:
def item_remove_order(item_id):
"""
This Function is used to remove an item from the ordered information present in the cart.txt File.
To verify that the item_id provided exists in the menu, check_item_details funcion is used.
After checking, the item's information is removed from the cart.txt File.
Then, the Function update the cart.txt File.
Arguments:
item_id : The Item ID is written in the string format.
Returns:
returns True, if it is is executed succesfully.
In case of any error, it returns False.
Raises:
UnknownError: Raises an exception when a error is found.
"""
try:
check = check_item_details(item_id)
if check == (True, False):
order_list = retrieve_data("cart.txt")
new_order = []
for value in order_list:
if value[0] != item_id:
new_order.append(value)
data_entry("cart.txt",new_order)
return True
else:
print("Entered Item id was wrong. Please Enter A Valid ID!\n")
return False
except Exception as e :
print("An Error Occured!")
print("ERROR :",e,"\n")
return False
# **Function to Get the Order History and to Display it from order_history.txt File!**
# In[20]:
def order_history():
"""
This Function is use to retrieve the data from the File order_history.txt,
into the Function using retrieve_data Function.
Then, print the Customer Order History with the total sale done till now.
Arguments:
No Argument Taken
Returns:
returns the Customer Order History in a Tabular form.
returns True, if is executed succesfully.
In case of any error, it returns False.
Raises:
UnknownError: Raises an exception when a error is found.
"""
print()
print(" *** ORDER HISTORY *** ")
print("." * 110)
print(": S.No : CUSTOMER NAME : ITEM ID : ITEM NAME : PRICE : QUANTITY :")
s_no = 1
total_sale = 0.0
order_list = retrieve_data("order_history.txt")
try :
for item in order_list:
print("." * 110)
print(": " , s_no , " " * (5 - len(str(s_no))) , ": " , item[-1] , " " * (16 - len(item[-1])) , ": " , item[0] ,
" " * (8 - len(item[0])) , ": " , item[1] , " " * (16 - len(str(item[1]))) , ": " , item[2] ,
" " * (7 - len(str(item[2]))) , ": " , item[3] , " " * (7 - len(item[3])) , ":")
s_no += 1
total_sale += (float(item[3]))*(float(item[2]))
print("." * 110)
print()
print()
print("." * 57)
print(": TOTAL SALE TILL NOW IN RUPEES : " , total_sale , " " * (10 - len(str(total_sale))) , ":")
print("." * 57)
return True
except Exception as e :
print("An Error Occured!")
print("ERROR :",e,"\n")
return False