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,7 +2905,11 @@ class APIController extends Controller implements LoggedController
|
|||
}
|
||||
|
||||
$sku = $warr_serial->getSKU();
|
||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
|
||||
// check if sku is null
|
||||
$batt = null;
|
||||
if ($sku != null)
|
||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
// TODO: put this in a config file
|
||||
$image_url = $req->getSchemeAndHttpHost() . '/battery/generic.png';
|
||||
if ($batt != null)
|
||||
|
|
@ -3060,15 +3064,12 @@ class APIController extends Controller implements LoggedController
|
|||
$sms_msg = $trans->trans('warranty_register_confirm');
|
||||
}
|
||||
|
||||
// check if sku is null
|
||||
// get sap battery
|
||||
$sku = $warr_serial->getSKU();
|
||||
$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;
|
||||
}
|
||||
$sap_bty = null;
|
||||
if ($sku != null)
|
||||
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
|
||||
// default date purchase to today
|
||||
// NOTE: might need to change this later
|
||||
|
|
|
|||
|
|
@ -381,10 +381,16 @@ class CustomerWarrantyController extends APIController
|
|||
error_log('sap battery check');
|
||||
// get sap battery
|
||||
$sku = $warr_serial->getSKU();
|
||||
$sap_bty = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
if ($sap_bty == null)
|
||||
$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
|
||||
|
|
|
|||
|
|
@ -199,10 +199,16 @@ class WarrantyController extends APIController
|
|||
if (!$plate)
|
||||
return new APIResponse(false, 'Invalid plate number.');
|
||||
|
||||
// battery
|
||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
if ($batt == null)
|
||||
return new APIResponse(false, 'Invalid battery SKU.');
|
||||
// check if sku is blank
|
||||
if ((empty($sku)) || ($sku == null))
|
||||
$batt = null;
|
||||
else
|
||||
{
|
||||
// battery
|
||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
if ($batt == null)
|
||||
return new APIResponse(false, 'Invalid battery SKU.');
|
||||
}
|
||||
|
||||
/*
|
||||
// battery model
|
||||
|
|
@ -382,10 +388,16 @@ class WarrantyController extends APIController
|
|||
if (!$plate)
|
||||
return new APIResponse(false, 'Invalid plate number.');
|
||||
|
||||
// battery
|
||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
if ($batt == null)
|
||||
return new APIResponse(false, 'Invalid battery SKU.');
|
||||
// check if sku is blank
|
||||
if ((empty($sku)) || ($sku == null))
|
||||
$batt = null;
|
||||
else
|
||||
{
|
||||
// battery
|
||||
$batt = $em->getRepository(SAPBattery::class)->find($sku);
|
||||
if ($batt == null)
|
||||
return new APIResponse(false, 'Invalid battery SKU.');
|
||||
}
|
||||
|
||||
$warr->setSerial($serial)
|
||||
->setWarrantyClass($warr_class)
|
||||
|
|
|
|||
|
|
@ -181,31 +181,52 @@ class WarrantyController extends Controller
|
|||
}
|
||||
|
||||
// custom validation for battery model
|
||||
$model = $em->getRepository(BatteryModel::class)
|
||||
->find($req->request->get('battery_model'));
|
||||
// check if battery model is blank
|
||||
$bmodel = $req->request->get('battery_model');
|
||||
if (!empty($bmodel))
|
||||
{
|
||||
$model = $em->getRepository(BatteryModel::class)
|
||||
->find($req->request->get('battery_model'));
|
||||
|
||||
if (empty($model))
|
||||
$error_array['battery_model'] = 'Invalid model selected.';
|
||||
if (empty($model))
|
||||
$error_array['battery_model'] = 'Invalid model selected.';
|
||||
else
|
||||
$obj->setBatteryModel($model);
|
||||
}
|
||||
else
|
||||
$obj->setBatteryModel($model);
|
||||
$obj->setBatteryModel(null);
|
||||
|
||||
// custom validation for battery size
|
||||
$size = $em->getRepository(BatterySize::class)
|
||||
->find($req->request->get('battery_size'));
|
||||
// check if battery size is blank
|
||||
$bsize = $req->request->get('battery_size');
|
||||
if (!empty($bsize))
|
||||
{
|
||||
$size = $em->getRepository(BatterySize::class)
|
||||
->find($req->request->get('battery_size'));
|
||||
|
||||
if (empty($size))
|
||||
$error_array['battery_size'] = 'Invalid size selected.';
|
||||
if (empty($size))
|
||||
$error_array['battery_size'] = 'Invalid size selected.';
|
||||
else
|
||||
$obj->setBatterySize($size);
|
||||
}
|
||||
else
|
||||
$obj->setBatterySize($size);
|
||||
$obj->setBatterySize(null);
|
||||
|
||||
// custom validation for SAP battery
|
||||
$sap = $em->getRepository(SAPBattery::class)
|
||||
->find($req->request->get('sap_battery'));
|
||||
// check if sap battery is blank
|
||||
$sap_battery = $req->request->get('sap_battery');
|
||||
if (!empty($sap_battery))
|
||||
{
|
||||
$sap = $em->getRepository(SAPBattery::class)
|
||||
->find($req->request->get('sap_battery'));
|
||||
|
||||
if (empty($sap))
|
||||
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
|
||||
if (empty($sap))
|
||||
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
|
||||
else
|
||||
$obj->setSAPBattery($sap);
|
||||
}
|
||||
else
|
||||
$obj->setSAPBattery($sap);
|
||||
$obj->setSAPBattery(null);
|
||||
|
||||
// validate
|
||||
$errors = $validator->validate($obj);
|
||||
|
|
@ -303,31 +324,52 @@ class WarrantyController extends Controller
|
|||
}
|
||||
|
||||
// custom validation for battery model
|
||||
$model = $em->getRepository(BatteryModel::class)
|
||||
->find($req->request->get('battery_model'));
|
||||
// check if battery model is blank
|
||||
$bmodel = $req->request->get('battery_model');
|
||||
if (!empty($bmodel))
|
||||
{
|
||||
$model = $em->getRepository(BatteryModel::class)
|
||||
->find($req->request->get('battery_model'));
|
||||
|
||||
if (empty($model))
|
||||
$error_array['battery_model'] = 'Invalid model selected.';
|
||||
if (empty($model))
|
||||
$error_array['battery_model'] = 'Invalid model selected.';
|
||||
else
|
||||
$obj->setBatteryModel($model);
|
||||
}
|
||||
else
|
||||
$obj->setBatteryModel($model);
|
||||
$obj->setBatteryModel(null);
|
||||
|
||||
// custom validation for battery size
|
||||
$size = $em->getRepository(BatterySize::class)
|
||||
->find($req->request->get('battery_size'));
|
||||
// check if battery size is blank
|
||||
$bsize = $req->request->get('battery_size');
|
||||
if (!empty($bsize))
|
||||
{
|
||||
$size = $em->getRepository(BatterySize::class)
|
||||
->find($req->request->get('battery_size'));
|
||||
|
||||
if (empty($size))
|
||||
$error_array['battery_size'] = 'Invalid size selected.';
|
||||
if (empty($size))
|
||||
$error_array['battery_size'] = 'Invalid size selected.';
|
||||
else
|
||||
$obj->setBatterySize($size);
|
||||
}
|
||||
else
|
||||
$obj->setBatterySize($size);
|
||||
$obj->setBatterySize(null);
|
||||
|
||||
// custom validation for SAP battery
|
||||
$sap = $em->getRepository(SAPBattery::class)
|
||||
->find($req->request->get('sap_battery'));
|
||||
// check if sap battery is blank
|
||||
$sap_battery = $req->request->get('sap_battery');
|
||||
if (!empty($sap_battery))
|
||||
{
|
||||
$sap = $em->getRepository(SAPBattery::class)
|
||||
->find($req->request->get('sap_battery'));
|
||||
|
||||
if (empty($sap))
|
||||
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
|
||||
if (empty($sap))
|
||||
$error_array['sap_battery'] = 'Invalid SAP battery selected.';
|
||||
else
|
||||
$obj->setSAPBattery($sap);
|
||||
}
|
||||
else
|
||||
$obj->setSAPBattery($sap);
|
||||
$obj->setSAPBattery(null);
|
||||
|
||||
// validate
|
||||
$errors = $validator->validate($obj);
|
||||
|
|
|
|||
|
|
@ -98,6 +98,7 @@
|
|||
SAP Battery
|
||||
</label>
|
||||
<select name="sap_battery" class="form-control m-input">
|
||||
<option value=""></option>
|
||||
{% for sap_battery in sap_batts %}
|
||||
<option value="{{ sap_battery.getID }}"{{ obj.getSAPBattery.getID|default(0) == sap_battery.getID ? ' selected' }}>{{ sap_battery.getID }}</option>
|
||||
{% endfor %}
|
||||
|
|
@ -109,6 +110,7 @@
|
|||
Battery Model
|
||||
</label>
|
||||
<select name="battery_model" class="form-control m-input">
|
||||
<option value=""></option>
|
||||
{% for model in batt_models %}
|
||||
<option value="{{ model.getID }}"{{ obj.getBatteryModel.getID|default(0) == model.getID ? ' selected' }}>{{ model.getName }}</option>
|
||||
{% endfor %}
|
||||
|
|
|
|||
Loading…
Reference in a new issue