def payersreport(): """View payers spending report""" # Generate a data structure that combines the users payers and expense data for chart and table payersReport = tendie_reports.generatePayersReport(session["user_id"]) return render_template("payersreport.html", payers=payersReport)
def payersreport(year=None): """View payers spending report""" # Make sure the year from route is valid if year: currentYear = datetime.now().year if not 2020 <= year <= currentYear: return apology(f"Please select a valid budget year: 2020 through {currentYear}") else: # Set year to current year if it was not in the route (this will set UX to display current years report) year = datetime.now().year # Generate a data structure that combines the users payers and expense data for chart and table payersReport = tendie_reports.generatePayersReport( session["user_id"], year) return render_template("payersreport.html", payers=payersReport, year=year)
def index(): """Show dashboard of budget/expenses""" # User reached route via GET if request.method == "GET": # TODO reduce or completely remove the redundant use of javascript code in dashboard.js and reports.js # Initialize metrics to None to render the appropriate UX if data does not exist yet for the user expenses_year = None expenses_month = None expenses_week = None expenses_last5 = None spending_week = [] spending_month = [] # Get the users spend categories (for quick expense modal) categories = tendie_categories.getSpendCategories(session["user_id"]) # Get the users payers (for quick expense modal) payers = tendie_account.getPayers(session["user_id"]) # Get todays date (for quick expense modal) date = datetime.today().strftime('%Y-%m-%d') # Get the users income income = tendie_account.getIncome(session["user_id"]) # Get current years total expenses for the user expenses_year = tendie_dashboard.getTotalSpend_Year(session["user_id"]) # Get current months total expenses for the user expenses_month = tendie_dashboard.getTotalSpend_Month( session["user_id"]) # Get current week total expenses for the user expenses_week = tendie_dashboard.getTotalSpend_Week(session["user_id"]) # Get last 5 expenses for the user expenses_last5 = tendie_dashboard.getLastFiveExpenses( session["user_id"]) # Get every budgets spent/remaining for the user budgets = tendie_dashboard.getBudgets(session["user_id"]) # Get weekly spending for the user weeks = tendie_dashboard.getLastFourWeekNames() spending_week = tendie_dashboard.getWeeklySpending( weeks, session["user_id"]) # Get monthly spending for the user (for the current year) spending_month = tendie_dashboard.getMonthlySpending( session["user_id"]) # Get spending trends for the user spending_trends = tendie_dashboard.getSpendingTrends( session["user_id"]) # Get payer spending for the user payersChart = tendie_reports.generatePayersReport(session["user_id"]) return render_template("index.html", categories=categories, payers=payers, date=date, income=income, expenses_year=expenses_year, expenses_month=expenses_month, expenses_week=expenses_week, expenses_last5=expenses_last5, budgets=budgets, spending_week=spending_week, spending_month=spending_month, spending_trends=spending_trends, payersChart=payersChart) # User reached route via POST else: # Get all of the expenses provided from the HTML form formData = list(request.form.items()) # Add expenses to the DB for user expenses = tendie_expenses.addExpenses(formData, session["user_id"]) # Redirect to results page and render a summary of the submitted expenses return render_template("expensed.html", results=expenses)