From f89e8548a9fa6de0adb0cd25146e77203b944f1f Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 13 May 2022 07:22:10 +0000 Subject: [PATCH] Add checking for sap code for warranty creation. #654 --- src/Command/FulfillOpenJobOrderCommand.php | 30 +++++++++++++++++----- 1 file changed, 23 insertions(+), 7 deletions(-) diff --git a/src/Command/FulfillOpenJobOrderCommand.php b/src/Command/FulfillOpenJobOrderCommand.php index f18c5baf..37cd6c07 100644 --- a/src/Command/FulfillOpenJobOrderCommand.php +++ b/src/Command/FulfillOpenJobOrderCommand.php @@ -231,13 +231,23 @@ class FulfillOpenJobOrderCommand extends Command $sap_code = $batt_info['sap_code']; // populate the values string for the values to be inserted into warranty - // TODO: add checking for sap code. we need another value string and sql statement if sap_code is blank - // where sap_code is not inserted - $value_string = '(' . $model_id . ',' . $size_id . ',\'' . $sap_code . '\',\'' . $warranty_class . '\',\'' - . $plate_number . '\',\'' . $warranty_status . '\',\'' . $str_current_date . '\',\'' . $str_date_schedule - . '\',\'' . $str_date_expire . '\',\'' . $first_name . '\',\'' . $last_name . '\',\'' . $mobile . '\',' . 1 . ',' . $vehicle_id . ',' . $cust_id . ',\'' . WarrantySource::ADMIN_PANEL . '\')'; + // check for sap_code. Not all batteries have sap_code + if (empty($sap_code)) + { + $value_string = '(' . $model_id . ',' . $size_id . ',\'' . $warranty_class . '\',\'' + . $plate_number . '\',\'' . $warranty_status . '\',\'' . $str_current_date . '\',\'' . $str_date_schedule + . '\',\'' . $str_date_expire . '\',\'' . $first_name . '\',\'' . $last_name . '\',\'' . $mobile . '\',' . 1 . ',' . $vehicle_id . ',' . $cust_id . ',\'' . WarrantySource::ADMIN_PANEL . '\')'; - $sql_statement = 'INSERT INTO `warranty` (bty_model_id,bty_size_id,sap_bty_id,warranty_class,plate_number,status,date_create,date_purchase,date_expire,first_name,last_name,mobile_number,flag_activated,vehicle_id,customer_id, create_source) VALUES ' . $value_string . ';' . "\n"; + $sql_statement = 'INSERT INTO `warranty` (bty_model_id,bty_size_id,warranty_class,plate_number,status,date_create,date_purchase,date_expire,first_name,last_name,mobile_number,flag_activated,vehicle_id,customer_id, create_source) VALUES ' . $value_string . ';' . "\n"; + } + else + { + $value_string = '(' . $model_id . ',' . $size_id . ',\'' . $sap_code . '\',\'' . $warranty_class . '\',\'' + . $plate_number . '\',\'' . $warranty_status . '\',\'' . $str_current_date . '\',\'' . $str_date_schedule + . '\',\'' . $str_date_expire . '\',\'' . $first_name . '\',\'' . $last_name . '\',\'' . $mobile . '\',' . 1 . ',' . $vehicle_id . ',' . $cust_id . ',\'' . WarrantySource::ADMIN_PANEL . '\')'; + + $sql_statement = 'INSERT INTO `warranty` (bty_model_id,bty_size_id,sap_bty_id,warranty_class,plate_number,status,date_create,date_purchase,date_expire,first_name,last_name,mobile_number,flag_activated,vehicle_id,customer_id, create_source) VALUES ' . $value_string . ';' . "\n"; + } error_log($sql_statement); @@ -327,7 +337,13 @@ class FulfillOpenJobOrderCommand extends Command protected function cleanPlateNumber($plate) { - return strtoupper(str_replace(' ', '', $plate)); + // trim plate number down to 20 characters + $trim_plate = str_replace(' ','', $plate); + + // truncate plate number down to 20 (max length) + $trunc_plate = substr($trim_plate, 0, 20); + + return strtoupper($trunc_plate); } }