diff options
| author | Adam Soltys <[email protected]> | 2016-02-14 17:58:31 -0800 |
|---|---|---|
| committer | Adam Soltys <[email protected]> | 2016-02-14 17:58:31 -0800 |
| commit | d270e7367c6968f16e39392f01b96a219b0ab047 (patch) | |
| tree | 6d92339a116102b607efc9389e85f373351556c7 /public/js/report.js | |
| parent | 28365158a300bd1d9d7cc6882ce3b350dd1320ed (diff) | |
| download | coinos-server-d270e7367c6968f16e39392f01b96a219b0ab047.tar.gz coinos-server-d270e7367c6968f16e39392f01b96a219b0ab047.zip | |
Record and display tips (closes #7)
Diffstat (limited to 'public/js/report.js')
| -rw-r--r-- | public/js/report.js | 44 |
1 files changed, 28 insertions, 16 deletions
diff --git a/public/js/report.js b/public/js/report.js index 51d091cf..e73a691d 100644 --- a/public/js/report.js +++ b/public/js/report.js @@ -52,23 +52,39 @@ }; display = function(transactions) { - var btc, cad; + var btc_tips_total, btc_total, fiat_tips_total, fiat_total; $('.report tbody tr').remove(); if (transactions.length === 0) { $('.report').hide(); return $('.alert').fadeIn(); } else { $('.alert').hide(); + btc_total = btc_tips_total = 0; + fiat_total = fiat_tips_total = 0; $.each(transactions, function() { - var address, amount, date, exchange, notes, received, row, txid; + var btc, btc_tip, btc_tip_str, date, exchange, fiat, fiat_tip, fiat_tip_str, notes, row, tip, txid; + btc_tip_str = ""; + fiat_tip_str = ""; exchange = parseFloat(this.exchange); - received = parseFloat(this.received); - amount = received * exchange; + tip = this.tip; + btc = parseFloat(this.received); + fiat = btc * exchange; + btc_total += parseFloat(btc.toFixed(8)); + fiat_total += parseFloat(fiat.toFixed(2)); + if (tip > 1) { + btc = btc / tip; + btc_tip = (btc * tip - btc).toFixed(8); + fiat_tip = (btc_tip * exchange).toFixed(2); + btc_tips_total += parseFloat(btc_tip); + fiat_tips_total += parseFloat(fiat_tip); + btc_tip_str = "<br /><small>+ " + btc_tip + "</small>"; + fiat_tip_str = "<br /><small>+ " + fiat_tip + "</small>"; + } + fiat = btc * exchange; notes = this.notes; txid = this.txid; - address = this.address; date = moment(this.date, 'YYYY-MM-DD h:mm:ss').format('MMM D h:mma'); - row = $("<tr id='" + this.txid + "'>\n <td>" + date + " <span class='glyphicon glyphicon-tag hidden'></span></td>\n <td>" + (exchange.toFixed(2)) + "</td>\n <td>" + (received.toFixed(8)) + "</td>\n <td>" + (amount.toFixed(2)) + "</td>\n</tr>"); + row = $("<tr id='" + this.txid + "'>\n <td>" + date + " <span class='glyphicon glyphicon-tag hidden'></span></td>\n <td>" + (exchange.toFixed(2)) + "</td>\n <td>" + (btc.toFixed(8)) + btc_tip_str + "</td>\n <td>" + (fiat.toFixed(2)) + fiat_tip_str + "</td>\n</tr>"); if (notes) { row.attr('data-notes', notes); row.find('span').removeClass('hidden'); @@ -115,16 +131,12 @@ } }); }); - btc = 0; - $('table.report tbody td:nth-child(3)').each(function() { - return btc += parseFloat($(this).html()); - }); - $('#btc').html(btc.toFixed(8)); - cad = 0; - $('table.report tbody td:nth-child(4)').each(function() { - return cad += parseFloat($(this).html()); - }); - $('#cad').html(cad.toFixed(2)); + $('#btc_total').html("" + (parseFloat(btc_total).toFixed(8))); + $('#fiat_total').html("" + (parseFloat(fiat_total).toFixed(2))); + $('#btc_tips').html("" + (parseFloat(btc_tips_total).toFixed(8))); + $('#fiat_tips').html("" + (parseFloat(fiat_tips_total).toFixed(2))); + $('#btc').html("" + (parseFloat(btc_total - btc_tips_total).toFixed(8))); + $('#fiat').html("" + (parseFloat(fiat_total - fiat_tips_total).toFixed(2))); return $('.report').fadeIn(); } }; |
