Fix issues found during testing of warranty creation. #551

This commit is contained in:
Korina Cordero 2021-04-20 06:42:36 +00:00
parent c97755cce0
commit a13c364934
3 changed files with 19 additions and 8 deletions

View file

@ -3013,14 +3013,14 @@ class APIController extends Controller implements LoggedController
// $cust = $this->updateCustomerInfo($req, $em);
// update warranty
$res = $this->updateWarranty($res, $em, $trans, $req, $serial, $inv_filename, $wcard_filename);
$res = $this->updateWarranty($res, $em, $trans, $req, $serial, $inv_filename, $wcard_filename, $rt);
$em->flush();
return $res->getReturnResponse();
}
protected function updateWarranty($res, $em, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null)
protected function updateWarranty($res, $em, $trans, $req, $serial, $inv_filename = null, $wcard_filename = null, $rt)
{
// get serial
$warr_serial = $em->getRepository(WarrantySerial::class)->find($serial);
@ -3052,7 +3052,7 @@ class APIController extends Controller implements LoggedController
if (!$is_customer_warranty)
{
$res->setError(true)
->setErrorMessage('Warranty registred to a vehicle not in your list of vehicles.');
->setErrorMessage('Warranty registered to a vehicle not in your list of vehicles.');
return $res;
}

View file

@ -232,7 +232,11 @@ class CustomerWarrantyController extends APIController
}
$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)
@ -279,6 +283,8 @@ class CustomerWarrantyController extends APIController
{
error_log('HERE - register');
// check required parameters
// TODO: maybe add vmake_id? since warranty cannot be created with no vmake
// TODO: maye also add mobile and email since customer creation won't let mobile and email be null
$required_params = [
'first_name',
'last_name',
@ -409,15 +415,19 @@ class CustomerWarrantyController extends APIController
// default date purchase to today
// NOTE: might need to change this later
$date_pur = new DateTime();
$date_pur_cust = new DateTime();
// get date purchase specified by customer
$date_pur_cust = DateTime::createFromFormat('Y-m-d', $req->request->get('date_purchase'));
if (!$date_pur_cust)
if (!empty($req->request->get('date_purchase')))
{
return new APIResponse(false, 'Invalid date format for date of purchase.');
$date_pur_cust = DateTime::createFromFormat('Y-m-d', $req->request->get('date_purchase'));
if (!$date_pur_cust)
{
return new APIResponse(false, 'Invalid date format for date of purchase.');
}
}
// chstomer check
// customer check
$priv_promo = $req->request->get('priv_promo', false);
if ($cust == null)
{

View file

@ -646,6 +646,7 @@ class WarrantyController extends APIController
$w_last_name = $warranty->getLastName();
$new_cust = new Customer();
// TODO: add customer source
$new_cust->setFirstName($w_first_name)
->setLastName($w_last_name)
->setPhoneMobile($w_mobile_num);