-
Create a new savings goal
- Input: • User ID, • Target Date, • Target Amount, • Goal Name, • Amount Saved
- Output: Return the new goal
-
Update a savings goal
- Input: Goal ID, New Target Amount
- Output: Return the updated savings goal
-
Record savings progress
- Input: Goal ID, Amount to Add
- Output: Store the updated savings progress and return the updated goal
-
Retrieve savings goal status
- Input: Goal ID
- Output: Return the goal status (including current amount saved, target amount, target date, etc.)
-
Check savings goal progress and notify if behind schedule
- Input: Goal ID, Current Date
- Output: Return a message indicating the number of days left until the target date and whether the user is on track (or a warning if the goal is at risk of not being met)
# ==========================================
# SAVINGS GOAL FUNCTIONS
# ==========================================
# Adds a new goal to the database for a specific user
FUNCTION addSavingsGoal(user_id, target_date, target_amount, goal_name):
Find the user record using user_id
Create a new entry in the 'goals' table with the provided details
Set initial amount_saved to 0
SAVE changes to database
# Updates the target amount of an existing goal
FUNCTION updateSavingsGoal(goal_id, new_target_amount):
Find the specific goal in the database using goal_id
UPDATE goal set target_amount = new_target_amount
SAVE changes to database
# Returns the raw currency amount remaining to reach the goal
FUNCTION getSavingsProgressAmount(goal_id):
goal = Find goal by goal_id
remaining_balance = calculateDifference(goal.target_amount, goal.amount_saved)
RETURN remaining_balance
# Returns the percentage of the goal completed
FUNCTION getSavingsStatusPercentage(goal_id):
goal = Find goal by goal_id
percentage = (goal.amount_saved / goal.target_amount) * 100
RETURN percentage
# Notifies the user if the goal date has passed without meeting the target
FUNCTION checkGoalNotification(goal_id, current_date):
goal = Find goal by goal_id
IF goal.amount_saved < goal.target_amount AND current_date >= goal.target_date:
days_past = current_date - goal.target_date
RETURN "Goal not met. It is " + days_past + " days past your target date."
ELSE:
RETURN None
# ==========================================
# HELPERS
# ==========================================
# Calculates the remaining gap toward the target
FUNCTION calculateDifference(target, current):
RETURN target - current