File size: 2,032 Bytes
7068b71
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
import streamlit as st
import datetime

# Initialize session state
if "balance" not in st.session_state:
    st.session_state.balance = 0
if "transactions" not in st.session_state:
    st.session_state.transactions = []
if "multiple" not in st.session_state:
    st.session_state.multiple = 5  # default multiple

# Function to calculate round-up
def round_up(transaction, multiple):
    rounded = ((transaction + multiple - 1) // multiple) * multiple
    savings = rounded - transaction
    return rounded, savings

# App title
st.title("πŸ’° Smart Round-Up Savings (User Controlled)")

st.markdown("*Choose your round-up multiple:*")
multiple = st.selectbox("Round to nearest:", [5, 10, 20, 50], index=[5,10,20,50].index(st.session_state.multiple))
st.session_state.multiple = multiple

# Transaction input
transaction = st.number_input("Enter transaction amount (β‚Ή):", min_value=1, step=1)

if st.button("Add Transaction"):
    rounded, savings = round_up(transaction, st.session_state.multiple)
    st.session_state.balance += savings
    st.session_state.transactions.append(
        {"amount": transaction, "rounded": rounded, "savings": savings, "date": datetime.date.today()}
    )
    st.success(f"Spent β‚Ή{transaction} β†’ Rounded to β‚Ή{rounded} β†’ Saved β‚Ή{savings}")

# Show Smart Pot Balance
st.metric("πŸ’° Smart Pot Balance", f"β‚Ή{st.session_state.balance}")

# Show transaction history
st.subheader("πŸ“œ Transaction History")
if st.session_state.transactions:
    for t in reversed(st.session_state.transactions[-5:]):
        st.write(f"🟒 β‚Ή{t['amount']} β†’ β‚Ή{t['rounded']} (Saved β‚Ή{t['savings']}) on {t['date']}")
else:
    st.write("No transactions yet.")

# Monthly reminder simulation
if st.button("πŸ“… New Month"):
    st.info(f"Last month you saved β‚Ή{st.session_state.balance} with multiples of β‚Ή{st.session_state.multiple}.")
    st.info("πŸ‘‰ Do you want to keep it the same, lower for less pressure, or increase for faster savings?")