From 3b2fd5d0d684cd78ece02dc4a9583b92ed431850 Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Thu, 19 Nov 2020 20:45:18 -0600 Subject: Update expected pages to include in/out/net --- src/server/index.js | 29 ++++++++++++++++++++++++----- src/templates/expected.html | 18 +++++++++++++++--- 2 files changed, 39 insertions(+), 8 deletions(-) (limited to 'src') diff --git a/src/server/index.js b/src/server/index.js index 75c00d1..c34e9d6 100644 --- a/src/server/index.js +++ b/src/server/index.js @@ -145,15 +145,34 @@ 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 + let day_in = 0 + let day_out = 0 expecteds.forEach((element, i) => { element.index = i + 1 - day_average += (element.total / element.days) + let day = (element.total / element.days) + if(day < 0) { // negative since that is income + day_in += day; + } else { + day_out += day; + } }); + let day_net = day_in + day_out; let name = res.locals.user.username - let week = Math.round(day_average * 7) - let month = Math.round(day_average * 31) - let year = Math.round(day_average * 365) + let week = { + net: Math.round(day_net * 7), + in: Math.round(day_in * 7), + out: Math.round(day_out * 7), + } + let month = { + net: Math.round(day_net * 31), + in: Math.round(day_in * 31), + out: Math.round(day_out * 31), + } + let year = { + net: Math.round(day_net * 365), + in: Math.round(day_in * 365), + out: Math.round(day_out * 365), + } let body = templates["expected"]({ name, expecteds, week, month, year }) res.status(200).send(body); } catch (e) { diff --git a/src/templates/expected.html b/src/templates/expected.html index 78d6482..1a05266 100644 --- a/src/templates/expected.html +++ b/src/templates/expected.html @@ -33,17 +33,29 @@ {{/each}} + + + + + + - + + + - + + + - + + +
PeriodInOutNet
Weekly:{{week}}{{week.in}}{{week.out}}{{week.net}}
Monthly:{{month}}{{month.in}}{{month.out}}{{month.net}}
Yearly:{{year}}{{year.in}}{{year.out}}{{year.net}}
-- cgit v1.2.3