From d510448277ae325f5de5cd3b9bc23b201ed6b1e5 Mon Sep 17 00:00:00 2001 From: Dennis Eriksen Date: Fri, 24 May 2013 22:06:12 +0200 Subject: added overview and example of dividing. --- controllers/system.js | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'controllers/system.js') diff --git a/controllers/system.js b/controllers/system.js index 9629c17..c083835 100644 --- a/controllers/system.js +++ b/controllers/system.js @@ -153,6 +153,7 @@ exports.project = function(req, res) { , user: [] // this array will contain every user. Every user will then have it's own object inside this. , total: 0 // the overall total. , each: 0 // what each person has to pay + , otot: 0 // how much is owned in total! }; // then we calculate how many users we have, and initiate objects foreach user @@ -160,9 +161,11 @@ exports.project = function(req, res) { if (String(a.user._id) === String(req.user._id)) req.user.permissions = a.permissions; //sets YOUR permissions in this project pro.users++; - pro.user[a.user.id] = { + pro.user[a.user._id] = { total: 0 , diff: 0 + , coeff: 0 // the coefficient of hom much you are owned + , name: a.user.name }; }); @@ -178,8 +181,11 @@ exports.project = function(req, res) { // then calculate how much each person owe and is owned for(var i in pro.user) { pro.user[i].diff = parseFloat(pro.user[i].total - pro.each).toFixed(2); + if (pro.user[i].diff > 0) pro.otot += parseFloat(pro.user[i].diff); + } + for (var i in pro.user) { + if (pro.user[i].diff > 0) pro.user[i].coeff = pro.user[i].diff / pro.otot; } - console.log(pro); res.render('project', { title: project.name -- cgit v1.2.3