From b245aceaa941d1344aa3d577bc24627fb5c80a9a Mon Sep 17 00:00:00 2001 From: Eddy Harrington Date: Sat, 27 Mar 2021 21:01:33 -0700 Subject: [PATCH] Fix expense history sorting issues --- static/js/reports.js | 2 +- tendie_expenses.py | 2 +- tendie_reports.py | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/static/js/reports.js b/static/js/reports.js index 4dae475..e403f07 100644 --- a/static/js/reports.js +++ b/static/js/reports.js @@ -174,7 +174,7 @@ function loadMonthlySpendingTable(monthlySpendingTable) { else { $('#monthlyExpenses').DataTable({ "pagingType": "full_numbers", - "order": [[0, "asc"]], + "order": [[0, "desc"]], "scrollY": "300px", "scrollCollapse": true, "paging": false, diff --git a/tendie_expenses.py b/tendie_expenses.py index 98da15c..10e46e4 100644 --- a/tendie_expenses.py +++ b/tendie_expenses.py @@ -63,7 +63,7 @@ def addExpenses(formData, userID): # Get and return the users lifetime expense history def getHistory(userID): - results = db.execute("SELECT description, category, expenseDate AS date, payer, amount, submitTime FROM expenses WHERE user_id = :usersID ORDER BY submitTime ASC", + results = db.execute("SELECT description, category, expenseDate AS date, payer, amount, submitTime FROM expenses WHERE user_id = :usersID ORDER BY id ASC", {"usersID": userID}).fetchall() history = convertSQLToDict(results) diff --git a/tendie_reports.py b/tendie_reports.py index 61f10c6..198d0fb 100644 --- a/tendie_reports.py +++ b/tendie_reports.py @@ -55,7 +55,7 @@ def generateMonthlyReport(userID, year=None): # Get the spending data from DB for the table (individual expenses per month) results = db.execute( - "SELECT description, category, expensedate, amount, payer FROM expenses WHERE user_id = :usersID AND date_part('year', date(expensedate)) = :year ORDER BY id DESC", {"usersID": userID, "year": year}).fetchall() + "SELECT description, category, expensedate, amount, payer FROM expenses WHERE user_id = :usersID AND date_part('year', date(expensedate)) = :year ORDER BY id ASC", {"usersID": userID, "year": year}).fetchall() spending_month_table = convertSQLToDict(results) # Combine both data points (chart and table) into a single data structure