Skip to content

Commit 186c551

Browse files
Added a finance tracker app
1 parent 792e5b3 commit 186c551

File tree

5 files changed

+1705
-0
lines changed

5 files changed

+1705
-0
lines changed

PYTHON APPS/FinanceTracker/Finance.db

40 KB
Binary file not shown.

PYTHON APPS/FinanceTracker/confirm.ui

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<ui version="4.0">
3+
<class>Dialog</class>
4+
<widget class="QDialog" name="Dialog">
5+
<property name="geometry">
6+
<rect>
7+
<x>0</x>
8+
<y>0</y>
9+
<width>1190</width>
10+
<height>766</height>
11+
</rect>
12+
</property>
13+
<property name="windowTitle">
14+
<string>Dialog</string>
15+
</property>
16+
<property name="styleSheet">
17+
<string notr="true">QDialog#Dialog{
18+
background-color: qlineargradient(spread:pad, x1:0, y1:0, x2:1, y2:1, stop:0 rgba(67, 206, 162, 1), stop:1 rgba(24, 90, 157, 1));
19+
}</string>
20+
</property>
21+
<widget class="QPushButton" name="proceedButton">
22+
<property name="geometry">
23+
<rect>
24+
<x>350</x>
25+
<y>250</y>
26+
<width>140</width>
27+
<height>50</height>
28+
</rect>
29+
</property>
30+
<property name="font">
31+
<font>
32+
<pointsize>14</pointsize>
33+
<weight>75</weight>
34+
<bold>true</bold>
35+
</font>
36+
</property>
37+
<property name="styleSheet">
38+
<string notr="true">QPushButton{
39+
background-color: rgb(222, 255, 201); font-size: 14pt;
40+
border-radius: 10px;
41+
}
42+
43+
QPushButton:hover{
44+
background-color: rgb(85, 255, 255);
45+
}</string>
46+
</property>
47+
<property name="text">
48+
<string>Yes Proceed</string>
49+
</property>
50+
</widget>
51+
<widget class="QPushButton" name="cancelButton">
52+
<property name="geometry">
53+
<rect>
54+
<x>580</x>
55+
<y>250</y>
56+
<width>170</width>
57+
<height>50</height>
58+
</rect>
59+
</property>
60+
<property name="font">
61+
<font>
62+
<pointsize>14</pointsize>
63+
<weight>75</weight>
64+
<bold>true</bold>
65+
</font>
66+
</property>
67+
<property name="styleSheet">
68+
<string notr="true">QPushButton{
69+
background-color: rgb(222, 255, 201); font-size: 14pt;
70+
border-radius: 10px;
71+
}
72+
73+
QPushButton:hover{
74+
background-color: rgb(255, 83, 83);
75+
}</string>
76+
</property>
77+
<property name="text">
78+
<string>Cancel/Go back</string>
79+
</property>
80+
</widget>
81+
<widget class="QLabel" name="warning">
82+
<property name="geometry">
83+
<rect>
84+
<x>270</x>
85+
<y>170</y>
86+
<width>801</width>
87+
<height>61</height>
88+
</rect>
89+
</property>
90+
<property name="font">
91+
<font>
92+
<pointsize>13</pointsize>
93+
<weight>75</weight>
94+
<bold>true</bold>
95+
</font>
96+
</property>
97+
<property name="text">
98+
<string>Are you sure you want to delete eveyrthing? This action CANNOT be undone!</string>
99+
</property>
100+
</widget>
101+
</widget>
102+
<resources/>
103+
<connections/>
104+
</ui>
Lines changed: 188 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,188 @@
1+
import sqlite3
2+
from matplotlib import pyplot as plt
3+
4+
plt.style.use('ggplot')
5+
6+
7+
def send_bg_color(color):
8+
connection = sqlite3.connect("Finance.db")
9+
cur = connection.cursor()
10+
cur.execute(f"UPDATE colorChoice SET color = (:color) WHERE rowid = 1", {"color": color})
11+
connection.commit()
12+
connection.close()
13+
14+
15+
def get_bg_color():
16+
connection = sqlite3.connect("Finance.db")
17+
cur = connection.cursor()
18+
cur.execute(f"SELECT * FROM colorChoice")
19+
data = cur.fetchall()
20+
return data[0][0]
21+
22+
23+
def send_data(query, data):
24+
connection = sqlite3.connect("Finance.db")
25+
cur = connection.cursor()
26+
num_data = int(data)
27+
cur.execute(f"INSERT INTO {query} VALUES (:payed)", {"payed": num_data})
28+
connection.commit()
29+
connection.close()
30+
31+
32+
def update_record(query, data):
33+
connection = sqlite3.connect("Finance.db")
34+
cur = connection.cursor()
35+
num_data = int(data)
36+
cur.execute(f"UPDATE {query} SET userGoal = (:goal) WHERE rowid = 1", {"goal": num_data})
37+
connection.commit()
38+
connection.close()
39+
40+
41+
def sum_partic_expense(query):
42+
connection = sqlite3.connect("Finance.db")
43+
cur = connection.cursor()
44+
cur.execute(f"SELECT SUM(payed) FROM {query}")
45+
d = cur.fetchall()
46+
connection.commit()
47+
connection.close()
48+
return d[0][0]
49+
50+
51+
def get_total_spent():
52+
spent = 0
53+
spent_fun = sum_partic_expense("FUN")
54+
spent_transportation = sum_partic_expense("TRANSPORTATION")
55+
spent_food = sum_partic_expense("FOOD")
56+
spent_clothes = sum_partic_expense("CLOTHES")
57+
spent_bills = sum_partic_expense("BILLS")
58+
spent_other = sum_partic_expense("OTHER")
59+
60+
if spent_fun is not None:
61+
spent += spent_fun
62+
63+
if spent_transportation is not None:
64+
spent += spent_transportation
65+
66+
if spent_food is not None:
67+
spent += spent_food
68+
69+
if spent_clothes is not None:
70+
spent += spent_clothes
71+
72+
if spent_bills is not None:
73+
spent += spent_bills
74+
75+
if spent_other is not None:
76+
spent += spent_other
77+
78+
return spent
79+
80+
81+
def get_data(query):
82+
connection = sqlite3.connect("Finance.db")
83+
cur = connection.cursor()
84+
cur.execute(f"SELECT * FROM {query}")
85+
c = cur.fetchall()
86+
connection.commit()
87+
connection.close()
88+
return c
89+
90+
91+
def graph(graph_type):
92+
g_type = get_data(graph_type)
93+
plt.plot(range(1, len(g_type) + 1), g_type)
94+
plt.title(f"MONEY($) spent on category: {graph_type}")
95+
plt.xlabel("Number of purchases")
96+
plt.ylabel("CAD ($)")
97+
plt.show()
98+
99+
100+
def graph_all():
101+
labels = []
102+
slices = []
103+
104+
fun = sum_partic_expense("FUN")
105+
transport = sum_partic_expense("TRANSPORTATION")
106+
food = sum_partic_expense("FOOD")
107+
clothes = sum_partic_expense("CLOTHES")
108+
bills = sum_partic_expense("BILLS")
109+
other = sum_partic_expense("OTHER")
110+
111+
if fun is not None:
112+
labels.append("FUN")
113+
slices.append(fun)
114+
115+
if transport is not None:
116+
labels.append("TRANSPORT")
117+
slices.append(transport)
118+
119+
if food is not None:
120+
labels.append("FOOD")
121+
slices.append(food)
122+
123+
if clothes is not None:
124+
labels.append("CLOTHES")
125+
slices.append(clothes)
126+
127+
if bills is not None:
128+
labels.append("BILLS")
129+
slices.append(bills)
130+
131+
if other is not None:
132+
labels.append("OTHER")
133+
slices.append(other)
134+
135+
colors = ("limegreen", "cyan", "yellow", "pink",
136+
"red", "lightblue")
137+
138+
plt.pie(slices, labels=labels, shadow=True, wedgeprops={'edgecolor': 'black'}, autopct=f"%0.2f%%", colors=colors)
139+
plt.title("PIE CHART")
140+
plt.tight_layout()
141+
plt.show()
142+
143+
144+
def get_count(query):
145+
con = sqlite3.connect("Finance.db")
146+
cur = con.cursor()
147+
cur.execute(f"SELECT COUNT (*) FROM {query}")
148+
count = cur.fetchall()
149+
con.commit()
150+
con.close()
151+
return count[0][0]
152+
153+
154+
def delete_recent(query):
155+
con = sqlite3.connect("Finance.db")
156+
count = get_count(query)
157+
cur = con.cursor()
158+
cur.execute(f"DELETE FROM {query} WHERE rowid= (:delete)", {"delete": count})
159+
con.commit()
160+
con.close()
161+
162+
163+
"""
164+
This will drop the table,
165+
then it will create a new table since there sqlite does not support truncate function
166+
"""
167+
168+
169+
def delete_data_in_table(query):
170+
con = sqlite3.connect("Finance.db")
171+
cur = con.cursor()
172+
cur.execute(f"DROP TABLE {query}")
173+
cur.execute(f"""CREATE TABLE {query}(
174+
payed real
175+
)""")
176+
con.commit()
177+
con.close()
178+
179+
180+
def delete_all():
181+
delete_data_in_table("fun")
182+
delete_data_in_table("transportation")
183+
delete_data_in_table("food")
184+
delete_data_in_table("clothes")
185+
delete_data_in_table("bills")
186+
delete_data_in_table("other")
187+
188+

0 commit comments

Comments
 (0)