Fix display of discount when reset button for invoice is clicked. #270

This commit is contained in:
Korina Cordero 2020-02-18 02:29:22 +00:00
parent e48e86340a
commit 688ccd8a91

View file

@ -1369,14 +1369,13 @@ $(function() {
generateInvoice(); generateInvoice();
}); });
// reset the invoice table // reset the invoice table
$("#btn-reset-invoice").click(function() { $("#btn-reset-invoice").click(function() {
$("#invoice-discount").prop('selectedIndex', 0); $("#invoice-discount").val(0);
$('.sc-select').closest('.row').remove(); $('.sc-select').closest('.row').remove();
invoiceItems = []; invoiceItems = [];
sc_array = []; generateInvoice();
generateInvoice(); });
});
// recompute // recompute
$("#btn-recompute-invoice").click(function() { $("#btn-recompute-invoice").click(function() {
@ -1389,8 +1388,14 @@ $(function() {
var stype = $("#service_type").val(); var stype = $("#service_type").val();
var cvid = $("#customer-vehicle").val(); var cvid = $("#customer-vehicle").val();
$.each(sc_array, function(index){ sc_array = [];
console.log('generateInvoice ' + this.id);
// get the service charges
$('.sc-select').each(function() {
var id = $(this).children('option:selected').val();
sc_array.push({
id: id,
});
}); });
// generate invoice values // generate invoice values
@ -1409,39 +1414,39 @@ $(function() {
$("#invoice-change").val(1); $("#invoice-change").val(1);
var invoice = response.invoice; var invoice = response.invoice;
// populate totals // populate totals
$("#invoice-discount").val(invoice.discount); $("#invoice-discount").val(invoice.discount);
$("#invoice-price").val(invoice.price); $("#invoice-price").val(invoice.price);
$("#invoice-trade-in").val(invoice.trade_in); $("#invoice-trade-in").val(invoice.trade_in);
$("#invoice-vat").val(invoice.vat); $("#invoice-vat").val(invoice.vat);
$("#invoice-total-amount").val(invoice.total_price); $("#invoice-total-amount").val(invoice.total_price);
// populate rows // populate rows
var html = ''; var html = '';
if (invoice.items.length > 0) { 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>' +
'<td class="text-right">' + item.quantity + '</td>' + '<td class="text-right">' + item.quantity + '</td>' +
'<td class="text-right">' + item.unit_price + '</td>' + '<td class="text-right">' + item.unit_price + '</td>' +
'<td class="text-right">' + item.amount + '</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>' + '<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>'; '</tr>';
}); });
} else { } else {
html = '<tr class="placeholder-row">' + html = '<tr class="placeholder-row">' +
'<td colspan="4">' + '<td colspan="4">' +
'No items to display.' + 'No items to display.' +
'</td>' + '</td>' +
'</tr>'; '</tr>';
} }
table.html(html); table.html(html);
}); });
} }
// remove from invoice table // remove from invoice table
// TODO: figure out a way to delete rows, and should deleting trade ins be allowed since they count as items on the table? // TODO: figure out a way to delete rows, and should deleting trade ins be allowed since they count as items on the table?
@ -1677,9 +1682,6 @@ $(function() {
$('#sc-section').append(html); $('#sc-section').append(html);
// clear the sc_array
sc_array.length = 0;
// trigger change in select // trigger change in select
$('#sc-section').find('.sc-select').last().change(); $('#sc-section').find('.sc-select').last().change();
return false; return false;
@ -1691,16 +1693,6 @@ $(function() {
$(this).closest('.row').remove(); $(this).closest('.row').remove();
sc_array.length = 0;
// get the service charges
$('.sc-select').each(function() {
var id = $(this).children('option:selected').val();
sc_array.push({
id: id,
});
});
generateInvoice(); generateInvoice();
return false; return false;
@ -1710,17 +1702,6 @@ $(function() {
var amount = $(this).children('option:selected').data('amount'); var amount = $(this).children('option:selected').data('amount');
$(this).closest('.row').find('.sc-amount').val(amount); $(this).closest('.row').find('.sc-amount').val(amount);
// clear the sc_array
sc_array.length = 0;
// get the service charges
$('.sc-select').each(function() {
var id = $(this).children('option:selected').val();
sc_array.push({
id: id,
});
});
generateInvoice(); generateInvoice();
}); });