Skip to content

Commit

Permalink
Fix dashboard year/ordering issues
Browse files Browse the repository at this point in the history
  • Loading branch information
eddyharrington committed Mar 27, 2021
1 parent 86c87c9 commit 3bed487
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 18 deletions.
28 changes: 14 additions & 14 deletions templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,8 @@ <h5 class="modal-title" id="quickExpenseModalLabel">Add Expense</h5>
</div>
<div class="form-group">
<label for="date" class="col-form-label">Date:</label>
<input type="date" class="form-control" name="date" id="date" value="{{ date }}" form="quickExpense"
required>
<input type="date" class="form-control" name="date" id="date" value="{{ date }}"
form="quickExpense" required>
</div>
<div class="form-group">
<label for="payer" class="col-form-label">Payer:</label>
Expand Down Expand Up @@ -88,17 +88,16 @@ <h2 style="text-align:left">Your Expenses</h2>
<div class="card-header"><strong>Remaining Income</strong></div>
<div class="card-body">
{% set remainingIncome = (income - expenses_year) %}
{% if remainingIncome < 0 %}
<h4 class="card-title">$0</h4>
{% else %}
<h4 class="card-title">{{ remainingIncome | usd }}</h4>
{% endif %}
{% if remainingIncome < 0 %} <h4 class="card-title">$0</h4>
{% else %}
<h4 class="card-title">{{ remainingIncome | usd }}</h4>
{% endif %}
</div>
</div>
</div>
<div class="col">
<div class="card text-white bg-warning mb-3" style="max-width: 20rem;">
<div class="card-header"><strong>2020 Expenses</strong></div>
<div class="card-header"><strong>{{ date[:4] }} Expenses</strong></div>
<div class="card-body">
{% if expenses_year != None %}
<h4 class="card-title">{{ expenses_year | usd }}</h4>
Expand Down Expand Up @@ -191,8 +190,8 @@ <h2 style="text-align:left">Your Budgets</h2>
{% for budget in budgets %}
<div class="col">
<div class="card bg-light mb-3" style="max-width: 14rem;">
<div class="card-header"><strong><a
href="/updatebudget/{{ budget['name'] }}">{{ budget["name"] }}</a></strong></div>
<div class="card-header"><strong><a href="/updatebudget/{{ budget['name'] }}">{{ budget["name"]
}}</a></strong></div>
<div class="card-body-dash">
{% set percent = ((budget["spent"] / budget["amount"]) * 100) %}
{% set totalBudgetAmount = (budget["amount"] | usd) %}
Expand Down Expand Up @@ -303,10 +302,11 @@ <h2 style="text-align:left">Payer Spending</h2>
<div class="row">
{% if payersChart %}
<div class="col-12">
<div class="chart-container" style="position: relative; height:40vh">
<canvas id="payersChart" width="400" height="400"></canvas>
</div>
<p><small class="text-muted">Chart note: does not include payers that represent less than 1% of overall spending</small></p>
<div class="chart-container" style="position: relative; height:40vh">
<canvas id="payersChart" width="400" height="400"></canvas>
</div>
<p><small class="text-muted">Chart note: does not include payers that represent less than 1% of overall
spending</small></p>
</div>
{% else %}
<div class="col">
Expand Down
8 changes: 4 additions & 4 deletions tendie_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 3bed487

Please sign in to comment.