Improve balance display
This commit is contained in:
parent
3b507dfe74
commit
13f3db00d5
3 changed files with 41 additions and 11 deletions
14
inc/myco.js
14
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('<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>';
|
||||
}
|
||||
$('#display_balance_modal #total-value').html(sum+' €');
|
||||
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(bal.sum.toFixed(2)+' €');
|
||||
$('#display_balance_modal').modal('show');
|
||||
}
|
||||
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
return ret;
|
||||
if(max<sum) {
|
||||
max=sum;
|
||||
}
|
||||
total[c]=sum;
|
||||
}
|
||||
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
|
||||
};
|
||||
}
|
||||
|
||||
/*
|
||||
|
|
|
@ -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> </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>
|
||||
|
|
Loading…
Reference in a new issue