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>
<button type="button" class="btn btn-primary" id="btn-add-to-invoice">Add to Invoice</button>
</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>
@ -926,6 +930,13 @@ $(function() {
generateInvoice();
});
// reset the invoice table
$("#btn-reset-invoice").click(function() {
$("#invoice-promo").prop('selectedIndex', 0);
invoiceItems = [];
generateInvoice();
});
function generateInvoice() {
var promo = $("#invoice-promo").val();
var table = $("#invoice-table tbody");
@ -951,20 +962,26 @@ $(function() {
// populate rows
var html = '';
$.each(invoice.items, function(key, item) {
html += '<tr data-key="' + key + '">' +
'<td>' + item.title + '</td>' +
'<td class="text-right">' + item.quantity + '</td>' +
'<td class="text-right">' + item.unit_price + '</td>' +
'<td class="text-right">' + item.amount + '</td>' +
/*
'<td><button type="button" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-invoice-delete" title="Delete"><i class="la la-trash"></i></button></td>' +
*/
if (invoice.items.length > 0) {
$.each(invoice.items, function(key, item) {
html += '<tr data-key="' + key + '">' +
'<td>' + item.title + '</td>' +
'<td class="text-right">' + item.quantity + '</td>' +
'<td class="text-right">' + item.unit_price + '</td>' +
'<td class="text-right">' + item.amount + '</td>' +
/*
'<td><button type="button" class="m-portlet__nav-link btn m-btn m-btn--hover-danger m-btn--icon m-btn--icon-only m-btn--pill btn-invoice-delete" title="Delete"><i class="la la-trash"></i></button></td>' +
*/
'</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);
});
}