incorporate bills for dates/amounts into calculations, still need to do future bills on triggers
This commit is contained in:
60
calc.py
60
calc.py
@@ -5,6 +5,23 @@ from defines import END_YEAR
|
||||
# GLOBAL CONSTANTS
|
||||
LEASE = 0
|
||||
|
||||
def bill_amount_today(day, bill_data):
|
||||
amt=0
|
||||
day_str = day.strftime("%Y-%m-%d")
|
||||
for b in bill_data:
|
||||
# there may be more than one bill on this day, keep add amount and keep going in loop
|
||||
if b['bill_date'] == day_str:
|
||||
amt += b['amount']
|
||||
# bills are desc order so if the bill is before the day we are after then stop looking
|
||||
if b['bill_date'] < day_str:
|
||||
if amt:
|
||||
print( f"bill_amt_today for {day_str} has amt={amt}" )
|
||||
return amt
|
||||
#failsafe, doubt this even can occur with bills older than today
|
||||
if amt:
|
||||
print( f"bill_amt_today for {day} has amt={amt}" )
|
||||
return amt
|
||||
|
||||
def add_annotation(finance, dt, total, delta, text):
|
||||
# dont add an annotation for small changes (jic)
|
||||
tm = dt.timestamp() * 1000
|
||||
@@ -15,7 +32,7 @@ def add_annotation(finance, dt, total, delta, text):
|
||||
finance['annotations'].append( { 'label': text, 'x': tm, 'y': total } )
|
||||
return
|
||||
|
||||
def calculate_savings_depletion(finance):
|
||||
def calculate_savings_depletion(finance, bill_data):
|
||||
# Extract all the financial data from the database
|
||||
D_Salary = finance['D_Salary']
|
||||
D_Num_fortnights_pay = finance['D_Num_fortnights_pay']
|
||||
@@ -93,6 +110,17 @@ def calculate_savings_depletion(finance):
|
||||
current_date = datetime.today()
|
||||
end_date = datetime(END_YEAR, 4, 15)
|
||||
|
||||
# TODO: need to refactor Living_Expenses to exclude bills
|
||||
total=0
|
||||
yr=str(current_date.year)
|
||||
for b in bill_data:
|
||||
if yr in b['bill_date']:
|
||||
total += b['amount']
|
||||
|
||||
print( f"this yr={current_date.year} - total={total}" )
|
||||
Living_Expenses -= total
|
||||
print( f"LE is now={Living_Expenses}" )
|
||||
|
||||
# Calculate daily living expenses
|
||||
daily_living_expenses = Living_Expenses / 365
|
||||
|
||||
@@ -134,6 +162,9 @@ def calculate_savings_depletion(finance):
|
||||
# Subtract daily living expenses
|
||||
current_savings -= daily_living_expenses
|
||||
|
||||
# TODO: need to see if a date matches a bill's date, if so subtract bill amount
|
||||
current_savings -= bill_amount_today( current_date, bill_data )
|
||||
|
||||
# Calculate daily interest but apply at the end of the month
|
||||
monthly_interest += current_savings * daily_interest_rate
|
||||
|
||||
@@ -191,6 +222,7 @@ def calculate_savings_depletion(finance):
|
||||
current_savings += monthly_interest
|
||||
#print(f"{current_date}: interest paid - ${monthly_interest}")
|
||||
monthly_interest = 0
|
||||
|
||||
# monthly increase living expenses by a monthly inflation multiplier
|
||||
Living_Expenses += (Inflation/100.0)/12 * Living_Expenses
|
||||
daily_living_expenses = Living_Expenses / 365
|
||||
@@ -213,20 +245,20 @@ def calculate_savings_depletion(finance):
|
||||
# Anniversary of Car purchase/balloon so potentially insurance/rego
|
||||
# when I quit, the if we haven't paid the car outright, then need to add rego, but not insurance
|
||||
# if we pay-out the car, then add insurace and rego
|
||||
if current_date.month == car_balloon_date.month and current_date.day == car_balloon_date.day:
|
||||
# staying with the lease (0), if I have quit, then pay monthly rego only up to lease date, but full cost after car balloon date
|
||||
if Ioniq6_future == LEASE:
|
||||
if current_date.year >= car_balloon_date.year:
|
||||
current_savings -= (ioniq6_ins + ioniq6_rego)
|
||||
add_annotation(finance, current_date, current_savings, -(ioniq6_ins+ioniq6_rego), "IONIQ 6 ins/rego" )
|
||||
# if we buy car outright, then as long as this anniversary is after buyout date, pay ins and rego
|
||||
elif current_date.year >= car_buyout_date.year:
|
||||
current_savings -= (ioniq6_ins + ioniq6_rego)
|
||||
add_annotation(finance, current_date, current_savings, -(ioniq6_ins+ioniq6_rego), "IONIQ 6 ins/rego" )
|
||||
# if current_date.month == car_balloon_date.month and current_date.day == car_balloon_date.day:
|
||||
# # staying with the lease (0), if I have quit, then pay monthly rego only up to lease date, but full cost after car balloon date
|
||||
# if Ioniq6_future == LEASE:
|
||||
# if current_date.year >= car_balloon_date.year:
|
||||
# current_savings -= (ioniq6_ins + ioniq6_rego)
|
||||
# add_annotation(finance, current_date, current_savings, -(ioniq6_ins+ioniq6_rego), "IONIQ 6 ins/rego" )
|
||||
# # if we buy car outright, then as long as this anniversary is after buyout date, pay ins and rego
|
||||
# elif current_date.year >= car_buyout_date.year:
|
||||
# current_savings -= (ioniq6_ins + ioniq6_rego)
|
||||
# add_annotation(finance, current_date, current_savings, -(ioniq6_ins+ioniq6_rego), "IONIQ 6 ins/rego" )
|
||||
|
||||
if current_date.date() == overseas_trip_date.date():
|
||||
current_savings -= Overseas_trip
|
||||
add_annotation(finance, current_date, current_savings, -Overseas_trip, "O/S trip")
|
||||
# if current_date.date() == overseas_trip_date.date():
|
||||
# current_savings -= Overseas_trip
|
||||
# add_annotation(finance, current_date, current_savings, -Overseas_trip, "O/S trip")
|
||||
|
||||
if current_date.date() == mich_present_date.date():
|
||||
current_savings -= Mich_present
|
||||
|
||||
Reference in New Issue
Block a user