diff --git a/calc.py b/calc.py index 19a1ea9..e0d616f 100644 --- a/calc.py +++ b/calc.py @@ -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,17 @@ 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: + 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: + current_savings -= phone_d # Calculate daily interest but apply at the end of the month monthly_interest += current_savings * daily_interest_rate @@ -192,6 +211,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 +225,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 +283,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)