diff --git a/templates/job-order/cmb.form.onestep.html.twig b/templates/job-order/cmb.form.onestep.html.twig index d59172dd..8a266b63 100644 --- a/templates/job-order/cmb.form.onestep.html.twig +++ b/templates/job-order/cmb.form.onestep.html.twig @@ -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 += '' + - '' + item.title + '' + - '' + item.quantity + '' + - '' + item.unit_price + '' + - '' + item.amount + '' + - /* - '' + - */ - ''; - }); - } else { - html = '' + - '' + - 'No items to display.' + - '' + - ''; - } - - table.html(html); - }); - } + if (invoice.items.length > 0) { + $.each(invoice.items, function(key, item) { + html += '' + + '' + item.title + '' + + '' + item.quantity + '' + + '' + item.unit_price + '' + + '' + item.amount + '' + + /* + '' + + */ + ''; + }); + } else { + html = '' + + '' + + 'No items to display.' + + '' + + ''; + } + + 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(); });