put back ioniq 6 future bills, but use bill data to set values - assumption at present is they are yearly bills, could do better, but good enough for now. This commit also changes selects to return bill_type not bill_type_id and removed some debugs for bill amt in calc loop
This commit is contained in:
2
bills.py
2
bills.py
@@ -306,7 +306,7 @@ def process_bill_data(bd, bt, bf):
|
||||
bill_info={}
|
||||
|
||||
for bill in bd:
|
||||
bill_type = bill['bill_type_id']
|
||||
bill_type = bill['bill_type']
|
||||
if bill['bill_date'] == 'future':
|
||||
print("Having a future data - skip this one")
|
||||
continue
|
||||
|
||||
45
calc.py
45
calc.py
@@ -14,12 +14,12 @@ def bill_amount_today(day, bill_data):
|
||||
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}" )
|
||||
# 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}" )
|
||||
# if amt:
|
||||
# print( f"bill_amt_today for {day} has amt={amt}" )
|
||||
return amt
|
||||
|
||||
def add_annotation(finance, dt, total, delta, text):
|
||||
@@ -32,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, bill_data):
|
||||
def calculate_savings_depletion(finance, bill_data, bill_type):
|
||||
# Extract all the financial data from the database
|
||||
D_Salary = finance['D_Salary']
|
||||
D_Num_fortnights_pay = finance['D_Num_fortnights_pay']
|
||||
@@ -110,10 +110,23 @@ def calculate_savings_depletion(finance, bill_data):
|
||||
current_date = datetime.today()
|
||||
end_date = datetime(END_YEAR, 4, 15)
|
||||
|
||||
# work out which bill_types relate to future bills
|
||||
for bt in bill_type:
|
||||
if 'Hyundai' in bt['name']:
|
||||
if 'Car Ins' in bt['name']:
|
||||
ioniq6_ins_bt = bt['id']
|
||||
if 'Car Rego' in bt['name']:
|
||||
ioniq6_rego_bt = bt['id']
|
||||
|
||||
# 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:
|
||||
ioniq6_rego = b['amount']
|
||||
if b['bill_type'] == ioniq6_ins_bt:
|
||||
ioniq6_ins = b['amount']
|
||||
|
||||
if yr in b['bill_date']:
|
||||
total += b['amount']
|
||||
|
||||
@@ -125,8 +138,6 @@ def calculate_savings_depletion(finance, bill_data):
|
||||
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
|
||||
ioniq6_rego = 800
|
||||
ioniq6_ins = 2200
|
||||
|
||||
# Start the calculation
|
||||
current_savings = Savings
|
||||
@@ -245,16 +256,16 @@ def calculate_savings_depletion(finance, bill_data):
|
||||
# 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
|
||||
|
||||
4
db.py
4
db.py
@@ -275,11 +275,11 @@ def get_bill_data(order_by):
|
||||
conn = connect_db(True)
|
||||
cur = conn.cursor()
|
||||
if order_by == "order_by_date_only":
|
||||
cur.execute('''SELECT bd.id, bt.id as bill_type_id, bt.name, bd.amount, bd.bill_date, bd.estimated
|
||||
cur.execute('''SELECT bd.id, bt.id as bill_type, bt.name, bd.amount, bd.bill_date, bd.estimated
|
||||
FROM bill_type bt, bill_data bd
|
||||
where bt.id = bd.bill_type order by bd.bill_date desc''')
|
||||
else:
|
||||
cur.execute('''SELECT bd.id, bt.id as bill_type_id, bt.name, bd.amount, bd.bill_date, bd.estimated
|
||||
cur.execute('''SELECT bd.id, bt.id as bill_type, bt.name, bd.amount, bd.bill_date, bd.estimated
|
||||
FROM bill_type bt, bill_data bd
|
||||
where bt.id = bd.bill_type order by bt.name, bd.bill_date desc''')
|
||||
bd = cur.fetchall()
|
||||
|
||||
3
main.py
3
main.py
@@ -26,7 +26,8 @@ def index():
|
||||
finance_data = get_finance_data()
|
||||
get_comp_set_options(finance_data)
|
||||
bill_data = get_bill_data("order_by_date_only")
|
||||
depletion_date, savings_per_fortnight, final_savings = calculate_savings_depletion(finance_data, bill_data)
|
||||
bill_types = get_bill_types()
|
||||
depletion_date, savings_per_fortnight, final_savings = calculate_savings_depletion(finance_data, bill_data, bill_types)
|
||||
BUDGET=get_budget_data(finance_data)
|
||||
|
||||
if depletion_date:
|
||||
|
||||
Reference in New Issue
Block a user