Update app.py
Browse files
app.py
CHANGED
|
@@ -267,36 +267,36 @@ def main_app():
|
|
| 267 |
allocated_savings = st.number_input(f"Enter Amount to Allocate for {goal_name_selected}",
|
| 268 |
min_value=0, max_value=max_savings, step=100, key=f"allocate_{goal_name_selected}")
|
| 269 |
|
| 270 |
-
# Button to save the allocation
|
| 271 |
save_allocation_button = st.button(f"Save Allocation for {goal_name_selected}")
|
| 272 |
|
| 273 |
if save_allocation_button and allocated_savings > 0:
|
| 274 |
# Find the index of the selected goal and update the savings
|
| 275 |
idx = st.session_state["saving_goals"][st.session_state["saving_goals"]["Goal"] == goal_name_selected].index[0]
|
| 276 |
-
|
| 277 |
# Update the saving goal
|
| 278 |
st.session_state["saving_goals"].at[idx, "Allocated Savings"] += allocated_savings
|
| 279 |
max_savings -= allocated_savings # Adjust max savings
|
| 280 |
st.session_state["saving_goals"].at[idx, "Current Savings"] += allocated_savings # Update current savings
|
| 281 |
-
|
| 282 |
# Ensure the transaction log exists in session_state
|
| 283 |
if "transaction_log" not in st.session_state:
|
| 284 |
st.session_state["transaction_log"] = pd.DataFrame(columns=["Date", "Amount", "Type", "Goal"])
|
| 285 |
|
| 286 |
-
# Append the transaction entry
|
| 287 |
transaction_entry = {
|
| 288 |
"Date": pd.to_datetime("today"), # Ensuring Date is a datetime object
|
| 289 |
"Amount": allocated_savings,
|
| 290 |
-
"Type": "Saving",
|
| 291 |
-
"Goal": goal_name_selected
|
| 292 |
}
|
| 293 |
|
| 294 |
-
# Append the entry to the transaction log
|
| 295 |
st.session_state["transaction_log"] = st.session_state["transaction_log"].append(transaction_entry, ignore_index=True)
|
| 296 |
-
|
| 297 |
# Success message
|
| 298 |
st.success(f"Allocated {allocated_savings} to goal '{goal_name_selected}'")
|
| 299 |
-
|
| 300 |
elif save_allocation_button:
|
| 301 |
st.error("Please allocate a valid amount greater than 0.")
|
| 302 |
|
|
@@ -304,6 +304,7 @@ def main_app():
|
|
| 304 |
|
| 305 |
|
| 306 |
|
|
|
|
| 307 |
else:
|
| 308 |
st.write("No saving goals set yet.")
|
| 309 |
|
|
|
|
| 267 |
allocated_savings = st.number_input(f"Enter Amount to Allocate for {goal_name_selected}",
|
| 268 |
min_value=0, max_value=max_savings, step=100, key=f"allocate_{goal_name_selected}")
|
| 269 |
|
| 270 |
+
# Button to save the allocation for a goal
|
| 271 |
save_allocation_button = st.button(f"Save Allocation for {goal_name_selected}")
|
| 272 |
|
| 273 |
if save_allocation_button and allocated_savings > 0:
|
| 274 |
# Find the index of the selected goal and update the savings
|
| 275 |
idx = st.session_state["saving_goals"][st.session_state["saving_goals"]["Goal"] == goal_name_selected].index[0]
|
| 276 |
+
|
| 277 |
# Update the saving goal
|
| 278 |
st.session_state["saving_goals"].at[idx, "Allocated Savings"] += allocated_savings
|
| 279 |
max_savings -= allocated_savings # Adjust max savings
|
| 280 |
st.session_state["saving_goals"].at[idx, "Current Savings"] += allocated_savings # Update current savings
|
| 281 |
+
|
| 282 |
# Ensure the transaction log exists in session_state
|
| 283 |
if "transaction_log" not in st.session_state:
|
| 284 |
st.session_state["transaction_log"] = pd.DataFrame(columns=["Date", "Amount", "Type", "Goal"])
|
| 285 |
|
| 286 |
+
# Append the transaction entry for the saving allocation
|
| 287 |
transaction_entry = {
|
| 288 |
"Date": pd.to_datetime("today"), # Ensuring Date is a datetime object
|
| 289 |
"Amount": allocated_savings,
|
| 290 |
+
"Type": "Saving", # Type set as Saving
|
| 291 |
+
"Goal": goal_name_selected # Record the goal name
|
| 292 |
}
|
| 293 |
|
| 294 |
+
# Append the new transaction entry to the transaction log
|
| 295 |
st.session_state["transaction_log"] = st.session_state["transaction_log"].append(transaction_entry, ignore_index=True)
|
| 296 |
+
|
| 297 |
# Success message
|
| 298 |
st.success(f"Allocated {allocated_savings} to goal '{goal_name_selected}'")
|
| 299 |
+
|
| 300 |
elif save_allocation_button:
|
| 301 |
st.error("Please allocate a valid amount greater than 0.")
|
| 302 |
|
|
|
|
| 304 |
|
| 305 |
|
| 306 |
|
| 307 |
+
|
| 308 |
else:
|
| 309 |
st.write("No saving goals set yet.")
|
| 310 |
|