-
Notifications
You must be signed in to change notification settings - Fork 0
/
accounting.py
766 lines (553 loc) · 23 KB
/
accounting.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
from datetime import datetime
from datetime import date
import os
class check: # check
is_payed = False
def __init__(self, price, deadLine, starting_date):
self.price = price
self._deadLine = deadLine
self.starting_date = starting_date
def __str__(self):
return f"Price: {self.price}\nDeadline: {self._deadLine}\nStarting date: {self.starting_date}\nPayment status: {self.is_payed}\nRemaining days: {self.getRemainingDay()}"
def print(self):
# print(
# f"Price: {self.price}\nDeadline: {self._deadLine}\nStarting date: {self.starting_date}\nPayment status: {self.is_payed}")
# print(
# f"Remaining days: {(self._deadLine - self.starting_date).days}\n")
print(str(self))
def getRemainingDay(self):
if not self.is_payed:
return (self._deadLine - self.starting_date).days
return 0
def getPayStatus(self):
return self.is_payed
def pay(self):
self.is_payed = True
class installment: # aqsat
lastPayment = 0 # akharin pardakhti ke bayad anjam shavad
is_payed = False # tamami pardakht ha tamam shode
def __init__(self, price, number, interval, startingDate):
self.price = price # qeymate har pardakht
self._number = number # tedade kolle pardakht ha
self._interval = interval # moddat zamane har pardakht
self.startingDate = startingDate # tarikhe shuru
def __str__(self):
return str(f"Price: {self.price}\nPayment number(s): {self._number}\nStarting date: {self.startingDate}\nPayment interval: {self._interval.day} day(s)\nAll payments finished: {self.is_payed}\nPaid payments: {self.lastPayment}\nRemaining days untill next payment: {self.getRemainingDaysToLastPayment()}")
def print(self):
# print(f"Price: {self.price}\nPayment number(s): {self._number}\nStarting date: {self.startingDate}\nPayment interval: {self._interval.day} day(s)\nPayment status: {self.is_payed}")
# print(f"{self.lastPayment} paid or out of time installment(s).")
# print(f"Remaining days untill next payment: {self.getRemainingDaysToLastPayment()}\n")
print(str(self))
def isFinished(self):
return self.lastPayment - 1 == self._number
def notPayed(self): # returns installments that are out of time
temp1 = (date.today() - self.startingDate).days / self._interval.day
temp2 = int(temp1) - (self.lastPayment - 1)
if temp2 >= 1:
self.lastPayment += temp2
return installment(
self.price,
int(temp2),
self._interval,
self.startingDate)
return False
def pay(self, num):
if not self.is_payed and self.lastPayment - 1 + num <= self._number:
self.lastPayment += num
if self.lastPayment - 1 == self._number:
self.is_payed = True
return True
else:
return False
def getRemainingDaysToLastPayment(self):
return self._interval.day * (self.lastPayment + 1) - (date.today() - self.startingDate).days
def getPayStatus(self):
return self.is_payed
class customer: # moshtari
total_transaction = 0 # kolle tedade tarakonesh ha
total_debt = 0 # kolle tedade bedehi ha
def __init__(self, user_name, password, address, code):
self._user_name = user_name
self._password = password
self.address = address
self.code = code
self._checks_list = []
self._installment_list = []
self._debt_list = set()
def __str__(self):
return str(
f"Customer's information (Name: {self._user_name}, Address: {self.address}, National Code: {self.code})")
def getInfo(self): # returns a tuple of username and password
return (self._user_name, self._password)
def add_check(self, chk):
self._checks_list.append(chk)
self.total_transaction += 1
def add_inst(self, inst):
self._installment_list.append(inst)
self.total_transaction += 1
def show_checks(self):
if len(self._checks_list) == 0:
print("No checks yet.")
return
i = 1
for item in self._checks_list:
print("Check", i, ':')
i += 1
item.print()
def show_installments(self):
if len(self._installment_list) == 0:
print("No installment yet.")
return
i = 1
for item in self._installment_list:
print("Installment", i, ':')
i += 1
item.print()
def show_debts(self):
if len(self._debt_list) == 0:
print("No debt yet.")
return
i = 1
for item in self._debt_list:
print("Number", i, ':')
item.print()
i += 1
def trust_status(self):
if self.total_transaction == 0:
print("No checks yet!")
return
else:
temp = (self.total_debt / self.total_transaction) * 100
if temp < 20:
print("\tGood trust status.")
elif temp > 70:
print("\tBad trust status.")
else:
print("\tMid-level trust status.")
def setUser(self, newUser):
self._user_name = newUser
def setPassword(self, newPass):
self._password = newPass
def setAddress(self, newAddress):
self.address = newAddress
# evaluates if there is any check that is 1 day ahead to it's deadline
def oneDayToFinishCheck(self):
i = 0
for item in self._checks_list:
if item.getRemainingDay() is not None:
if item.getRemainingDay() <= 1:
i += 1
return i
# evaluates if there is any installment that is 1 day ahead to it's
# deadline
def oneDayToFinishInstallment(self):
i = 0
for item in self._installment_list:
if item.getRemainingDaysToLastPayment() <= 1:
i += 1
return i
def debts(self): # returns number of debts
i = 0
for item in self._checks_list:
if item.getRemainingDay() is not None: # if it's not payed
if item.getRemainingDay() <= 1 and not item.getPayStatus(
): # if it's out of time and not payed
i += 1
self._debt_list.add(item)
for item in self._installment_list:
inst = item.notPayed() # if it's out of time and not payed
if inst:
i += 1
self._debt_list.add(inst)
self.total_debt = i
return i
def payCheck(self, index):
if index < len(
self._checks_list) and not self._checks_list[index].getPayStatus():
self._checks_list[index].pay()
flag = False
for item in self._debt_list: # cleaning the check if it is in debt list
if item == self._checks_list[index]:
flag = True
break
if flag:
self._debt_list.remove(item)
return True
return False
def payInstallment(self, index, num):
if index < len(
self._installment_list) and not self._installment_list[index].getPayStatus():
return self._installment_list[index].pay(num)
return False
def payDebt(self, choice):
i = 0
for item in self._debt_list:
if i == choice: # finding the item for payment
if not item.getPayStatus(): # checking if we can pay it or not
item.pay() # paying
if item.getPayStatus() or isinstance(
item, check): # checking if it is finished or not
self._debt_list.remove(item)
return True
i += 1
class employee: # karmand
def __init__(self, user_name, password):
self._user_name = user_name
self._password = password
def __str__(self):
return str(f"Employee's information (Name: {self._user_name})")
def getInfo(self): # returns a tuple of username and password
return (self._user_name, self._password)
# global list of customer and list of employees
customers = []
employees = []
def writeToFile(string):
file1 = open("payments.txt", "a")
file1.write(string)
file1.close()
def clear(): # waits for an input then clears the screen
input("\nPress ENTER key to continue")
os.system("cls")
def clear2(): # just clears the screen
os.system("cls")
def payments_menu(cst):
while(True):
clear()
print("What do you want to pay?")
print("\t\t\t1.Pay a check\n")
print("\t\t\t2.Pay an installment\n")
print("\t\t\t3.Pay a debt\n")
print("\t\t\t4.Pay multiple installments\n")
print("\t\t\t5.Back to Customers menu\n")
sel = input("\t\t\tYour selection: ")
clear2()
if sel == '1':
if len(cst._checks_list) == 0:
print("No checks yet.")
continue
print("Checks list: ")
cst.show_checks()
print(
"Enter which check do you want to pay? (enter the number beside the check)")
choice = int(input("Your selection: ")) - 1
if cst.payCheck(choice):
writeToFile(
f"----{str(cst)} payed for :\n{str(cst._checks_list[choice])}\nPayment date:{date.today()}\n\n")
print("Payment successfull!")
else:
print("Wrong choice!")
elif sel == '2':
if len(cst._installment_list) == 0:
print("No checks yet.")
continue
print("Installments list: ")
cst.show_installments()
print(
"Enter which installment do you want to pay? (enter the number beside the installment)")
choice = int(input("Your selection: ")) - 1
if cst.payInstallment(choice, 1):
writeToFile(
f"----{str(cst)} payed for :\n{str(cst._installment_list[choice])}\nPayment date:{date.today()}\n\n")
print("Payment successfull!")
else:
print("Wrong choice!")
elif sel == '3':
if len(cst._debt_list) == 0:
print("No checks yet.")
continue
print("Debt list: ")
cst.show_debts()
print(
"Enter which debt do you want to pay? (enter the number beside the debt)")
choice = int(input("Your selection: ")) - 1
if cst.payDebt(
choice): # as we didn't change the set therfore the indexes are the same
i = 0
tmp = ""
for item in cst._debt_list:
if i == choice:
tmp = str(item)
break
i += 1
writeToFile(
f"----{str(cst)} payed for :\n{tmp}\nPayment date:{date.today()}\n\n")
print("Payment successfull!")
else:
print("Wrong choice!")
elif sel == '4':
if len(cst._installment_list) == 0:
print("No checks yet.")
continue
print("Installments list: ")
cst.show_installments()
print(
"Enter which installment do you want to pay? (enter the number beside the installment)")
choice = int(input("Your selection: ")) - 1
num = int(input("Enter how many installment you do want to pay: "))
if cst.payInstallment(choice, num):
writeToFile(
f"----{str(cst)} payed for :\n{str(cst._installment_list[choice])}\nPayment date:{date.today()}\n\n")
print("Payment successfull!")
else:
print("Wrong choice!")
elif sel == '5':
return
else:
print("Wrong selection, please try again!")
def employee_menu(emp):
while(True):
clear()
for item in customers: # updating all customers debts
item.debts()
print("You are logged in as:")
print(emp)
print("\nOptions:")
print("\t\t\t1.Create new account for customer\n")
print("\t\t\t2.Edit customer's information\n")
print("\t\t\t3.Delete customer's account\n")
print("\t\t\t4.Create checks for a customer\n") # check ha
print("\t\t\t5.Create Installments for a customer\n")
print("\t\t\t6.Show customer's trust status\n") # aqsat
# taiidieye pardakhte naqdi
print("\t\t\t7.Confirm customer's payment(in cash)\n")
print("\t\t\t8.Logout\n")
# temperary variables for exchanging inputs
cst_user = ""
cst_pass = ""
cst_add = ""
cst_code = ""
sel = input("\t\t\tYour selection: ")
clear2()
if sel == '1':
print("Please enter customer's information!")
cst_user = input("Username: ")
cst_pass = input("Password: ")
cst_add = input("Address: ")
cst_code = input("National code: ")
# to do : check the user pass if is duplicate
cst = customer(cst_user, cst_pass, cst_add, cst_code)
customers.append(cst)
del cst
print("New customer account successfully added.")
elif sel == '2':
print(
"Please enter customer's username and password to edit their information!")
cst_user = input("Username: ")
cst_pass = input("Password: ")
flag = False
for item in customers:
info_tuple = item.getInfo()
if info_tuple[0] == cst_user and info_tuple[1] == cst_pass:
print("Customer account found.\n")
str1 = input("Please enter new password: ")
str2 = input("Please enter new address: ")
item.setPassword(str1)
item.setAddress(str2)
print("Info changed.")
flag = True
break
if not flag:
print("User not found! Wrong username or password.")
elif sel == '3':
print(
"Please enter customer's username and password to delete their account!")
cst_user = input("Username: ")
cst_pass = input("Password: ")
flag = False
for item in customers:
info_tuple = item.getInfo()
if info_tuple[0] == cst_user and info_tuple[1] == cst_pass:
customers.remove(item)
print("Customer's account deleted from list.")
flag = True
break
if not flag:
print("User not found! Wrong username or password.")
elif sel == '4':
print("Please enter customer's username and password!")
cst_user = input("Username: ")
cst_pass = input("Password: ")
flag = False
for item in customers:
info_tuple = item.getInfo()
if info_tuple[0] == cst_user and info_tuple[1] == cst_pass:
print("Customer found.\n")
deadLine = input(
"Please enter deadline of check(in the from of date.month.year): ")
price = input("Please enter price of check: ")
chk = check(int(price), datetime.strptime(
deadLine, "%d.%m.%Y").date(), date.today())
item.add_check(chk)
print("Check succesfully added.")
flag = True
break
if not flag:
print("User not found! Wrong username or password.")
elif sel == '5':
print("Please enter customer's username and password!")
cst_user = input("Username: ")
cst_pass = input("Password: ")
flag = False
for item in customers:
info_tuple = item.getInfo()
if info_tuple[0] == cst_user and info_tuple[1] == cst_pass:
print("Customer found.\n")
# hatman be vahede ruz bashe
interval = input(
"Please enter time between each payment(beware that it should be in DAYS form): ")
price = input(
"Please enter price of each payment of installment: ")
number = input(
"Please enter number of payments for installment: ")
inst = installment(int(price), int(number), datetime.strptime(interval, "%d").date(), date.today())
item.add_inst(inst)
print("Installment succesfully added.")
flag = True
break
if not flag:
print("User not found! Wrong username or password.")
elif sel == '6':
print("Please enter customer's username and password!")
cst_user = input("Username: ")
cst_pass = input("Password: ")
flag = False
for item in customers:
info_tuple = item.getInfo()
if info_tuple[0] == cst_user and info_tuple[1] == cst_pass:
print("Trust Status:")
item.trust_status()
flag = True
break
if not flag:
print("User not found! Wrong username or password.")
elif sel == '7':
print("Please enter customer's username and password.")
cst_user = input("Username: ")
cst_pass = input("Password: ")
flag = False
for item in customers:
info_tuple = item.getInfo()
if info_tuple[0] == cst_user and info_tuple[1] == cst_pass:
payments_menu(item)
flag = True
break
if not flag:
print("User not found! Wrong username or password.")
elif sel == '8':
print("Logged out!")
return
else:
print("Wrong selection, please try again!")
def customer_menu(cst):
while(True):
clear()
print("You are logged in as:")
print(cst)
print("\nWARNINGS:")
print(
f"-You have {cst.oneDayToFinishCheck()} check(s) that have one or less than one day to pay.")
print(
f"-You have {cst.oneDayToFinishInstallment()} installment(s) that have one or less than one day to pay.")
print(
f"-You have {cst.debts()} debt(s).\n")
print("Options:")
print("\t\t\t1.Show Installment's status\n")
print("\t\t\t2.Show Check's status\n")
print("\t\t\t3.Show Debt's status\n")
print("\t\t\t4.Show customer's trust status\n")
print("\t\t\t5.Pay online\n")
print("\t\t\t6.Pay in cash\n")
print("\t\t\t7.Logout\n")
sel = input("\t\t\tYour selection: ")
clear2()
if sel == '1':
cst.show_installments()
elif sel == '2':
cst.show_checks()
elif sel == '3':
cst.show_debts()
elif sel == '4':
print("Trust Status:")
cst.trust_status()
elif sel == '5':
payments_menu(cst)
elif sel == '6':
print("Please ask an employee to take your payments in cash.")
elif sel == '7':
print("Logged out!")
return
else:
print("Wrong selection, please try again!")
def main():
print("\t\t\t\t** Welcome! **")
while(True): # Main menu
clear()
print("What type of user are you?(Customer or Employee)\n")
print("\t\t\t1.Customer\n")
print("\t\t\t2.Employee\n")
print("\t\t\t3.Exit\n")
sel = input("\t\t\tYour selection: ")
# resetting username and password for login
cst_user = ""
cst_pass = ""
if sel == '1': # Customer login
print("\n")
print("Please enter your username and password!")
cst_user = input("Username: ")
cst_pass = input("Password: ")
flag = False # flag is a boolean for saving the login status
for item in customers:
info_tuple = item.getInfo()
if info_tuple[0] == cst_user and info_tuple[1] == cst_pass:
print("Login successfull!")
customer_menu(item)
flag = True
break
if not flag:
print("Login not successfull! Wrong username or password.")
elif sel == '2': # Employee login
while(True):
clear()
# reseting username and password for login
emp_user = ""
emp_pass = ""
print("What type of employee are you?\n")
print("\t\t\t1.Log in(for already signed up employees)\n")
print("\t\t\t2.Sign up(for new employees)\n")
print("\t\t\t3.Back to Main menu\n")
sel2 = input("Your selection: ")
if sel2 == '1':
print("Please enter your username and password!")
emp_user = input("Username: ")
emp_pass = input("Password: ")
flag = False # flag is a boolean for saving the login status
for item in employees:
info_tuple = item.getInfo()
if info_tuple[0] == emp_user and info_tuple[1] == emp_pass:
print("Login successful!")
employee_menu(item)
flag = True
break
if not flag:
print("Login not successful! Wrong username or password.")
elif sel2 == '2':
print("Please enter your username and password!")
emp_user = input("Username: ")
emp_pass = input("Password: ")
# to do : check the user pass if duplicate
# adding new employee(emp) to list of employees
emp = employee(emp_user, emp_pass)
employees.append(emp)
print("Sign up successful!")
# it can be uncommented for going to employee menu right after signing up
# employee_menu(emp)
elif sel2 == '3':
break
else:
print("Wrong selection, please try again!")
elif sel == '3':
quit()
else:
print("Wrong selection, please try again!")
if __name__ == "__main__":
main()