File size: 7,171 Bytes
9af1696
95bad29
 
 
9af1696
b398e78
d769745
b398e78
9af1696
b398e78
 
 
 
9af1696
b398e78
 
 
 
9af1696
b398e78
 
d769745
9af1696
 
 
d769745
 
95bad29
 
 
 
d769745
 
 
 
 
 
 
9af1696
 
d769745
 
 
 
 
 
 
 
95bad29
d769745
 
 
 
 
 
 
 
95bad29
d769745
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b398e78
 
 
 
 
 
9af1696
 
 
 
b398e78
95bad29
b398e78
95bad29
 
 
 
 
 
 
 
 
 
 
 
 
b398e78
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
9af1696
 
 
 
d769745
9af1696
 
 
 
 
 
 
 
 
 
 
 
 
 
b398e78
 
 
 
5858a75
 
 
 
 
 
 
 
 
 
 
 
 
 
b398e78
 
 
95bad29
5858a75
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
b398e78
 
 
 
 
 
95bad29
b398e78
 
 
 
 
95bad29
 
b398e78
 
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
import pandas as pd
import streamlit as st

from functions import Functions, StreamlitFunctions
from logs import logger


def calculate_salary_parameters():
    logger.info("Calculating based on Salary parameters")
    st.session_state.type_to_calculate = "salary_parameters"


def calculate_initial_salary_parameter():
    logger.info("Calculating based on Desired Salary")
    st.session_state.type_to_calculate = "desired_salary"


def calculate_tax_on_current_salary():
    logger.info("Calculating Tax on Current Salary")
    st.session_state.type_to_calculate = "tax_on_current_salary"


def calculate_tax_on_yearly_salary():
    logger.info("Calculating Tax on Yearly Salary")
    st.session_state.type_to_calculate = "tax_on_yearly_salary"


StreamlitFunctions.initialize_session_values()
StreamlitFunctions.print_tax_brackets()
StreamlitFunctions.reset_tax_brackets()

tab1, tab2, tab3, tab4 = st.tabs(
    [
        "Tax on Monthly Salary",
        "Tax on Yearly Salary",
        "Final Desired Net Salary",
        "Desired Salary Calculation",
    ]
)

with tab1:
    StreamlitFunctions.print_tax_on_current_salary()
    StreamlitFunctions.reset_tax_on_current_salary()
    st.button(
        "Calculate Tax on Current Salary",
        use_container_width=True,
        on_click=calculate_tax_on_current_salary,
    )

with tab2:
    StreamlitFunctions.print_tax_on_yearly_salary()
    StreamlitFunctions.reset_tax_on_yearly_salary()
    st.button(
        "Calculate Tax on Yearly Salary",
        use_container_width=True,
        on_click=calculate_tax_on_yearly_salary,
    )

with tab3:
    StreamlitFunctions.initial_salary_parameter()
    StreamlitFunctions.reset_initial_salary_parameter()
    st.button(
        "Calculate Based on Desired Net Salary",
        use_container_width=True,
        on_click=calculate_initial_salary_parameter,
    )

with tab4:
    StreamlitFunctions.print_salary_parameters()
    StreamlitFunctions.reset_salary_parameters()
    st.button(
        "Calculate Based on Salary Parameters",
        use_container_width=True,
        on_click=calculate_salary_parameters,
    )

if st.session_state.type_to_calculate is not None:
    if st.session_state.type_to_calculate == "tax_on_current_salary":
        initial_desired_net = Functions.calculated_current_salary_after_tax(
            st.session_state.tax_on_current_salary, st.session_state.tax_brackets
        )
    elif st.session_state.type_to_calculate == "tax_on_yearly_salary":
        initial_desired_net = Functions.calculated_yearly_salary_after_tax(
            st.session_state.tax_on_yearly_salary, st.session_state.tax_brackets
        )
    elif st.session_state.type_to_calculate == "desired_salary":
        initial_desired_net = st.session_state.user_initial_desired_net
    elif st.session_state.type_to_calculate == "salary_parameters":
        initial_desired_net = Functions.calculated_initial_desired_net(
            st.session_state.current_salary,
            st.session_state.desired_increment_percentage,
            st.session_state.daily_cost_of_travel,
            st.session_state.physical_days_per_week,
        )

    result = Functions.calculate_additional_amount(
        initial_desired_net, st.session_state.tax_brackets
    )

    # Display how initial_desired_net was determined
    st.markdown("---")
    if st.session_state.type_to_calculate == "tax_on_current_salary":
        st.success(
            "βœ… Calculation was done based on the selected value of 'Tax on Current Salary'"
        )
        summary_df = pd.DataFrame(
            {
                "Parameter": [
                    "Current Salary",
                    "Tax",
                    "Gross Salary",
                ],
                "Value": [
                    f"PKR {result['final_net_salary']:,.2f}",
                    f"PKR {result['tax']:,.2f}",
                    f"PKR {result['gross_salary_needed']:,.2f}",
                ],
            }
        )
    elif st.session_state.type_to_calculate == "tax_on_yearly_salary":
        st.success(
            "βœ… Calculation was done based on the selected value of 'Tax on Yearly Salary'"
        )
        result = {key: value * 12 for key, value in result.items()}
        summary_df = pd.DataFrame(
            {
                "Parameter": [
                    "Yearly Salary",
                    "Yearly Tax",
                    "Gross Yearly Salary",
                ],
                "Value": [
                    f"PKR {result['final_net_salary']:,.2f}",
                    f"PKR {result['tax']:,.2f}",
                    f"PKR {result['gross_salary_needed']:,.2f}",
                ],
            }
        )
    elif st.session_state.type_to_calculate == "desired_salary":
        st.success(
            "βœ… Calculation was done based on the selected value of 'Final Desired Net Salary'"
        )
        summary_df = pd.DataFrame(
            {
                "Parameter": [
                    "Final Net Salary",
                    "Tax",
                    "Gross Salary",
                ],
                "Value": [
                    f"PKR {result['final_net_salary']:,.2f}",
                    f"PKR {result['tax']:,.2f}",
                    f"PKR {result['gross_salary_needed']:,.2f}",
                ],
            }
        )
    elif st.session_state.type_to_calculate == "salary_parameters":
        st.success(
            "βœ… Calculation was done based on the selected values of 'Salary Parameters'"
        )
        summary_df = pd.DataFrame(
            {
                "Parameter": [
                    "Current Salary",
                    "Desired Increment",
                    "Daily Travel Cost",
                    "On-Site Days/Week",
                    "Gross Salary",
                    "Tax",
                    "Final Net Salary",
                ],
                "Value": [
                    f"PKR {st.session_state.current_salary:,.2f}",
                    f"{st.session_state.desired_increment_percentage:.2%}",
                    f"PKR {st.session_state.daily_cost_of_travel:,.2f}",
                    f"{st.session_state.physical_days_per_week}",
                    f"PKR {result['gross_salary_needed']:,.2f}",
                    f"PKR {result['tax']:,.2f}",
                    f"PKR {result['final_net_salary']:,.2f}",
                ],
            }
        )
    st.header("Salary Calculation Results")
    col1, col2 = st.columns(2)
    with col1:
        # custom_metric("Initial Desired Net Salary", result['initial_desired_net'])
        StreamlitFunctions.custom_metric("Final Net Salary", result["final_net_salary"])
        StreamlitFunctions.custom_metric("Tax", result["tax"])

    with col2:
        # custom_metric("Additional Amount Needed", result['additional_amount'])
        StreamlitFunctions.custom_metric(
            "Gross Salary Needed", result["gross_salary_needed"]
        )
    # Display a summary of the calculation
    st.subheader("Calculation Summary")
    st.data_editor(summary_df, use_container_width=True, hide_index=True)
    st.session_state.type_to_calculate = None