Fix battery fetching for new customer in one step jo form #319

This commit is contained in:
Kendrick Chan 2020-02-05 05:14:42 +08:00
parent cb5fa96307
commit 6cdb5d0312
3 changed files with 15 additions and 9 deletions

View file

@ -696,8 +696,10 @@ class JobOrderController extends Controller
// get customer vehicle
$cv = $em->getRepository(CustomerVehicle::class)->find($cvid);
/*
if ($cv == null)
throw new \Exception('Could not get customer vehicle');
*/
// instantiate invoice criteria

View file

@ -104,7 +104,7 @@ class InvoiceCriteria
return $this->entries;
}
public function setCustomerVehicle(CustomerVehicle $cv)
public function setCustomerVehicle(CustomerVehicle $cv = null)
{
$this->cv = $cv;
return $this;

View file

@ -30,6 +30,7 @@
</div>
</div>
<form id="row-form" class="m-form m-form--fit m-form--label-align-right" method="post" action="{{ submit_url }}">
<input type="hidden" id="vid" name="vid" value="0">
<input type="hidden" id="invoice-change" name="invoice_change" value="0">
<div class="m-portlet__body">
{%if ftags.vehicle_dropdown %}
@ -1072,6 +1073,7 @@ $(function() {
data: { id: data.id }
}).done(function(response) {
vdata = response.data;
$('#vid').val(vdata.vehicle.id);
$('#flag-new-customer').prop('checked', false).change();
@ -1198,7 +1200,6 @@ $(function() {
// vehicle manufacturer change
$("#cv-mfg").change(function() {
console.log('mfg dropdown');
var id = $(this).val();
field = $('#cv-make');
@ -1212,17 +1213,20 @@ $(function() {
get_vehicle_makes(id);
});
// vehicle make change (store in vid)
$("#cv-make").change(function() {
$('#vid').val($('#cv-make').val());
$('#invoice-bmfg').change();
});
// update battery list when changing manufacturer
$("#invoice-bmfg").change(function() {
{% if ftags.preset_vehicle %}
vdata = {
'vehicle': {
'id': {{ vid }}
}
};
$('#vid').val({{ vid }});
{% endif %}
// must have a selected vehicle
if (!vdata)
vid = $('#vid').val();
if (vid == 0)
return;
var id = $(this).val();
@ -1240,7 +1244,7 @@ $(function() {
url: "{{ url('vehicle_batteries') }}",
data: {
id: id,
vehicle_id: vdata.vehicle.id
vehicle_id: vid
}
}).done(function(response) {
if (response.data.length > 0) {