From 3bed4871ae42c21fdc895c011dcb6bc5dabc6125 Mon Sep 17 00:00:00 2001 From: Eddy Harrington Date: Sat, 27 Mar 2021 10:30:20 -0700 Subject: [PATCH] Fix dashboard year/ordering issues --- templates/index.html | 28 ++++++++++++++-------------- tendie_dashboard.py | 8 ++++---- 2 files changed, 18 insertions(+), 18 deletions(-) diff --git a/templates/index.html b/templates/index.html index 8c42db9..a859351 100644 --- a/templates/index.html +++ b/templates/index.html @@ -42,8 +42,8 @@
- +
@@ -88,17 +88,16 @@

Your Expenses

Remaining Income
{% set remainingIncome = (income - expenses_year) %} - {% if remainingIncome < 0 %} -

$0

- {% else %} -

{{ remainingIncome | usd }}

- {% endif %} + {% if remainingIncome < 0 %}

$0

+ {% else %} +

{{ remainingIncome | usd }}

+ {% endif %}
-
2020 Expenses
+
{{ date[:4] }} Expenses
{% if expenses_year != None %}

{{ expenses_year | usd }}

@@ -191,8 +190,8 @@

Your Budgets

{% for budget in budgets %}
- +
{% set percent = ((budget["spent"] / budget["amount"]) * 100) %} {% set totalBudgetAmount = (budget["amount"] | usd) %} @@ -303,10 +302,11 @@

Payer Spending

{% if payersChart %}
-
- -
-

Chart note: does not include payers that represent less than 1% of overall spending

+
+ +
+

Chart note: does not include payers that represent less than 1% of overall + spending

{% else %}
diff --git a/tendie_dashboard.py b/tendie_dashboard.py index b13cce0..89582b8 100644 --- a/tendie_dashboard.py +++ b/tendie_dashboard.py @@ -28,7 +28,7 @@ def getTotalSpend_Year(userID): # Get and return the users total spend for the current month def getTotalSpend_Month(userID): results = db.execute( - "SELECT SUM(amount) AS expenses_month FROM expenses WHERE user_id = :usersID AND date_part('month', date(expensedate)) = date_part('month', CURRENT_DATE)", + "SELECT SUM(amount) AS expenses_month FROM expenses WHERE user_id = :usersID AND date_part('year', date(expensedate)) = date_part('year', CURRENT_DATE) AND date_part('month', date(expensedate)) = date_part('month', CURRENT_DATE)", {"usersID": userID}).fetchall() totalSpendMonth = convertSQLToDict(results) @@ -40,7 +40,7 @@ def getTotalSpend_Month(userID): def getTotalSpend_Week(userID): # Query note: Day 0 of a week == Sunday. This query grabs expenses between the *current* weeks Monday and Sunday. results = db.execute( - "SELECT SUM(amount) AS expenses_week FROM expenses WHERE user_id = :usersID AND date_part('week', date(expensedate)) = date_part('week', CURRENT_DATE)", + "SELECT SUM(amount) AS expenses_week FROM expenses WHERE user_id = :usersID AND date_part('year', date(expensedate)) = date_part('year', CURRENT_DATE) AND date_part('week', date(expensedate)) = date_part('week', CURRENT_DATE)", {"usersID": userID}).fetchall() totalSpendWeek = convertSQLToDict(results) @@ -51,7 +51,7 @@ def getTotalSpend_Week(userID): # Get and return the users last 5 expenses def getLastFiveExpenses(userID): results = db.execute( - "SELECT description, category, expenseDate, payer, amount FROM expenses WHERE user_id = :usersID ORDER BY submitTime DESC LIMIT 5", {"usersID": userID}).fetchall() + "SELECT description, category, expenseDate, payer, amount FROM expenses WHERE user_id = :usersID ORDER BY id DESC LIMIT 5", {"usersID": userID}).fetchall() lastFiveExpenses = convertSQLToDict(results) @@ -125,7 +125,7 @@ def getWeeklySpending(weekNames, userID): week["endOfWeek"] = str(name["endofweek"]) week["startOfWeek"] = str(name["startofweek"]) results = db.execute( - "SELECT SUM(amount) AS amount FROM expenses WHERE user_id = :usersID AND date_part('week', date(expensedate)) = date_part('week',date(:weekName))", + "SELECT SUM(amount) AS amount FROM expenses WHERE user_id = :usersID AND date_part('year', date(expensedate)) = date_part('year', date(:weekName)) AND date_part('week', date(expensedate)) = date_part('week',date(:weekName))", {"usersID": userID, "weekName": week["endOfWeek"]}).fetchall() weekSpending = convertSQLToDict(results)