Benjamin Renard commited on 2014-01-12 19:07:01
Showing 3 changed files, with 41 additions and 11 deletions.
... | ... |
@@ -338,12 +338,16 @@ display_balance=function(group) { |
338 | 338 |
bal=group.balance(); |
339 | 339 |
tbody=$($('#display_balance_modal tbody')[0]); |
340 | 340 |
tbody.html(''); |
341 |
- sum=0; |
|
342 |
- for (c in bal) { |
|
343 |
- tbody.append('<tr><td>'+c+'</td><td>'+bal[c]+' €</td></tr>'); |
|
344 |
- sum+=bal[c]; |
|
341 |
+ for (c in bal['balance']) { |
|
342 |
+ if(bal['balance'][c]['diff']<0) { |
|
343 |
+ diff='<td class="negative">'+bal['balance'][c]['diff'].toFixed(2)+' €</td>'; |
|
344 |
+ } |
|
345 |
+ else { |
|
346 |
+ diff='<td><span class="glyphicon glyphicon-thumbs-up"></span></td>'; |
|
347 |
+ } |
|
348 |
+ tbody.append('<tr><td>'+c+'</td><td>'+bal['balance'][c]['total']+' €</td>'+diff+'</tr>'); |
|
345 | 349 |
} |
346 |
- $('#display_balance_modal #total-value').html(sum+' €'); |
|
350 |
+ $('#display_balance_modal #total-value').html(bal.sum.toFixed(2)+' €'); |
|
347 | 351 |
$('#display_balance_modal').modal('show'); |
348 | 352 |
} |
349 | 353 |
|
... | ... |
@@ -174,17 +174,39 @@ function Group(name,data) { |
174 | 174 |
* Balance |
175 | 175 |
*/ |
176 | 176 |
this.balance=function() { |
177 |
- ret={} |
|
177 |
+ total={} |
|
178 |
+ min=-1; |
|
179 |
+ max=0; |
|
178 | 180 |
for (idx in this.contributors) { |
179 |
- sum=0; |
|
181 |
+ var sum=0; |
|
180 | 182 |
c=this.contributors[idx].name; |
181 | 183 |
cl=this.contributionsByContributorName(c); |
182 | 184 |
for (idc in cl) { |
183 | 185 |
sum+=cl[idc].cost; |
184 | 186 |
} |
185 |
- ret[c]=sum; |
|
187 |
+ if (min==-1 || min>sum) { |
|
188 |
+ min=sum; |
|
186 | 189 |
} |
187 |
- return ret; |
|
190 |
+ if(max<sum) { |
|
191 |
+ max=sum; |
|
192 |
+ } |
|
193 |
+ total[c]=sum; |
|
194 |
+ } |
|
195 |
+ balance={} |
|
196 |
+ var sum=0; |
|
197 |
+ for (c in total) { |
|
198 |
+ balance[c]={ |
|
199 |
+ 'total': total[c], |
|
200 |
+ 'diff': total[c]-max, |
|
201 |
+ } |
|
202 |
+ sum=sum+total[c]; |
|
203 |
+ } |
|
204 |
+ return { |
|
205 |
+ 'balance': balance, |
|
206 |
+ 'sum': sum, |
|
207 |
+ 'min': min, |
|
208 |
+ 'max': max |
|
209 |
+ }; |
|
188 | 210 |
} |
189 | 211 |
|
190 | 212 |
/* |
... | ... |
@@ -293,13 +293,17 @@ body{ |
293 | 293 |
<div class="modal-body"> |
294 | 294 |
<table class="table table-striped"> |
295 | 295 |
<thead> |
296 |
- <tr><th>Participant</th><th>Participation</th></tr> |
|
296 |
+ <tr> |
|
297 |
+ <th>Participant</th> |
|
298 |
+ <th>Participation</th> |
|
299 |
+ <th> </th> |
|
300 |
+ </tr> |
|
297 | 301 |
</thead> |
298 | 302 |
<tbody></tbody> |
299 | 303 |
<tfoot> |
300 | 304 |
<tr> |
301 | 305 |
<td id='total-label'>Total :</td> |
302 |
- <td id='total-value'></td> |
|
306 |
+ <td colspan='2' id='total-value'></td> |
|
303 | 307 |
</tr> |
304 | 308 |
</tfoot> |
305 | 309 |
</table> |
306 | 310 |