diff --git a/db.py b/db.py index 8df61b6..5bd5319 100644 --- a/db.py +++ b/db.py @@ -88,7 +88,9 @@ def init_db(): id INTEGER PRIMARY KEY AUTOINCREMENT, freq INTEGER, name STRING, - ann_growth REAL, + ann_growth_min REAL, + ann_growth_avg REAL, + ann_growth_max REAL, FOREIGN KEY(freq) REFERENCES bill_freq(id) )''') @@ -103,6 +105,7 @@ def init_db(): bill_type INTEGER, amount INTEGER, bill_date DATE, + estimated INTEGER, FOREIGN KEY(bill_type) REFERENCES bill_type(id) )''') @@ -260,7 +263,9 @@ def get_comp_set_options(finance): def get_bill_data(): conn = connect_db(True) cur = conn.cursor() - cur.execute('SELECT bd.id, bt.id as bill_type_id, bt.name, bd.amount, bd.bill_date FROM bill_type bt, bill_data bd where bt.id = bd.bill_type order by bt.name, bd.bill_date desc') + cur.execute('''SELECT bd.id, bt.id as bill_type_id, 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() conn.close() return bd @@ -282,10 +287,10 @@ def get_bill_freqs(): return bf -def new_bill( name, amount, bill_date ): +def new_bill( bill_type, amount, bill_date, estimated ): conn = connect_db(False) cur = conn.cursor() - cur.execute( f"insert into bill_data ( 'bill_type', 'amount', 'bill_date' ) values ( '{name}', '{amount}', '{bill_date}' )" ) + cur.execute( f"insert into bill_data ( 'bill_type', 'amount', 'bill_date', 'estimated' ) values ( '{bill_type}', '{amount}', '{bill_date}', {estimated} )" ) conn.commit() conn.close() return @@ -302,7 +307,7 @@ def insert_bill_type( bt, fq ): conn = connect_db(False) cur = conn.cursor() print( f"fq={fq}" ) - cur.execute( f"insert into bill_type ( 'name', 'freq', 'ann_growth' ) values ( '{bt}', {fq}, 0 )" ) + cur.execute( f"insert into bill_type ( 'name', 'freq', 'ann_growth_min', 'ann_growth_avg', 'ann_growth_max' ) values ( '{bt}', {fq}, 0, 0, 0 )" ) conn.commit() conn.close() return @@ -331,10 +336,10 @@ def delete_bill_type( id ): conn.close() return -def set_bill_type_growth( id, g ): +def set_bill_type_growth( id, min_g, avg_g, max_g ): conn = connect_db(False) cur = conn.cursor() - cur.execute( f"update bill_type set ann_growth ='{g}' where id = {id}" ) + cur.execute( f"update bill_type set ann_growth_min='{min_g}', ann_growth_avg ='{avg_g}', ann_growth_max='{max_g}' where id = {id}" ) conn.commit() conn.close() return