diff options
| -rw-r--r-- | public/js/report.coffee | 62 |
1 files changed, 40 insertions, 22 deletions
diff --git a/public/js/report.coffee b/public/js/report.coffee index b8a85f3e..8e9ba633 100644 --- a/public/js/report.coffee +++ b/public/js/report.coffee @@ -1,32 +1,50 @@ #= require jquery-1.8.2.min.js #= require jquery-ui-1.9.0.custom.min.js +#= require moment.min.js + +g = exports ? this $(-> - $('.date').datepicker() + $('.date').datepicker(onClose: -> + transactions = $.grep(g.transactions, (e, i) -> + from = moment($('#from').val(), "MM/DD/YYYY") + to = moment($('#to').val(), "MM/DD/YYYY") + d = moment(e.date) - $.getJSON('transactions', (data) -> - $.each(data.transactions, -> - $('tbody').append(""" - <tr> - <td>#{this.date}</td> - <td>#{this.address}</td> - <td>#{parseFloat(this.exchange).toFixed(2)}</td> - <td>#{parseFloat(this.received).toFixed(2)}</td> - <td>#{(this.received * this.exchange).toFixed(2)}</td> - </tr> - """) + return (!from? || d.diff(from) >= 0) && (!to? || d.diff(to) <= 0) ) - btc = 0 - $('td:nth-child(4)').each(-> - btc += parseFloat($(this).html()) - ) - $('#btc').html(btc.toFixed(2)) + display(transactions) + ) - cad = 0 - $('td:nth-child(5)').each(-> - cad += parseFloat($(this).html()) - ) - $('#cad').html(cad.toFixed(2)) + $.getJSON('transactions', (data) -> + g.transactions = data.transactions + display(g.transactions) ) ) + +display = (transactions) -> + $('tbody tr').remove() + $.each(transactions, -> + $('tbody').append(""" + <tr> + <td>#{this.date}</td> + <td>#{this.address}</td> + <td>#{parseFloat(this.exchange).toFixed(2)}</td> + <td>#{parseFloat(this.received).toFixed(2)}</td> + <td>#{(this.received * this.exchange).toFixed(2)}</td> + </tr> + """) + ) + + btc = 0 + $('td:nth-child(4)').each(-> + btc += parseFloat($(this).html()) + ) + $('#btc').html(btc.toFixed(2)) + + cad = 0 + $('td:nth-child(5)').each(-> + cad += parseFloat($(this).html()) + ) + $('#cad').html(cad.toFixed(2)) |
