Improve balance display

This commit is contained in:
Benjamin Renard 2014-01-12 20:07:01 +01:00
parent 3b507dfe74
commit 13f3db00d5
3 changed files with 41 additions and 11 deletions

View file

@ -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('<tr><td>'+c+'</td><td>'+bal[c]+' €</td></tr>');
sum+=bal[c];
for (c in bal['balance']) {
if(bal['balance'][c]['diff']<0) {
diff='<td class="negative">'+bal['balance'][c]['diff'].toFixed(2)+' €</td>';
}
else {
diff='<td><span class="glyphicon glyphicon-thumbs-up"></span></td>';
}
tbody.append('<tr><td>'+c+'</td><td>'+bal['balance'][c]['total']+' €</td>'+diff+'</tr>');
}
$('#display_balance_modal #total-value').html(sum+' €');
$('#display_balance_modal #total-value').html(bal.sum.toFixed(2)+' €');
$('#display_balance_modal').modal('show');
}

View file

@ -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<sum) {
max=sum;
}
total[c]=sum;
}
return ret;
balance={}
var sum=0;
for (c in total) {
balance[c]={
'total': total[c],
'diff': total[c]-max,
}
sum=sum+total[c];
}
return {
'balance': balance,
'sum': sum,
'min': min,
'max': max
};
}
/*

View file

@ -293,13 +293,17 @@ body{
<div class="modal-body">
<table class="table table-striped">
<thead>
<tr><th>Participant</th><th>Participation</th></tr>
<tr>
<th>Participant</th>
<th>Participation</th>
<th>&nbsp;</th>
</tr>
</thead>
<tbody></tbody>
<tfoot>
<tr>
<td id='total-label'>Total :</td>
<td id='total-value'></td>
<td colspan='2' id='total-value'></td>
</tr>
</tfoot>
</table>