From 13f3db00d591a5709d95231fe13c2630885eaf9b Mon Sep 17 00:00:00 2001 From: Benjamin Renard Date: Sun, 12 Jan 2014 20:07:01 +0100 Subject: [PATCH] Improve balance display --- inc/myco.js | 14 +++++++++----- inc/myco_objects.js | 30 ++++++++++++++++++++++++++---- index.html | 8 ++++++-- 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/inc/myco.js b/inc/myco.js index c303d89..5e1a33d 100644 --- a/inc/myco.js +++ b/inc/myco.js @@ -338,12 +338,16 @@ display_balance=function(group) { bal=group.balance(); tbody=$($('#display_balance_modal tbody')[0]); tbody.html(''); - sum=0; - for (c in bal) { - tbody.append(''+c+''+bal[c]+' €'); - sum+=bal[c]; + for (c in bal['balance']) { + if(bal['balance'][c]['diff']<0) { + diff=''+bal['balance'][c]['diff'].toFixed(2)+' €'; + } + else { + diff=''; + } + tbody.append(''+c+''+bal['balance'][c]['total']+' €'+diff+''); } - $('#display_balance_modal #total-value').html(sum+' €'); + $('#display_balance_modal #total-value').html(bal.sum.toFixed(2)+' €'); $('#display_balance_modal').modal('show'); } diff --git a/inc/myco_objects.js b/inc/myco_objects.js index e97910c..8ed0340 100644 --- a/inc/myco_objects.js +++ b/inc/myco_objects.js @@ -174,17 +174,39 @@ function Group(name,data) { * Balance */ this.balance=function() { - ret={} + total={} + min=-1; + max=0; for (idx in this.contributors) { - sum=0; + var sum=0; c=this.contributors[idx].name; cl=this.contributionsByContributorName(c); for (idc in cl) { sum+=cl[idc].cost; } - ret[c]=sum; + if (min==-1 || min>sum) { + min=sum; + } + if(max - + + + + + - +
ParticipantParticipation
ParticipantParticipation 
Total :