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();
});
// reset the invoice table
$("#btn-reset-invoice").click(function() {
$("#invoice-discount").prop('selectedIndex', 0);
// reset the invoice table
$("#btn-reset-invoice").click(function() {
$("#invoice-discount").val(0);
$('.sc-select').closest('.row').remove();
invoiceItems = [];
sc_array = [];
generateInvoice();
});
invoiceItems = [];
generateInvoice();
});
// recompute
$("#btn-recompute-invoice").click(function() {
@ -1389,8 +1388,14 @@ $(function() {
var stype = $("#service_type").val();
var cvid = $("#customer-vehicle").val();
$.each(sc_array, function(index){
console.log('generateInvoice ' + this.id);
sc_array = [];
// get the service charges
$('.sc-select').each(function() {
var id = $(this).children('option:selected').val();
sc_array.push({
id: id,
});
});
// generate invoice values
@ -1409,39 +1414,39 @@ $(function() {
$("#invoice-change").val(1);
var invoice = response.invoice;
// populate totals
$("#invoice-discount").val(invoice.discount);
$("#invoice-price").val(invoice.price);
$("#invoice-trade-in").val(invoice.trade_in);
$("#invoice-vat").val(invoice.vat);
$("#invoice-total-amount").val(invoice.total_price);
// populate totals
$("#invoice-discount").val(invoice.discount);
$("#invoice-price").val(invoice.price);
$("#invoice-trade-in").val(invoice.trade_in);
$("#invoice-vat").val(invoice.vat);
$("#invoice-total-amount").val(invoice.total_price);
// populate rows
var html = '';
// populate rows
var html = '';
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>';
}
table.html(html);
});
}
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>';
}
table.html(html);
});
}
// 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?
@ -1677,9 +1682,6 @@ $(function() {
$('#sc-section').append(html);
// clear the sc_array
sc_array.length = 0;
// trigger change in select
$('#sc-section').find('.sc-select').last().change();
return false;
@ -1691,16 +1693,6 @@ $(function() {
$(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();
return false;
@ -1710,17 +1702,6 @@ $(function() {
var amount = $(this).children('option:selected').data('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();
});