-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
113 lines (97 loc) · 3.8 KB
/
main.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
import os
from expense import *
from helpers.constants import MainMenu, BackButton
from helpers.menu import Menu
if __name__ == '__main__':
u_handler = UserHandler()
g_handler = GroupHandler()
e_handler = ExpenseHandler()
while True:
m = Menu()
menu_items = [x.value for x in MainMenu]
menu_items.append(BackButton.EXIT.name)
m.draw_menu(menu_items)
input()
if MainMenu.AddExpense.value == menu_items[m.index]:
amt = input('enter total amount: ')
name = input('enter expense description: ')
os.system('cls')
print('select group\n')
gpr_menu = [x for x in g_handler.groups.keys()]
gpr_menu.append(BackButton.EXIT.name)
m = Menu()
m.draw_menu(gpr_menu)
group = g_handler.groups[gpr_menu[m.index]]
input()
os.system('cls')
print('enter split Amount for group users\n')
u_map = []
t_amount = 0
for u in group.users:
a = input(f'enter amount for {u}: ')
u_map.append((u,float(a)*-1))
t_amount+= float(a)
if abs(t_amount-float(amt))>0:
print('total amount and divide amount does not match, try again... ')
input()
os.system('cls')
continue
os.system('cls')
print('enter Amount paid by group users\n')
t_amount = 0
for u in group.users:
a = input(f'enter amount for {u}: ')
u_map.append((u, float(a)))
t_amount += float(a)
os.system('cls')
if abs(t_amount-float(amt))>0:
print('total amount and paid amount does not match, try again... ')
input()
os.system('cls')
continue
e_handler.add_expense(amt, u_map, group, name)
input('expense added successfully, press any key to continue...')
os.system('cls')
elif MainMenu.AddUser.value == menu_items[m.index]:
u_name = input('enter user name: ')
u_handler.add_user(u_name)
os.system('cls')
elif MainMenu.AddGrpMember.value == menu_items[m.index]:
print('select group\n')
gpr_menu = [x for x in g_handler.groups.keys()]
m = Menu()
gpr_menu.append(BackButton.EXIT.name)
m.draw_menu(gpr_menu)
group = gpr_menu[m.index]
input()
cgu = set(x for x in g_handler.groups[group].users)
usr_menu = [x for x in u_handler.users.keys() if x not in cgu]
usr_menu.append(BackButton.EXIT.name)
print('select user \n')
m = Menu()
m.draw_menu(usr_menu)
input()
user = usr_menu[m.index]
g_handler.add_memeber(group, user)
elif MainMenu.AddGroup.value == menu_items[m.index]:
g_name = input('enter group name: ')
g_handler.add_group(g_name)
os.system('cls')
elif MainMenu.SimplifyGroupExpense.value == menu_items[m.index]:
print('select group\n')
gpr_menu = [x for x in g_handler.groups.keys()]
m = Menu()
gpr_menu.append(BackButton.EXIT.name)
m.draw_menu(gpr_menu)
group = gpr_menu[m.index]
input()
os.system('cls')
number_of_transactions, graph = e_handler.settle_grp_expense(group)
print(f'number of transactions will be {number_of_transactions}\n')
print(f' Settlement graph:\n')
print(graph)
print('\n')
input('press any key to continue ... ')
os.system('cls')
else:
break