diff --git a/db.py b/db.py index cefe028..b9f7ed7 100644 --- a/db.py +++ b/db.py @@ -85,6 +85,14 @@ def init_db(): )''') cur.execute('''CREATE TABLE IF NOT EXISTS bill_type ( + id INTEGER PRIMARY KEY AUTOINCREMENT, + freq INTEGER, + name STRING, + ann_growth REAL, + FOREIGN KEY(freq) REFERENCES bill_freq(id) + )''') + + cur.execute('''CREATE TABLE IF NOT EXISTS bill_freq ( id INTEGER PRIMARY KEY AUTOINCREMENT, name STRING )''') @@ -113,6 +121,9 @@ def init_db(): Inflation, Mich_present, Overseas_trip, Mark_reno, D_leave_owed_in_days, D_TLS_shares, M_TLS_shares, D_CBA_shares, TLS_price, CBA_price, Overseas_trip_date, Mark_reno_date, Car_buyout_date, Sell_shares, compare_to, Ioniq6_future) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?)''', (4762.29, 10, 24000, 620, 2412, 45824.68, 83738.74, 80000, 424875.26, 4.75, 2.4, 10000, 50000, 10000, 76.85, 1000, 750, 1111, 4.52, 163.32, '2025-06-01', '2025-09-01', '2025-02-20', 4, 0, 0)) + cur.execute( "INSERT INTO bill_freq values ( 1, 'Annual' )" ) + cur.execute( "INSERT INTO bill_freq values ( 2, 'Quarterly' )" ) + cur.execute( "INSERT INTO bill_freq values ( 3, 'Monthly' )" ) conn.commit() conn.close() @@ -248,7 +259,7 @@ 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') + 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') bd = cur.fetchall() conn.close() return bd @@ -256,11 +267,20 @@ def get_bill_data(): def get_bill_types(): conn = connect_db(True) cur = conn.cursor() - cur.execute('SELECT id, name FROM bill_type order by name') + cur.execute('SELECT * FROM bill_type order by name') bt = cur.fetchall() conn.close() return bt +def get_bill_freqs(): + conn = connect_db(True) + cur = conn.cursor() + cur.execute('SELECT * FROM bill_freq order by name') + bf = cur.fetchall() + conn.close() + return bf + + def new_bill( name, amount, bill_date ): conn = connect_db(False) cur = conn.cursor() @@ -277,18 +297,19 @@ def update_bill_data( id, name, amount, bill_date ): conn.close() return -def insert_bill_type( bt ): +def insert_bill_type( bt, fq ): conn = connect_db(False) cur = conn.cursor() - cur.execute( f"insert into bill_type ( 'name' ) values ( '{bt}' )" ) + print( f"fq={fq}" ) + cur.execute( f"insert into bill_type ( 'name', 'freq', 'ann_growth' ) values ( '{bt}', {fq}, 0 )" ) conn.commit() conn.close() return -def update_bill_type(id, bill_type): +def update_bill_type(id, bill_type, freq): conn = connect_db(False) cur = conn.cursor() - cur.execute( f"update bill_type set name ='{bill_type}' where id = {id}" ) + cur.execute( f"update bill_type set name ='{bill_type}', freq={freq} where id = {id}" ) conn.commit() conn.close() return @@ -308,3 +329,11 @@ def delete_bill_type( id ): conn.commit() conn.close() return + +def set_bill_type_growth( id, g ): + conn = connect_db(False) + cur = conn.cursor() + cur.execute( f"update bill_type set ann_growth ='{g}' where id = {id}" ) + conn.commit() + conn.close() + return