Viewing File: /home/ubuntu/codegamaai-test/taxtrax_calculators/app.py
import os
from fastapi.middleware.cors import CORSMiddleware
from fastapi import FastAPI,Form,BackgroundTasks
from supertokens_fastapi import get_cors_allowed_headers
import uvicorn
import shutil
from fastapi import FastAPI
from threading import Thread
from help_calc import *
app = FastAPI()
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"] + get_cors_allowed_headers(),
)
@app.post("/api/v1/sip-calculator")
async def calculate_sip(data:dict):
principal = data['principal']
rate_of_interest = data['rate_of_interest']
time_period = data['time_period']
maturity_amount, invested_amount, estimated_return = sip_calculator(principal, rate_of_interest, time_period)
return {"maturity_amount": maturity_amount, "invested_amount": invested_amount, "estimated_return": estimated_return, "status": "success", "message": "Calculation successful"}
@app.post("/api/v1/lumpsum-calculator")
async def calculate_lumpsum(data:dict):
principal = data['principal']
rate_of_interest = data['rate_of_interest']
time_period = data['time_period']
maturity_amount, invested_amount, estimated_return = lumpsum_calculator(principal, rate_of_interest, time_period)
return {"maturity_amount": maturity_amount, "invested_amount": invested_amount, "estimated_return": estimated_return, "status": "success", "message": "Calculation successful"}
@app.post("/api/v1/swp-calculator")
async def calculate_swp(data:dict):
total_investment = data['total_investment']
withdrawl_per_month = data['withdrawl_per_month']
rate_of_interest = data['rate_of_interest']
time_period = data['time_period']
compounding_frequency = data['compounding_frequency']
total_investment, total_withdrawl, final_value = swp_calculator(total_investment, withdrawl_per_month, rate_of_interest, time_period, compounding_frequency)
return {"total_investment": total_investment, "total_withdrawl": total_withdrawl, "final_value": final_value, "status": "success", "message": "Calculation successful"}
@app.post("/api/v1/mf_calculator")
async def calculate_mf(data:dict):
principal = data['principal']
rate_of_interest = data['rate_of_interest']
time_period = data['time_period']
maturity_amount, invested_amount, estimated_return = mf_calculator(principal, rate_of_interest, time_period)
return {"maturity_amount": maturity_amount, "invested_amount": invested_amount, "estimated_return": estimated_return, "status": "success", "message": "Calculation successful"}
@app.post("/api/v1/ssy_calculator")
async def calculate_ssy(data:dict):
yearly_investment = data['yearly_investment']
girl_age = data['girl_age']
start_period = data['start_period']
ssy_interest_rate = data['ssy_interest_rate']
compounding_frequency = data['compounding_frequency']
total_investment, maturity_amount, interest_earned, maturity_year = ssy_calculator(yearly_investment, girl_age, start_period, ssy_interest_rate, compounding_frequency)
return {"total_investment": total_investment, "maturity_amount": maturity_amount, "interest_earned": interest_earned, "maturity_year": maturity_year, "status": "success", "message": "Calculation successful"}
@app.post("/api/v1/ppf_calculator")
async def calculate_ppf(data:dict):
principal = data['principal']
rate_of_interest = data['rate_of_interest']
time_period = data['time_period']
maturity_amount, invested_amount, estimated_return = ppf_calculator(principal, time_period, rate_of_interest)
return {"maturity_amount": maturity_amount, "invested_amount": invested_amount, "estimated_return": estimated_return, "status": "success", "message": "Calculation successful"}
@app.post("/api/v1/epf_calculator")
async def calculate_epf(data:dict):
monthly_salary = data['monthly_salary']
age = data['age']
epf_contribution = data['epf_contribution']
rate_of_interest = data['rate_of_interest']
annual_increase = data['annual_increase']
estimated_return = epf_calculator(monthly_salary, age, epf_contribution, rate_of_interest, annual_increase)
return {"estimated_return": estimated_return, "status": "success", "message": "Calculation successful"}
@app.post("/api/v1/fd_calculator")
async def calculate_fd(data:dict):
principal = data['principal']
rate_of_interest = data['rate_of_interest']
time_period = data['time_period']
compounding_frequency = data['compounding_frequency']
maturity_amount, invested_amount, estimated_return = fd_calculator_compound(principal, rate_of_interest, time_period, compounding_frequency)
return {"maturity_amount": maturity_amount, "invested_amount": invested_amount, "estimated_return": estimated_return, "status": "success", "message": "Calculation successful"}
@app.post("/api/v1/rd_calculator")
async def calculate_rd(data:dict):
monthly_investment = data['monthly_investment']
rate_of_interest = data['rate_of_interest']
time_period = data['time_period']
maturity_amount, invested_amount, estimated_return = rd_calculator(monthly_investment, rate_of_interest, time_period)
return {"maturity_amount": maturity_amount, "invested_amount": invested_amount, "estimated_return": estimated_return, "status": "success", "message": "Calculation successful"}
@app.post("/api/v1/nps_calculator")
async def calculate_nps(data:dict):
monthly_investment = data['monthly_investment']
rate_of_interest = data['rate_of_interest']
current_age = data['current_age']
compound_frequency = data['compound_frequency']
maturity_amount, invested_amount, estimated_return, min_annuity_amount = nps_calculator(monthly_investment, rate_of_interest, current_age, compound_frequency)
return {"maturity_amount": maturity_amount, "invested_amount": invested_amount, "estimated_return": estimated_return, "min_annuity_amount": min_annuity_amount, "status": "success", "message": "Calculation successful"}
@app.post("/api/v1/calculate_hra")
async def calculate_hra(data:dict):
location = data['location'] # Metro or Non-Metro
basic_salary = data['basic_salary']
dearness_allownces = data['dearness_allownces']
hra = data['hra']
hra_actual = data['hra_actual']
hra_exemption = hra_calculator(location, basic_salary, dearness_allownces, hra, hra_actual)
taxable_hra = hra - hra_exemption
return {"hra_exemption": hra_exemption, "taxable_hra":taxable_hra, "status": "success", "message": "Calculation successful"}
@app.post("/api/v1/calculate_retirement_plan")
async def calculate_retirement_plan(data:dict):
current_age = data['current_age']
retirement_age = data['retirement_age']
monthly_expense = data['monthly_expense']
current_savings = data['current_savings']
rate_of_return = data['rate_of_return']
retirement_type = data['retirement_type']
retirement_corpous, saving_per_month = retirement_calculator(monthly_expense, rate_of_return, current_age, retirement_age, retirement_type)
return {"retirement_corpous": retirement_corpous, "saving_per_month" : saving_per_month, "status": "success", "message": "Calculation successful"}
# Calculate EMI
@app.post("/api/v1/calculate_emi")
async def calculate_emi(data:dict):
principal = data['principal']
rate_of_interest = data['rate_of_interest']
time_period = data['time_period']
loan_type = data['loan_type']
monthly_emi, principal_amount, total_interest, total_payment = emi_calculator(principal, rate_of_interest, time_period,loan_type)
return {"monthly_emi": monthly_emi, "principal_amount": principal_amount, "total_interest": total_interest, "total_payment": total_payment, "status": "success", "message": "Calculation successful"}
# Calculate Simple Interest
@app.post("/api/v1/calculate_simple_interest")
async def calculate_simple_interest(data:dict):
principal = data['principal']
rate_of_interest = data['rate_of_interest']
time_period = data['time_period']
simple_interest, principal, total_amount = simple_interest_calculator(principal, rate_of_interest, time_period)
return {"simple_interest": simple_interest, "principal": principal, "total_amount": total_amount, "status": "success", "message": "Calculation successful"}
# Calculate Compound Interest
@app.post("/api/v1/calculate_compound_interest")
async def calculate_compound_interest(data:dict):
principal = data['principal']
rate_of_interest = data['rate_of_interest']
time_period = data['time_period']
compounding_frequency = data['compounding_frequency']
total_amount, principal, total_interest = compound_interest_calculator(principal, rate_of_interest, time_period, compounding_frequency)
return {"compound_interest": total_interest, "principal": principal, "total_amount": total_amount, "status": "success", "message": "Calculation successful"}
# Calculate National Savings Certificate (NSC)
@app.post("/api/v1/calculate_nsc")
async def calculate_nsc(data:dict):
principal = data['principal']
rate_of_interest = data['rate_of_interest']
time_period = data['time_period']
compounding_frequency = data['compounding_frequency']
maturity_amount, invested_amount, estimated_return = nsc_calculator(principal, rate_of_interest, time_period, compounding_frequency)
return {"maturity_amount": maturity_amount, "invested_amount": invested_amount, "estimated_return": estimated_return, "status": "success", "message": "Calculation successful"}
# Calculate Step Up SIP
@app.post("/api/v1/calculate_stepup_sip")
async def calculate_stepup_sip(data:dict):
principal = data['principal']
rate_of_interest = data['rate_of_interest']
time_period = data['time_period']
step_up_rate = data['step_up_rate']
step_up_frequency = data['step_up_frequency']
maturity_amount, invested_amount, estimated_return = step_up_sip_calculator(principal, rate_of_interest, time_period, step_up_rate, step_up_frequency)
return {"maturity_amount": maturity_amount, "invested_amount": invested_amount, "estimated_return": estimated_return, "status": "success", "message": "Calculation successful"}
# Calculate Gratuity
@app.post("/api/v1/calculate_gratuity")
async def calculate_gratuity(data:dict):
basic_salary = data['basic_salary']
dearness_allownces = data['dearness_allownces']
gratuity_service_period = data['gratuity_service_period']
gratuity_amount = gratuity_calculator(basic_salary, dearness_allownces, gratuity_service_period)
return {"gratuity_amount": gratuity_amount, "status": "success", "message": "Calculation successful"}
# APY Calculator
@app.post("/api/v1/calculate_apy")
async def calculate_apy(data:dict):
joining_age = data['joining_age']
desired_monthly_pension = data['desired_monthly_pension']
monthly_contribution, invested_amount, investment_duration = apy_calculator(joining_age, desired_monthly_pension)
return {"monthly_contribution": monthly_contribution, "invested_amount": invested_amount, "investment_duration": investment_duration, "status": "success", "message": "Calculation successful"}
# Calculate CAGR (Compound Annual Growth Rate)
@app.post("/api/v1/calculate_cagr")
async def calculate_cagr(data:dict):
present_value = data['present_value']
future_value = data['future_value']
time_period = data['time_period']
cagr = cagr_calculator(present_value, future_value, time_period)
return {"cagr": cagr, "status": "success", "message": "Calculation successful"}
# Calculate GST
@app.post("/api/v1/calculate_gst")
async def calculate_gst(data:dict):
amount = data['amount']
gst_rate = data['gst_rate']
is_including_gst = data['is_including_gst'] # True or False
final_amount, gst_amount, cgst, sgst_ugst = gst_calculator(amount, gst_rate, is_including_gst)
return {"final_amount": final_amount, "gst_amount": gst_amount, "cgst": cgst, "sgst_ugst": sgst_ugst, "status": "success", "message": "Calculation successful"}
@app.post("/api/v1/calculate_flat_vs_reducing")
async def calculate_flat_vs_reducing(data:dict):
principal = data['principal']
annual_interest_rate = data['annual_interest_rate']
tenure_years = data['tenure_years']
flat_emi, flat_total_interest, flat_total_amount, reducing_emi, reducing_total_interest, reducing_total_amount = flat_vs_reducing_rate(principal, annual_interest_rate, tenure_years)
saved_amount = flat_total_amount - reducing_total_amount
return {"flat_emi": flat_emi, "flat_total_interest": flat_total_interest, "flat_total_amount": flat_total_amount, "reducing_emi": reducing_emi, "reducing_total_interest": reducing_total_interest, "reducing_total_amount": reducing_total_amount, "saved_amount": saved_amount, "status": "success", "message": "Calculation successful"}
# Calculate Inflation
@app.post("/api/v1/calculate_inflation")
async def calculate_inflation(data:dict):
current_cost = data['current_cost']
rate_of_inflation = data['rate_of_inflation']
time_period = data['time_period']
cost_increase, future_cost = inflation_calculator(current_cost, rate_of_inflation, time_period)
return {"cost_increase": cost_increase, "future_cost": future_cost, "status": "success", "message": "Calculation successful"}
# Calculate Winning Amount
@app.post("/api/v1/calculate_winning_amount")
async def calculate_winning_amount(data:dict):
winning_amount = data['winning_amount']
tax_rate = data['tax_rate']
winning_amount_after_tax = winning_prize_calculator(winning_amount, tax_rate)
return {"winning_amount_after_tax": winning_amount_after_tax, "status": "success", "message": "Calculation successful"}
# Bitcoin Calculator
@app.post("/api/v1/calculate_bitcoin")
async def calculate_bitcoin(data:dict):
purchase_amount = data['purchase_amount']
sale_amount = data['sale_amount']
tax_rate = data['tax_rate']
bitcoin_inr, tax_amount = bitcoin_tax_calculator(purchase_amount, sale_amount, tax_rate)
return {"bitcoin_inr": bitcoin_inr, "tax_amount": tax_amount, "status": "success", "message": "Calculation successful"}
# Calculate Take Home Salary
@app.post("/api/v1/calculate_take_home_salary")
async def calculate_take_home_salary(data:dict):
cost_to_company = data['cost_to_company']
bonus = data['bonus']
professional_tax = data['professional_tax']
employer_pf = data['employer_pf']
employee_pf = data['employee_pf']
additional_deductions = data['additional_deductions']
take_home_salary, monthly_deducted_salary, final_deducations, nett_salary = take_home_salary_calculator(cost_to_company, bonus, professional_tax, employer_pf, employee_pf, additional_deductions)
return {"take_home_salary": take_home_salary, "monthly_deducted_salary": monthly_deducted_salary, "final_deducations": final_deducations, "nett_salary": nett_salary, "status": "success", "message": "Calculation successful"}
# Calculate TDS
@app.post("/api/v1/calculate_tds")
async def calculate_tds(data:dict):
section = data['section']
amount = data['amount']
income = data['income']
tax_regime = data['tax_regime']
recipient_type = data['recipient_type']
tds = tds_calculator(section, amount, income, tax_regime, recipient_type)
return {"tds": tds, "status": "success", "message": "Calculation successful"}
@app.post("/api/v1/calculate-tax")
async def calculator_in(data:dict):
uuid = data['uuid']
if 'country_code' not in data:
response = {"tax_old_regime": None, "tax_new_regime": None, "status": "fail", "message": "Country code not provided"}
return response
else:
if data['country_code'] != "IN":
response = {"tax_old_regime": None, "tax_new_regime": None, "status": "fail", "message": "Country code not supported"}
return response
else:
country_code = data['country_code']
# Check all the required fields are present
location = data['location']
basic_salary = int(data['basic_salary'])
dearness_allownces = int(data['dearness_allownces'])
hra = int(data['hra'])
hra_actual = int(data['hra_actual'])
special_allowance = int(data['special_allowance'])
pf_deduction = int(data['pf_deduction'])
deduction_80c = int(data['deduction_80c'])
pt_deduction = int(data['pt_deduction'])
deduction_80d = int(data['deduction_80d'])
deduction_NPS = int(data['deduction_NPS'])
deduction_80G = int(data['deduction_80G'])
deduction_interest_on_loan = int(data['deduction_interest_on_loan'])
tax_old_regime = deduction_old_regime(location, basic_salary, dearness_allownces, hra, hra_actual, special_allowance, pf_deduction, deduction_80c, pt_deduction, deduction_80d, deduction_NPS, deduction_80G, deduction_interest_on_loan)
tax_new_regime = deduction_new_regime(basic_salary, dearness_allownces, hra, special_allowance)
return {"tax_old_regime": tax_old_regime, "tax_new_regime": tax_new_regime, "status": "success", "message": "Tax calculation successful"}
@app.post("/api/v1/brokerage_calculator")
async def calculate_brokerage(data:dict):
buy_price = data['buy_price']
sell_price = data['sell_price']
quantity = data['quantity']
broker_charges = data['broker_charges']
trade_type = data['trade_type']
if trade_type == "delivery":
turnover, profit_and_loss, total_charges, non_brorkerage_charges, total_profit_loss, brokerage, stt, exchange_transaction_charges, gst, sebi_charges, stamp_duty = brokerage_delivery(buy_price, sell_price, quantity, broker_charges)
elif trade_type == "intraday":
turnover, profit_and_loss, total_charges, non_brorkerage_charges, total_profit_loss, brokerage, stt, exchange_transaction_charges, gst, sebi_charges, stamp_duty = brokerage_intraday(buy_price, sell_price, quantity, broker_charges)
elif trade_type == "future":
turnover, profit_and_loss, total_charges, non_brorkerage_charges, total_profit_loss, brokerage, stt, exchange_transaction_charges, gst, sebi_charges, stamp_duty = future_trading(buy_price, sell_price, quantity, broker_charges)
elif trade_type == "option":
turnover, profit_and_loss, total_charges, non_brorkerage_charges, total_profit_loss, brokerage, stt, exchange_transaction_charges, gst, sebi_charges, stamp_duty = option_trading(buy_price, sell_price, quantity, broker_charges)
else:
return "Invalid trade type. Please enter 'delivery', 'intraday', 'future', or 'option'."
return {"turnover": turnover, "profit_and_loss": profit_and_loss, "total_charges": total_charges, "non_brorkerage_charges": non_brorkerage_charges, "total_profit_loss": total_profit_loss, "brokerage": brokerage, "stt": stt, "exchange_transaction_charges": exchange_transaction_charges, "gst": gst, "sebi_charges": sebi_charges, "stamp_duty": stamp_duty, "status": "success", "message": "Calculation successful"}
if __name__ == "__main__":
uvicorn.run(app, host="0.0.0.0",port=5005,ssl_keyfile="privkey.pem",ssl_certfile="fullchain.pem")
Back to Directory
File Manager