aboutsummaryrefslogtreecommitdiffstatshomepage
diff options
context:
space:
mode:
authorDennis Eriksen <dennis.se@gmail.com>2013-05-24 22:06:12 +0200
committerDennis Eriksen <dennis.se@gmail.com>2013-05-24 22:06:12 +0200
commitd510448277ae325f5de5cd3b9bc23b201ed6b1e5 (patch)
tree506420f9e7c82edff128377600bb1d43e80a4efd
parentremoved the invitethingy. this will have to be for later. closes #49 (diff)
downloadDivid-d510448277ae325f5de5cd3b9bc23b201ed6b1e5.tar.gz
added overview and example of dividing.
-rw-r--r--controllers/system.js10
-rw-r--r--views/project.ejs42
2 files changed, 45 insertions, 7 deletions
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
diff --git a/views/project.ejs b/views/project.ejs
index d78d11c..dedd5e4 100644
--- a/views/project.ejs
+++ b/views/project.ejs
@@ -53,7 +53,7 @@
- <div class="span6 smallfullwidth">
+ <div class="span6 smallfullwidth" id="accordion">
<section class="status">
<div class="row-fluid">
<div class="span6 smallfullwidth">
@@ -69,12 +69,44 @@
</tr>
</table><a href="#table-info" class="accordion-toggle" data-toggle="collapse"><i class="icon-info-sign"></i></a>
</div>
- <div class="row-fluid accordion collapse" id="table-info">
- <p class="text-info"><small>Her vises hvor mye andre skylder deg totalt, hvor mye du skylder andre totalt, og differansen mellom disse to tallene</small></p>
- </div>
</div>
</div>
- <canvas id="myChart" width="450" height="200"></canvas>
+ <div class="row-fluid accordion-body collapse" id="table-info">
+ <p>Det er til sammen brukt <strong><%= (pro.total).toFixed(2) %></strong> <%= project.currency %>. Deltakerne skal altså betale <strong><%= (pro.each).toFixed(2) %></strong> <%= project.currency %> hver.</p>
+ <% for (var i in pro.user) { %>
+ <%- pro.user[i].name %> har betalt <%= pro.user[i].total %> <%= project.currency %>, og <%- pro.user[i].diff >= 0 ? 'skyldes <span class="text-success">' + pro.user[i].diff : 'skylder <span class="text-error">' + Math.abs(pro.user[i].diff) %></span> <%= project.currency %><br>
+ <% } %>
+ <p><small><a href="#example" data-toggle="collapse" class="accordion-toggle">Eksempel på hvordan oppgjøret kan gjøres</a></small></p>
+ </div>
+ <div class="row-fluid collapse" id="example">
+ <table>
+ <%
+ // FUGLY LAST-MINUTE CODE
+ var i = 1;
+ for (var u in pro.user) {
+ if (pro.user[u].coeff === 0) {
+ if (i === 1) {%>
+ <tr>
+ <td></td>
+ <% for (var p in pro.user) { %>
+ <%- pro.user[p].coeff > 0 ? '<td>' + pro.user[p].name + '</td>' : '' %>
+ <% } %>
+ </tr>
+ <% } %>
+ <tr>
+ <td><%- pro.user[u].name %></td>
+ <% for (var p in pro.user) { %>
+ <%- pro.user[p].coeff > 0 ? '<td>' + (Math.abs(pro.user[u].diff) * pro.user[p].coeff).toFixed(2) + '</td>' : '' %>
+ <% } %>
+ </tr>
+<% i++;
+ }} %>
+ </table>
+
+ </div>
+ <div class="row-fluid accordion-body in collapse" id="chart">
+ <canvas id="myChart" width="450" height="200"></canvas>
+ </div>
</section>
</div>
</div>