-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcalculate.py
240 lines (218 loc) · 9.63 KB
/
calculate.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
"""
Copyright 2021 Ashley Hines
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
https://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
Formatted in accordance with PEP-8 Using Black
"""
import json
import sys
import constants as CONSTS
# calculations Class Declaration
class taxCalculations:
## Called when class initalised
def __init__(self, fIncome, strPayIncrement, dcitTaxOptions, iHours=40):
# Get Tax Rates
self.__fIncome = fIncome
self.__payIncrement = strPayIncrement
self.__taxOptions = dcitTaxOptions
## Fixes issues where hours and !hours is increment
if strPayIncrement == CONSTS.C_INCREMENT_HOURLY:
self.__iHours = iHours
else:
self.__iHours = 40
## Open taxrates as json object and converts to object
try:
with open(CONSTS.C_TAXFILE) as fileTaxRates:
jsonData = json.load(fileTaxRates)
# print("type: ", type(self. jsonData))
strFY = dcitTaxOptions.get("iFY")
self.taxRates = jsonData["t{}".format(strFY)]
## Exit on fatal exception
except Exception as e:
print(str(e))
print(
"FATAL EXCEPTION: Cannot grab {}; Now Exiting".format(CONSTS.C_TAXFILE)
)
sys.exit(1) # sys.exit(1) Indicate non normal exit code
## Public method to calculate and return results
def calculate(self) -> dict:
self.__calcTaxableIncomeToAnnually()
self.__calculateTax()
self.__fMedicareLevy = self.__fTaxableIncome * CONSTS.C_MEDICARE_LEVY_RATE
self.__fTotaltax = self.tax + self.__fMedicareLevy + self.__fHecsOwed
self.__fNetIncome = self.__fTaxableIncome - self.__fTotaltax
self.__totalPackage = self.__fTaxableIncome + self.__fSuper
dictResponse = {
"taxableIncome": self.__fTaxableIncome,
"super": self.__fSuper,
"tax": self.tax,
"medicareLevy": self.__fMedicareLevy,
"hecsOwed": self.__fHecsOwed,
"totalTax": self.__fTotaltax,
"netIncome": self.__fNetIncome,
}
return dictResponse, self.__iHours
## Calculates taxable income and ensures its in annual format
def __calcTaxableIncomeToAnnually(self):
# PYTHON WHY NO SWITCH!!!!>.>!>!>!>!>!>!>!>>!>!>!>!
if self.__payIncrement == CONSTS.C_INCREMENT_HOURLY:
self.__fTaxableIncome = self.__fIncome * self.__iHours * CONSTS.C_WEEKSPYEAR
elif self.__payIncrement == CONSTS.C_INCREMENT_DAILY:
self.__fTaxableIncome = self.__fIncome * 5 * CONSTS.C_WEEKSPYEAR
elif self.__payIncrement == CONSTS.C_INCREMENT_WEEKLY:
self.__fTaxableIncome = self.__fIncome * CONSTS.C_WEEKSPYEAR
elif self.__payIncrement == CONSTS.C_INCREMENT_FORTNIGHTLY:
self.__fTaxableIncome = self.__fIncome * CONSTS.C_WEEKSPYEAR / 2
elif self.__payIncrement == CONSTS.C_INCREMENT_MONTHLY:
self.__fTaxableIncome = self.__fIncome * 12
else:
self.__fTaxableIncome = self.__fIncome
## PROCESS SUPERANNUATION
fSuperPercentage = 9.5 / 100
## If includes super extract super or just calculate it based off 9.5%
if self.__taxOptions.get("bSuper"):
self.__fSuper = (
self.__fTaxableIncome / (1 + fSuperPercentage) * fSuperPercentage
)
self.__fTaxableIncome -= self.__fSuper
else:
self.__fSuper = self.__fTaxableIncome * fSuperPercentage
## Calculate Income Tax & HECS
def __calculateTax(self):
self.tax = 0 # Init tax value
self.__fHecsOwed = 0
## Determine if using No Tax Free Threeshold rates or normal
if self.__taxOptions.get("bNTFT"):
taxTable = self.taxRates["NTFT"]
else:
taxTable = self.taxRates["normal"]
hecsRates = self.taxRates["HECS"]
## Calculate HECS if required
## HECS is not tax deductable so dont modify taxable income
if self.__taxOptions.get("bHECS"):
for i in hecsRates:
if self.__fTaxableIncome > hecsRates[i][0]:
self.__fHecsOwed = self.__fTaxableIncome * hecsRates[i][1]
break
remainingTaxableIncome = self.__fTaxableIncome
## Loop to calculate tax
for i in taxTable:
# print(taxTable[i])
if remainingTaxableIncome > taxTable[i][0]:
tax = (remainingTaxableIncome - taxTable[i][0]) * taxTable[i][1]
self.tax += tax
remainingTaxableIncome = taxTable[i][0]
## Calculates all the divided values for an increment
def calculateIncrementVaribles(self, INCAnnually, hours) -> tuple:
# hourly
INCHourly = {}
INCHourly.update({"Increment": "Hourly ({})".format(hours)})
INCHourly.update(
{
"taxableIncome": (
INCAnnually.get("taxableIncome") / CONSTS.C_WEEKSPYEAR / hours
)
}
)
INCHourly.update(
{"super": (INCAnnually.get("super") / CONSTS.C_WEEKSPYEAR / hours)}
)
INCHourly.update({"tax": (INCAnnually.get("tax") / CONSTS.C_WEEKSPYEAR / hours)})
INCHourly.update(
{
"medicareLevy": (
INCAnnually.get("medicareLevy") / CONSTS.C_WEEKSPYEAR / hours
)
}
)
INCHourly.update(
{"hecsOwed": (INCAnnually.get("hecsOwed") / CONSTS.C_WEEKSPYEAR / hours)}
)
INCHourly.update(
{"totalTax": (INCAnnually.get("totalTax") / CONSTS.C_WEEKSPYEAR / hours)}
)
INCHourly.update(
{"netIncome": (INCAnnually.get("netIncome") / CONSTS.C_WEEKSPYEAR / hours)}
)
# Daily
INCDaily = {}
INCDaily.update({"Increment": "Daily"})
INCDaily.update(
{"taxableIncome": (INCAnnually.get("taxableIncome") / CONSTS.C_WEEKSPYEAR / 5)}
)
INCDaily.update({"super": (INCAnnually.get("super") / CONSTS.C_WEEKSPYEAR / 5)})
INCDaily.update({"tax": (INCAnnually.get("tax") / CONSTS.C_WEEKSPYEAR / 5)})
INCDaily.update(
{"medicareLevy": (INCAnnually.get("medicareLevy") / CONSTS.C_WEEKSPYEAR / 5)}
)
INCDaily.update(
{"hecsOwed": (INCAnnually.get("hecsOwed") / CONSTS.C_WEEKSPYEAR / 5)}
)
INCDaily.update(
{"totalTax": (INCAnnually.get("totalTax") / CONSTS.C_WEEKSPYEAR / 5)}
)
INCDaily.update(
{"netIncome": (INCAnnually.get("netIncome") / CONSTS.C_WEEKSPYEAR / 5)}
)
# Weekly
INCWeekly = {}
INCWeekly.update({"Increment": "Weekly"})
INCWeekly.update(
{"taxableIncome": (INCAnnually.get("taxableIncome") / CONSTS.C_WEEKSPYEAR)}
)
INCWeekly.update({"super": (INCAnnually.get("super") / CONSTS.C_WEEKSPYEAR)})
INCWeekly.update({"tax": (INCAnnually.get("tax") / CONSTS.C_WEEKSPYEAR)})
INCWeekly.update(
{"medicareLevy": (INCAnnually.get("medicareLevy") / CONSTS.C_WEEKSPYEAR)}
)
INCWeekly.update({"hecsOwed": (INCAnnually.get("hecsOwed") / CONSTS.C_WEEKSPYEAR)})
INCWeekly.update({"totalTax": (INCAnnually.get("totalTax") / CONSTS.C_WEEKSPYEAR)})
INCWeekly.update(
{"netIncome": (INCAnnually.get("netIncome") / CONSTS.C_WEEKSPYEAR)}
)
# Fortnightly
INCFornightly = {}
INCFornightly.update({"Increment": "Fortnightly"})
INCFornightly.update(
{
"taxableIncome": (
INCAnnually.get("taxableIncome") / (CONSTS.C_WEEKSPYEAR / 2)
)
}
)
INCFornightly.update(
{"super": (INCAnnually.get("super") / (CONSTS.C_WEEKSPYEAR / 2))}
)
INCFornightly.update({"tax": (INCAnnually.get("tax") / (CONSTS.C_WEEKSPYEAR / 2))})
INCFornightly.update(
{"medicareLevy": (INCAnnually.get("medicareLevy") / (CONSTS.C_WEEKSPYEAR / 2))}
)
INCFornightly.update(
{"hecsOwed": (INCAnnually.get("hecsOwed") / (CONSTS.C_WEEKSPYEAR / 2))}
)
INCFornightly.update(
{"totalTax": (INCAnnually.get("totalTax") / (CONSTS.C_WEEKSPYEAR / 2))}
)
INCFornightly.update(
{"netIncome": (INCAnnually.get("netIncome") / (CONSTS.C_WEEKSPYEAR / 2))}
)
# Monthly
INCMonthly = {}
INCMonthly.update({"Increment": "Monthly"})
INCMonthly.update({"taxableIncome": (INCAnnually.get("taxableIncome") / 12)})
INCMonthly.update({"super": (INCAnnually.get("super") / 12)})
INCMonthly.update({"tax": (INCAnnually.get("tax") / 12)})
INCMonthly.update({"medicareLevy": (INCAnnually.get("medicareLevy") / 12)})
INCMonthly.update({"hecsOwed": (INCAnnually.get("hecsOwed") / 12)})
INCMonthly.update({"totalTax": (INCAnnually.get("totalTax") / 12)})
INCMonthly.update({"netIncome": (INCAnnually.get("netIncome") / 12)})
INCAnnually.update({"Increment": "Annually"})
tupleRows = (INCHourly, INCDaily, INCWeekly, INCFornightly, INCMonthly, INCAnnually)
return tupleRows