From a13c364934b7d108bdd168386481d324fca7bbe5 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 20 Apr 2021 06:42:36 +0000 Subject: [PATCH] Fix issues found during testing of warranty creation. #551 --- src/Controller/APIController.php | 6 +++--- .../CAPI/CustomerWarrantyController.php | 20 ++++++++++++++----- src/Controller/CAPI/WarrantyController.php | 1 + 3 files changed, 19 insertions(+), 8 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 2d3a662e..d59121f7 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -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; } diff --git a/src/Controller/CAPI/CustomerWarrantyController.php b/src/Controller/CAPI/CustomerWarrantyController.php index bd9c7be9..52b305c9 100644 --- a/src/Controller/CAPI/CustomerWarrantyController.php +++ b/src/Controller/CAPI/CustomerWarrantyController.php @@ -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) { diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index d49e0374..31dbec58 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -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);