Compare commits

...

8 Commits

6 changed files with 39 additions and 17 deletions

3
BUGS
View File

@@ -1,3 +1,6 @@
* can put in dumb dates - DO SOME INPUT VALIDATION, *sigh*
- e.g. 0026-02-19 for a Gas bill
* kayo bills are wrong in between normal bills * kayo bills are wrong in between normal bills
* added an electricity bill by accident for 2018, that kills lots :( * added an electricity bill by accident for 2018, that kills lots :(

View File

@@ -643,8 +643,7 @@ def recalcFutureBills():
for fb in future_car_bills: for fb in future_car_bills:
amt=fb['amount'] amt=fb['amount']
bt=fb['bill_type'] bt=fb['bill_type']
# only can use simple growth as its a future bill growth = get_growth_value( bill_types, bt )
growth=bill_types[bt]['ann_growth_simple']
# factor in growth for next bills # factor in growth for next bills
for yr in range( int(car_yr), END_YEAR+1 ): for yr in range( int(car_yr), END_YEAR+1 ):
new_date=f"{yr}-{car_mmdd}" new_date=f"{yr}-{car_mmdd}"
@@ -661,7 +660,7 @@ def recalcFutureBills():
# deal with future bills due to their starting dates being dynamic # deal with future bills due to their starting dates being dynamic
amt=fb['amount'] amt=fb['amount']
bt=fb['bill_type'] bt=fb['bill_type']
growth=bill_types[bt]['ann_growth_simple'] growth = get_growth_value( bill_types, bt )
num_ann_bills= bf_id_num[bt_id_freq[bt]] num_ann_bills= bf_id_num[bt_id_freq[bt]]
if num_ann_bills == 1: if num_ann_bills == 1:
# factor in growth for next bill # factor in growth for next bill

2
db.py
View File

@@ -8,6 +8,8 @@ def connect_db(as_object):
conn = sqlite3.connect('/data/finance.db') conn = sqlite3.connect('/data/finance.db')
else: else:
conn = sqlite3.connect('./finance.db') conn = sqlite3.connect('./finance.db')
# allow deleting cset to clear our compare_to properly in finance table
conn.execute("PRAGMA foreign_keys = ON;")
if as_object: if as_object:
conn.row_factory = sqlite3.Row # This allows us to access columns by name conn.row_factory = sqlite3.Row # This allows us to access columns by name
return conn return conn

14
main.py
View File

@@ -41,7 +41,10 @@ def index():
depletion_date=depletion_date.date(); # just show date depletion_date=depletion_date.date(); # just show date
# if we are comparing...(compare_to will be 0 / None to start with, and then COMP will be None # if we are comparing...(compare_to will be 0 / None to start with, and then COMP will be None
if finance_data['compare_to']:
COMP=get_comp_set_data(finance_data['compare_to']) COMP=get_comp_set_data(finance_data['compare_to'])
else:
COMP={}
DISP=[] DISP=[]
# Row 1 # Row 1
@@ -114,14 +117,18 @@ def index():
@app.route('/save', methods=['POST']) @app.route('/save', methods=['POST'])
def save(): def save():
insert_cset( request.get_json() ) cset_id=insert_cset( request.get_json() )
return "200" name = request.get_json()['vars']['name']
return jsonify( cset_id=cset_id, name=name )
@app.route('/update', methods=['POST']) @app.route('/update', methods=['POST'])
def update(): def update():
old_finance_data = get_finance_data() old_finance_data = get_finance_data()
raw_compare_to = request.form.get('compare_to')
compare_to_value = None if raw_compare_to == "0" else int(raw_compare_to)
finance_data = ( finance_data = (
request.form['D_Salary'], request.form['D_Salary'],
request.form['D_Num_fortnights_pay'], request.form['D_Num_fortnights_pay'],
@@ -147,9 +154,10 @@ def update():
request.form['Mark_reno_date'], request.form['Mark_reno_date'],
request.form['Car_buyout_date'], request.form['Car_buyout_date'],
request.form['Sell_shares'], request.form['Sell_shares'],
request.form['compare_to'], compare_to_value,
request.form['Ioniq6_future'] request.form['Ioniq6_future']
) )
update_finance(finance_data) update_finance(finance_data)
new_finance_data = get_finance_data() new_finance_data = get_finance_data()
# changed Ioniq6_future, Car_buyout_date or D_Num_fortnights_pay, so lets force recalc key_dates, and therefore estimated bills # changed Ioniq6_future, Car_buyout_date or D_Num_fortnights_pay, so lets force recalc key_dates, and therefore estimated bills

View File

@@ -456,7 +456,7 @@
function SaveTab( last_tab ) function SaveTab( last_tab )
{ {
// set the drop-down for new bill to be this tab now... // set the drop-down for new bill to be this tab now...
$("#new-bill-data-type").val( $('.nav-tabs .nav-link.active').prop('id').replace("tab-but-", "") ) $("#new-bill-data-type").val( $('.nav-link.active').prop('id').replace("tab-but-", "") )
$.ajax( { type: 'POST', url: '/saveui', contentType: 'application/json', data: JSON.stringify( { 'last_tab': last_tab } ), success: function() { } } ) $.ajax( { type: 'POST', url: '/saveui', contentType: 'application/json', data: JSON.stringify( { 'last_tab': last_tab } ), success: function() { } } )
} }

View File

@@ -11,6 +11,7 @@
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script> <script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script> <script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script src="https://code.highcharts.com/highcharts.js"></script> <script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/mouse-wheel-zoom.js"></script>
<script src="https://code.highcharts.com/modules/annotations.js"></script> <script src="https://code.highcharts.com/modules/annotations.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script> <script src="https://code.highcharts.com/modules/accessibility.js"></script>
<script src="https://code.highcharts.com/themes/adaptive.js"></script> <script src="https://code.highcharts.com/themes/adaptive.js"></script>
@@ -229,7 +230,12 @@
$(function() { $('[data-bs-toggle="popover"]').popover(); }); $(function() { $('[data-bs-toggle="popover"]').popover(); });
window.onload = function() { window.onload = function() {
$('#Sell_shares').val( {{finance['Sell_shares']}} ) $('#Sell_shares').val( {{finance['Sell_shares']}} )
{% if finance['compare_to'] %}
$('#compare_to').val( {{finance['compare_to']}} ) $('#compare_to').val( {{finance['compare_to']}} )
{% else %}
// set this to Nothing by default
$('#compare_to').val( 0 )
{% endif %}
$('#Ioniq6_future').val( {{finance['Ioniq6_future']}} ) $('#Ioniq6_future').val( {{finance['Ioniq6_future']}} )
if( $("#Ioniq6_future option:selected"). text() == 'lease' ) if( $("#Ioniq6_future option:selected"). text() == 'lease' )
@@ -358,7 +364,7 @@
// Highcharts configuration // Highcharts configuration
Highcharts.chart('graph', { Highcharts.chart('graph', {
chart: { type: 'line' }, chart: { type: 'line', zooming: { type: 'x' } },
colors: [ 'orange' ], colors: [ 'orange' ],
title: { text: 'Savings Over Time' }, title: { text: 'Savings Over Time' },
xAxis: { xAxis: {
@@ -385,7 +391,7 @@
{% if COMP %} {% if COMP %}
// Highcharts configuration // Highcharts configuration
Highcharts.chart('graph-comp', { Highcharts.chart('graph-comp', {
chart: { type: 'line' }, chart: { type: 'line', zooming: { type: 'x' } },
colors: [ colors: [
'orange', // Custom color 1 'orange', // Custom color 1
'cyan', // Custom color 2 'cyan', // Custom color 2
@@ -433,13 +439,17 @@
<button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button> <button type="button" class="btn btn-secondary" data-bs-dismiss="modal">Cancel</button>
<button type="button" class="btn btn-info" <button type="button" class="btn btn-info"
onClick=" onClick="
vars['name']=$('#save_name').val(); vars['name'] = $('#save_name').val();
$.ajax( { $.ajax({
type: 'POST', type: 'POST',
url: '/save', url: '/save',
contentType: 'application/json', contentType: 'application/json',
data: JSON.stringify( { 'vars': vars, 'savings_data' :savingsData } ), data: JSON.stringify({ 'vars': vars, 'savings_data': savingsData }),
success: function() { $('#save_modal').modal('hide'); } } )" success: function(resp) {
$('#save_modal').modal('hide');
$('#compare_to').append($('<option>', { value: resp.cset_id, text: resp.name }));
}
});"
>Save</button> >Save</button>
</div> </div>
</div> </div>