mattoofahad commited on
Commit
9af1696
β€’
1 Parent(s): e947fcb

adding yearly salary tax calculator

Browse files
Files changed (3) hide show
  1. app.py +48 -11
  2. constants.py +1 -0
  3. functions.py +42 -0
app.py CHANGED
@@ -1,31 +1,45 @@
 
1
  import streamlit as st
2
 
3
  from functions import Functions, StreamlitFunctions
4
- import pandas as pd
5
-
6
 
7
  def calculate_salary_parameters():
 
8
  st.session_state.type_to_calculate = "salary_parameters"
9
 
10
 
11
  def calculate_initial_salary_parameter():
 
12
  st.session_state.type_to_calculate = "desired_salary"
13
 
14
 
15
  def calculate_tax_on_current_salary():
 
16
  st.session_state.type_to_calculate = "tax_on_current_salary"
17
 
18
-
 
 
 
19
  StreamlitFunctions.initialize_session_values()
20
  StreamlitFunctions.print_tax_brackets()
21
  StreamlitFunctions.reset_tax_brackets()
22
 
23
- StreamlitFunctions.print_salary_parameters()
24
- StreamlitFunctions.reset_salary_parameters()
25
  st.button(
26
- "Calculate Based on Salary Parameters",
27
  use_container_width=True,
28
- on_click=calculate_salary_parameters,
 
 
 
 
 
 
 
 
29
  )
30
 
31
  StreamlitFunctions.initial_salary_parameter()
@@ -36,12 +50,12 @@ st.button(
36
  on_click=calculate_initial_salary_parameter,
37
  )
38
 
39
- StreamlitFunctions.print_tax_on_current_salary()
40
- StreamlitFunctions.reset_tax_on_current_salary()
41
  st.button(
42
- "Calculate Tax on Current Salary",
43
  use_container_width=True,
44
- on_click=calculate_tax_on_current_salary,
45
  )
46
 
47
  if st.session_state.type_to_calculate is not None:
@@ -49,6 +63,10 @@ if st.session_state.type_to_calculate is not None:
49
  initial_desired_net = Functions.calculated_current_salary_after_tax(
50
  st.session_state.tax_on_current_salary, st.session_state.tax_brackets
51
  )
 
 
 
 
52
  elif st.session_state.type_to_calculate == "desired_salary":
53
  initial_desired_net = st.session_state.user_initial_desired_net
54
  elif st.session_state.type_to_calculate == "salary_parameters":
@@ -83,6 +101,25 @@ if st.session_state.type_to_calculate is not None:
83
  ],
84
  }
85
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
  elif st.session_state.type_to_calculate == "desired_salary":
87
  st.success(
88
  "βœ… Calculation was done based on the selected value of 'Final Desired Net Salary'"
 
1
+ import pandas as pd
2
  import streamlit as st
3
 
4
  from functions import Functions, StreamlitFunctions
5
+ from logs import logger
 
6
 
7
  def calculate_salary_parameters():
8
+ logger.info("Calculating based on Salary parameters")
9
  st.session_state.type_to_calculate = "salary_parameters"
10
 
11
 
12
  def calculate_initial_salary_parameter():
13
+ logger.info("Calculating based on Desired Salary")
14
  st.session_state.type_to_calculate = "desired_salary"
15
 
16
 
17
  def calculate_tax_on_current_salary():
18
+ logger.info("Calculating Tax on Current Salary")
19
  st.session_state.type_to_calculate = "tax_on_current_salary"
20
 
21
+ def calculate_tax_on_yearly_salary():
22
+ logger.info("Calculating Tax on Yearly Salary")
23
+ st.session_state.type_to_calculate = "tax_on_yearly_salary"
24
+
25
  StreamlitFunctions.initialize_session_values()
26
  StreamlitFunctions.print_tax_brackets()
27
  StreamlitFunctions.reset_tax_brackets()
28
 
29
+ StreamlitFunctions.print_tax_on_current_salary()
30
+ StreamlitFunctions.reset_tax_on_current_salary()
31
  st.button(
32
+ "Calculate Tax on Current Salary",
33
  use_container_width=True,
34
+ on_click=calculate_tax_on_current_salary,
35
+ )
36
+
37
+ StreamlitFunctions.print_tax_on_yearly_salary()
38
+ StreamlitFunctions.reset_tax_on_yearly_salary()
39
+ st.button(
40
+ "Calculate Tax on Yearly Salary",
41
+ use_container_width=True,
42
+ on_click=calculate_tax_on_yearly_salary,
43
  )
44
 
45
  StreamlitFunctions.initial_salary_parameter()
 
50
  on_click=calculate_initial_salary_parameter,
51
  )
52
 
53
+ StreamlitFunctions.print_salary_parameters()
54
+ StreamlitFunctions.reset_salary_parameters()
55
  st.button(
56
+ "Calculate Based on Salary Parameters",
57
  use_container_width=True,
58
+ on_click=calculate_salary_parameters,
59
  )
60
 
61
  if st.session_state.type_to_calculate is not None:
 
63
  initial_desired_net = Functions.calculated_current_salary_after_tax(
64
  st.session_state.tax_on_current_salary, st.session_state.tax_brackets
65
  )
66
+ elif st.session_state.type_to_calculate == "tax_on_yearly_salary":
67
+ initial_desired_net = Functions.calculated_yearly_salary_after_tax(
68
+ st.session_state.tax_on_yearly_salary, st.session_state.tax_brackets
69
+ )
70
  elif st.session_state.type_to_calculate == "desired_salary":
71
  initial_desired_net = st.session_state.user_initial_desired_net
72
  elif st.session_state.type_to_calculate == "salary_parameters":
 
101
  ],
102
  }
103
  )
104
+ elif st.session_state.type_to_calculate == "tax_on_yearly_salary":
105
+ st.success(
106
+ "βœ… Calculation was done based on the selected value of 'Tax on Yearly Salary'"
107
+ )
108
+ result = {key:value*12 for key, value in result.items()}
109
+ summary_df = pd.DataFrame(
110
+ {
111
+ "Parameter": [
112
+ "Yearly Salary",
113
+ "Yearly Tax",
114
+ "Gross Yearly Salary",
115
+ ],
116
+ "Value": [
117
+ f"PKR {result['final_net_salary']:,.2f}",
118
+ f"PKR {result['tax']:,.2f}",
119
+ f"PKR {result['gross_salary_needed']:,.2f}",
120
+ ],
121
+ }
122
+ )
123
  elif st.session_state.type_to_calculate == "desired_salary":
124
  st.success(
125
  "βœ… Calculation was done based on the selected value of 'Final Desired Net Salary'"
constants.py CHANGED
@@ -5,6 +5,7 @@ class Constants:
5
  DEFAULT_PHYSICAL_DAYS = 5
6
  DEFAULT_INITIAL_NET = 212500.0
7
  DEFAULT_CURRENT_SALARY_WITH_TAX = 200000.0
 
8
 
9
  DEFAULT_TAX_BRACKETS = [
10
  (0, 600000, 0),
 
5
  DEFAULT_PHYSICAL_DAYS = 5
6
  DEFAULT_INITIAL_NET = 212500.0
7
  DEFAULT_CURRENT_SALARY_WITH_TAX = 200000.0
8
+ DEFAULT_YEARLY_SALARY_WITH_TAX = 1500000.0
9
 
10
  DEFAULT_TAX_BRACKETS = [
11
  (0, 600000, 0),
functions.py CHANGED
@@ -8,6 +8,12 @@ class Functions:
8
  return current_salary - Functions.calculate_monthly_tax(
9
  current_salary, tax_brackets
10
  )
 
 
 
 
 
 
11
 
12
  @staticmethod
13
  def calculate_monthly_tax(monthly_income, tax_brackets):
@@ -150,6 +156,19 @@ class StreamlitFunctions:
150
  on_click=reset_values,
151
  )
152
 
 
 
 
 
 
 
 
 
 
 
 
 
 
153
  @staticmethod
154
  def print_tax_on_current_salary():
155
  st.header("Tax on Current Salary")
@@ -168,6 +187,25 @@ class StreamlitFunctions:
168
  key="tax_on_current_salary_state",
169
  on_change=update_tax_on_current_salary_parameter,
170
  )
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
171
 
172
  @staticmethod
173
  def print_salary_parameters():
@@ -257,6 +295,10 @@ class StreamlitFunctions:
257
  st.session_state.tax_on_current_salary = (
258
  Constants.DEFAULT_CURRENT_SALARY_WITH_TAX
259
  )
 
 
 
 
260
  if "current_salary" not in st.session_state:
261
  st.session_state.current_salary = Constants.DEFAULT_CURRENT_SALARY
262
  if "desired_increment_percentage" not in st.session_state:
 
8
  return current_salary - Functions.calculate_monthly_tax(
9
  current_salary, tax_brackets
10
  )
11
+
12
+ @staticmethod
13
+ def calculated_yearly_salary_after_tax(current_salary, tax_brackets):
14
+ return current_salary/12 - Functions.calculate_monthly_tax(
15
+ current_salary/12, tax_brackets
16
+ )
17
 
18
  @staticmethod
19
  def calculate_monthly_tax(monthly_income, tax_brackets):
 
156
  on_click=reset_values,
157
  )
158
 
159
+ @staticmethod
160
+ def reset_tax_on_yearly_salary():
161
+ def reset_values():
162
+ st.session_state.tax_on_yearly_salary = (
163
+ Constants.DEFAULT_YEARLY_SALARY_WITH_TAX
164
+ )
165
+
166
+ st.button(
167
+ "Reset Yearly Salary",
168
+ use_container_width=True,
169
+ on_click=reset_values,
170
+ )
171
+
172
  @staticmethod
173
  def print_tax_on_current_salary():
174
  st.header("Tax on Current Salary")
 
187
  key="tax_on_current_salary_state",
188
  on_change=update_tax_on_current_salary_parameter,
189
  )
190
+
191
+ @staticmethod
192
+ def print_tax_on_yearly_salary():
193
+ st.header("Tax on Yearly Salary")
194
+
195
+ def update_tax_on_yearly_salary_parameter():
196
+ st.session_state.tax_on_yearly_salary = (
197
+ st.session_state.tax_on_yearly_salary_state
198
+ )
199
+ st.session_state.type_to_calculate = "tax_on_current_salary"
200
+
201
+ st.number_input(
202
+ "Current Yearly Salary (PKR)",
203
+ min_value=0.0,
204
+ step=50000.0,
205
+ value=st.session_state.tax_on_yearly_salary,
206
+ key="tax_on_yearly_salary_state",
207
+ on_change=update_tax_on_yearly_salary_parameter,
208
+ )
209
 
210
  @staticmethod
211
  def print_salary_parameters():
 
295
  st.session_state.tax_on_current_salary = (
296
  Constants.DEFAULT_CURRENT_SALARY_WITH_TAX
297
  )
298
+ if "tax_on_yearly_salary" not in st.session_state:
299
+ st.session_state.tax_on_yearly_salary = (
300
+ Constants.DEFAULT_YEARLY_SALARY_WITH_TAX
301
+ )
302
  if "current_salary" not in st.session_state:
303
  st.session_state.current_salary = Constants.DEFAULT_CURRENT_SALARY
304
  if "desired_increment_percentage" not in st.session_state: