Compare commits

...

5 Commits

4 changed files with 54 additions and 28 deletions

12
TODO
View File

@@ -1,15 +1,9 @@
UI:
future bill (like for health) when I click change should either get fancy and allow toggle, or at least just disable the text field with future in it
For bills:
* estimate future bills/growth:
[DONE] - calculate pragmatic min/avg/max/simple
[DONE] - need to handle future only bills
[DONE] - remove bills from Living_Expenses
- fold future bills into calc so they are processed on the day of the bill
==> need to factor in future bills based on events (such as health/phone when I quit), car when I settle it...
[DONE] ==> and remove hard-coded future costs (like Ioniq rego/ins) when we do above
- inflation can then be put to a more realistic quarterly figure, and fix up Int Rate, again
Future bills:
* longer-term: make the moment we quit / own car trigger new bill creation, and remove hard-coded logic on costs - just use bill_data created
- this will then cover handling different bill_types or growth models
* might need to be able to mark a specific bill as an outlier - so we ignore the data somehow (think Gas is messing with my bills)
- and even electricity, water, etc. for when we were away in Europe but mostly gas/elec

65
calc.py
View File

@@ -5,21 +5,22 @@ from defines import END_YEAR
# GLOBAL CONSTANTS
LEASE = 0
def bill_amount_today(day, bill_data):
def bill_amount_today(finance, day, bill_data, bt_id_name, total ):
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']
if b['amount'] > 1000:
n=bt_id_name[ b['bill_type'] ]
print( f"bill_amt_today {n} for {day_str} has amt={amt}" )
add_annotation(finance, day, total-amt, amt, f"Pay {n}" )
# 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):
@@ -114,31 +115,37 @@ def calculate_savings_depletion(finance, bill_data, bill_type):
for bt in bill_type:
if 'Hyundai' in bt['name']:
if 'Car Ins' in bt['name']:
ioniq6_ins_bt = bt['id']
ioniq6_ins_bt = bt
if 'Car Rego' in bt['name']:
ioniq6_rego_bt = bt['id']
ioniq6_rego_bt = bt
if 'Health Ins' in bt['name']:
health_ins_bt = bt
if 'Phone' in bt['name'] and 'Damien' in bt['name']:
phone_d_bt = bt
# TODO: need to refactor Living_Expenses to exclude bills
total=0
yr=str(current_date.year)
for b in bill_data:
if b['bill_type'] == ioniq6_rego_bt:
if b['bill_type'] == ioniq6_rego_bt['id']:
ioniq6_rego = b['amount']
if b['bill_type'] == ioniq6_ins_bt:
if b['bill_type'] == ioniq6_ins_bt['id']:
ioniq6_ins = b['amount']
if b['bill_type'] == health_ins_bt['id']:
health_ins = b['amount']
if b['bill_type'] == phone_d_bt['id']:
phone_d = b['amount']
if yr in b['bill_date']:
total += b['amount']
print( f"this yr={current_date.year} - total={total}" )
print( f"this yr={current_date.year} - total={total} -- hi={health_ins}, phone_d={phone_d}" )
Living_Expenses -= total
print( f"LE is now={Living_Expenses}" )
# Calculate daily living expenses
daily_living_expenses = Living_Expenses / 365
# take a stab at future rego and insurance on the Ioniq 6 when we finish the lease - paid every anniversary of the Car balloon payment date
# Start the calculation
current_savings = Savings
depletion_date = None
@@ -165,6 +172,9 @@ def calculate_savings_depletion(finance, bill_data, bill_type):
# (key is date, text is for larger spend items by hand)
finance['annotations']=[]
#quick convenience lookup of bill types name for annotations.
bt_id_name = {row["id"]: row["name"] for row in bill_type}
while current_date <= end_date:
#paid on 8th or 22nd of Jan (so 8th day of fortnight)
is_fortnight = (days_count % 14 == 7)
@@ -173,8 +183,21 @@ def calculate_savings_depletion(finance, bill_data, bill_type):
# 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 )
# if we have a bill for today, pay for it
current_savings -= bill_amount_today( finance, current_date, bill_data, bt_id_name, current_savings )
# KLUDGE for future bills for now:
# if I have quit, pay monthly future bills - assume 1st day of month for health ins
if D_has_quit and current_date.day == 1:
health_ins = health_ins * 1+((health_ins_bt['ann_growth_simple'])/100)*12
current_savings -= health_ins
# once a year from when I quit, pay the phone bill (year I quit comes below)
if D_has_quit and current_date.month == D_quit_date.month and current_date.day == D_quit_date.day:
amt=phone_d
for y in range( D_quit_date.year, current_date.year):
amt = amt * (1+phone_d_bt['ann_growth_simple']/100)
current_savings -= amt
# Calculate daily interest but apply at the end of the month
monthly_interest += current_savings * daily_interest_rate
@@ -192,6 +215,7 @@ def calculate_savings_depletion(finance, bill_data, bill_type):
if D_Num_fortnights_pay == 0 and D_leave_after_tax > 0:
D_has_quit = True
D_quit_date = current_date
D_quit_year = current_date.year
# okay, if we leave before Jun 30th 2024, then I pay full tax, otherwise I get 'extra', but have to await end of next fin year
if current_date > new_fin_year_25:
@@ -205,10 +229,13 @@ def calculate_savings_depletion(finance, bill_data, bill_type):
current_savings += D_leave_after_tax
add_annotation(finance, current_date, current_savings, D_leave_after_tax, "D quit" )
D_leave_after_tax = 0
# pay for 1st year of phone for Damien
current_savings -= phone_d
# its end of 'next' fin year, if tax_diff > 0, then ddp quit after new tax year and gets back the overpaid tax
if current_date > new_fin_year_26 and claim_tax_on_leave:
current_savings += tax_diff_D_leave
print( f"I quit last fin year, so now its 1st July {current_date.year}, get tax back of {tax_diff_D_leave}" )
add_annotation(finance, current_date, current_savings, tax_diff_D_leave, "D quit - tax back" )
# can only claim the tax back once :)
claim_tax_on_leave=False
@@ -260,8 +287,14 @@ def calculate_savings_depletion(finance, bill_data, bill_type):
# 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" )
ins_amt=ioniq6_ins
for y in range( car_balloon_date.year, current_date.year):
ins_amt = ins_amt * (1+ioniq6_ins_bt['ann_growth_simple']/100)
rego_amt=ioniq6_rego
for y in range( car_balloon_date.year, current_date.year):
rego_amt = rego_amt * (1+ioniq6_rego_bt['ann_growth_simple']/100)
current_savings -= (ins_amt+rego_amt)
add_annotation(finance, current_date, current_savings, -(ins_amt+rego_amt), "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)

2
db.py
View File

@@ -121,7 +121,7 @@ def init_db():
if cur.fetchone()[0] == 0:
###
# For now manually update below on the fortnight of the original pay shcedule to compare saved version vs. our reality. Update:
# Savings (Macq+me bank) -- noting ME bank is: $1876.19, nab is 2727.95
# Savings (Macq+me bank) -- noting ME bank is: $2001.19, nab is -5200
# TLS/CBA prices
# Interest rate
# D_leave_owed_in_days

View File

@@ -36,7 +36,6 @@
{% endfor %}
</table>
#}
<div class="mt-4 col-7">
<div class="row">
<div class="col-2 form-control-inline d-none new-bill-type-class">Bill Type</div>
@@ -190,7 +189,7 @@
<div class="px-0 col-4"><label class="form-control text-center border-0 fw-bold bg-body-tertiary rounded-0">Actions</ ></div>
</div>
{% endif %}
{% if bd.bill_type_id == bt.id %}
{% if bd.bill_type == bt.id %}
{% if bd.estimated == 1 %}
<div class="row est d-none fst-italic">
{% set classes="fst-italic form-control text-center" %}