-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMT20073_MT20058_Project2.py
1359 lines (1241 loc) · 52.8 KB
/
MT20073_MT20058_Project2.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 sqlite3
from time import sleep
from subprocess import call
from os import system, name
from getpass import getpass
from tabulate import tabulate
from dateutil.relativedelta import relativedelta
from datetime import datetime
from datetime import date
''' CLASS DEFINITIONS '''
class BaseClient:
''' object class '''
def __init__(self,username='',password='',accounts=None):
''' constructor '''
self.__username=username
self.__password=password
self.__accounts=list()
def get_username(self):
''' getter '''
return self.__username
def get_password(self):
''' getter '''
return self.__password
def get_accounts(self):
''' getter '''
''' returns a list of accounts '''
return self.__acounts
def set_username(self,username):
''' setter '''
self.__username=username
def set_password(self,password):
''' setter '''
self.__password=password
def set_accounts(self,accounts):
''' setter '''
''' Takes list of accounts, before settings
remember to get list of accounts (handle in child class)'''
self.__accounts=accounts
''' Client Class Definition End '''
class ClientAccManagement(BaseClient):
''' service class '''
def __init__(self):
super().__init__()
def add_account(self,category):
call('clear' if name =='posix' else 'cls')
print('''
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$ Which type of account would you like? $$$$$
$$$$$ $$$$$
$$$$$ 1. Fixed Deposit $$$$$
$$$$$ 2. Savings Deposit $$$$$
$$$$$ 3. Loan $$$$$
$$$$$ 4. Go Back $$$$$
$$$$$ Enter any option [1..4] $$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
''')
accounts = super().get_accounts()
option = input()
if option == '4':
print("Thank you, See you soon.")
sleep(3)
return None
#find the value of period...
elif option == '1':
fa = FixedAccount()
elif option == '2':
sa = SavingAccount()
elif option == '3':
la = LoanAccount()
else:
return None
def remove_account(self):
pass
''' ClientManagement Class End '''
class ClientPassManagement(BaseClient):
def __init__(self):
super().__init__()
def update_password(self,un):
call('clear' if name =='posix' else 'cls')
print('''
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$ Set New Password! $$$$$
$$$$$ Note: Typed passwords wont be displayed $$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
''')
old_pass = getpass("Enter Existing Password:\t")
new_pass = getpass("Enter New Password to Set:\t")
#username = super().get_username()
username = un
conn = sqlite3.connect("database.db")
cr = conn.cursor()
search_query = "SELECT * FROM accounts WHERE username = ?"
try:
a = cr.execute(search_query, (username,))
record=cr.fetchone()
if record==None:
print("No Such Username Exists in our Database")
sleep(3)
else:
if record[2] == old_pass:
update_query = "UPDATE accounts SET password = ? WHERE username = ?"
try:
cr.execute(update_query, (new_pass,username,))
print("Password Updated.")
sleep(3)
except Exception as e:
print("Error while Updating Password")
print(str(e))
conn.rollback()
else:
print("Wrong Old Password Entered")
sleep(3)
except Exception as e:
print("Error while Searching User")
print(str(e))
conn.rollback()
conn.commit()
conn.close()
class Client(ClientAccManagement,ClientPassManagement):
def __init__(self):
super().__init__()
def print_details(self):
pass
class Accounts:
def __init__(self):
#self.__acc_type=''
#self.__amount=0
#self.__accid=0
pass
#ABSTRACT METHOD
def to_bank(self):
pass
class SavingAccount(Accounts):
def __init__(self):
pass
def to_bank(self):
conn = sqlite3.connect("database.db")
cr = conn.cursor()
username = input("Enter the Username to Deposit Money:\t")
search_query = "SELECT * FROM accounts WHERE username = ?"
try:
a = cr.execute(search_query, (username,))
record=cr.fetchone()
if record==None:
print("No Such Username Exists in our Database")
sleep(3)
except Exception as e:
print(e)
conn.close()
return None
fetch_id = "SELECT aid FROM accounts WHERE username = ?"
ids = cr.execute(fetch_id,(username,))
userid = cr.fetchone()[0]
amount = input("Enter the Amount to Deposit:\t")
fetch_amount = "SELECT * FROM deposits as d, accounts as a WHERE d.userid=a.aid and a.username = ?"
try: # find if already savings deposit exists for the user
a = cr.execute(fetch_amount,(username,))
info = cr.fetchone()
print(info)
if info == None:
print("Initial Deposit for User")
add_amount_query = "INSERT INTO deposits(userid,amount) VALUES(?,?)"
try:
cr.execute(add_amount_query,(userid,amount,))
print("Amount Added.")
sleep(3)
except Exception as e:
print("Error in creating new savings deposit")
print(str(e))
sleep(3)
conn.rollback()
update_log_query = "INSERT INTO logs(username,amount) VALUES(?,?)"
try:
cr.execute(update_log_query,(username,amount,))
print("Log Updated.")
sleep(3)
except Exception as e:
print("Error in updating log")
print(str(e))
sleep(3)
conn.rollback()
else:
print("Saving Deposit already Exists for User, Adding new amount...")
current_amount = int(info[1])
new_amount = current_amount + int(amount)
add_amount_query = "UPDATE deposits SET amount = ? WHERE userid = ?"
try:
cr.execute(add_amount_query,(new_amount,userid,))
print("Amount Added.")
sleep(3)
except:
print("Error in adding money to savings deposit")
sleep(3)
conn.rollback()
update_log_query = "INSERT INTO logs(username,amount) VALUES(?,?)"
try:
cr.execute(update_log_query,(username,amount,))
print("Log Updated.")
sleep(3)
except Exception as e:
print("Error in updating log")
print(str(e))
sleep(3)
conn.rollback()
except Exception as e:
print("Error in creating/fetching savings deposit details")
print(e)
sleep(3)
conn.rollback()
conn.commit() # commit all changes made
conn.close()
''' deposit function end '''
def from_bank(self):
'''
Can be used to withdraw money from saving deposits.
'''
conn = sqlite3.connect("database.db")
cr = conn.cursor()
call('clear' if name =='posix' else 'cls')
username = input("Enter the Username to Withdraw Money From:\t")
get_username = "SELECT * FROM accounts WHERE username=?"
try:
cr.execute(get_username,(username,))
res = cr.fetchone()
if res == None:
print("No Such Username")
sleep(3)
withdraw_money()
else:
fetch_id = "SELECT aid FROM accounts WHERE username = ?"
ids = cr.execute(fetch_id,(username,))
userid = cr.fetchone()[0]
try:
amount = int(input("Enter the Amount to Withdraw:\t"))
except:
print("Not valid number")
conn.close()
return None
fetch_amount = "SELECT * FROM deposits WHERE userid = ?"
try: # find if already savings deposit exists for the user
a = cr.execute(fetch_amount,(userid,))
info = cr.fetchone()
if info == None:
print("No Deposit exists for User")
conn.close()
sleep(3)
return None
else:
current_money = info[1] #current amount in database
if ( current_money - amount ) < 0:
print("Not enough money in Bank")
conn.close()
sleep(3)
return None
# if enough amount -> continue
add_amount_query = "UPDATE deposits SET amount = ? WHERE userid = ?"
new_amount = current_money - amount
try:
cr.execute(add_amount_query,(new_amount,userid,))
print("Amount Updated.")
sleep(3)
except Exception as e:
print("Error in creating new savings deposit")
print(str(e))
sleep(3)
conn.rollback()
amount = amount * -1
update_log_query = "INSERT INTO logs(username,amount) VALUES(?,?)"
try:
cr.execute(update_log_query,(username,amount,))
print("Log Updated.")
sleep(3)
except Exception as e:
print("Error in updating log")
print(str(e))
sleep(3)
conn.rollback()
except Exception as e:
print("Error in fetching bank details")
print(str(e))
sleep(3)
except Exception as e:
print("Error in fetching username")
print(str(e))
sleep(3)
conn.commit()
conn.close()
''' withdraw function end '''
''' Class SavingAccount End '''
class FixedAccount(Accounts):
def __init__(self):
pass
def to_bank(self):
call('clear' if name =='posix' else 'cls')
print('''
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$ How long should the fixed deposit be? $$$$$
$$$$$ $$$$$
$$$$$ 1. Fixed Deposit for 1 Year $$$$$
$$$$$ 2. Fixed Deposit for 3 Year $$$$$
$$$$$ 3. Fixed Deposit for 5 and more Years $$$$$
$$$$$ 4. Go Back $$$$$
$$$$$ Enter any option [1..4] $$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
''')
option = input()
if option == '4':
print("Thank you, See you soon.")
sleep(3)
return None
#find the value of period...
elif option == '1':
period = 1
rate_name = "fixed1"
elif option == '2':
period = 3
rate_name = "fixed3"
elif option == '3':
while True:
period = int(input("Enter the period for fixed deposit(Must be greater than 5 years):\t"))
if period < 5:
print("Entered period is less than or equal to 5:")
else:
break
rate_name = "fixed5"
elif int(option) not in range(1,4):
print("I didn't understand you, try again...")
sleep(3)
self.to_bank()
conn = sqlite3.connect("database.db")
cr = conn.cursor()
#username = input("Enter the Username to Deposit Money:\t")
username = input("ENTER USERNAME:\t")
search_query = "SELECT * FROM accounts WHERE username = ?"
try:
a = cr.execute(search_query, (username,))
record=cr.fetchone()
if record==None:
print("No Such Username Exists in our Database")
sleep(3)
except Exception as e:
print(e)
conn.close()
return None
amount = input("Enter the Amount to Deposit:\t")
#get Interest
get_interest_query = "SELECT rate_val FROM rates WHERE rate_name = ?"
interest = 0
try:
cr.execute(get_interest_query,(rate_name,))
interest = cr.fetchone()
interest = float(interest[0])
except Exception as e:
print("Error in fetching interest rate")
print(str(e))
sleep(3)
conn.rollback()
#calculate end_date using period
current_date = date.today()
end_date = current_date + relativedelta(years=period)
fetch_id = "SELECT aid FROM accounts WHERE username = ?"
ids = cr.execute(fetch_id,(username,))
userid = cr.fetchone()[0]
add_fixed_amount_query = "INSERT INTO fixed_deposits(user_id,amount,period,end_date,interest) VALUES(?,?,?,?,?)"
try:
cr.execute(add_fixed_amount_query,(userid,amount,period,end_date,interest))
print("Fixed Amount Added.")
sleep(3)
except Exception as e:
print("Error in creating new fixed deposit")
print(str(e))
sleep(3)
conn.rollback()
conn.commit()
conn.close()
def from_bank(self): # need to ask which fixed deposit in case many or different account for each fixed deposit?
print("BY BANK POLICY YOU ARE NOT ALLOWED TO BREAK FIXED DEPOSIT BEFORE MATURITY DATE")
class LoanAccount(Accounts):
def request_loan(self):
pass
class LoanAccountManagement(LoanAccount):
''' service class '''
def accept_emi_payment(self):
conn = sqlite3.connect("database.db")
cr = conn.cursor()
username = input("Enter Username of Client:\t")
search_query = "SELECT * FROM accounts WHERE username = ?"
try:
a = cr.execute(search_query, (username,))
record=cr.fetchone()
if record==None:
print("No Such Username Exists in our Database")
sleep(3)
except Exception as e:
print(e)
conn.close()
return None
fetch_id = "SELECT aid FROM accounts WHERE username = ?"
ids = cr.execute(fetch_id,(username,))
userid = cr.fetchone()[0]
search_loan_requests = "SELECT next_due_date FROM loans as l, accounts as a WHERE l.user__id=a.aid and a.username = ?"
try:
cr.execute(search_loan_requests,(username,))
res = cr.fetchone()
due_date = datetime.strptime(res[0], '%Y-%m-%d').date()
new_due_date = due_date + relativedelta(months=1)
update_due_date = "UPDATE loans SET next_due_date = ? WHERE user__id = ?"
try:
cr.execute(update_due_date,(new_due_date,userid,))
print("EMI Paid, Due Date Updated")
sleep(3)
except Exception as e:
print(e)
conn.rollback()
except Exception as e:
print("Error in fetching loan requests")
print(str(e))
conn.rollback()
conn.commit()
conn.close()
''' accept_emi_payment function end '''
''' service class '''
def view_loans(self):
conn = sqlite3.connect("database.db")
cr = conn.cursor()
search_loan_requests = "SELECT loan_id, username, amount FROM loans as l, accounts as a where a.aid=l.user__id and loan_status = 0"
try:
cr.execute(search_loan_requests)
record=cr.fetchall()
call('clear' if name =='posix' else 'cls')
print(tabulate(record, headers=['Username', 'Amount'], tablefmt='orgtbl'))
input("Enter any character(s) to Go Back\n")
except Exception as e:
print("Error in fetching loan requests")
print(str(e))
conn.rollback()
conn.commit()
conn.close()
def accept_loans(self):
conn = sqlite3.connect("database.db")
cr = conn.cursor()
search_loan_requests = "SELECT loan_id, username, amount FROM loans as l, accounts as a where a.aid=l.user__id and loan_status = 0"
try:
cr.execute(search_loan_requests)
record=cr.fetchall()
call('clear' if name =='posix' else 'cls')
print(tabulate(record, headers=['username', 'Amount'], tablefmt='orgtbl'))
print('''
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$5$$$$$$$$$$$$$$$$$$$$$
$$$$$ WELCOME LOANS SECTION $$$$$
$$$$$ Choose any option: $$$$$
$$$$$ 1. Approve any Loan Request $$$$$
$$$$$ 2. Go Back $$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$''')
option = input("Enter any number in range (1,2):\t")
if option == '2' or option != '1':
return None
print()
loan_id = input("Enter any loan_id to Approve it\n")
interest = float(input("Enter Interest to be Set for this loan:\t"))
period = int(input("Enter the period(in year) for repayment of loan:\t"))
approve_date = date.today()
due_date = approve_date + relativedelta(years=period)
next_due_date = approve_date + relativedelta(months=1)
amount = 0
#fetch amount for loan_id
try:
get_amount_query = "SELECT amount FROM loans WHERE loan_id = ?"
cr.execute(get_amount_query,(loan_id,))
res = cr.fetchone()
amount = res[0]
except Exception as e:
print(e)
interest = interest / (12 * 100)
period = period * 12
emi = (amount * interest * pow(1 + interest, period)) / (pow(1 + interest, period) - 1)
update_loan_requests = "UPDATE loans SET interest = ?, date_taken = ?, due_date = ?, next_due_date = ?, emi = ?, loan_status = 1 WHERE loan_id = ?"
try:
cr.execute(update_loan_requests,(interest,approve_date,due_date,next_due_date,emi,loan_id,))
print("Approved Loan")
sleep(3)
except Exception as e:
print("Error in approving loan requests")
print(str(e))
conn.rollback()
except Exception as e:
print("Error in fetching loan requests")
print(str(e))
conn.rollback()
conn.commit()
conn.close()
''' Class LoanAccountManagement End '''
class OperationalManagement:
''' service class '''
def set_interest_rates(self):
call('clear' if name =='posix' else 'cls')
print('''
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$ Set Interest For? $$$$$
$$$$$ $$$$$
$$$$$ 1. Savings accounts $$$$$
$$$$$ 2. 1 year Fixed Deposits $$$$$
$$$$$ 3. 3 year Fixed Deposits $$$$$
$$$$$ 4. 5+ year Fixed Deposits $$$$$
$$$$$ 5. Go Back $$$$$
$$$$$ Enter any option [1..5] $$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
''')
option = input() #Take user input
conn = sqlite3.connect("database.db")
cr = conn.cursor() #Create cursor object
create_table_rates = """CREATE TABLE IF NOT EXISTS rates(
rate_id INTEGER PRIMARY KEY AUTOINCREMENT,
rate_name TEXT UNIQUE NOT NULL,
rate_val REAL NOT NULL
)"""
#Note: SQLite understands the column type of "VARCHAR(N)" to be the same as "TEXT"
try:
cr.execute(create_table_rates) # Create rates table if not exists
except Exception as e:
print("Error in creating 'rates' table")
print(str(e))
conn.rollback()
update_query = "REPLACE INTO rates(rate_name, rate_val) VALUES(?,?)"
if option == '1':
rate_val = input("Enter value for interest rate:")
try:
cr.execute(update_query, ("savings",rate_val))
print("Interest rates updated.")
sleep(3)
except:
print("Error while updating rates in 'rates' table")
conn.rollback()
elif option == '2':
rate_val = input("Enter value for interest rate:")
try:
cr.execute(update_query, ("fixed1",rate_val))
print("Interest rates updated.")
sleep(3)
except:
print("Error while updating rates in 'rates' table")
conn.rollback()
elif option == '3':
rate_val = input("Enter value for interest rate:")
try:
cr.execute(update_query, ("fixed3",rate_val))
print("Interest rates updated.")
sleep(3)
except:
print("Error while updating rates in 'rates' table")
conn.rollback()
elif option == '4':
rate_val = input("Enter value for interest rate:")
try:
cr.execute(update_query, ("fixed5",rate_val))
print("Interest rates updated.")
sleep(3)
except:
print("Error while updating rates in 'rates' table")
conn.rollback()
elif option == '5':
return None
else:
print("Sorry I didn't understand, make sure you enter number in range [1..5]")
sleep(3)
set_interest()
conn.commit()
conn.close()
''' End of Function set_interest_rates '''
''' End Class OperationalManagement '''
class UserManagement:
''' service class '''
def add_user(self):
call('clear' if name =='posix' else 'cls')
print('''
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$ ENTER /q TO GO BACK $$$$$
$$$$ anything else to continue $$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
''')
option = input()
if option != '/q':
username = input("Enter Username for New Account:\t")
password = getpass("Enter Password for New Account:\t")
conn = sqlite3.connect("database.db")
cr = conn.cursor()
create_table_accounts = """CREATE TABLE IF NOT EXISTS accounts(
user_id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL
)"""
try:
cr.execute(create_table_accounts) # if accounts table doesnt exists create it
except Exception as e:
print("Error in creating 'accounts' table")
print(str(e))
conn.rollback()
update_query = "INSERT INTO accounts(username, password) VALUES(?,?)"
try:
cr.execute(update_query, (username,password)) # add new user
print("Account Added.")
sleep(3)
except:
print("Error while Creating User")
conn.rollback() #roll back in case of any errors
conn.commit()
conn.close()
else:
return None# GO BACK
''' end of function add_user '''
def remove_user(self):
call('clear' if name =='posix' else 'cls')
print('''
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$ ENTER /q TO GO BACK $$$$$
$$$$ anything else to continue $$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
''')
option = input()
if option != '/q':
username = input("Enter Username of the Account to be Deleted:\t")
conn = sqlite3.connect("database.db")
cr = conn.cursor()
create_table_accounts = """CREATE TABLE IF NOT EXISTS accounts(
user_id INTEGER PRIMARY KEY AUTOINCREMENT,
username TEXT UNIQUE NOT NULL,
password TEXT NOT NULL
)"""
try:
cr.execute(create_table_accounts)
except Exception as e:
print("Error in creating 'accounts' table")
print(str(e))
conn.rollback()
search_query = "SELECT * FROM accounts WHERE username = ?"
try:
a = cr.execute(search_query, (username,))
record=cr.fetchone()
if record==None:
print("No Such Username Exists in our Database")
sleep(3)
else:
update_query = "DELETE FROM accounts WHERE username = ?"
try:
cr.execute(update_query, (username,))
print("Account Deleted.")
sleep(3)
except:
print("Error while Deleting User")
conn.rollback()
except Exception as e:
print("Error while Searching User")
print(str(e))
conn.rollback()
conn.commit()
conn.close()
else:
return None
''' end of function remove_user '''
''' End Class UserManagement '''
class Admin(LoanAccountManagement,OperationalManagement,UserManagement):
''' service class '''
def __init__(self):
#Code for admin interface
print('''
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$5$$$$$$$$$$$$$$$$$$$$$
$$$$$ WELCOME TO MINI BANK $$$$$
$$$$$ Admin Panel $$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Date:''',date.today())
print('''
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$ How may I help you? $$$$$
$$$$$ $$$$$
$$$$$ 1. Set Interest Rates $$$$$
$$$$$ 2. View Customer Summary $$$$$
$$$$$ 3. View Loan Requests $$$$$
$$$$$ 4. Approve Loan Requests $$$$$
$$$$$ 5. Add User $$$$$
$$$$$ 6. Remove User $$$$$
$$$$$ 7. Deposit Money $$$$$
$$$$$ 8. Withdraw $$$$$
$$$$$ 9. View Complaints $$$$$
$$$$$ 10. Accept EMI Payment $$$$$
$$$$$ 11. Exit $$$$$
$$$$$ Enter any option between[1..11] $$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
''')
try: #Exception may be generated if user enters non integer value
option = int(input("Enter:\t"))
while option not in range(1,12):
print("Sorry I didn't understand, make sure you enter number in range [1..11]")
sleep(3)
call('clear' if name =='posix' else 'cls')
option = int(input("Enter:\t"))
except Exception as e:
print("You entered non integer input")
print(e)
self.__init__()
return None
if option == 1:
super().set_interest_rates()
self.__init__()
elif option == 2:
self.view_customer_summary()
self.__init__()
elif option == 3:
super().view_loans()
self.__init__()
elif option == 4:
super().accept_loans()
self.__init__()
elif option == 5:
super().add_user()
self.__init__()
elif option == 6:
super().remove_user()
self.__init__()
elif option == 7:
call('clear' if name =='posix' else 'cls')
print('''
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$5$$$$$$$$$$$$$$$$$$$$$
$$$$$ WELCOME DEPOSITS SECTION $$$$$
$$$$$ Choose any option: $$$$$
$$$$$ 1. Savings Deposit $$$$$
$$$$$ 2. Fixed Deposit $$$$$
$$$$$ 3. Go Back $$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$''')
option = input("Enter any number in range (1,3):\t")
if option == '1':
sa = SavingAccount()
sa.to_bank()
self.__init__()
elif option == '2':
fa = FixedAccount()
fa.to_bank()
self.__init__()
elif option == '3':
self.__init__()
else:
print("I didn't understand you, try again...")
sleep(3)
elif option == 8:
sa = SavingAccount()
sa.from_bank()
self.__init__()
elif option == 9:
self.view_complaints()
self.__init__()
elif option == 10:
lam = LoanAccountManagement()
lam.accept_emi_payment()
self.__init__()
elif option == 11:
print("Thank you, Goodbye.")
sleep(3)
call('clear' if name =='posix' else 'cls')
exit(0)
''' end of constructor '''
def view_customer_summary(self):
'''
Displays non-performing Clients i.e., clients who haven't payed their dues yet.
'''
conn = sqlite3.connect("database.db")
cr = conn.cursor()
curr_date = date.today()
find_non_performing = "SELECT * FROM loans"
try:
cr.execute(find_non_performing)
res = cr.fetchall()
non_performers = []
for r in res:
stored_date = datetime.strptime(r[5], '%Y-%m-%d').date()
if stored_date < curr_date: #r[5] = next_due_date, if due_date crossed
non_performers.append(r)
call('clear' if name =='posix' else 'cls')
print(tabulate(non_performers, headers=['Username', 'Amount','Date Taken','Due Date','Next Due Date','Interest','EMI','Loan Status'], tablefmt='orgtbl'))
input("{RESS ENTER TO GO BACK\n")
except Exception as e:
print(e)
print("Couldnt fetch non performing clients")
conn.commit()
conn.close()
''' view_customer_summary function end '''
def view_complaints(self):
conn = sqlite3.connect("database.db")
cr = conn.cursor()
create_table_complaints = """CREATE TABLE IF NOT EXISTS complaints(
complaints_id INTEGER PRIMARY KEY AUTOINCREMENT,
complaint_text TEXT NOT NULL,
complaint_date TEXT NOT NULL DEFAULT CURRENT_TIMESTAMP,
complaint_status INTEGER NOT NULL DEFAULT 1
)"""
#1 in complaint status = active, 0: inactive
try:
cr.execute(create_table_complaints)
except Exception as e:
print("Error in creating 'complaints' table")
print(str(e))
conn.rollback()
search_complaints = "SELECT complaints_id, complaint_text, complaint_date FROM complaints where complaint_status = 1"
try:
cr.execute(search_complaints)
record=cr.fetchall()
call('clear' if name =='posix' else 'cls')
print(tabulate(record, headers=['Complaint Text', 'Complaint Date'], tablefmt='orgtbl'))
print('''
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$5$$$$$$$$$$$$$$$$$$$$$
$$$$$ WELCOME COMPLAINTS SECTION $$$$$
$$$$$ Choose any option: $$$$$
$$$$$ 1. Mark a Complaint as resolved $$$$$
$$$$$ 2. Go back $$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$''')
option = input("Enter 1 or 2:\t")
if option == '1':
com_id = input("Enter Complaint ID to mark as Resolved:\t")
update_query = "UPDATE complaints SET complaint_status = 0 WHERE complaints_id = ?"
try:
cr.execute(update_query,(com_id,))
print("Resolved the complaint")
sleep(3)
except Exception as e:
print("Error in updating complaint_status ")
print(str(e))
conn.rollback()
except Exception as e:
print("Error in fetching 'complaints' table")
print(str(e))
conn.rollback()
conn.commit()
conn.close()
''' view_complaints function end '''
''' Class Admin End '''
class SystemServices:
''' service class '''
def login(self):
''' takes Nothing and returns whether logged in Successfully '''
print('''
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$5$$$$$$$$$$$$$$$$$$$$$
$$$$$ WELCOME TO MINI BANK $$$$$
$$$$$ Please Enter your Credentials $$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$''')
username = input("Enter your username(case-sensitive):\t")
password = getpass("Enter your password(hidden):\t")
conn = sqlite3.connect("database.db")
cr = conn.cursor()
authorize_query = "SELECT * FROM accounts WHERE username = ?"
try:
cr.execute(authorize_query, (username,))
except Exception as e:
print("Error during Login - while fetching username")
print(str(e)) #Print error
conn.rollback() #Roll back changes made
record=cr.fetchone() #Fetch one record
if record==None: #If no record with given username found in database
print("No such username exists") #print message
sleep(3) #Sleep the program for 3 seconds
#clear screen based on whether windows or linux
conn.close() #close connection
return False, None #Return false as operation unsuccessful
else:
if record[2] == password:
print("Logged in Successfully")
sleep(3)
if record[1] == 'admin':
return True, 'admin'
else:
cl = Client()
cl.set_username=username
cl.set_password=password
fetch_id = "SELECT aid FROM accounts WHERE username = ?"
ids = cr.execute(fetch_id,(username,))
userid = cr.fetchone()[0]
#search all saving account and add
fetch = "SELECT * FROM deposits WHERE userid = ?"
try:
abc = cr.execute(fetch_id,(userid,))
accou = cr.fetchone()[0]
cl.add_account(accou)
except:
print('no deposit accounts for user')
fetch = "SELECT * FROM fixed_deposits WHERE userid = ?"
try:
abc = cr.execute(fetch_id,(userid,))
accou = cr.fetchone()[0]
cl.add_account(accou)
except:
print('no deposit accounts for user')
fetch = "SELECT * FROM loans WHERE userid = ?"
try:
abc = cr.execute(fetch_id,(userid,))
accou = cr.fetchone()[0]
cl.add_account(accou)
except:
print('no deposit accounts for user')
conn.close()
return True, username
else:
print("Wrong Passoword! Contact admin if any trouble.")
sleep(3)
conn.close()
return False, '' #Return false as operation unsuccessful
''' login function end '''
''' Class SystemServices End '''
# class interface and account management(intrest calculation) code frm here
class Client_Interface(Client):
"""docstring for Client_Interface"""
def __init__(self, username):
self.username = username
# Welcome screen of client interface after log in to client
print('''
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$5$$$$$$$$$$$$$$$$$$$$$
$$$$$ WELCOME TO MINI BANK $$$$$
$$$$$ User Panel $$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
Date:''',date.today())
print('''
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
$$$$$ How may I help you? $$$$$
$$$$$ $$$$$
$$$$$ 1. Check Transactions $$$$$
$$$$$ 2. Register Complaint $$$$$
$$$$$ 3. Request Loan $$$$$
$$$$$ 4. Update Password $$$$$
$$$$$ 5. Exit $$$$$
$$$$$ Enter any option between[1..5] $$$$$
$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$
''')
try: #Exception may be generated if user enters non integer value
option = int(input("Enter:\t"))
while option not in range(1,6):
print("Sorry I didn't understand, make sure you enter number in range [1..5]")
sleep(3)
option = int(input("Enter:\t"))
except Exception as e:
print("You entered non integer input")