Compare commits

..

5 Commits

5 changed files with 57 additions and 44 deletions

9
TODO
View File

@@ -1,6 +1,8 @@
UI:
* do I want to save the front tab?
CALC:
* if I quit at different times of the financial year, technically the amount I earn will be taxed
differently, but hard to cal - slides around with tax brackets in future
UI:
* have a comparison management capability - somehow, at least be able to delete csets (can I put an x inside the menu? OR, have a manage button and pop-up?)
* maybe a help/note/set of links somehow, to common things: e.g. macquarie int rate page, inflation source, etc.
@@ -9,6 +11,9 @@ UI:
and it walks me through the manual update steps and when I finish its datestamped until next time
For bills:
* quick hack, Force Re-estimate (delete estimates and reload bill page)
* if we change certain items on the finance page, need to re-do bills, e.g.
- change D # pays to quit, or Car lease/buy out
* 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

68
calc.py
View File

@@ -6,13 +6,11 @@ from defines import END_YEAR
LEASE = 0
# Dates that don't change
car_balloon_date = datetime(2026, 11, 15)
new_fin_year_25 = datetime(2025, 7, 1)
new_fin_year_26 = datetime(2026, 7, 1)
end_date = datetime(END_YEAR, 4, 15)
school_fees_date = datetime(2025, 12, 5)
mich_present_date = datetime(2026,10,15)
first_pay_date = datetime(2025,1,8)
school_fees_date = datetime(2025, 12, 5)
car_balloon_date = datetime(2026, 11, 15)
mich_present_date = datetime(2026,10,15)
end_date = datetime(END_YEAR, 4, 15)
def bill_amount_today(finance, day, bill_data, bt_id_name, total ):
amt=0
@@ -24,8 +22,8 @@ def bill_amount_today(finance, day, bill_data, bt_id_name, total ):
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}" )
print( f"bill_amt_today {n} for {day_str} has amt={b['amount']}" )
add_annotation(finance, day, total-b['amount'], -b['amount'], 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:
return amt
@@ -84,22 +82,18 @@ def calculate_savings_depletion(finance, bill_data, bill_type):
payout = 83115.84
print( f"leave payout gross={payout}" )
# as the leave is just on top of my existing earnings and if in 2024 fin year, just take tax at 37% for the extra leave amount
# hardcoded 6 represents the 12 weeks or 6 fornights of pay owed to me when I give notice or they sack me
D_leave_after_tax = payout * (1-0.37)
# However, if I quit in the next fin year - tax for 2025 will be: $4,288 plus 30c for each $1 over $45,000
# (assuming the 7830.42 * ~90/bus_days_in_fortnight = ~ $64k - > 45k and < $135k bracket is 30%)
# Given, I probably can't stop Deakin doing PAYG deductions, I won't get
# the tax back until the end of the financial year, so work out the
# amount of tax I will get back info: tax_diff_D_leave
tax_on_leave = (payout - 45000)*.37 + 4288
D_leave_after_tax_new_fin_year = payout - tax_on_leave
D_leave_after_tax = payout - tax_on_leave
# just use redunancy calc...
D_leave_after_tax_new_fin_year = 56518.77
D_leave_after_tax = 56518.77
tax_diff_D_leave = payout - D_leave_after_tax_new_fin_year
tax_diff_D_leave = payout - D_leave_after_tax
print( f"tax_diff_D_leave: {tax_diff_D_leave}")
@@ -107,7 +101,6 @@ def calculate_savings_depletion(finance, bill_data, bill_type):
# convenience vars to make it easier to read conditional leave tax/payment logic below
D_has_quit = False
D_quit_year = 0
claim_tax_on_leave = False
# Constants for interest calculations
@@ -118,7 +111,7 @@ def calculate_savings_depletion(finance, bill_data, bill_type):
current_date = datetime.today()
# TODO: need to refactor Living_Expenses to exclude bills
# refactor Living_Expenses to exclude bills (as we have detailed future projections for them that usually exceed inflation)
total=0
yr=str(current_date.year)
for b in bill_data:
@@ -131,6 +124,8 @@ def calculate_savings_depletion(finance, bill_data, bill_type):
# Calculate daily living expenses
daily_living_expenses = Living_Expenses / 365
print( f"daily LE starts at={daily_living_expenses}" )
print( f"fortnightly LE starts at={daily_living_expenses*14}" )
# Start the calculation
current_savings = Savings
@@ -181,31 +176,17 @@ def calculate_savings_depletion(finance, bill_data, bill_type):
current_savings -= Car_loan_via_pay
print( f"{current_date}: making car loan pay as pre-tax lease: ${Car_loan_via_pay}" )
# no more pay and if leave after tax > 0 this is the day I quit
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:
claim_tax_on_leave = True
print(f"{current_date}: D has resigned in new year- get paid out my 12 weeks + remaining leave and lose some to tax - ${D_leave_after_tax_new_fin_year}" )
current_savings += D_leave_after_tax_new_fin_year
add_annotation(finance, current_date, current_savings, D_leave_after_tax_new_fin_year, "D quit" )
else:
claim_tax_on_leave = False
print(f"{current_date}: D has resigned - get paid out my 12 weeks + remaining leave and lose some to tax - ${D_leave_after_tax}" )
current_savings += D_leave_after_tax
add_annotation(finance, current_date, current_savings, D_leave_after_tax, "D quit" )
# going to pay tax on payout, so claim it back next year
claim_tax_on_leave = True
print(f"{current_date}: D has resigned in new year- get paid out my 12 weeks + remaining leave and lose some to tax - ${D_leave_after_tax}" )
current_savings += D_leave_after_tax
add_annotation(finance, current_date, current_savings, D_leave_after_tax, "D quit" )
D_leave_after_tax = 0
# 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
if fortnight_income:
print(f"{current_date}: salary paid by Deakin - adding: {fortnight_income}" )
current_savings += fortnight_income
@@ -213,6 +194,14 @@ def calculate_savings_depletion(finance, bill_data, bill_type):
savings_per_fortnight.append((current_date.strftime("%Y-%m-%d"), round(current_savings, 2)))
# its end of fin year, if claim_tax_on_leave > 0 then get tax back
if current_date.month == 7 and current_date.day == 1 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
# if I have quit, then car lease payments are made on the 15th of the month for full Car_loan
if D_has_quit and current_date.day == 15:
if Ioniq6_future == LEASE and current_date <= car_balloon_date:
@@ -230,7 +219,7 @@ def calculate_savings_depletion(finance, bill_data, bill_type):
# monthly increase living expenses by a monthly inflation multiplier
Living_Expenses += (Inflation/100.0)/12 * Living_Expenses
daily_living_expenses = Living_Expenses / 365
#print(f"{current_date}: Living Exp inceased - ${Living_Expenses}")
# print(f"{current_date}: Living Exp inceased - ${Living_Expenses}")
if current_date.date() == school_fees_date.date():
current_savings -= School_Fees
@@ -269,7 +258,7 @@ def calculate_savings_depletion(finance, bill_data, bill_type):
# if selling shares, and its 1st of July...
# BUT not if D quits before end of financial year - as I won't be able to sell CBA shares for no cap gains
# so wait until the following year
if current_date.month == 7 and current_date.day == 1 and D_has_quit and Sell_shares>0 and (current_date.year > D_quit_year or current_date.year == D_quit_year and claim_tax_on_leave == False):
if current_date.month == 7 and current_date.day == 1 and D_has_quit and Sell_shares>0 and (D_quit_date.month<7 or D_quit_date.year < current_date.year ):
# 2024 Govt. value
tax_threshold = 18200
# cap-gains is 50% of profit (lazy profit calc here, just assume its all profit)
@@ -321,6 +310,5 @@ def calc_key_dates( finance ):
else:
key_dates['D_hyundai_owned'] = finance['Car_buyout_date']
print( f"kd={key_dates}" )
return key_dates

9
db.py
View File

@@ -395,3 +395,12 @@ def save_ui(data):
conn.commit()
conn.close()
return
def delete_estimated_bills():
conn = connect_db(False)
cur = conn.cursor()
cur.execute( "delete from bill_data where estimated=1" )
conn.commit()
conn.close()
return

View File

@@ -2,7 +2,7 @@
from flask import Flask, render_template, request, redirect, url_for, Response, jsonify
from calc import calculate_savings_depletion, calc_key_dates
from db import init_db, get_finance_data, update_finance, get_budget_data, insert_cset, get_comp_set_data, get_comp_set_options, get_bill_freqs
from db import get_bill_data, new_bill, update_bill_data, delete_bill
from db import get_bill_data, new_bill, update_bill_data, delete_bill, delete_estimated_bills
from db import get_bill_ui, save_ui
from db import get_bill_types, insert_bill_type, update_bill_type, delete_bill_type, use_growth
from bills import process_bill_data, calc_future_totals, set_bill_type_growth
@@ -142,6 +142,7 @@ def update():
request.form['Ioniq6_future']
)
update_finance(finance_data)
# FIXME: need code here to delete/rebuild future bills if we change "D # Pays to quit "
return redirect(url_for('index'))
@app.route('/bills')
@@ -214,6 +215,10 @@ def SaveUI():
save_ui( data )
return "200"
@app.route('/force_recalc_bills', methods=['POST'])
def force_recalc_bills():
delete_estimated_bills()
return "200"
# Main program
if __name__ == '__main__':

View File

@@ -52,6 +52,7 @@
</div>
<button id="save-bill-type" class="new-bill-type-class px-0 col-1 btn btn-success bg-success-subtle text-success d-none" onClick="NewBillType()"><span class="bi bi-floppy"></span> Save</button>
<button id="canc-bill-type" class="new-bill-type-class px-0 col-1 btn btn-danger bg-danger-subtle text-danger d-none" onClick="CancelNewBillType()"><span class="bi bi-x"> Cancel</span></button>
<button id="recalc-bills" class="mt-4 col-2 offset-3 btn btn-warning bg-warning-subtle text-warning" onClick="ForceRecalcBills()"><span class="bi bi-repeat"> Recalculate</span></button>
</div>
<div class="row">
<div class="px-0 col-2"><label class="form-control text-center border-0 fw-bold bg-body-tertiary rounded-0">Name</ ></div>
@@ -131,7 +132,7 @@
<!-- right-hand-side, bill types (e.g. gas, phone, etc.) -->
<div class="pt-4 col-5">
<div class="col-5">
<div class="row">
<div class="col-2 form-control-inline d-none new-bill-data-class">Bill Type</div>
<div id="new-bill-data-date-label" class="col-4 form-control-inline d-none new-bill-data-class">Date</div>
@@ -466,6 +467,11 @@
});
});
function ForceRecalcBills()
{
$.ajax( { type: 'POST', url: '/force_recalc_bills', contentType: 'application/json', success: function() { window.location='bills' } } )
}
</script>
</body>
</html>