From 35b6d276bdeabdf7bf5eee59d85dfefee7531fce Mon Sep 17 00:00:00 2001 From: Mark Powers Date: Wed, 7 Oct 2020 10:54:15 -0500 Subject: Add expected expenses --- src/index.html | 47 +++++++++++++++++++++++++++++++++++------------ src/index.js | 18 ++++++++++++++++++ src/main.js | 32 +++++++++++++++++++++----------- src/server.js | 23 +++++++++++++++++++++++ 4 files changed, 97 insertions(+), 23 deletions(-) (limited to 'src') diff --git a/src/index.html b/src/index.html index 08c5007..cba242d 100644 --- a/src/index.html +++ b/src/index.html @@ -16,20 +16,21 @@

{{summary.username}}'s budget

- - - + + + +
-
+
- +
@@ -50,14 +51,14 @@
{{transaction.subcategory}} - +
- +
@@ -83,12 +84,12 @@ - +
Date
-
+

Weekly

@@ -150,13 +151,13 @@ -
+
New Goal - +
Allocate funds @@ -167,7 +168,7 @@ out of {{total_to_allocate}} - +
@@ -181,6 +182,28 @@
NameAmountTotalRemaining
+ + +
+
+
+ New Expected + + + + +
+ + + + + + + + +
NameTotalPeriod
{{i+1}}{{e.name}}{{e.total}}{{e.days}}
+
+
diff --git a/src/index.js b/src/index.js index bf64586..0cbba31 100644 --- a/src/index.js +++ b/src/index.js @@ -90,6 +90,24 @@ function setUpModels() { allowNull: false, } }), + "expected": database.define('expected', { + username: { + type: Sequelize.STRING, + allowNull: false, + }, + name: { + type: Sequelize.STRING, + allowNull: false, + }, + total: { + type: Sequelize.DECIMAL, + allowNull: false, + }, + days: { + type: Sequelize.INTEGER, + allowNull: false, + } + }), "users": database.define('user', { username: { type: Sequelize.STRING, diff --git a/src/main.js b/src/main.js index 78b918e..0a381b0 100644 --- a/src/main.js +++ b/src/main.js @@ -2,12 +2,13 @@ window.onload = function () { var transactionData = new Vue({ el: '#data', data: { - activeTab: 0, + activeTab: "ledger", transactions: [], summary: {username : ""}, selTodoType: "all", total_to_allocate: 0, - goals: [] + goals: [], + expected: [] }, methods: { setTab: function (value) { @@ -33,17 +34,24 @@ window.onload = function () { total: "", amount: 0 } + this.e = { + name: "", + total: "", + days: 7 + } this.na = { selected: "", amount: "" } }, - requestThenUpdate: function (request) { + requestThenUpdate: function (request, app, field) { fetch(request) .then(response => response.json()) - .then(response => this.transactions = response); + .then(response => { + app[field] = response + }); }, - post: function (obj, path) { + post: function (obj, path, save_to) { console.log(obj); console.log(path); this.requestThenUpdate(new Request(path, { @@ -53,10 +61,10 @@ window.onload = function () { 'Content-Type': 'application/json' }, body: JSON.stringify(obj) - })); + }), this, save_to); this.clearData(); }, - remove: function (obj) { + remove: function (obj, save_to) { if (confirm(`Delete transaction?`)) { this.requestThenUpdate(new Request("/transaction", { method: 'delete', @@ -65,7 +73,7 @@ window.onload = function () { 'Content-Type': 'application/json' }, body: JSON.stringify(obj) - })) + }), this, save_to) } }, prepareEntryEdit: function(transaction){ @@ -75,9 +83,9 @@ window.onload = function () { this.em.amount=transaction.amount; this.em.category=transaction.category; this.em.subcategory=transaction.subcategory; - this.activeTab=10; + this.activeTab='ledger-edit'; }, - updateMany: function (obj) { + updateMany: function (obj, save_to) { update = {} update = obj; this.requestThenUpdate(new Request("/transaction", { @@ -87,11 +95,13 @@ window.onload = function () { 'Content-Type': 'application/json' }, body: JSON.stringify({ id: obj.id, update: update }) - })) + }), this, save_to) }, }, created() { this.clearData(); + fetch(new Request(`/expected`)).then(response => response.json()) + .then(response => this.expected = response); fetch(new Request(`/goals`)).then(response => response.json()) .then(response => this.goals = response); fetch(new Request(`/transaction`)).then(response => response.json()) diff --git a/src/server.js b/src/server.js index 69d3968..f72f21b 100644 --- a/src/server.js +++ b/src/server.js @@ -163,6 +163,29 @@ function setUpRoutes(models, jwtFunctions, database) { res.status(400).send(e.message); } }) + server.get(`/expected`, async (req, res, next) => { + try { + var result = await database.query("SELECT * FROM expecteds WHERE username = '" + res.locals.user.username + "' ORDER BY `name` DESC", { type: database.QueryTypes.SELECT }) + res.status(200).send(result); + next(); + } catch (e) { + console.log(e) + res.status(400).send(e.message); + } + }) + server.post(`/expected`, async (req, res, next) => { + try { + let item = req.body; + console.log(item); + item.username = res.locals.user.username + await models.expected.create(item); + var result = await database.query("SELECT * FROM expecteds WHERE username = '" + res.locals.user.username + "' ORDER BY `name` DESC", { type: database.QueryTypes.SELECT }) + res.status(200).send(result); + } catch (e) { + console.log(e); + res.status(400).send(e.message); + } + }) server.get(`/summary`, async (req, res, next) => { try { res.status(200).send({ -- cgit v1.2.3