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 // get customer vehicle
$cv = $em->getRepository(CustomerVehicle::class)->find($cvid); $cv = $em->getRepository(CustomerVehicle::class)->find($cvid);
/*
if ($cv == null) if ($cv == null)
throw new \Exception('Could not get customer vehicle'); throw new \Exception('Could not get customer vehicle');
*/
// instantiate invoice criteria // instantiate invoice criteria

View file

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

View file

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