From 3bc4bb8db798f680477447d1fa548b6ea3384a38 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Fri, 19 Mar 2021 02:23:22 +0800 Subject: [PATCH] Allow for same plate number update on register api call #540 --- src/Controller/CAPI/CustomerWarrantyController.php | 14 +++++++++++++- 1 file changed, 13 insertions(+), 1 deletion(-) diff --git a/src/Controller/CAPI/CustomerWarrantyController.php b/src/Controller/CAPI/CustomerWarrantyController.php index 29095240..5a8e87f0 100644 --- a/src/Controller/CAPI/CustomerWarrantyController.php +++ b/src/Controller/CAPI/CustomerWarrantyController.php @@ -88,6 +88,11 @@ class CustomerWarrantyController extends APIController return trim(strtoupper($serial)); } + protected function cleanPlateNumber($plate_num) + { + return preg_replace('/\s+/', '', strtoupper($plate_num)); + } + public function check($serial, EntityManagerInterface $em, Request $req) { // check required parameters @@ -303,6 +308,8 @@ class CustomerWarrantyController extends APIController protected function updateWarranty($em, $req, $serial, $inv_filename = null, $wcard_filename = null) { + $plate_num = $this->cleanPlateNumber($req->request->get('plate_num')); + error_log('warranty serial check'); // get serial $warr_serial = $em->getRepository(WarrantySerial::class)->find($serial); @@ -317,7 +324,12 @@ class CustomerWarrantyController extends APIController // skip warranty if it already exists if ($warr != null) { - return new APIResponse(false, 'Warranty registred to a vehicle not in your list of vehicles.'); + $warr_plate_num = $this->cleanPlateNumber($warr->getPlateNumber()); + + if ($plate_num != $warr_plate_num) + { + return new APIResponse(false, 'Plate number does not match vehicle registered to warranty.'); + } /* // check if warranty is registered to a serial owned by customer