Add reset invoice button

This commit is contained in:
Ramon Gutierrez 2018-02-05 03:53:00 +08:00
parent 46ebd223a2
commit 075c9e7dd5

View file

@ -350,6 +350,10 @@
<div><label>&nbsp;</label></div> <div><label>&nbsp;</label></div>
<button type="button" class="btn btn-primary" id="btn-add-to-invoice">Add to Invoice</button> <button type="button" class="btn btn-primary" id="btn-add-to-invoice">Add to Invoice</button>
</div> </div>
<div class="col-lg-2 text-right">
<div><label>&nbsp;</label></div>
<button type="button" class="btn btn-danger" id="btn-reset-invoice">Reset Invoice</button>
</div>
</div> </div>
</div> </div>
@ -926,6 +930,13 @@ $(function() {
generateInvoice(); generateInvoice();
}); });
// reset the invoice table
$("#btn-reset-invoice").click(function() {
$("#invoice-promo").prop('selectedIndex', 0);
invoiceItems = [];
generateInvoice();
});
function generateInvoice() { function generateInvoice() {
var promo = $("#invoice-promo").val(); var promo = $("#invoice-promo").val();
var table = $("#invoice-table tbody"); var table = $("#invoice-table tbody");
@ -951,6 +962,7 @@ $(function() {
// populate rows // populate rows
var html = ''; var html = '';
if (invoice.items.length > 0) {
$.each(invoice.items, function(key, item) { $.each(invoice.items, function(key, item) {
html += '<tr data-key="' + key + '">' + html += '<tr data-key="' + key + '">' +
'<td>' + item.title + '</td>' + '<td>' + item.title + '</td>' +
@ -962,9 +974,14 @@ $(function() {
*/ */
'</tr>'; '</tr>';
}); });
} else {
html = '<tr class="placeholder-row">' +
'<td colspan="4">' +
'No items to display.' +
'</td>' +
'</tr>';
}
// save to invoice table
table.find('.placeholder-row').addClass('hide');
table.html(html); table.html(html);
}); });
} }