@@ -139,6 +139,11 @@ def initial_check():
139139| | | | | | | | |
140140| | | | | | | | |
141141| | | | | | | | |
142+ | | | | | | | | |
143+ | | | | | | | | |
144+ | | | | | | | | |
145+ | | | | | | | | |
146+ | | | | | | | | |
142147+-----------+----------+-------+--------+-----------+-------+-------------+------------+
143148\n \n
144149""" )
@@ -152,9 +157,15 @@ def initial_check():
152157| | | | | | |
153158| | | | | | |
154159| | | | | | |
160+ | | | | | | |
161+ | | | | | | |
162+ | | | | | | |
163+ | | | | | | |
164+ | | | | | | |
155165+-------------+-------------+----------------+-------+-----------+--------------+
156166\n \n """ )
157167
168+
158169def addition_of_records_Member ():
159170 '''
160171 This function adds additional records to the table titled
@@ -270,7 +281,57 @@ def modify_records_in_member_table():
270281 pass
271282
272283
273- def return_of_books_and_fine_calculator ():#Not complete, add the returning book function
284+ def issuing_books_to_member ():
285+ '''
286+ This function issues the book to the member
287+ if the number of books issued is less than the alloted number of books
288+ else it displays an appropriate message
289+ '''
290+
291+ mem_code = int (input ('Enter the Member Code: ' ))
292+
293+ cur .execute ('select * from member where Member_Code = {}' .format (mem_code ))
294+ member_record = cur .fetchall ()
295+
296+ for i in member_record :
297+ max_limit = i [4 ]
298+ number_of_issued_books = i [5 ]
299+
300+ if (max_limit - number_of_issued_books ) == 0 :
301+ print ('You cannot issue any book.\n Kindly return some of the book(s) which you have issued.' )
302+
303+ else :
304+ cur .execute ('select Book_Code, Sub_Code, Title, Author from library where Member_Code = 0' )
305+ available_books = cur .fetchall ()
306+
307+ print ('\n \t Books which are available Currently: \n ' )
308+ for i in available_books :
309+ print ('Book Code: ' , i [0 ])
310+ print ('Subject Code: ' , i [1 ])
311+ print ('Title: ' , i [2 ])
312+ print ('Author: ' , i [3 ])
313+ print ('\n ' )
314+
315+ book_code_req_issue = i [0 ]
316+
317+ query = input ('Is this the book which you want to issue?(Y/n): ' )
318+
319+ if query .lower () == 'n' :
320+ pass
321+
322+ else :
323+ cur .execute ('select CURDATE' )
324+ current_date = cur .fetchall ()
325+
326+ number_of_issued_books += 1
327+ cur .execute ('update library set Member_Code = {} where Book_Code = {}' .format (mem_code , book_code_req_issue ))
328+ cur .execute ('update library set Issue_Date = {} where Book_Code = {}' .format (current_date , book_code_req_issue ))
329+ cur .execute ('update member set N_O_B_Issued = {} where Member_Code = {}' .format (number_of_issued_books , mem_code ))
330+ cur .execute ('commit' )
331+ break
332+
333+
334+ def return_of_books_and_fine_calculator ():
274335 '''
275336 This function allows the returning of books and calculates the amount to be paid as fine
276337
@@ -300,6 +361,9 @@ def return_of_books_and_fine_calculator():#Not complete, add the returning book
300361 cur .execute ('select Book_Code from Library where Member_Code = {}' .format (m_code ))
301362 issued_books_by_member = cur .fetchall ()
302363
364+ cur .execute ('select N_O_B_Issued from Member where Member_Code = {}' .format (m_code ))
365+ books_issued = cur .fetchall ()
366+
303367 for j in issued_books_by_member :
304368 if (book_code ,) == j :
305369 print ("Book Found\n " )
@@ -332,6 +396,20 @@ def return_of_books_and_fine_calculator():#Not complete, add the returning book
332396
333397 else :
334398 pass
399+
400+ return_query = input ('Do you want to return the book(Y/n): ' )
401+ if return_query .lower () == 'y' :
402+ for i in issued_books_by_member :
403+ cur .execute ('update library set Issue_Date = "{}" and Member_Code = {}' .format (("1111-01-01" ), 0 ))
404+ cur .execute ('update Member set N_O_B_Issued = {} where Member_Code = {}' .format ((books_issued - 1 ), m_code ))
405+ cur .execute ('commit' )
406+
407+ else :
408+ print ('Book not returned' )
409+ print ('Setting issue date as Current date: {}' .format (curdate ))
410+ cur .execute ('update library set Issue_Date = {} where Member_Code = {} and Book_Code = {}' .format (curdate , m_code , book_code ))
411+ cur .execute ('commit' )
412+
335413
336414def availability_of_a_certain_book ():
337415 '''
@@ -364,7 +442,6 @@ def availability_of_a_certain_book():
364442 print ("Price: " , i [5 ])
365443 print ('\n \n ' )
366444
367-
368445 book_code = int (input ("Enter the Book Code: " ))
369446
370447 cur .execute ('select * from Library where Sub_Code like ("{}") and Book_Code = {}' .format (book_sub , book_code ))
@@ -425,6 +502,7 @@ def availability_of_a_certain_book():
425502 else :
426503 print ('The Book is Issued by another member\n ' )
427504
505+
428506def book_report ():
429507 '''
430508 Generates a Book Report which is ordered by
@@ -457,6 +535,7 @@ def book_report():
457535 for i in list_subject :
458536 print (i )
459537
538+
460539def books_issued_by_member ():
461540 '''
462541 This function generates a report which displays
@@ -490,6 +569,7 @@ def books_issued_by_member():
490569
491570 print ('Number of books issued by Member {} is/are: {}' .format (i , book_count ))
492571
572+
493573def available_books ():
494574 '''
495575 This function generates a report for
@@ -522,6 +602,7 @@ def available_books():
522602
523603 print ('There is / are {} available book(s)' .format (count_available ))
524604
605+
525606def book_defaulter ():
526607 '''
527608 This function displays the defaulters
@@ -562,6 +643,7 @@ def book_defaulter():
562643 for i in defaulter_lst :
563644 print (i )
564645
646+
565647def members_in_the_library ():
566648 '''
567649 This function displays all the
@@ -579,6 +661,7 @@ def members_in_the_library():
579661
580662 print ('There are {} registered members' .format (count_member ))
581663
664+
582665def Report_of_DataBase ():
583666 '''
584667 This function generates a report which consists of the following
@@ -614,22 +697,59 @@ def Report_of_DataBase():
614697 else :
615698 print ('Invalid Option Entered' )
616699
700+
701+ def exit ():
702+ '''
703+ This function exists the code
704+ and
705+ Closes the connection to the DataBase
706+ '''
707+
708+ print ('Closing connection to Server DataBase in....' )
709+ for i in range (3 , 0 , - 1 ):
710+ print (i , '\n ' )
711+ time .sleep (1 )
712+
713+ print ('Connection Closed Successfully' )
714+
715+ cur .close ()
716+
717+
617718ans = 'y'
618719while ans .lower () == 'y' :
619720 print ('\t \t \t \t Main Menu\n \n ' )
620- print ('1. Addition of Books\n 2. Addition of Members\n 3. Modifying Records \n 4. Modifying Member info\n 5 . Issue Book\n 6 . Return Books' )
621- print ('7 . Availability of a certain book\n 8 . Report\n \n ' )
721+ print ('1. Addition of Books\n 2. Addition of Members\n 3. Modifying Member info\n 4 . Issue Book\n 5 . Return Books' )
722+ print ('6 . Availability of a certain book\n 7 . Report\n 8. Exit \n \n ' )
622723
623724 choice = int (input ("Enter your choice: " ))
624725
625-
726+ if choice == 1 :
727+ addition_of_records_Library ()
728+
729+ elif choice == 2 :
730+ addition_of_records_Member ()
731+
732+ elif choice == 3 :
733+ modify_records_in_member_table ()
734+
735+ elif choice == 4 :
736+ issuing_books_to_member ()
626737
738+ elif choice == 5 :
739+ return_of_books_and_fine_calculator ()
627740
628- print ('Closing connection to Server DataBase in....' )
629- for i in range (3 , 0 , - 1 ):
630- print (i , '\n ' )
631- time .sleep (1 )
741+ elif choice == 6 :
742+ availability_of_a_certain_book ()
632743
633- print ('Connection Closed Successfully' )
744+ elif choice == 7 :
745+ Report_of_DataBase ()
634746
635- cur .close ()
747+ elif choice == 8 :
748+ exit ()
749+
750+ else :
751+ print ('Invalid Option Entered' )
752+
753+ print ('\n ' )
754+ ans = input ('Do you wish to continue?(Y/n): ' )
755+ print ()
0 commit comments