Add checking for empty sku. #551
This commit is contained in:
parent
9e1d855433
commit
00c65d1e56
5 changed files with 112 additions and 49 deletions
|
|
@ -2905,6 +2905,10 @@ class APIController extends Controller implements LoggedController
|
||||||
}
|
}
|
||||||
|
|
||||||
$sku = $warr_serial->getSKU();
|
$sku = $warr_serial->getSKU();
|
||||||
|
|
||||||
|
// check if sku is null
|
||||||
|
$batt = null;
|
||||||
|
if ($sku != null)
|
||||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||||
// TODO: put this in a config file
|
// TODO: put this in a config file
|
||||||
$image_url = $req->getSchemeAndHttpHost() . '/battery/generic.png';
|
$image_url = $req->getSchemeAndHttpHost() . '/battery/generic.png';
|
||||||
|
|
@ -3060,15 +3064,12 @@ class APIController extends Controller implements LoggedController
|
||||||
$sms_msg = $trans->trans('warranty_register_confirm');
|
$sms_msg = $trans->trans('warranty_register_confirm');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// check if sku is null
|
||||||
// get sap battery
|
// get sap battery
|
||||||
$sku = $warr_serial->getSKU();
|
$sku = $warr_serial->getSKU();
|
||||||
|
$sap_bty = null;
|
||||||
|
if ($sku != null)
|
||||||
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
||||||
if ($sap_bty == null)
|
|
||||||
{
|
|
||||||
$res->setError(true)
|
|
||||||
->setErrorMessage('Could not find battery entry for warranty.');
|
|
||||||
return $res;
|
|
||||||
}
|
|
||||||
|
|
||||||
// default date purchase to today
|
// default date purchase to today
|
||||||
// NOTE: might need to change this later
|
// NOTE: might need to change this later
|
||||||
|
|
|
||||||
|
|
@ -381,10 +381,16 @@ class CustomerWarrantyController extends APIController
|
||||||
error_log('sap battery check');
|
error_log('sap battery check');
|
||||||
// get sap battery
|
// get sap battery
|
||||||
$sku = $warr_serial->getSKU();
|
$sku = $warr_serial->getSKU();
|
||||||
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
$sap_bty = null;
|
||||||
if ($sap_bty == null)
|
|
||||||
|
// check if sku is null
|
||||||
|
if ($sku != null)
|
||||||
{
|
{
|
||||||
return new APIResponse(false, 'Could not find battery entry for warranty.');
|
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
||||||
|
//if ($sap_bty == null)
|
||||||
|
//{
|
||||||
|
// return new APIResponse(false, 'Could not find battery entry for warranty.');
|
||||||
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
// vehicle fetch
|
// vehicle fetch
|
||||||
|
|
|
||||||
|
|
@ -199,10 +199,16 @@ class WarrantyController extends APIController
|
||||||
if (!$plate)
|
if (!$plate)
|
||||||
return new APIResponse(false, 'Invalid plate number.');
|
return new APIResponse(false, 'Invalid plate number.');
|
||||||
|
|
||||||
|
// check if sku is blank
|
||||||
|
if ((empty($sku)) || ($sku == null))
|
||||||
|
$batt = null;
|
||||||
|
else
|
||||||
|
{
|
||||||
// battery
|
// battery
|
||||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||||
if ($batt == null)
|
if ($batt == null)
|
||||||
return new APIResponse(false, 'Invalid battery SKU.');
|
return new APIResponse(false, 'Invalid battery SKU.');
|
||||||
|
}
|
||||||
|
|
||||||
/*
|
/*
|
||||||
// battery model
|
// battery model
|
||||||
|
|
@ -382,10 +388,16 @@ class WarrantyController extends APIController
|
||||||
if (!$plate)
|
if (!$plate)
|
||||||
return new APIResponse(false, 'Invalid plate number.');
|
return new APIResponse(false, 'Invalid plate number.');
|
||||||
|
|
||||||
|
// check if sku is blank
|
||||||
|
if ((empty($sku)) || ($sku == null))
|
||||||
|
$batt = null;
|
||||||
|
else
|
||||||
|
{
|
||||||
// battery
|
// battery
|
||||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||||
if ($batt == null)
|
if ($batt == null)
|
||||||
return new APIResponse(false, 'Invalid battery SKU.');
|
return new APIResponse(false, 'Invalid battery SKU.');
|
||||||
|
}
|
||||||
|
|
||||||
$warr->setSerial($serial)
|
$warr->setSerial($serial)
|
||||||
->setWarrantyClass($warr_class)
|
->setWarrantyClass($warr_class)
|
||||||
|
|
|
||||||
|
|
@ -181,6 +181,10 @@ class WarrantyController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
// custom validation for battery model
|
// custom validation for battery model
|
||||||
|
// check if battery model is blank
|
||||||
|
$bmodel = $req->request->get('battery_model');
|
||||||
|
if (!empty($bmodel))
|
||||||
|
{
|
||||||
$model = $em->getRepository(BatteryModel::class)
|
$model = $em->getRepository(BatteryModel::class)
|
||||||
->find($req->request->get('battery_model'));
|
->find($req->request->get('battery_model'));
|
||||||
|
|
||||||
|
|
@ -188,8 +192,15 @@ class WarrantyController extends Controller
|
||||||
$error_array['battery_model'] = 'Invalid model selected.';
|
$error_array['battery_model'] = 'Invalid model selected.';
|
||||||
else
|
else
|
||||||
$obj->setBatteryModel($model);
|
$obj->setBatteryModel($model);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$obj->setBatteryModel(null);
|
||||||
|
|
||||||
// custom validation for battery size
|
// custom validation for battery size
|
||||||
|
// check if battery size is blank
|
||||||
|
$bsize = $req->request->get('battery_size');
|
||||||
|
if (!empty($bsize))
|
||||||
|
{
|
||||||
$size = $em->getRepository(BatterySize::class)
|
$size = $em->getRepository(BatterySize::class)
|
||||||
->find($req->request->get('battery_size'));
|
->find($req->request->get('battery_size'));
|
||||||
|
|
||||||
|
|
@ -197,8 +208,15 @@ class WarrantyController extends Controller
|
||||||
$error_array['battery_size'] = 'Invalid size selected.';
|
$error_array['battery_size'] = 'Invalid size selected.';
|
||||||
else
|
else
|
||||||
$obj->setBatterySize($size);
|
$obj->setBatterySize($size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$obj->setBatterySize(null);
|
||||||
|
|
||||||
// custom validation for SAP battery
|
// custom validation for SAP battery
|
||||||
|
// check if sap battery is blank
|
||||||
|
$sap_battery = $req->request->get('sap_battery');
|
||||||
|
if (!empty($sap_battery))
|
||||||
|
{
|
||||||
$sap = $em->getRepository(SAPBattery::class)
|
$sap = $em->getRepository(SAPBattery::class)
|
||||||
->find($req->request->get('sap_battery'));
|
->find($req->request->get('sap_battery'));
|
||||||
|
|
||||||
|
|
@ -206,6 +224,9 @@ class WarrantyController extends Controller
|
||||||
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
|
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
|
||||||
else
|
else
|
||||||
$obj->setSAPBattery($sap);
|
$obj->setSAPBattery($sap);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$obj->setSAPBattery(null);
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
$errors = $validator->validate($obj);
|
$errors = $validator->validate($obj);
|
||||||
|
|
@ -303,6 +324,10 @@ class WarrantyController extends Controller
|
||||||
}
|
}
|
||||||
|
|
||||||
// custom validation for battery model
|
// custom validation for battery model
|
||||||
|
// check if battery model is blank
|
||||||
|
$bmodel = $req->request->get('battery_model');
|
||||||
|
if (!empty($bmodel))
|
||||||
|
{
|
||||||
$model = $em->getRepository(BatteryModel::class)
|
$model = $em->getRepository(BatteryModel::class)
|
||||||
->find($req->request->get('battery_model'));
|
->find($req->request->get('battery_model'));
|
||||||
|
|
||||||
|
|
@ -310,8 +335,15 @@ class WarrantyController extends Controller
|
||||||
$error_array['battery_model'] = 'Invalid model selected.';
|
$error_array['battery_model'] = 'Invalid model selected.';
|
||||||
else
|
else
|
||||||
$obj->setBatteryModel($model);
|
$obj->setBatteryModel($model);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$obj->setBatteryModel(null);
|
||||||
|
|
||||||
// custom validation for battery size
|
// custom validation for battery size
|
||||||
|
// check if battery size is blank
|
||||||
|
$bsize = $req->request->get('battery_size');
|
||||||
|
if (!empty($bsize))
|
||||||
|
{
|
||||||
$size = $em->getRepository(BatterySize::class)
|
$size = $em->getRepository(BatterySize::class)
|
||||||
->find($req->request->get('battery_size'));
|
->find($req->request->get('battery_size'));
|
||||||
|
|
||||||
|
|
@ -319,8 +351,15 @@ class WarrantyController extends Controller
|
||||||
$error_array['battery_size'] = 'Invalid size selected.';
|
$error_array['battery_size'] = 'Invalid size selected.';
|
||||||
else
|
else
|
||||||
$obj->setBatterySize($size);
|
$obj->setBatterySize($size);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$obj->setBatterySize(null);
|
||||||
|
|
||||||
// custom validation for SAP battery
|
// custom validation for SAP battery
|
||||||
|
// check if sap battery is blank
|
||||||
|
$sap_battery = $req->request->get('sap_battery');
|
||||||
|
if (!empty($sap_battery))
|
||||||
|
{
|
||||||
$sap = $em->getRepository(SAPBattery::class)
|
$sap = $em->getRepository(SAPBattery::class)
|
||||||
->find($req->request->get('sap_battery'));
|
->find($req->request->get('sap_battery'));
|
||||||
|
|
||||||
|
|
@ -328,6 +367,9 @@ class WarrantyController extends Controller
|
||||||
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
|
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
|
||||||
else
|
else
|
||||||
$obj->setSAPBattery($sap);
|
$obj->setSAPBattery($sap);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
$obj->setSAPBattery(null);
|
||||||
|
|
||||||
// validate
|
// validate
|
||||||
$errors = $validator->validate($obj);
|
$errors = $validator->validate($obj);
|
||||||
|
|
|
||||||
|
|
@ -98,6 +98,7 @@
|
||||||
SAP Battery
|
SAP Battery
|
||||||
</label>
|
</label>
|
||||||
<select name="sap_battery" class="form-control m-input">
|
<select name="sap_battery" class="form-control m-input">
|
||||||
|
<option value=""></option>
|
||||||
{% for sap_battery in sap_batts %}
|
{% for sap_battery in sap_batts %}
|
||||||
<option value="{{ sap_battery.getID }}"{{ obj.getSAPBattery.getID|default(0) == sap_battery.getID ? ' selected' }}>{{ sap_battery.getID }}</option>
|
<option value="{{ sap_battery.getID }}"{{ obj.getSAPBattery.getID|default(0) == sap_battery.getID ? ' selected' }}>{{ sap_battery.getID }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
@ -109,6 +110,7 @@
|
||||||
Battery Model
|
Battery Model
|
||||||
</label>
|
</label>
|
||||||
<select name="battery_model" class="form-control m-input">
|
<select name="battery_model" class="form-control m-input">
|
||||||
|
<option value=""></option>
|
||||||
{% for model in batt_models %}
|
{% for model in batt_models %}
|
||||||
<option value="{{ model.getID }}"{{ obj.getBatteryModel.getID|default(0) == model.getID ? ' selected' }}>{{ model.getName }}</option>
|
<option value="{{ model.getID }}"{{ obj.getBatteryModel.getID|default(0) == model.getID ? ' selected' }}>{{ model.getName }}</option>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue