From 6cc9cddf1f9682e6212bbf0938bbe823eb73e3af Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 6 Apr 2022 11:01:27 +0000 Subject: [PATCH 01/19] Add command to import vehicle battery compatibility for Yokohama. #655 --- ...hamaVehicleBatteryCompatibilityCommand.php | 425 ++++++++++++++++++ 1 file changed, 425 insertions(+) create mode 100644 src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php diff --git a/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php b/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php new file mode 100644 index 00000000..ba45414d --- /dev/null +++ b/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php @@ -0,0 +1,425 @@ +em = $em; + $this->vmfg_index = []; + $this->v_index = []; + $this->batt_index = []; + + parent::__construct(); + } + + protected function configure() + { + $this->setName('yokohamavehicle:import') + ->setDescription('Import Yokohama data CSV file with vehicles and batteries.') + ->setHelp('Creates vehicles and batteries based on imported Yokohama CSV.') + ->addArgument('input_file', InputArgument::REQUIRED, 'Path to the CSV file.') + ->addArgument('output_file', InputArgument::REQUIRED, 'Path to output file.'); + } + + protected function execute(InputInterface $input, OutputInterface $output) + { + $csv_file = $input->getArgument('input_file'); + $output_file = $input->getArgument('output_file'); + + $this->populateVehicleIndex(); + $this->populateBatteryIndex(); + + // attempt to open file + try + { + $fh = fopen($csv_file, "r"); + } + catch (Exception $e) + { + throw new Exception('The file "' . $csv_file . '" could be read.'); + } + + // get entity manager + $em = $this->em; + + $vbrands = []; + $output_info = []; + + // loop through rows + $row_num = 1; + $prem_mf_name = ''; + $prem_lm_name = ''; + $super_prem_mf_name = ''; + $supreme_mf_name = ''; + $platinum_mf_name = ''; + while (($fields = fgetcsv($fh)) !== false) + { + $output->writeln("Parsing row " . $row_num . "..."); + + // get the alternate battery brand header names + if ($row_num == 2) + { + $prem_mf_name = $this->normalizeName($fields[SELF::F_B_ALT_PREM_MF]); + $prem_lm_name = $this->normalizeName($fields[SELF::F_B_ALT_PREM_LM]); + $super_prem_mf_name = $this->normalizeName($fields[SELF::F_B_ALT_SUPER_PREM_MF]); + $supreme_mf_name = $this->normalizeName($fields[SELF::F_B_ALT_SUPREME_MF]); + $platinum_mf_name = $this->normalizeName($fields[SELF::F_B_ALT_PLATINUM_MF]); + } + + // process row + $output_info[] = $this->processRow($fields, $vbrands, $row_num, $prem_mf_name, $prem_lm_name, + $super_prem_mf_name, $supreme_mf_name, $platinum_mf_name); + + $row_num++; + } + // print_r($b_models); + // print_r($batteries); + // save to db + + foreach ($vbrands as $brand_name => $vbrand) + { + // vehicles + foreach ($vbrand['vehicles'] as $row_num => $vdata) + { + $model = $vdata['model']; + if ($model == 'NONE') + { + $m_year_from = 0; + $m_year_to = 0; + } + else + { + $ex_model = explode('-', $model); + $m_year_from = trim($ex_model[0]); + + if (isset($ex_model[1])) + $m_year_to = trim($ex_model[1]); + else + $m_year_to = 0; + } + + $vehicle = $this->v_index[$brand_name][$vdata['make'] . '|' . intval($m_year_from) . '|' . intval($m_year_to)]; + + // recommended battery + $vdata['battery']->addVehicle($vehicle); + + // alt_batteries + if (isset($vdata['alt_battery_prem_mf'])) + $vdata['alt_battery_prem_mf']->addVehicle($vehicle); + if (isset($vdata['alt_battery_prem_lm'])) + $vdata['alt_battery_prem_lm']->addVehicle($vehicle); + if (isset($vdata['alt_battery_super_prem_mf'])) + $vdata['alt_battery_super_prem_mf']->addVehicle($vehicle); + if (isset($vdata['alt_battery_supreme_mf'])) + $vdata['alt_battery_supreme_mf']->addVehicle($vehicle); + if (isset($vdata['alt_battery_platinum_mf'])) + $vdata['alt_battery_platinum_mf']->addVehicle($vehicle); + } + } + + $em->flush(); + + // write to output file + $this->outputVehicleBatteryInfo($output_file, $output_info); + + fclose($fh); + + return 0; + } + + protected function processRow($fields, &$vbrands, $row_num, $prem_mf_name, $prem_lm_name, + $super_prem_mf_name, $supreme_mf_name, $platinum_mf_nam) + { + $output_info = []; + $brand = $this->normalizeName($fields[0]); + $make = $this->normalizeName($fields[1]); + $model = trim($fields[2]); + $bsize = $this->normalizeName($fields[self::F_B_SIZE]); + $bmodel = $this->normalizeName($fields[self::F_B_MODEL]); + + // checking for valid vehicles and batteries should be done here so that only valid entries + // go into the vbrands array + $output_info = $this->validateManufacturerVehicle($fields, $brand, $make, $model, $bsize, $bmodel); + + error_log(count($output_info)); + + if (!empty($output_info)) + return $output_info; + + if (!isset($vbrands[$brand])) + { + // build array + $vbrands[$brand] = [ + 'vehicles' => [], + ]; + } + + if (empty($model)) + $model = 'NONE'; + + $vbrands[$brand]['vehicles'][$row_num] = [ + 'make' => $make, + 'model' => $model, + ]; + + // at this point we are sure we have battery + $batt_key = $this->getBatteryKey($bsize, $bmodel); + $vbrands[$brand]['vehicles'][$row_num]['battery'] = $this->batt_index[$batt_key]; + + // need to check alternate brands if battery exists + // go through the alternate fields, look for 'P'. Not kidding. It's what is in the csv file. + if ($this->normalizeName($fields[SELF::F_B_ALT_PREM_MF]) == 'P') + { + // check if we have battery for name + size combo + $alt_batt_key = $this->getBatteryKey($field_bsize, $prem_mf_name); + if (isset($this->batt_index[$alt_batt_key])) + { + $vbrands[$brand]['vehicles'][$row_num]['alt_battery_prem_mf'] = $this->batt_index[$alt_batt_key]; + } + } + if ($this->normalizeName($fields[SELF::F_B_ALT_PREM_LM]) == 'P') + { + // check if we have battery for name + size combo + $alt_batt_key = $this->getBatteryKey($field_bsize, $prem_lm_name); + if (isset($this->batt_index[$alt_batt_key])) + { + $vbrands[$brand]['vehicles'][$row_num]['alt_battery_prem_lm'] = $this->batt_index[$alt_batt_key]; + } + } + if ($this->normalizeName($fields[SELF::F_B_ALT_SUPER_PREM_MF]) == 'P') + { + // check if we have battery for name + size combo + $alt_batt_key = $this->getBatteryKey($field_bsize, $super_prem_mf_name); + if (isset($this->batt_index[$alt_batt_key])) + { + $vbrands[$brand]['vehicles'][$row_num]['alt_battery_super_prem_mf'] = $this->batt_index[$alt_batt_key]; + } + } + if ($this->normalizeName($fields[SELF::F_B_ALT_SUPREME_MF]) == 'P') + { + // check if we have battery for name + size combo + $alt_batt_key = $this->getBatteryKey($field_bsize, $supreme_mf_name); + if (isset($this->batt_index[$alt_batt_key])) + { + $vbrands[$brand]['vehicles'][$row_num]['alt_battery_supreme_mf'] = $this->batt_index[$alt_batt_key]; + } + } + if ($this->normalizeName($fields[SELF::F_B_ALT_PLATINUM_MF]) == 'P') + { + // check if we have battery for name + size combo + $alt_batt_key = $this->getBatteryKey($field_bsize, $platinum_mf_name); + if (isset($this->batt_index[$alt_batt_key])) + { + $vbrands[$brand]['vehicles'][$row_num]['alt_battery_platinum_mf'] = $this->batt_index[$alt_batt_key]; + } + } + } + + protected function validateManufacturerVehicle($fields, $brand, $make, $model, $bsize, $bmodel) + { + $output_info = []; + // process model year data + if ($model == 'NONE') + { + $m_year_from = 0; + $m_year_to = 0; + } + else + { + $ex_model = explode('-', $model); + $m_year_from = trim($ex_model[0]); + + if (isset($ex_model[1])) + $m_year_to = trim($ex_model[1]); + else + $m_year_to = 0; + } + + if (!isset($this->v_index[$brand][$make . '|' . intval($m_year_from) . '|' . intval($m_year_to)])) + { + $message = 'Invalid vehicle'; + $output_info = $this->setOutputInfo($fields, 'NOT ADDED', $message); + return $output_info; + } + + // recommended battery + $batt_key = $this->getBatteryKey($bsize, $bmodel); + if (!isset($this->batt_index[$batt_key])) + { + $message = 'Could not find battery - ' . $bsize . ' - ' . $bmodel; + $output_info = $this->setOutputInfo($fields, 'NOT ADDED', $message); + return $output_info; + } + + return $output_info; + } + + protected function setOutputInfo($fields, $status, $reason) + { + $mfg_name = trim($fields[SELF::F_V_BRAND]); + $model_name = trim($fields[SELF::F_V_MAKE]); + $model_year = trim($fields[SELF::F_V_MODEL_YEAR]); + $bsize = trim($fields[SELF::F_B_SIZE]); + $bmodel = trim($fields[SELF::F_B_MODEL]); + $alt_prem_mf = trim($fields[SELF::F_B_ALT_PREM_MF]); + $alt_prem_lm = trim($fields[SELF::F_B_ALT_PREM_LM]); + $alt_super_prem_mf = trim($fields[SELF::F_B_ALT_SUPER_PREM_MF]); + $alt_supreme_mf = trim($fields[SELF::F_B_ALT_SUPREME_MF]); + $alt_platinum_mf = trim($fields[SELF::F_B_ALT_PLATINUM_MF]); + + return [ + $mfg_name, + $model_name, + $model_year, + $bsize, + $bmodel, + $alt_prem_mf, + $alt_prem_lm, + $alt_super_prem_mf, + $alt_supreme_mf, + $alt_platinum_mf, + $status, + $reason + ]; + } + + protected function outputVehicleBatteryInfo($output_file, $entries) + { + try + { + $fh = fopen($output_file, "w"); + } + catch (Exception $e) + { + throw new Exception('The file "' . $report_file . '" could be opened.'); + } + + // write the headers + fputcsv($fh, [ + 'Manufacturer', + 'Vehicle Model', + 'Year Model', + 'Battery Size', + 'Battery Model', + 'Status', + 'Reason', + ]); + + foreach($entries as $row) + { + fputcsv($fh, $row); + } + + fclose($fh); + } + + protected function populateVehicleIndex() + { + $vs = $this->em->getRepository(Vehicle::class)->findAll(); + + $this->v_index = []; + $this->vmfg_index = []; + foreach ($vs as $v) + { + $mfg_name = $this->normalizeName($v->getManufacturer()->getName()); + $this->vmfg_index[$mfg_name] = $v->getManufacturer(); + if (!isset($this->v_index[$mfg_name])) + $this->v_index[$mfg_name] = []; + + error_log('vehicle keys ' . $mfg_name . ' ' . $this->normalizeName($v->getMake()) . '|' . $v->getModelYearFrom() . '|' . $v->getModelYearTo()); + + $this->v_index[$mfg_name][$this->normalizeName($v->getMake()) . '|' . $v->getModelYearFrom() . '|' . $v->getModelYearTo()] = $v; + } + } + + protected function populateBatteryIndex() + { + $bs = $this->em->getRepository(Battery::class)->findAll(); + + $this->batt_index = []; + foreach ($bs as $b) + { + // get the battery size + $bsize = $b->getSize()->getName(); + + error_log($bsize); + + // check if size has / + $bsizes = []; + $pos = stripos($bsize, '/'); + if ($pos == false) + { + // no '/' in size + $bsizes[] = $this->normalizeName($bsize); + } + else + { + // if yes, we need to split it. + $sizes = explode('/', $bsize); + foreach ($sizes as $size) + { + $bsizes[] = $this->normalizeName($size); + } + } + + foreach ($bsizes as $battery_size) + { + error_log('Adding ' . $battery_size . ' to key'); + $key = $this->getBatteryKey($battery_size, $b->getModel()->getName()); + + $this->batt_index[$key] = $b; + } + } + } + + protected function getBatteryKey($size_name, $model_name) + { + return $this->normalizeName(str_replace(' ', '', $size_name)) . + '|' . + $this->normalizeName(str_replace(' ', '', $model_name)); + } + + protected function normalizeName($name) + { + $normalized_key = trim(strtoupper($name)); + + return $normalized_key; + } + +} From 928257ccdcbf47fe55a12bb0c4f4ca83ce8b30fd Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 7 Apr 2022 09:58:17 +0000 Subject: [PATCH 02/19] Add motiv call to initializeOpenHubForm. #656 --- src/Controller/JobOrderController.php | 4 +- .../JobOrderHandler/CMBJobOrderHandler.php | 2 +- .../JobOrderHandler/ResqJobOrderHandler.php | 46 ++++++++++++++++++- src/Service/JobOrderHandlerInterface.php | 2 +- 4 files changed, 48 insertions(+), 6 deletions(-) diff --git a/src/Controller/JobOrderController.php b/src/Controller/JobOrderController.php index fbab3cb2..f847a842 100644 --- a/src/Controller/JobOrderController.php +++ b/src/Controller/JobOrderController.php @@ -506,13 +506,13 @@ class JobOrderController extends Controller * @Menu(selected="jo_open") */ public function openHubForm(HubSelector $hub_selector, $id, JobOrderHandlerInterface $jo_handler, - GISManagerInterface $gis) + GISManagerInterface $gis, MotivConnector $motiv) { $this->denyAccessUnlessGranted('jo_open.list', null, 'No access.'); try { - $params = $jo_handler->initializeHubForm($id, $hub_selector); + $params = $jo_handler->initializeHubForm($id, $hub_selector, $motiv); } catch (NotFoundHttpException $e) { diff --git a/src/Service/JobOrderHandler/CMBJobOrderHandler.php b/src/Service/JobOrderHandler/CMBJobOrderHandler.php index 1dc1e735..24933e8f 100644 --- a/src/Service/JobOrderHandler/CMBJobOrderHandler.php +++ b/src/Service/JobOrderHandler/CMBJobOrderHandler.php @@ -1873,7 +1873,7 @@ class CMBJobOrderHandler implements JobOrderHandlerInterface } // initialize hub form - public function initializeHubForm($id, $map_tools) + public function initializeHubForm($id, $map_tools, $motiv) { $em = $this->em; diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index a5ce340a..40be027a 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -2315,7 +2315,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface } // initialize hub form - public function initializeHubForm($id, HubSelector $hub_selector) + public function initializeHubForm($id, HubSelector $hub_selector, $motiv) { $em = $this->em; @@ -2445,9 +2445,51 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface } } - $params['hubs'][] = $hub; + // handle inventory data + $bcode = $hub['hub']->getBranchCode(); + $hub['inventory'] = 0; + if ($bcode != '') + { + $branch_codes[] = $bcode; + $inv_data[$bcode] = [ + 'hub_id' => $hub_id, + 'branch_code' => $bcode, + 'inventory' => 0, + ]; + } + + $params['hubs'][$hub_id] = $hub; } + // get battery (if any) + $skus = []; + $invoice = $obj->getInvoice(); + $inv_items = $invoice->getItems(); + foreach ($inv_items as $inv_item) + { + $batt = $inv_item->getBattery(); + if ($batt == null) + continue; + + $skus[] = $batt->getSapCode(); + } + + // get inventory + $mres = $motiv->getInventory($branch_codes, $skus); + foreach ($mres as $mres_item) + { + $bcode = $mres_item['BranchCode']; + $inv_count = $mres_item['Quantity']; + if (isset($inv_data[$bcode])) + { + $hub_id = $inv_data[$bcode]['hub_id']; + + $params['hubs'][$hub_id]['inventory'] = $inv_count; + } + } + + error_log(print_r($mres, true)); + $params['obj'] = $obj; // get template to display $params['template'] = $this->getTwigTemplate('jo_open_hub_form'); diff --git a/src/Service/JobOrderHandlerInterface.php b/src/Service/JobOrderHandlerInterface.php index cff06242..644db54a 100644 --- a/src/Service/JobOrderHandlerInterface.php +++ b/src/Service/JobOrderHandlerInterface.php @@ -77,7 +77,7 @@ interface JobOrderHandlerInterface public function initializeFulfillmentForm(int $id); // initialize hub form - public function initializeHubForm(int $id, HubSelector $hub_selector); + public function initializeHubForm(int $id, HubSelector $hub_selector, $motiv); // initialize rider form public function initializeRiderForm(int $id); From bc1c6110e82e140728e109ba9cf4047a15ec5e94 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 8 Apr 2022 09:06:55 +0000 Subject: [PATCH 03/19] Fix issues found during testing. #655 --- ...hamaVehicleBatteryCompatibilityCommand.php | 67 +++++++------------ 1 file changed, 23 insertions(+), 44 deletions(-) diff --git a/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php b/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php index ba45414d..50296cad 100644 --- a/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php +++ b/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php @@ -26,11 +26,11 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command const F_V_MODEL_YEAR = 2; const F_B_SIZE = 7; const F_B_MODEL = 8; - const F_B_ALT_PREM_MF = 10; - const F_B_ALT_PREM_LM = 11; - const F_B_ALT_SUPER_PREM_MF = 12; - const F_B_ALT_SUPREME_MF = 13; - const F_B_ALT_PLATINUM_MF = 14; + //const F_B_ALT_PREM_MF = 10; + //const F_B_ALT_PREM_LM = 11; + //const F_B_ALT_SUPER_PREM_MF = 12; + //const F_B_ALT_SUPREME_MF = 13; + //const F_B_ALT_PLATINUM_MF = 14; // the rest of the fields are irrelevant protected $em; @@ -92,7 +92,9 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command { $output->writeln("Parsing row " . $row_num . "..."); + // alternate brands are not in file, so we just comment out // get the alternate battery brand header names + /* if ($row_num == 2) { $prem_mf_name = $this->normalizeName($fields[SELF::F_B_ALT_PREM_MF]); @@ -101,6 +103,7 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $supreme_mf_name = $this->normalizeName($fields[SELF::F_B_ALT_SUPREME_MF]); $platinum_mf_name = $this->normalizeName($fields[SELF::F_B_ALT_PLATINUM_MF]); } + */ // process row $output_info[] = $this->processRow($fields, $vbrands, $row_num, $prem_mf_name, $prem_lm_name, @@ -108,10 +111,8 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $row_num++; } - // print_r($b_models); - // print_r($batteries); - // save to db + // save to db the valid ones foreach ($vbrands as $brand_name => $vbrand) { // vehicles @@ -140,6 +141,8 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $vdata['battery']->addVehicle($vehicle); // alt_batteries + // alternate brands are not in file, so we just comment out + /* if (isset($vdata['alt_battery_prem_mf'])) $vdata['alt_battery_prem_mf']->addVehicle($vehicle); if (isset($vdata['alt_battery_prem_lm'])) @@ -150,12 +153,14 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $vdata['alt_battery_supreme_mf']->addVehicle($vehicle); if (isset($vdata['alt_battery_platinum_mf'])) $vdata['alt_battery_platinum_mf']->addVehicle($vehicle); + */ } } $em->flush(); // write to output file + // error_log(print_r($output_info, true)); $this->outputVehicleBatteryInfo($output_file, $output_info); fclose($fh); @@ -177,8 +182,6 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command // go into the vbrands array $output_info = $this->validateManufacturerVehicle($fields, $brand, $make, $model, $bsize, $bmodel); - error_log(count($output_info)); - if (!empty($output_info)) return $output_info; @@ -202,8 +205,10 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $batt_key = $this->getBatteryKey($bsize, $bmodel); $vbrands[$brand]['vehicles'][$row_num]['battery'] = $this->batt_index[$batt_key]; + // alternate brands are not in file, so we just comment out // need to check alternate brands if battery exists // go through the alternate fields, look for 'P'. Not kidding. It's what is in the csv file. + /* if ($this->normalizeName($fields[SELF::F_B_ALT_PREM_MF]) == 'P') { // check if we have battery for name + size combo @@ -249,6 +254,7 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $vbrands[$brand]['vehicles'][$row_num]['alt_battery_platinum_mf'] = $this->batt_index[$alt_batt_key]; } } + */ } protected function validateManufacturerVehicle($fields, $brand, $make, $model, $bsize, $bmodel) @@ -297,11 +303,14 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $model_year = trim($fields[SELF::F_V_MODEL_YEAR]); $bsize = trim($fields[SELF::F_B_SIZE]); $bmodel = trim($fields[SELF::F_B_MODEL]); + // alternate brands are not in file, so we just comment out + /* $alt_prem_mf = trim($fields[SELF::F_B_ALT_PREM_MF]); $alt_prem_lm = trim($fields[SELF::F_B_ALT_PREM_LM]); $alt_super_prem_mf = trim($fields[SELF::F_B_ALT_SUPER_PREM_MF]); $alt_supreme_mf = trim($fields[SELF::F_B_ALT_SUPREME_MF]); $alt_platinum_mf = trim($fields[SELF::F_B_ALT_PLATINUM_MF]); + */ return [ $mfg_name, @@ -309,11 +318,6 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $model_year, $bsize, $bmodel, - $alt_prem_mf, - $alt_prem_lm, - $alt_super_prem_mf, - $alt_supreme_mf, - $alt_platinum_mf, $status, $reason ]; @@ -343,7 +347,8 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command foreach($entries as $row) { - fputcsv($fh, $row); + if ($row != null) + fputcsv($fh, $row); } fclose($fh); @@ -362,8 +367,6 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command if (!isset($this->v_index[$mfg_name])) $this->v_index[$mfg_name] = []; - error_log('vehicle keys ' . $mfg_name . ' ' . $this->normalizeName($v->getMake()) . '|' . $v->getModelYearFrom() . '|' . $v->getModelYearTo()); - $this->v_index[$mfg_name][$this->normalizeName($v->getMake()) . '|' . $v->getModelYearFrom() . '|' . $v->getModelYearTo()] = $v; } } @@ -378,33 +381,9 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command // get the battery size $bsize = $b->getSize()->getName(); - error_log($bsize); + $key = $this->getBatteryKey($bsize, $b->getModel()->getName()); - // check if size has / - $bsizes = []; - $pos = stripos($bsize, '/'); - if ($pos == false) - { - // no '/' in size - $bsizes[] = $this->normalizeName($bsize); - } - else - { - // if yes, we need to split it. - $sizes = explode('/', $bsize); - foreach ($sizes as $size) - { - $bsizes[] = $this->normalizeName($size); - } - } - - foreach ($bsizes as $battery_size) - { - error_log('Adding ' . $battery_size . ' to key'); - $key = $this->getBatteryKey($battery_size, $b->getModel()->getName()); - - $this->batt_index[$key] = $b; - } + $this->batt_index[$key] = $b; } } From 688b890fd74bdf4f1ab472213881f65e02f4e68b Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 11 Apr 2022 03:04:43 +0000 Subject: [PATCH 04/19] Modify script to create vehicle if vehicle does not exist. Modify length of make in Vehicle. #655 --- ...hamaVehicleBatteryCompatibilityCommand.php | 69 +++++++++++++++++-- src/Entity/Vehicle.php | 2 +- 2 files changed, 65 insertions(+), 6 deletions(-) diff --git a/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php b/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php index 50296cad..1599eef3 100644 --- a/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php +++ b/src/Command/ImportYokohamaVehicleBatteryCompatibilityCommand.php @@ -62,6 +62,7 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $csv_file = $input->getArgument('input_file'); $output_file = $input->getArgument('output_file'); + $this->populateVehicleManufacturerIndex(); $this->populateVehicleIndex(); $this->populateBatteryIndex(); @@ -260,6 +261,23 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command protected function validateManufacturerVehicle($fields, $brand, $make, $model, $bsize, $bmodel) { $output_info = []; + + // check if manufacturer is blank + if (empty($brand)) + { + $message = 'No manufacturer provided.'; + $output_info = $this->setOutputInfo($fields, 'NOT ADDED', $message); + return $output_info; + } + + // check if make is blank + if (empty($make)) + { + $message = 'No make provided.'; + $output_info = $this->setOutputInfo($fields, 'NOT ADDED', $message); + return $output_info; + } + // process model year data if ($model == 'NONE') { @@ -277,12 +295,42 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command $m_year_to = 0; } + // get manufacturer or make one + if (!isset($this->vmfg_index[$brand])) + { + // manufacturer + $mfg = new VehicleManufacturer(); + $mfg->setName($brand); + $this->em->persist($mfg); + } + else + { + $mfg = $this->vmfg_index[$brand]; + } + if (!isset($this->v_index[$brand][$make . '|' . intval($m_year_from) . '|' . intval($m_year_to)])) { - $message = 'Invalid vehicle'; - $output_info = $this->setOutputInfo($fields, 'NOT ADDED', $message); - return $output_info; + // vehicle + $vehicle = new Vehicle(); + $vehicle->setManufacturer($mfg) + ->setMake($make) + ->setModelYearFrom($m_year_from) + ->setModelYearTo($m_year_to); + $this->em->persist($vehicle); } + else + { + $vehicle = $this->v_index[$brand][$make . '|' . intval($m_year_from) . '|' . intval($m_year_to)]; + } + + // save to db new manufacturer and vehicle + $this->em->flush(); + + // add the vehicle manufacturer to hash + $this->vmfg_index[$brand] = $mfg; + + // add the new vehicle to hash + $this->v_index[$brand][$make . '|' . $m_year_from . '|' . $m_year_to] = $vehicle; // recommended battery $batt_key = $this->getBatteryKey($bsize, $bmodel); @@ -354,16 +402,27 @@ class ImportYokohamaVehicleBatteryCompatibilityCommand extends Command fclose($fh); } + protected function populateVehicleManufacturerIndex() + { + $vmfgs = $this->em->getRepository(VehicleManufacturer::class)->findAll(); + + $this->vmfg_index = []; + + foreach ($vmfgs as $vmfg) + { + $mfg_name = $this->normalizeName($vmfg->getName()); + $this->vmfg_index[$mfg_name] = $vmfg; + } + } + protected function populateVehicleIndex() { $vs = $this->em->getRepository(Vehicle::class)->findAll(); $this->v_index = []; - $this->vmfg_index = []; foreach ($vs as $v) { $mfg_name = $this->normalizeName($v->getManufacturer()->getName()); - $this->vmfg_index[$mfg_name] = $v->getManufacturer(); if (!isset($this->v_index[$mfg_name])) $this->v_index[$mfg_name] = []; diff --git a/src/Entity/Vehicle.php b/src/Entity/Vehicle.php index a93bed4e..61fdcec9 100644 --- a/src/Entity/Vehicle.php +++ b/src/Entity/Vehicle.php @@ -36,7 +36,7 @@ class Vehicle // make /** - * @ORM\Column(type="string", length=80) + * @ORM\Column(type="string", length=110) * @Assert\NotBlank() */ protected $make; From 466d6c124f6fbac876093f06bb4b31cc6a8d1545 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 12 Apr 2022 09:30:00 +0000 Subject: [PATCH 05/19] Prepend country code to mobile numbers for SMS messaging. #658 --- src/Service/RisingTideGateway.php | 36 +++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/Service/RisingTideGateway.php b/src/Service/RisingTideGateway.php index acd7d4d5..bcbc1073 100644 --- a/src/Service/RisingTideGateway.php +++ b/src/Service/RisingTideGateway.php @@ -32,6 +32,10 @@ class RisingTideGateway public function sendSMS($mobile_num, $mask, $message) { + // make sure number is acceptable to RT + // at this point, assume that mobile is numeric and valid mobile number + $clean_num = $this->cleanPhoneNumber($mobile_num); + $headers = [ 'Content-Type: application/vnd.net.wyrls.Document-v3+json' ]; @@ -39,7 +43,7 @@ class RisingTideGateway $sms = new SMSMessage(); $sms->setFrom($this->shortcode) ->setFromAlias($mask) - ->setTo($mobile_num) + ->setTo($clean_num) ->setMessage($message) ->setStatus('sent'); @@ -54,7 +58,7 @@ class RisingTideGateway 'id' => $sms->getID(), 'from' => $this->shortcode, 'from_alias' => $mask, - 'to' => $mobile_num, + 'to' => $clean_num, 'content_type' => 'text/plain', 'body' => $message, 'date' => $date_string, @@ -107,4 +111,32 @@ class RisingTideGateway return true; } + + protected function cleanPhoneNumber($mobile) + { + $num = trim($mobile); + + // at this point, assume that mobile is numeric and valid mobile number + + // check if number begins with 63 and length is 12 for the format 639XXXXXXXXX + if ((strlen($num) == 12) && (substr($num, 0, 2) == '63')) + return $num; + + if ($num[0] == '0') + { + // remove the 0, prepend 63 + $stripped_num = substr($num, 1); + $clean_num = '63' . $stripped_num; + return $clean_num; + } + + if ($num[0] == '9') + { + // prepend 63 + $clean_num = '63' . $num; + return $clean_num; + } + + return $num; + } } From a6add363bd64fccc336a7b14ad9d784b743bf43f Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 12 Apr 2022 09:53:01 +0000 Subject: [PATCH 06/19] Refine the cleaning of mobile number. #658 --- src/Service/RisingTideGateway.php | 134 +++++++++++++++++------------- 1 file changed, 74 insertions(+), 60 deletions(-) diff --git a/src/Service/RisingTideGateway.php b/src/Service/RisingTideGateway.php index bcbc1073..2a01799c 100644 --- a/src/Service/RisingTideGateway.php +++ b/src/Service/RisingTideGateway.php @@ -36,56 +36,61 @@ class RisingTideGateway // at this point, assume that mobile is numeric and valid mobile number $clean_num = $this->cleanPhoneNumber($mobile_num); - $headers = [ - 'Content-Type: application/vnd.net.wyrls.Document-v3+json' - ]; + if ($clean_num != '') + { + $headers = [ + 'Content-Type: application/vnd.net.wyrls.Document-v3+json' + ]; - $sms = new SMSMessage(); - $sms->setFrom($this->shortcode) - ->setFromAlias($mask) - ->setTo($clean_num) - ->setMessage($message) - ->setStatus('sent'); + $sms = new SMSMessage(); + $sms->setFrom($this->shortcode) + ->setFromAlias($mask) + ->setTo($clean_num) + ->setMessage($message) + ->setStatus('sent'); - $this->em->persist($sms); - $this->em->flush(); + $this->em->persist($sms); + $this->em->flush(); - $date = $sms->getDateCreate(); - // $date = new DateTime(); - $date_string = $date->format('Y-m-d') . 'T' . $date->format('H:m:s'); + $date = $sms->getDateCreate(); + // $date = new DateTime(); + $date_string = $date->format('Y-m-d') . 'T' . $date->format('H:m:s'); - $data = [ - 'id' => $sms->getID(), - 'from' => $this->shortcode, - 'from_alias' => $mask, - 'to' => $clean_num, - 'content_type' => 'text/plain', - 'body' => $message, - 'date' => $date_string, - 'usagetype' => $this->usage_type, - 'delivery_receipt_url' => $this->dr_url, - ]; - error_log(print_r($data, true)); + $data = [ + 'id' => $sms->getID(), + 'from' => $this->shortcode, + 'from_alias' => $mask, + 'to' => $clean_num, + 'content_type' => 'text/plain', + 'body' => $message, + 'date' => $date_string, + 'usagetype' => $this->usage_type, + 'delivery_receipt_url' => $this->dr_url, + ]; + error_log(print_r($data, true)); - $data_json = json_encode($data); + $data_json = json_encode($data); - $userpwd = $this->user . ':' . $this->pass; + $userpwd = $this->user . ':' . $this->pass; - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, self::SERVER_URL); - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - curl_setopt($curl, CURLOPT_VERBOSE, true); - curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json); - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); - curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($curl, CURLOPT_USERPWD, $userpwd); - $result = curl_exec($curl); - error_log('error_no - ' . curl_errno($curl)); - $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); - error_log($http_code); - curl_close($curl); + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, self::SERVER_URL); + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + curl_setopt($curl, CURLOPT_VERBOSE, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + curl_setopt($curl, CURLOPT_USERPWD, $userpwd); + $result = curl_exec($curl); + error_log('error_no - ' . curl_errno($curl)); + $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); + error_log($http_code); + curl_close($curl); - error_log($result); + error_log($result); + } + else + error_log('Invalid mobile number provided. Cannot send SMS message.'); } public function validatePhoneNumber($mobile) @@ -114,29 +119,38 @@ class RisingTideGateway protected function cleanPhoneNumber($mobile) { - $num = trim($mobile); + // remove any non digit character from string + $clean_number = preg_replace('~\D~', '', $mobile); + error_log('cleaned ' . $clean_number); - // at this point, assume that mobile is numeric and valid mobile number - - // check if number begins with 63 and length is 12 for the format 639XXXXXXXXX - if ((strlen($num) == 12) && (substr($num, 0, 2) == '63')) - return $num; - - if ($num[0] == '0') + // does it fit our 09XXXXXXXXX pattern? + if (preg_match('/^09[0-9]{9}$/', $clean_number)) { - // remove the 0, prepend 63 - $stripped_num = substr($num, 1); - $clean_num = '63' . $stripped_num; - return $clean_num; - } + // remove first '0' + $clean_number = substr($clean_number, 1); + + // prepend 63 + $clean_number = '63' . $clean_number; - if ($num[0] == '9') + error_log("CONVERTED TO $clean_number"); + return $clean_number; + } + // does it fit our 63XXXXXXXXXX pattern? + else if (preg_match('/^63[0-9]{10}$/', $clean_number)) + { + // leave alone + return $clean_number; + } + // does it fit our 9XXXXXXXXX pattern? + else if (preg_match('/^9[0-9]{9}$/', $clean_number)) { // prepend 63 - $clean_num = '63' . $num; - return $clean_num; + $clean_number = '63' . $clean_number; + + error_log("CONVERT TO $clean_number"); + return $clean_number; } - - return $num; + + return ""; } } From 6fff162c0e68f3a23d56b96fef531caa97bc04f0 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 12 Apr 2022 09:59:35 +0000 Subject: [PATCH 07/19] Improve error message and return value. #658 --- src/Service/RisingTideGateway.php | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Service/RisingTideGateway.php b/src/Service/RisingTideGateway.php index 2a01799c..0a4ba1aa 100644 --- a/src/Service/RisingTideGateway.php +++ b/src/Service/RisingTideGateway.php @@ -36,7 +36,9 @@ class RisingTideGateway // at this point, assume that mobile is numeric and valid mobile number $clean_num = $this->cleanPhoneNumber($mobile_num); - if ($clean_num != '') + if ($clean_num == false) + error_log('Invalid mobile number provided. Cannot send SMS message to ' . $mobile_num); + else { $headers = [ 'Content-Type: application/vnd.net.wyrls.Document-v3+json' @@ -89,8 +91,6 @@ class RisingTideGateway error_log($result); } - else - error_log('Invalid mobile number provided. Cannot send SMS message.'); } public function validatePhoneNumber($mobile) @@ -151,6 +151,6 @@ class RisingTideGateway return $clean_number; } - return ""; + return false; } } From b712b35a971639f86c339d1cc433e5357c89289e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 12 Apr 2022 10:01:14 +0000 Subject: [PATCH 08/19] Fix checking for return. #658 --- src/Service/RisingTideGateway.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Service/RisingTideGateway.php b/src/Service/RisingTideGateway.php index 0a4ba1aa..5928e72e 100644 --- a/src/Service/RisingTideGateway.php +++ b/src/Service/RisingTideGateway.php @@ -36,7 +36,7 @@ class RisingTideGateway // at this point, assume that mobile is numeric and valid mobile number $clean_num = $this->cleanPhoneNumber($mobile_num); - if ($clean_num == false) + if ($clean_num === false) error_log('Invalid mobile number provided. Cannot send SMS message to ' . $mobile_num); else { From 9bc1f44ca2323788e40b6b74870d2b60b0a6454b Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 12 Apr 2022 10:08:13 +0000 Subject: [PATCH 09/19] Clean up code. #658 --- src/Service/RisingTideGateway.php | 105 +++++++++++++++--------------- 1 file changed, 53 insertions(+), 52 deletions(-) diff --git a/src/Service/RisingTideGateway.php b/src/Service/RisingTideGateway.php index 5928e72e..0681edd4 100644 --- a/src/Service/RisingTideGateway.php +++ b/src/Service/RisingTideGateway.php @@ -37,60 +37,61 @@ class RisingTideGateway $clean_num = $this->cleanPhoneNumber($mobile_num); if ($clean_num === false) - error_log('Invalid mobile number provided. Cannot send SMS message to ' . $mobile_num); - else { - $headers = [ - 'Content-Type: application/vnd.net.wyrls.Document-v3+json' - ]; - - $sms = new SMSMessage(); - $sms->setFrom($this->shortcode) - ->setFromAlias($mask) - ->setTo($clean_num) - ->setMessage($message) - ->setStatus('sent'); - - $this->em->persist($sms); - $this->em->flush(); - - $date = $sms->getDateCreate(); - // $date = new DateTime(); - $date_string = $date->format('Y-m-d') . 'T' . $date->format('H:m:s'); - - $data = [ - 'id' => $sms->getID(), - 'from' => $this->shortcode, - 'from_alias' => $mask, - 'to' => $clean_num, - 'content_type' => 'text/plain', - 'body' => $message, - 'date' => $date_string, - 'usagetype' => $this->usage_type, - 'delivery_receipt_url' => $this->dr_url, - ]; - error_log(print_r($data, true)); - - $data_json = json_encode($data); - - $userpwd = $this->user . ':' . $this->pass; - - $curl = curl_init(); - curl_setopt($curl, CURLOPT_URL, self::SERVER_URL); - curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); - curl_setopt($curl, CURLOPT_VERBOSE, true); - curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json); - curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); - curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); - curl_setopt($curl, CURLOPT_USERPWD, $userpwd); - $result = curl_exec($curl); - error_log('error_no - ' . curl_errno($curl)); - $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); - error_log($http_code); - curl_close($curl); - - error_log($result); + error_log('Invalid mobile number provided. Cannot send SMS message to ' . $mobile_num); + return; } + + $headers = [ + 'Content-Type: application/vnd.net.wyrls.Document-v3+json' + ]; + + $sms = new SMSMessage(); + $sms->setFrom($this->shortcode) + ->setFromAlias($mask) + ->setTo($clean_num) + ->setMessage($message) + ->setStatus('sent'); + + $this->em->persist($sms); + $this->em->flush(); + + $date = $sms->getDateCreate(); + // $date = new DateTime(); + $date_string = $date->format('Y-m-d') . 'T' . $date->format('H:m:s'); + + $data = [ + 'id' => $sms->getID(), + 'from' => $this->shortcode, + 'from_alias' => $mask, + 'to' => $clean_num, + 'content_type' => 'text/plain', + 'body' => $message, + 'date' => $date_string, + 'usagetype' => $this->usage_type, + 'delivery_receipt_url' => $this->dr_url, + ]; + error_log(print_r($data, true)); + + $data_json = json_encode($data); + + $userpwd = $this->user . ':' . $this->pass; + + $curl = curl_init(); + curl_setopt($curl, CURLOPT_URL, self::SERVER_URL); + curl_setopt($curl, CURLOPT_HTTPHEADER, $headers); + curl_setopt($curl, CURLOPT_VERBOSE, true); + curl_setopt($curl, CURLOPT_POSTFIELDS, $data_json); + curl_setopt($curl, CURLOPT_CUSTOMREQUEST, 'POST'); + curl_setopt($curl, CURLOPT_HTTPAUTH, CURLAUTH_BASIC); + curl_setopt($curl, CURLOPT_USERPWD, $userpwd); + $result = curl_exec($curl); + error_log('error_no - ' . curl_errno($curl)); + $http_code = curl_getinfo($curl, CURLINFO_HTTP_CODE); + error_log($http_code); + curl_close($curl); + + error_log($result); } public function validatePhoneNumber($mobile) From dad3caecf34c1cf6feb135a12521208642f1430e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 12 Apr 2022 11:00:43 +0000 Subject: [PATCH 10/19] Fix bugs found when testing with app. #658 --- src/Controller/APIController.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 4c23cb17..73643bbf 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -249,7 +249,7 @@ class APIController extends Controller implements LoggedController $rt->sendSMS($phone_number, $translator->trans('message.battery_brand_allcaps'), $message); } - public function confirmNumber(RisingTideGateway $rt, Request $req) + public function confirmNumber(RisingTideGateway $rt, Request $req, TranslatorInterface $translator) { // check parameters $required_params = [ @@ -306,7 +306,7 @@ class APIController extends Controller implements LoggedController if ($otp_mode != 'test') { // send sms to number - $this->sendConfirmationCode($rt, $phone_number, $code); + $this->sendConfirmationCode($rt, $phone_number, $code, $translator); } // response From cea8df1a2c81b988ecbb123f53fca27296e6ba3e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 22 Apr 2022 08:26:13 +0000 Subject: [PATCH 11/19] Add script to copy the new certificates to vernemq folder and restart the needed services --- utils/post_cert_renewal/post_cert_renewal.sh | 11 +++++++++++ 1 file changed, 11 insertions(+) create mode 100755 utils/post_cert_renewal/post_cert_renewal.sh diff --git a/utils/post_cert_renewal/post_cert_renewal.sh b/utils/post_cert_renewal/post_cert_renewal.sh new file mode 100755 index 00000000..39d75ce1 --- /dev/null +++ b/utils/post_cert_renewal/post_cert_renewal.sh @@ -0,0 +1,11 @@ +#!/bin/bash +# copy the certificates into /etc/vernemq +cp -Lp /etc/letsencrypt/live/resqapi.jankstudio.com/*.pem /etc/vernemq + +# change ownership and group of the certificates from root to vernemq +chown vernemq:vernemq /etc/vernemq/*.pem + +sudo systemctl restart vernemq.service +sudo systemctl restart mqtt_sender.service +sudo systemctl restart riderloc.service + From 4d07f350bb8dde87d5e5b74edd167d62a8b0c444 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 22 Apr 2022 09:24:39 +0000 Subject: [PATCH 12/19] Add comments on how to install the script. #695 --- utils/post_cert_renewal/post_cert_renewal.sh | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/utils/post_cert_renewal/post_cert_renewal.sh b/utils/post_cert_renewal/post_cert_renewal.sh index 39d75ce1..2ee902c0 100755 --- a/utils/post_cert_renewal/post_cert_renewal.sh +++ b/utils/post_cert_renewal/post_cert_renewal.sh @@ -1,4 +1,8 @@ #!/bin/bash + +# copy this script into /etc/letsencrypt/renewal-hooks/post +# to test: sudo certbot renew --dry-run + # copy the certificates into /etc/vernemq cp -Lp /etc/letsencrypt/live/resqapi.jankstudio.com/*.pem /etc/vernemq From bbea317cf1da701939dc57c2bb942a3ab531bbc6 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 27 Apr 2022 05:56:15 +0000 Subject: [PATCH 13/19] Add Source of Awareness and Remarks to Ticket and ticket form. #661 --- src/Controller/TicketController.php | 24 ++++++++++++++++++-- src/Entity/JobOrder.php | 34 ++++++++++++++++++++++++++++ src/Entity/Ticket.php | 35 +++++++++++++++++++++++++++++ src/Ramcar/SourceOfAwareness.php | 25 +++++++++++++++++++++ templates/ticket/form.html.twig | 19 ++++++++++++++++ 5 files changed, 135 insertions(+), 2 deletions(-) create mode 100644 src/Ramcar/SourceOfAwareness.php diff --git a/src/Controller/TicketController.php b/src/Controller/TicketController.php index 303b34a6..0f9f3cd9 100644 --- a/src/Controller/TicketController.php +++ b/src/Controller/TicketController.php @@ -4,6 +4,8 @@ namespace App\Controller; use App\Ramcar\TicketType; use App\Ramcar\TicketStatus; +use App\Ramcar\SourceOfAwareness; + use App\Entity\Ticket; use App\Entity\Customer; use App\Entity\JobOrder; @@ -172,6 +174,7 @@ class TicketController extends Controller $params['statuses'] = TicketStatus::getCollection(); $params['other_ticket_type'] = TicketType::OTHER; $params['redirect_url'] = $this->generateUrl('ticket_list'); + $params['soa_types'] = SourceOfAwareness::getCollection(); // set redirect url if ($customer) @@ -240,6 +243,12 @@ class TicketController extends Controller $other_ticket_type = $req->request->get('other_ticket_type'); } + // get source of awareness if any + $soa_type = $req->request->get('source_of_awareness'); + + // get remarks + $remarks = $req->request->get('remarks', ''); + // set and save values $obj->setFirstName($first_name) ->setLastName($last_name) @@ -250,7 +259,9 @@ class TicketController extends Controller ->setDetails($req->request->get('details')) ->setPlateNumber($req->request->get('plate_number')) ->setDateCreate(new DateTime()) - ->setCreatedBy($this->getUser()); + ->setCreatedBy($this->getUser()) + ->setSourceOfAwareness($soa_type) + ->setRemarks($remarks); // if assigned to customer, set association if ($customer_id) { @@ -326,6 +337,7 @@ class TicketController extends Controller $params['statuses'] = TicketStatus::getCollection(); $params['other_ticket_type'] = TicketType::OTHER; $params['redirect_url'] = $this->generateUrl('ticket_list'); + $params['soa_types'] = SourceOfAwareness::getCollection(); // set redirect url if ($customer) @@ -423,6 +435,12 @@ class TicketController extends Controller $other_ticket_type = $req->request->get('other_ticket_type'); } + // get source of awareness if any + $soa_type = $req->request->get('source_of_awareness'); + + // get remarks + $remarks = $req->request->get('remarks', ''); + // set and save values $obj->setFirstName($first_name) ->setLastName($last_name) @@ -431,7 +449,9 @@ class TicketController extends Controller ->setTicketType($ticket_type) ->setOtherTicketType($other_ticket_type) ->setDetails($req->request->get('details')) - ->setPlateNumber($req->request->get('plate_number')); + ->setPlateNumber($req->request->get('plate_number')) + ->setSourceOfAwareness($soa_type) + ->setRemarks($remarks); // initialize error list $error_array = []; diff --git a/src/Entity/JobOrder.php b/src/Entity/JobOrder.php index 591a982e..67f317ca 100644 --- a/src/Entity/JobOrder.php +++ b/src/Entity/JobOrder.php @@ -372,6 +372,18 @@ class JobOrder */ protected $rating; + // source of awareness + /** + * @ORM\Column(type="string", length=80, nullable=true) + */ + protected $source_of_awareness; + + // remarks related to source of awareness + /** + * @ORM\Column(type="text", nullable=true) + */ + protected $remarks; + public function __construct() { $this->date_create = new DateTime(); @@ -1061,4 +1073,26 @@ class JobOrder { return $this->rating; } + + public function setSourceOfAwareness($source_of_awareness) + { + $this->source_of_awareness = $source_of_awareness; + return $this; + } + + public function getSourceOfAwareness() + { + return $this->source_of_awareness; + } + + public function setRemarks($remarks) + { + $this->remarks = $remarks; + return $this; + } + + public function getRemarks() + { + return $this->remarks; + } } diff --git a/src/Entity/Ticket.php b/src/Entity/Ticket.php index 35882075..a3218c47 100644 --- a/src/Entity/Ticket.php +++ b/src/Entity/Ticket.php @@ -108,6 +108,18 @@ class Ticket */ protected $job_order; + // source of awareness + /** + * @ORM\Column(type="string", length=80, nullable=true) + */ + protected $source_of_awareness; + + // remarks related to source of awareness + /** + * @ORM\Column(type="text", nullable=true) + */ + protected $remarks; + public function __construct() { $this->date_create = new DateTime(); @@ -265,4 +277,27 @@ class Ticket { return $this->job_order; } + + public function setSourceOfAwareness($source_of_awareness) + { + $this->source_of_awareness = $source_of_awareness; + return $this; + } + + public function getSourceOfAwareness() + { + return $this->source_of_awareness; + } + + public function setRemarks($remarks) + { + $this->remarks = $remarks; + return $this; + } + + public function getRemarks() + { + return $this->remarks; + } + } diff --git a/src/Ramcar/SourceOfAwareness.php b/src/Ramcar/SourceOfAwareness.php new file mode 100644 index 00000000..a466798f --- /dev/null +++ b/src/Ramcar/SourceOfAwareness.php @@ -0,0 +1,25 @@ + 'Facebook', + 'instagram' => 'Instagram', + 'radio_ads' => 'Radio Ads', + 'tarp_ads' => 'Tarp Ads', + 'flyers' => 'Flyers', + 'word_of_mouth' => 'Word of Mouth', + 'other' => 'Other', + ]; +} + diff --git a/templates/ticket/form.html.twig b/templates/ticket/form.html.twig index 84328ab8..327d924f 100644 --- a/templates/ticket/form.html.twig +++ b/templates/ticket/form.html.twig @@ -84,6 +84,25 @@ +
+
+ + + +
+
+
+
+ + + +
+
From ebaef973338cf5609a6d678e191b90d2137869bd Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 27 Apr 2022 06:45:54 +0000 Subject: [PATCH 14/19] Add Source of Awareness and Remarks to job order form. #661 --- .../JobOrderHandler/ResqJobOrderHandler.php | 68 +++++++++++++++++-- templates/job-order/form.html.twig | 17 +++++ templates/ticket/form.html.twig | 14 ++-- 3 files changed, 87 insertions(+), 12 deletions(-) diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 40be027a..4480c473 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -44,6 +44,7 @@ use App\Ramcar\WillingToWaitContent; use App\Ramcar\WarrantySource; use App\Ramcar\HubCriteria; use App\Ramcar\DeliveryStatus; +use App\Ramcar\SourceOfAwareness; use App\Service\InvoiceGeneratorInterface; use App\Service\JobOrderHandlerInterface; @@ -396,6 +397,12 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface } } + // get source of awareness if any + $soa_type = $req->request->get('source_of_awareness'); + + // get remarks + $remarks = $req->request->get('remarks', ''); + // TODO: check status before saving since JO might already // have a status that needs to be retained @@ -427,7 +434,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setWillWait($req->request->get('flag_willing_to_wait')) ->setReasonNotWait($reason) ->setNotWaitingNotes($more_reason) - ->setNoTradeInReason($no_trade_in_reason); + ->setNoTradeInReason($no_trade_in_reason) + ->setSourceOfAwareness($soa_type) + ->setRemarks($remarks); // check if user is null, meaning call to create came from API if ($user != null) @@ -622,6 +631,12 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface } } + // get source of awareness if any + $soa_type = $req->request->get('source_of_awareness'); + + // get remarks + $remarks = $req->request->get('remarks', ''); + if (empty($error_array)) { // get current user @@ -648,7 +663,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setWillWait($req->request->get('flag_willing_to_wait')) ->setReasonNotWait($reason) ->setNotWaitingNotes($more_reason) - ->setNoTradeInReason($no_trade_in_reason); + ->setNoTradeInReason($no_trade_in_reason) + ->setSourceOfAwareness($soa_type) + ->setRemarks($remarks); // did they change invoice? $invoice_items = $req->request->get('invoice_items', []); @@ -794,6 +811,12 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $more_reason = $req->request->get('not_wait_notes'); } + // get source of awareness if any + $soa_type = $req->request->get('source_of_awareness'); + + // get remarks + $remarks = $req->request->get('remarks', ''); + if (empty($error_array)) { // coordinates @@ -817,7 +840,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setLandmark($req->request->get('landmark')) ->setWillWait($req->request->get('flag_willing_to_wait')) ->setReasonNotWait($reason) - ->setNotWaitingNotes($more_reason); + ->setNotWaitingNotes($more_reason) + ->setSourceOfAwareness($soa_type) + ->setRemarks($remarks); // validate $errors = $this->validator->validate($obj); @@ -909,6 +934,12 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $more_reason = $req->request->get('not_wait_notes'); } + // get source of awareness if any + $soa_type = $req->request->get('source_of_awareness'); + + // get remarks + $remarks = $req->request->get('remarks', ''); + // get current user $user = $this->security->getUser(); @@ -934,7 +965,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setWillWait($req->request->get('flag_willing_to_wait')) ->setReasonNotWait($reason) ->setNotWaitingNotes($more_reason) - ->setDeliveryStatus(DeliveryStatus::RIDER_ASSIGN); + ->setDeliveryStatus(DeliveryStatus::RIDER_ASSIGN) + ->setSourceOfAwareness($soa_type) + ->setRemarks($remarks); if ($user != null) { @@ -1015,6 +1048,12 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $more_reason = $req->request->get('not_wait_notes'); } + // get source of awareness if any + $soa_type = $req->request->get('source_of_awareness'); + + // get remarks + $remarks = $req->request->get('remarks', ''); + if (empty($error_array)) { // coordinates $point = new Point($req->request->get('coord_lng'), $req->request->get('coord_lat')); @@ -1034,7 +1073,9 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setWillWait($req->request->get('flag_willing_to_wait')) ->setReasonNotWait($reason) ->setNotWaitingNotes($more_reason) - ->setDeliveryStatus(DeliveryStatus::FULFILLED); + ->setDeliveryStatus(DeliveryStatus::FULFILLED) + ->setSourceOfAwareness($soa_type) + ->setRemarks($remarks); // validate $errors = $this->validator->validate($obj); @@ -1235,6 +1276,12 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $more_reason = $req->request->get('not_wait_notes'); } + // get source of awareness if any + $soa_type = $req->request->get('source_of_awareness'); + + // get remarks + $remarks = $req->request->get('remarks', ''); + // get previously assigned hub, if any $old_hub = $obj->getHub(); @@ -1269,6 +1316,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setWillWait($req->request->get('flag_willing_to_wait')) ->setReasonNotWait($reason) ->setNotWaitingNotes($more_reason) + ->setSourceOfAwareness($soa_type) + ->setRemarks($remarks) ->clearRider(); if ($user != null) @@ -1465,6 +1514,12 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $more_reason = $req->request->get('not_wait_notes'); } + // get source of awareness if any + $soa_type = $req->request->get('source_of_awareness'); + + // get remarks + $remarks = $req->request->get('remarks', ''); + if (empty($error_array)) { // rider mqtt event // NOTE: need to send this before saving because rider will be cleared @@ -1505,6 +1560,8 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface ->setWillWait($req->request->get('flag_willing_to_wait')) ->setReasonNotWait($reason) ->setNotWaitingNotes($more_reason) + ->setSourceOfAwareness($soa_type) + ->setRemarks($remarks) ->setDeliveryStatus(DeliveryStatus::RIDER_ASSIGN); if ($user != null) @@ -3011,6 +3068,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $params['willing_to_wait_content'] = WillingToWaitContent::getCollection(); $params['no_wait_reasons'] = CustomerNotWaitReason::getCollection(); $params['no_trade_in_reasons'] = NoTradeInReason::getCollection(); + $params['soa_types'] = SourceOfAwareness::getCollection(); } protected function initFormTags(&$params) diff --git a/templates/job-order/form.html.twig b/templates/job-order/form.html.twig index 4fff73e0..2d510c36 100644 --- a/templates/job-order/form.html.twig +++ b/templates/job-order/form.html.twig @@ -449,6 +449,23 @@
+ +
+
+ + + +
+
+ + + +