aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAdam Soltys <[email protected]>2016-02-14 17:58:31 -0800
committerAdam Soltys <[email protected]>2016-02-14 17:58:31 -0800
commitd270e7367c6968f16e39392f01b96a219b0ab047 (patch)
tree6d92339a116102b607efc9389e85f373351556c7
parent28365158a300bd1d9d7cc6882ce3b350dd1320ed (diff)
downloadcoinos-server-d270e7367c6968f16e39392f01b96a219b0ab047.tar.gz
coinos-server-d270e7367c6968f16e39392f01b96a219b0ab047.zip
Record and display tips (closes #7)
-rw-r--r--public/css/coinos.css2
-rw-r--r--public/css/coinos.less2
-rw-r--r--public/js/calculator.coffee1
-rw-r--r--public/js/calculator.js3
-rw-r--r--public/js/report.coffee50
-rw-r--r--public/js/report.js44
-rw-r--r--views/transactions/index.html18
7 files changed, 81 insertions, 39 deletions
diff --git a/public/css/coinos.css b/public/css/coinos.css
index 9ddd44bd..59765af1 100644
--- a/public/css/coinos.css
+++ b/public/css/coinos.css
@@ -167,7 +167,7 @@ div#calculator #qr {
padding-bottom: 10px;
margin-left: 20px;
}
-td#total {
+td.total {
font-weight: bold;
text-align: right;
}
diff --git a/public/css/coinos.less b/public/css/coinos.less
index 42cdc3bc..6bc2cb6a 100644
--- a/public/css/coinos.less
+++ b/public/css/coinos.less
@@ -71,7 +71,7 @@ div#calculator {
#qr { padding-bottom: 10px; margin-left: 20px; }
}
-td#total { font-weight: bold; text-align: right; }
+td.total { font-weight: bold; text-align: right; }
#main-logo {
background-image: url('../img/coinos_logo.png');
diff --git a/public/js/calculator.coffee b/public/js/calculator.coffee
index e6cc813e..1b5f5034 100644
--- a/public/js/calculator.coffee
+++ b/public/js/calculator.coffee
@@ -217,6 +217,7 @@ logTransaction = (txid, amount) ->
date: moment().format("YYYY-MM-DD HH:mm:ss"),
received: amount,
exchange: g.exchange
+ tip: g.tip
)
getAddress()
diff --git a/public/js/calculator.js b/public/js/calculator.js
index fe3ce42c..f54e70bd 100644
--- a/public/js/calculator.js
+++ b/public/js/calculator.js
@@ -224,7 +224,8 @@
address: g.user.address,
date: moment().format("YYYY-MM-DD HH:mm:ss"),
received: amount,
- exchange: g.exchange
+ exchange: g.exchange,
+ tip: g.tip
});
}
return getAddress();
diff --git a/public/js/report.coffee b/public/js/report.coffee
index 57da46c4..64284cbc 100644
--- a/public/js/report.coffee
+++ b/public/js/report.coffee
@@ -52,21 +52,44 @@ display = (transactions) ->
$('.alert').fadeIn()
else
$('.alert').hide()
+ btc_total = btc_tips_total = 0
+ fiat_total = fiat_tips_total = 0
+
$.each(transactions, ->
+ btc_tip_str = ""
+ fiat_tip_str = ""
+
exchange = parseFloat(@exchange)
- received = parseFloat(@received)
- amount = received * exchange
+ tip = @tip
+ btc = parseFloat(@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 = @notes
txid = @txid
- address = @address
date = moment(@date, 'YYYY-MM-DD h:mm:ss').format('MMM D h:mma')
row = $("""
<tr id='#{@txid}'>
<td>#{date}&nbsp;&nbsp;<span class='glyphicon glyphicon-tag hidden'></span></td>
<td>#{exchange.toFixed(2)}</td>
- <td>#{received.toFixed(8)}</td>
- <td>#{amount.toFixed(2)}</td>
+ <td>#{btc.toFixed(8)}#{btc_tip_str}</td>
+ <td>#{fiat.toFixed(2)}#{fiat_tip_str}</td>
</tr>
""")
@@ -117,16 +140,11 @@ display = (transactions) ->
)
)
- btc = 0
- $('table.report tbody td:nth-child(3)').each(->
- btc += parseFloat($(this).html())
- )
- $('#btc').html(btc.toFixed(8))
-
- cad = 0
- $('table.report tbody td:nth-child(4)').each(->
- 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)}")
$('.report').fadeIn()
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 + "&nbsp;&nbsp;<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 + "&nbsp;&nbsp;<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();
}
};
diff --git a/views/transactions/index.html b/views/transactions/index.html
index 07c0c7db..a8a07f82 100644
--- a/views/transactions/index.html
+++ b/views/transactions/index.html
@@ -20,17 +20,27 @@
<tr>
<th>Time</th>
<th>Rate</th>
- <th>BTC</th>
- <th>CAD</th>
+ <th>&nbsp;&nbsp;&nbsp;BTC</th>
+ <th>&nbsp;&nbsp;&nbsp;CAD</th>
</tr>
</thead>
<tbody>
</tbody>
<tfoot>
<tr>
- <td id="total" colspan="2">Total:</td>
+ <td class="total" colspan="2">Subtotal:</td>
<td id="btc"></td>
- <td id="cad"></td>
+ <td id="fiat"></td>
+ </tr>
+ <tr>
+ <td class="total" colspan="2">Tips:</td>
+ <td id="btc_tips"></td>
+ <td id="fiat_tips"></td>
+ </tr>
+ <tr>
+ <td class="total" colspan="2">Total:</td>
+ <td id="btc_total"></td>
+ <td id="fiat_total"></td>
</tr>
</tfoot>
</table>