diff options
| author | Adam Soltys <[email protected]> | 2014-07-15 00:44:25 -0700 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2014-07-15 00:44:25 -0700 |
| commit | 5255f026a68be987dbccc191900752d7e9daf1af (patch) | |
| tree | 62e17454a7d364b39d9a7adca27fcfec32bd4a78 /public/js/report.js | |
| parent | 3b565f4f4dcea55779e00493e7cf507cf8392010 (diff) | |
| download | coinos-server-5255f026a68be987dbccc191900752d7e9daf1af.tar.gz coinos-server-5255f026a68be987dbccc191900752d7e9daf1af.zip | |
Add menu, change view engine, use Grunt
Diffstat (limited to 'public/js/report.js')
| -rw-r--r-- | public/js/report.js | 63 |
1 files changed, 63 insertions, 0 deletions
diff --git a/public/js/report.js b/public/js/report.js new file mode 100644 index 00000000..1fd882a7 --- /dev/null +++ b/public/js/report.js @@ -0,0 +1,63 @@ +(function() { + var display, filterDates, g; + + g = typeof exports !== "undefined" && exports !== null ? exports : this; + + $(function() { + $('#from').val(moment().subtract('days', 7).format("MM/DD/YYYY")); + $('#to').val(moment().format("MM/DD/YYYY")); + $('.date').datepicker({ + onClose: filterDates + }); + return $.getJSON('transactions.json', function(data) { + g.transactions = data.transactions; + display(g.transactions); + return filterDates(); + }); + }); + + filterDates = function() { + var transactions; + transactions = $.grep(g.transactions, function(e, i) { + var amount, d, from, to; + if (!e) { + return false; + } + from = moment($('#from').val(), "MM/DD/YYYY"); + to = moment($('#to').val(), "MM/DD/YYYY"); + d = moment(e.date); + amount = parseFloat(e.exchange) * parseFloat(e.received); + return !isNaN(parseFloat(amount)) && isFinite(amount) && ((from == null) || d.diff(from) >= 0) && ((to == null) || d.diff(to) <= 0); + }); + return display(transactions); + }; + + display = function(transactions) { + var btc, cad; + $('tbody tr').remove(); + $('thead, tfoot').show(); + if (transactions.length === 0) { + $('tbody').append("<tr>\n <td colspan='5'>\n No transactions were found for the specified time period\n </td>\n</tr>"); + $('thead, tfoot').hide(); + } + $.each(transactions, function() { + var amount, exchange, received; + exchange = parseFloat(this.exchange); + received = parseFloat(this.received); + amount = received * exchange; + received *= 1000; + return $('tbody').append("<tr>\n <td>" + this.date + "</td>\n <td>" + this.address + "</td>\n <td>" + (exchange.toFixed(2)) + "</td>\n <td>" + (received.toFixed(5)) + "</td>\n <td>" + (amount.toFixed(2)) + "</td>\n</tr>"); + }); + btc = 0; + $('table.report td:nth-child(4)').each(function() { + return btc += parseFloat($(this).html()); + }); + $('#btc').html(btc.toFixed(5)); + cad = 0; + $('table.report td:nth-child(5)').each(function() { + return cad += parseFloat($(this).html()); + }); + return $('#cad').html(cad.toFixed(2)); + }; + +}).call(this); |
