Update app.py
Browse files
app.py
CHANGED
|
@@ -187,36 +187,68 @@ def main_app():
|
|
| 187 |
else:
|
| 188 |
st.warning("No transactions recorded yet.")
|
| 189 |
|
| 190 |
-
#
|
| 191 |
elif tabs == "Savings":
|
| 192 |
st.header("Savings Goals")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 193 |
goal_name = st.text_input("Goal Name")
|
| 194 |
target_amount = st.number_input("Target Amount", min_value=0, step=100)
|
| 195 |
goal_deadline = st.date_input("Deadline", value=date.today())
|
|
|
|
|
|
|
| 196 |
set_goal_button = st.button("Set Saving Goal")
|
| 197 |
-
|
| 198 |
-
|
| 199 |
if set_goal_button:
|
| 200 |
-
|
| 201 |
-
|
| 202 |
-
|
| 203 |
-
|
| 204 |
-
|
| 205 |
-
|
| 206 |
-
|
| 207 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 208 |
if not st.session_state["saving_goals"].empty:
|
|
|
|
| 209 |
for idx, goal in st.session_state["saving_goals"].iterrows():
|
| 210 |
progress = (goal["Current Savings"] / goal["Target Amount"]) if goal["Target Amount"] > 0 else 0
|
| 211 |
st.write(f"**{goal['Goal']}**")
|
| 212 |
st.write(f"Target Amount: {goal['Target Amount']}, Current Savings: {goal['Current Savings']}, Deadline: {goal['Deadline']}")
|
| 213 |
st.progress(progress) # progress as a fraction (0.0 to 1.0)
|
| 214 |
st.write(f"Progress: {progress * 100:.2f}%") # Display as a percentage
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 215 |
|
| 216 |
-
delete_goal_idx = st.selectbox("Select Goal to Delete", options=[""] + list(st.session_state["saving_goals"]["Goal"]))
|
| 217 |
-
if delete_goal_idx:
|
| 218 |
-
st.session_state["saving_goals"] = st.session_state["saving_goals"][st.session_state["saving_goals"]["Goal"] != delete_goal_idx]
|
| 219 |
-
st.success(f"Goal '{delete_goal_idx}' deleted successfully.")
|
| 220 |
|
| 221 |
# Budget Recommendations Tab
|
| 222 |
elif tabs == "Budget Recommendations":
|
|
|
|
| 187 |
else:
|
| 188 |
st.warning("No transactions recorded yet.")
|
| 189 |
|
| 190 |
+
# Set Saving Goals Tab
|
| 191 |
elif tabs == "Savings":
|
| 192 |
st.header("Savings Goals")
|
| 193 |
+
|
| 194 |
+
# Fetch net savings from Home tab
|
| 195 |
+
total_income = st.session_state['income_data']['Amount'].sum()
|
| 196 |
+
total_expense = st.session_state['expense_data']['Amount'].sum()
|
| 197 |
+
net_savings = total_income - total_expense
|
| 198 |
+
max_savings = total_income - total_expense - net_savings
|
| 199 |
+
|
| 200 |
goal_name = st.text_input("Goal Name")
|
| 201 |
target_amount = st.number_input("Target Amount", min_value=0, step=100)
|
| 202 |
goal_deadline = st.date_input("Deadline", value=date.today())
|
| 203 |
+
|
| 204 |
+
# Form to create a new saving goal
|
| 205 |
set_goal_button = st.button("Set Saving Goal")
|
| 206 |
+
|
|
|
|
| 207 |
if set_goal_button:
|
| 208 |
+
if goal_name and target_amount > 0:
|
| 209 |
+
new_goal = {"Goal": goal_name,
|
| 210 |
+
"Target Amount": target_amount,
|
| 211 |
+
"Current Savings": net_savings,
|
| 212 |
+
"Deadline": goal_deadline,
|
| 213 |
+
"Allocated Savings": 0}
|
| 214 |
+
st.session_state["saving_goals"] = pd.concat(
|
| 215 |
+
[st.session_state["saving_goals"], pd.DataFrame([new_goal])], ignore_index=True
|
| 216 |
+
)
|
| 217 |
+
st.success("Goal set successfully!")
|
| 218 |
+
else:
|
| 219 |
+
st.error("Please provide valid goal name and target amount.")
|
| 220 |
+
|
| 221 |
+
# Form to allocate savings
|
| 222 |
+
st.subheader("Allocate Savings to Goals")
|
| 223 |
+
if not st.session_state["saving_goals"].empty:
|
| 224 |
+
for idx, goal in st.session_state["saving_goals"].iterrows():
|
| 225 |
+
allocated_savings = st.number_input(f"Allocate Savings for {goal['Goal']}", min_value=0,
|
| 226 |
+
max_value=max_savings, step=100, key=f"allocate_{idx}")
|
| 227 |
+
if allocated_savings > 0:
|
| 228 |
+
# Update the allocated savings for the respective goal
|
| 229 |
+
st.session_state["saving_goals"].at[idx, "Allocated Savings"] += allocated_savings
|
| 230 |
+
max_savings -= allocated_savings # Adjust max savings
|
| 231 |
+
st.session_state["saving_goals"].at[idx, "Current Savings"] += allocated_savings # Update current savings
|
| 232 |
+
st.success(f"Allocated {allocated_savings} to goal '{goal['Goal']}'")
|
| 233 |
+
|
| 234 |
+
# Display current goals and their progress
|
| 235 |
if not st.session_state["saving_goals"].empty:
|
| 236 |
+
st.subheader("Current Goals and Allocated Savings")
|
| 237 |
for idx, goal in st.session_state["saving_goals"].iterrows():
|
| 238 |
progress = (goal["Current Savings"] / goal["Target Amount"]) if goal["Target Amount"] > 0 else 0
|
| 239 |
st.write(f"**{goal['Goal']}**")
|
| 240 |
st.write(f"Target Amount: {goal['Target Amount']}, Current Savings: {goal['Current Savings']}, Deadline: {goal['Deadline']}")
|
| 241 |
st.progress(progress) # progress as a fraction (0.0 to 1.0)
|
| 242 |
st.write(f"Progress: {progress * 100:.2f}%") # Display as a percentage
|
| 243 |
+
|
| 244 |
+
# Option to delete a goal
|
| 245 |
+
delete_goal_idx = st.selectbox("Select Goal to Delete", options=[""] + list(st.session_state["saving_goals"]["Goal"]))
|
| 246 |
+
if delete_goal_idx:
|
| 247 |
+
st.session_state["saving_goals"] = st.session_state["saving_goals"][st.session_state["saving_goals"]["Goal"] != delete_goal_idx]
|
| 248 |
+
st.success(f"Goal '{delete_goal_idx}' deleted successfully.")
|
| 249 |
+
else:
|
| 250 |
+
st.write("No savings goals set yet.")
|
| 251 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 252 |
|
| 253 |
# Budget Recommendations Tab
|
| 254 |
elif tabs == "Budget Recommendations":
|