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();
|
bal=group.balance();
|
||||||
tbody=$($('#display_balance_modal tbody')[0]);
|
tbody=$($('#display_balance_modal tbody')[0]);
|
||||||
tbody.html('');
|
tbody.html('');
|
||||||
sum=0;
|
for (c in bal['balance']) {
|
||||||
for (c in bal) {
|
if(bal['balance'][c]['diff']<0) {
|
||||||
tbody.append('<tr><td>'+c+'</td><td>'+bal[c]+' €</td></tr>');
|
diff='<td class="negative">'+bal['balance'][c]['diff'].toFixed(2)+' €</td>';
|
||||||
sum+=bal[c];
|
}
|
||||||
|
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');
|
$('#display_balance_modal').modal('show');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -174,17 +174,39 @@ function Group(name,data) {
|
||||||
* Balance
|
* Balance
|
||||||
*/
|
*/
|
||||||
this.balance=function() {
|
this.balance=function() {
|
||||||
ret={}
|
total={}
|
||||||
|
min=-1;
|
||||||
|
max=0;
|
||||||
for (idx in this.contributors) {
|
for (idx in this.contributors) {
|
||||||
sum=0;
|
var sum=0;
|
||||||
c=this.contributors[idx].name;
|
c=this.contributors[idx].name;
|
||||||
cl=this.contributionsByContributorName(c);
|
cl=this.contributionsByContributorName(c);
|
||||||
for (idc in cl) {
|
for (idc in cl) {
|
||||||
sum+=cl[idc].cost;
|
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
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
|
|
@ -293,13 +293,17 @@ body{
|
||||||
<div class="modal-body">
|
<div class="modal-body">
|
||||||
<table class="table table-striped">
|
<table class="table table-striped">
|
||||||
<thead>
|
<thead>
|
||||||
<tr><th>Participant</th><th>Participation</th></tr>
|
<tr>
|
||||||
|
<th>Participant</th>
|
||||||
|
<th>Participation</th>
|
||||||
|
<th> </th>
|
||||||
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
<tbody></tbody>
|
<tbody></tbody>
|
||||||
<tfoot>
|
<tfoot>
|
||||||
<tr>
|
<tr>
|
||||||
<td id='total-label'>Total :</td>
|
<td id='total-label'>Total :</td>
|
||||||
<td id='total-value'></td>
|
<td colspan='2' id='total-value'></td>
|
||||||
</tr>
|
</tr>
|
||||||
</tfoot>
|
</tfoot>
|
||||||
</table>
|
</table>
|
||||||
|
|
Loading…
Reference in a new issue