diff options
author | Mark Powers <markppowers0@gmail.com> | 2020-10-18 18:16:26 -0500 |
---|---|---|
committer | Mark Powers <markppowers0@gmail.com> | 2020-10-18 18:16:26 -0500 |
commit | 3e16b66c86b59f7f6045f29ac66e4fae37d99e0d (patch) | |
tree | 3de3855f30860952d2f425116dd9112805d795b5 /src | |
parent | a1baf96009692aff2ca123b3071d34fdcba0de63 (diff) |
Add expected averages and category summary
Diffstat (limited to 'src')
-rw-r--r-- | src/server.js | 11 | ||||
-rw-r--r-- | src/templates/expected.html | 12 | ||||
-rw-r--r-- | src/templates/summary.html | 30 |
3 files changed, 52 insertions, 1 deletions
diff --git a/src/server.js b/src/server.js index b8ccef4..c108a00 100644 --- a/src/server.js +++ b/src/server.js @@ -92,11 +92,16 @@ function setUpRoutes(models, jwtFunctions, database, templates) { server.get(`/expected`, async (req, res, next) => { try { let expecteds = await database.query(`SELECT * FROM expecteds WHERE username = '${res.locals.user.username}' ORDER BY \`name\` DESC`, { type: database.QueryTypes.SELECT }) + let day_average = 0 expecteds.forEach((element, i) => { element.index = i + 1 + day_average = element.total / element.days }); let name = res.locals.user.username - let body = templates["expected"]({ name, expecteds }) + let week = Math.round(day_average * 7) + let month = Math.round(day_average * 31) + let year = Math.round(day_average * 365) + let body = templates["expected"]({ name, expecteds, week, month, year }) res.status(200).send(body); } catch (e) { console.log(e) @@ -306,6 +311,10 @@ async function formatSummary(database, username) { summary.year_avg = getBudgetAverage(summary.year) summary.month_avg = getBudgetAverage(summary.month) summary.week_avg = getBudgetAverage(summary.week) + + + summary.categories = await database.query(`select category, sum(amount) as s from transactions where category <> '' group by category`, { type: database.QueryTypes.SELECT }); + summary.subcategories = await database.query(`select subcategory, sum(amount) as s from transactions where subcategory <> '' group by subcategory`, { type: database.QueryTypes.SELECT }); summary.name = username return summary } diff --git a/src/templates/expected.html b/src/templates/expected.html index 15b9d7c..99bf6fd 100644 --- a/src/templates/expected.html +++ b/src/templates/expected.html @@ -33,6 +33,18 @@ </tr> {{/each}} </table> + <table> + <tr> + <td>Weekly:</td> + <td>{{week}}</td> + </tr><tr> + <td>Monthly:</td> + <td>{{month}}</td> + </tr><tr> + <td>Yearly:</td> + <td>{{year}}</td> + </tr> + </table> </body> </html> diff --git a/src/templates/summary.html b/src/templates/summary.html index d78182a..bdc2f44 100644 --- a/src/templates/summary.html +++ b/src/templates/summary.html @@ -99,6 +99,36 @@ </tr> </table> </div> + <div class="summary-panel"> + <h2>Categories</h2> + <table class="table"> + <tr> + <th>Category</th> + <th>Total</th> + </tr> + {{#each categories}} + <tr> + <td>{{this.category}}</td> + <td>{{this.s}}</td> + </tr> + {{/each}} + </table> + </div> + <div class="summary-panel"> + <h2>Sub-Categories</h2> + <table class="table"> + <tr> + <th>Sub-Category</th> + <th>Total</th> + </tr> + {{#each subcategories}} + <tr> + <td>{{this.subcategory}}</td> + <td>{{this.s}}</td> + </tr> + {{/each}} + </table> + </div> </body> </html>
\ No newline at end of file |