now remembers ui values for which tab we are on and whether we clicked show estimated or not

This commit is contained in:
2025-08-22 16:51:04 +10:00
parent 5bd94fc2c5
commit b05f7b05e8
4 changed files with 61 additions and 6 deletions

28
db.py
View File

@@ -109,6 +109,12 @@ def init_db():
FOREIGN KEY(bill_type) REFERENCES bill_type(id)
)''')
cur.execute('''CREATE TABLE IF NOT EXISTS bill_ui (
id INTEGER PRIMARY KEY AUTOINCREMENT,
last_tab INTEGER,
show_estimated INTEGER
)''')
# Check if table is empty, if so insert default values
cur.execute('SELECT COUNT(*) FROM finance')
if cur.fetchone()[0] == 0:
@@ -128,6 +134,8 @@ def init_db():
cur.execute( "INSERT INTO bill_freq values ( 1, 'Annual', 1 )" )
cur.execute( "INSERT INTO bill_freq values ( 2, 'Quarterly', 4 )" )
cur.execute( "INSERT INTO bill_freq values ( 3, 'Monthly', 12 )" )
# start with no specific Tab/bill_type to show, and dont show_estimated
cur.execute( "INSERT INTO bill_ui values ( 1, null, 0 )" )
conn.commit()
conn.close()
@@ -353,3 +361,23 @@ def set_bill_type_growth( id, min_g, avg_g, max_g ):
conn.commit()
conn.close()
return
def get_bill_ui():
conn = connect_db(True)
cur = conn.cursor()
# only ever be 1
cur.execute('SELECT * FROM bill_ui')
ui = cur.fetchone()
conn.close()
return ui
def save_ui(data):
conn = connect_db(False)
cur = conn.cursor()
if 'last_tab' in data:
cur.execute( f"update bill_ui set last_tab='{data['last_tab']}'" )
if 'show_estimated' in data:
cur.execute( f"update bill_ui set show_estimated='{data['show_estimated']}'" )
conn.commit()
conn.close()
return