From 29f1c34b2ce09f5851048be358df93748a934c85 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Fri, 4 Jun 2021 00:52:26 +0800 Subject: [PATCH 01/31] Change filename year to 4-digits #576 --- utils/get_warranty_serial/get_serials.php | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/get_warranty_serial/get_serials.php b/utils/get_warranty_serial/get_serials.php index 237ce266..3a0f3d24 100644 --- a/utils/get_warranty_serial/get_serials.php +++ b/utils/get_warranty_serial/get_serials.php @@ -23,10 +23,10 @@ $blob_client = BlobRestProxy::createBlobService($conn_string); $current_date = new DateTime(); $current_date->modify("-1 day"); -$date = $current_date->format('m-d-y'); +$date = $current_date->format('m-d-Y'); $filename = 'warrantylogs' . $date . '.csv'; -//print_r($filename); +error_log($filename); try { // NOTE: via download blob From b300814b500523c6ed9f72e80eef1efbc5fd7de8 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 4 Jun 2021 10:22:28 +0000 Subject: [PATCH 02/31] Add error checking to processing script. Create new script for downloading files from motiv. #576 --- utils/get_warranty_serial/get_serials.php | 17 ++++-- utils/get_warranty_serial/new_get_serials.php | 49 +++++++++++++++ utils/load_warranty_serial/load_serials.php | 59 +++++++++++++++---- utils/warranty_motiv_local_bulk.sh | 36 +++++++++++ 4 files changed, 143 insertions(+), 18 deletions(-) create mode 100644 utils/get_warranty_serial/new_get_serials.php create mode 100755 utils/warranty_motiv_local_bulk.sh diff --git a/utils/get_warranty_serial/get_serials.php b/utils/get_warranty_serial/get_serials.php index 3a0f3d24..e9538e3f 100644 --- a/utils/get_warranty_serial/get_serials.php +++ b/utils/get_warranty_serial/get_serials.php @@ -20,14 +20,20 @@ $conn_string = "BlobEndpoint=$blob_url;\nSharedAccessSignature=$sas_token"; $blob_client = BlobRestProxy::createBlobService($conn_string); -$current_date = new DateTime(); -$current_date->modify("-1 day"); +// get date argument +$proc_date = $argv[1]; -$date = $current_date->format('m-d-Y'); +error_log($proc_date); -$filename = 'warrantylogs' . $date . '.csv'; +//$current_date = new DateTime(); +//$current_date->modify("-1 day"); + +//$date = $current_date->format('m-d-Y'); + +$filename = 'warrantylogs' . $proc_date . '.csv'; error_log($filename); +/* try { // NOTE: via download blob $res = $blob_client->getBlob('warranty', $filename); @@ -36,8 +42,7 @@ try { file_put_contents("/tmp/warranty_download_serial.txt", $res->getContentStream()); } catch (Exception $e) { file_put_contents("/tmp/serial_download_error.txt", $filename . "\n" . $e->getMessage() . "\n" . "\n", FILE_APPEND); -} - +} */ /* // NOTE: getting via url diff --git a/utils/get_warranty_serial/new_get_serials.php b/utils/get_warranty_serial/new_get_serials.php new file mode 100644 index 00000000..45161f3a --- /dev/null +++ b/utils/get_warranty_serial/new_get_serials.php @@ -0,0 +1,49 @@ +getBlob('warranty', $filename); + // print_r($res); + + if ($flag_overwrite > 0) + { + file_put_contents($output_file, $res->getContentStream()); + } + else + { + file_put_contents($output_file, "\r\n", FILE_APPEND); + file_put_contents($output_file, $res->getContentStream(), FILE_APPEND); + } +} catch (Exception $e) { + file_put_contents("/tmp/serial_download_error.txt", $filename . "\n" . $e->getMessage() . "\n" . "\n", FILE_APPEND); +} + + + + + diff --git a/utils/load_warranty_serial/load_serials.php b/utils/load_warranty_serial/load_serials.php index cd1cce90..6eb1d918 100644 --- a/utils/load_warranty_serial/load_serials.php +++ b/utils/load_warranty_serial/load_serials.php @@ -5,6 +5,9 @@ $csv = fopen($argv[1], 'r'); $dsn = $argv[2]; $user = $argv[3]; $pass = $argv[4]; +$output_file = $argv[5]; + +$output_fh = fopen($output_file, "w"); // connect to db $db = new PDO($dsn, $user, $pass); @@ -13,33 +16,54 @@ $db = new PDO($dsn, $user, $pass); $sth = $db->prepare('insert into warranty_serial (id, sku, date_create, source, meta_info) values (:serial, :sku, :date_create, :source, :meta_info)'); // go through rows -$counter = 0; $source = 'motiv'; while (($row = fgetcsv($csv)) !== false) { - // skip first line - if ($counter == 0) + // TODO: verify if these are still the headers if there are headers + // possible lines in output file: + // (1) header in csv file + // SerialNumber,Sku,DispatchStatus,CreatedDate,InventoryStatus,CategoryID,CategoryName + // (2) No available data + // (3) CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF + // (4) Empty line + + // check if csv file has a header by checking contents of line + if (($row[0] == 'SerialNumber') || ($row[1] == 'Sku') || + ($row[2] == 'DispatchStatus') || ($row[3] == 'CreatedDate') || + ($row[4] == 'InventoryStatus') || ($row[5] == 'CategoryID') || + ($row[6] == 'CategoryName')) { - $counter++; + // skip the header + error_log('Skipping the headers... '); continue; } - /* - $serial = trim(strtoupper($row[0])); - $sku = trim($row[1]); - $date_create = $row[2]; - $ref_id = $row[3]; */ + // check if No available data + if ($row[0] == 'No available data') + { + // skip the line + error_log('No available data, skipping the line...'); + continue; + } + // check if new line + if (empty($row[0])) + { + // skip + error_log('Skipping empty line...'); + continue; + } + // sample of line in output file: // serial number, sku, dispatch status, created date, inventory status, category id, category name // CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF $serial = trim(strtoupper($row[0])); - $sku = trim($row[1]); + $sku = trim(strtoupper($row[1])); $dispatch_status = trim($row[2]); $date_create = $row[3]; $inventory_status = trim($row[4]); $cat_id = trim($row[5]); - $cat_name = trim($row[6]); + $cat_name = trim(strtoupper($row[6])); $meta_info = [ 'dispatch_status' => $dispatch_status, @@ -50,6 +74,8 @@ while (($row = fgetcsv($csv)) !== false) $info = json_encode($meta_info); + error_log('Processing ' . $serial . ' and ' . $sku); + if ($sku == 'N/A') $sku = null; @@ -63,12 +89,21 @@ while (($row = fgetcsv($csv)) !== false) if (!$res) { + // log the error $err = $sth->errorInfo(); - echo "Error ($serial) - " . $err[2] . "\n"; + $err_message = "$serial - ERROR - " . $err[2] . "\n"; + fwrite($output_fh, $err_message); + } + else + { + // log successful adding of serial + $message = "$serial - SUCCESS - " . "\n"; + fwrite($output_fh, $message); } } // close file fclose($csv); +fclose($output_fh); diff --git a/utils/warranty_motiv_local_bulk.sh b/utils/warranty_motiv_local_bulk.sh new file mode 100755 index 00000000..167e8566 --- /dev/null +++ b/utils/warranty_motiv_local_bulk.sh @@ -0,0 +1,36 @@ +#!/bin/bash +touch /tmp/warranty_download_serial.csv +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-03-2021 /tmp/warranty_download_serial.csv 1 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-04-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-05-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-06-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-07-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-08-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-09-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-10-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-11-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-12-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-13-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-14-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-15-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-16-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-17-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-18-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-19-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-20-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-21-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-22-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-23-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-24-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-25-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-26-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-27-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-28-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-29-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-30-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-31-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-01-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-02-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-03-2021 /tmp/warranty_download_serial.csv 0 +touch /tmp/warranty_load_status.txt +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=localhost;dbname=resq;charset=UTF8" root password /tmp/warranty_load_status.txt From ed14a3defd013b30b786cabf3cab91ab717662df Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 8 Jun 2021 08:38:02 +0000 Subject: [PATCH 03/31] Fix scripts for warranty serials. #576 --- utils/load_warranty_serial/load_serials.php | 74 ++++++++++++++++----- utils/warranty_motiv_local.sh | 9 +++ utils/warranty_motiv_local_bulk.sh | 68 ++++++++++--------- utils/warranty_motiv_prod.sh | 11 ++- utils/warranty_motiv_prod_bulk.sh | 40 +++++++++++ 5 files changed, 152 insertions(+), 50 deletions(-) create mode 100755 utils/warranty_motiv_local.sh create mode 100755 utils/warranty_motiv_prod_bulk.sh diff --git a/utils/load_warranty_serial/load_serials.php b/utils/load_warranty_serial/load_serials.php index 6eb1d918..9df178bc 100644 --- a/utils/load_warranty_serial/load_serials.php +++ b/utils/load_warranty_serial/load_serials.php @@ -9,6 +9,14 @@ $output_file = $argv[5]; $output_fh = fopen($output_file, "w"); +if (!file_exists($csv)) +{ + $err_message = "No csv input file found." . "\n"; + fwrite($output_fh, $err_message); + fclose($output_fh); + exit(); +} + // connect to db $db = new PDO($dsn, $user, $pass); @@ -27,17 +35,6 @@ while (($row = fgetcsv($csv)) !== false) // (3) CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF // (4) Empty line - // check if csv file has a header by checking contents of line - if (($row[0] == 'SerialNumber') || ($row[1] == 'Sku') || - ($row[2] == 'DispatchStatus') || ($row[3] == 'CreatedDate') || - ($row[4] == 'InventoryStatus') || ($row[5] == 'CategoryID') || - ($row[6] == 'CategoryName')) - { - // skip the header - error_log('Skipping the headers... '); - continue; - } - // check if No available data if ($row[0] == 'No available data') { @@ -53,18 +50,67 @@ while (($row = fgetcsv($csv)) !== false) error_log('Skipping empty line...'); continue; } + + // check if csv file has a header by checking contents of line + if (($row[0] == 'SerialNumber') || ($row[1] == 'Sku') || + ($row[2] == 'DispatchStatus') || ($row[3] == 'CreatedDate') || + ($row[4] == 'InventoryStatus') || ($row[5] == 'CategoryID') || + ($row[6] == 'CategoryName')) + { + // skip the header + error_log('Skipping the headers... '); + continue; + } // sample of line in output file: // serial number, sku, dispatch status, created date, inventory status, category id, category name // CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF + // MG2000313690,N/A,1,2021-05-14T23:47:30.6430000+08:00,0,10,GOLD $serial = trim(strtoupper($row[0])); $sku = trim(strtoupper($row[1])); $dispatch_status = trim($row[2]); - $date_create = $row[3]; + $str_date_create = trim($row[3]); $inventory_status = trim($row[4]); $cat_id = trim($row[5]); $cat_name = trim(strtoupper($row[6])); + error_log('Processing ' . $serial . ' and ' . $sku); + + // since some people cannot follow simple instructions... + // check the date format on the string + // try 2021-05-15T08:35:46+08:00 format on str_date_create + $date_create = DateTime::createFromFormat('Y-m-d\TH:i:sP', $str_date_create); + + if ($date_create == false) + { + // try this format: 2021-05-15T08:47:20.3330000+08:00 + // get the date, time and timezone from str_date_create + $str_date_time = substr($str_date_create, 0, 19); + $str_timezone = substr($str_date_create, 27); + $str_datetime_tz = $str_date_time . $str_timezone; + + // create DateTime object + // sample: 2021-05-15T12:16:06+08:00 + $date_create = DateTime::createFromFormat('Y-m-d\TH:i:sP', $str_datetime_tz); + + // check if datetime object was created + // if not, someone f*cked up and we have no date create + if ($date_create == false) + { + // log the serial + $message = "$serial - ERROR - " . "Invalid date format for create date." . "\n"; + fwrite($output_fh, $message); + continue; + } + } + + $created_date = $date_create->format('Y-m-d H:i:s'); + + //error_log($str_date_time); + //error_log($str_timezone); + //error_log($str_datetime_tz); + //error_log($date_create->format('Y-m-d H:i:s')); + $meta_info = [ 'dispatch_status' => $dispatch_status, 'inventory_status' => $inventory_status, @@ -74,15 +120,13 @@ while (($row = fgetcsv($csv)) !== false) $info = json_encode($meta_info); - error_log('Processing ' . $serial . ' and ' . $sku); - if ($sku == 'N/A') $sku = null; $res = $sth->execute([ ':serial' => $serial, ':sku' => $sku, - ':date_create' => $date_create, + ':date_create' => $created_date, ':source' => $source, ':meta_info' => $info, ]); diff --git a/utils/warranty_motiv_local.sh b/utils/warranty_motiv_local.sh new file mode 100755 index 00000000..403c62c2 --- /dev/null +++ b/utils/warranty_motiv_local.sh @@ -0,0 +1,9 @@ +#!/bin/bash +#touch /tmp/warranty_download_serial.csv +proc_date=`date +%m-%d-%y -d "1 day ago"` +download_file="/tmp/warranty_download_serial_$proc_date.csv" +load_status_file="/tmp/warranty_load_status_$proc_date.txt" +echo $download_file +echo $load_status_file +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php $proc_date $download_file 1 +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file "mysql:host=localhost;dbname=resq;charset=UTF8" root password $load_status_file diff --git a/utils/warranty_motiv_local_bulk.sh b/utils/warranty_motiv_local_bulk.sh index 167e8566..5e1a0ab4 100755 --- a/utils/warranty_motiv_local_bulk.sh +++ b/utils/warranty_motiv_local_bulk.sh @@ -1,36 +1,40 @@ #!/bin/bash touch /tmp/warranty_download_serial.csv -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-03-2021 /tmp/warranty_download_serial.csv 1 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-04-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-05-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-06-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-07-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-08-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-09-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-10-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-11-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-12-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-13-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-14-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-15-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-16-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-17-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-18-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-19-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-20-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-21-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-22-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-23-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-24-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-25-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-26-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-27-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-28-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-29-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-30-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-31-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-01-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-02-2021 /tmp/warranty_download_serial.csv 0 -/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-03-2021 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-03-21 /tmp/warranty_download_serial.csv 1 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-04-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-05-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-06-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-07-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-08-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-09-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-10-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-11-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-12-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-13-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-14-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-15-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-16-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-17-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-18-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-19-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-20-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-21-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-22-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-23-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-24-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-25-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-26-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-27-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-28-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-29-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-30-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-31-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-01-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-02-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-03-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-04-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-05-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-06-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-07-21 /tmp/warranty_download_serial.csv 0 touch /tmp/warranty_load_status.txt /usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=localhost;dbname=resq;charset=UTF8" root password /tmp/warranty_load_status.txt diff --git a/utils/warranty_motiv_prod.sh b/utils/warranty_motiv_prod.sh index f13a7d7d..12d00761 100755 --- a/utils/warranty_motiv_prod.sh +++ b/utils/warranty_motiv_prod.sh @@ -1,4 +1,9 @@ #!/bin/bash -touch /tmp/warranty_download_serial.txt -/usr/bin/php /var/www/resq/utils/get_warranty_serial/get_serials.php -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.txt "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" resq Motolite456 +proc_date=`date +%m-%d-%y -d "1 day ago"` +download_file="/tmp/warranty_download_serial_$proc_date.csv" +load_status_file="/tmp/warranty_load_status_$proc_date.txt" +#echo $download_file +#echo $load_status_file +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php $proc_date $download_file 1 +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" resq Motolite456 $load_status_file + diff --git a/utils/warranty_motiv_prod_bulk.sh b/utils/warranty_motiv_prod_bulk.sh new file mode 100755 index 00000000..231f6bc2 --- /dev/null +++ b/utils/warranty_motiv_prod_bulk.sh @@ -0,0 +1,40 @@ +#!/bin/bash +touch /tmp/warranty_download_serial.csv +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-03-21 /tmp/warranty_download_serial.csv 1 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-04-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-05-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-06-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-07-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-08-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-09-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-10-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-11-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-12-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-13-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-14-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-15-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-16-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-17-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-18-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-19-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-20-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-21-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-22-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-23-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-24-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-25-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-26-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-27-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-28-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-29-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-30-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 05-31-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-01-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-02-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-03-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-04-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-05-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-06-21 /tmp/warranty_download_serial.csv 0 +/usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-07-21 /tmp/warranty_download_serial.csv 0 +touch /tmp/warranty_load_status.txt +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" resq Motolite456 /tmp/warranty_load_status.txt From 560db62a0817158551d526cdc1889d727a47541e Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 8 Jun 2021 09:32:15 +0000 Subject: [PATCH 04/31] Fix error checking. #576 --- utils/load_warranty_serial/load_serials.php | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/utils/load_warranty_serial/load_serials.php b/utils/load_warranty_serial/load_serials.php index 9df178bc..323f3156 100644 --- a/utils/load_warranty_serial/load_serials.php +++ b/utils/load_warranty_serial/load_serials.php @@ -9,7 +9,7 @@ $output_file = $argv[5]; $output_fh = fopen($output_file, "w"); -if (!file_exists($csv)) +if (!file_exists($argv[1])) { $err_message = "No csv input file found." . "\n"; fwrite($output_fh, $err_message); @@ -34,6 +34,7 @@ while (($row = fgetcsv($csv)) !== false) // (2) No available data // (3) CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF // (4) Empty line + // (5) empty sku // check if No available data if ($row[0] == 'No available data') @@ -43,25 +44,22 @@ while (($row = fgetcsv($csv)) !== false) continue; } - // check if new line - if (empty($row[0])) + // check if empty line + if ($row == array(null)) { // skip error_log('Skipping empty line...'); continue; } - // check if csv file has a header by checking contents of line - if (($row[0] == 'SerialNumber') || ($row[1] == 'Sku') || - ($row[2] == 'DispatchStatus') || ($row[3] == 'CreatedDate') || - ($row[4] == 'InventoryStatus') || ($row[5] == 'CategoryID') || - ($row[6] == 'CategoryName')) + // check if empty serial + if (empty($row[0])) { - // skip the header - error_log('Skipping the headers... '); + $err_message = "Empty serial. " . "\n"; + fwrite($output_fh, $err_message); continue; } - + // sample of line in output file: // serial number, sku, dispatch status, created date, inventory status, category id, category name // CH2000012071,WCHD23BL-CPN00-LX,0,2020-08-11 04:05:27.090,0,4,CHAMPION MF From 8fa3551d47890403f4ea451139d62c104b2b9351 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 8 Jun 2021 10:48:38 +0000 Subject: [PATCH 05/31] Remove cred as arguments. #576 --- .env.dist | 4 ++++ utils/load_warranty_serial/load_serials.php | 15 ++++++++++++--- utils/warranty_motiv_local.sh | 2 +- utils/warranty_motiv_local_bulk.sh | 2 +- utils/warranty_motiv_prod.sh | 2 +- utils/warranty_motiv_prod_bulk.sh | 2 +- 6 files changed, 20 insertions(+), 7 deletions(-) diff --git a/.env.dist b/.env.dist index f6d35eec..06731d8f 100644 --- a/.env.dist +++ b/.env.dist @@ -80,3 +80,7 @@ API_VERSION=insert_api_version_here #SSL_ENABLE for websockets SSL_ENABLE=set_to_true_or_false + +# db +DB_USER=db_username +DB_PASSWORD=db_password diff --git a/utils/load_warranty_serial/load_serials.php b/utils/load_warranty_serial/load_serials.php index 323f3156..d5369aac 100644 --- a/utils/load_warranty_serial/load_serials.php +++ b/utils/load_warranty_serial/load_serials.php @@ -1,11 +1,13 @@ loadEnv(__DIR__.'/../../.env'); + +$user = $_ENV['DB_USER']; +$pass = $_ENV['DB_PASSWORD']; + // connect to db $db = new PDO($dsn, $user, $pass); diff --git a/utils/warranty_motiv_local.sh b/utils/warranty_motiv_local.sh index 403c62c2..ddfcd6f5 100755 --- a/utils/warranty_motiv_local.sh +++ b/utils/warranty_motiv_local.sh @@ -6,4 +6,4 @@ load_status_file="/tmp/warranty_load_status_$proc_date.txt" echo $download_file echo $load_status_file /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php $proc_date $download_file 1 -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file "mysql:host=localhost;dbname=resq;charset=UTF8" root password $load_status_file +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file "mysql:host=localhost;dbname=resq;charset=UTF8" $load_status_file diff --git a/utils/warranty_motiv_local_bulk.sh b/utils/warranty_motiv_local_bulk.sh index 5e1a0ab4..14a5e636 100755 --- a/utils/warranty_motiv_local_bulk.sh +++ b/utils/warranty_motiv_local_bulk.sh @@ -37,4 +37,4 @@ touch /tmp/warranty_download_serial.csv /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-06-21 /tmp/warranty_download_serial.csv 0 /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-07-21 /tmp/warranty_download_serial.csv 0 touch /tmp/warranty_load_status.txt -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=localhost;dbname=resq;charset=UTF8" root password /tmp/warranty_load_status.txt +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=localhost;dbname=resq;charset=UTF8" /tmp/warranty_load_status.txt diff --git a/utils/warranty_motiv_prod.sh b/utils/warranty_motiv_prod.sh index 12d00761..798158ef 100755 --- a/utils/warranty_motiv_prod.sh +++ b/utils/warranty_motiv_prod.sh @@ -5,5 +5,5 @@ load_status_file="/tmp/warranty_load_status_$proc_date.txt" #echo $download_file #echo $load_status_file /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php $proc_date $download_file 1 -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" resq Motolite456 $load_status_file +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" $load_status_file diff --git a/utils/warranty_motiv_prod_bulk.sh b/utils/warranty_motiv_prod_bulk.sh index 231f6bc2..446e68f1 100755 --- a/utils/warranty_motiv_prod_bulk.sh +++ b/utils/warranty_motiv_prod_bulk.sh @@ -37,4 +37,4 @@ touch /tmp/warranty_download_serial.csv /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-06-21 /tmp/warranty_download_serial.csv 0 /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-07-21 /tmp/warranty_download_serial.csv 0 touch /tmp/warranty_load_status.txt -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" resq Motolite456 /tmp/warranty_load_status.txt +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" /tmp/warranty_load_status.txt From 4b76e1e0d144dd372b387a55a4412fa1c5b4fe93 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 8 Jun 2021 10:48:57 +0000 Subject: [PATCH 06/31] Remove cred as arguments. #576 --- utils/warranty_motiv_dev.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/utils/warranty_motiv_dev.sh b/utils/warranty_motiv_dev.sh index 00c73418..95f687d6 100755 --- a/utils/warranty_motiv_dev.sh +++ b/utils/warranty_motiv_dev.sh @@ -1,4 +1,4 @@ #!/bin/bash touch /tmp/warranty_download_serial.txt -/usr/bin/php /usr/share/nginx/html/resqapi/utils/get_warranty_serial/get_serials.php -/usr/bin/php /usr/share/nginx/html/resqapi/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.txt "mysql:host=localhost;dbname=resq;charset=UTF8" resq Motolite456 +/usr/bin/php /usr/share/nginx/html/resqapi/utils/get_warranty_serial/get_serials.php `date +%m-%d-%Y` +/usr/bin/php /usr/share/nginx/html/resqapi/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.txt "mysql:host=localhost;dbname=resq;charset=UTF8" From 3df1989f68db40df90ee9e3b9675a1225312d9d5 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 9 Jun 2021 08:16:27 +0000 Subject: [PATCH 07/31] Remove the database information as an argument. #576 --- utils/load_warranty_serial/load_serials.php | 24 ++++++++++++++++++--- utils/warranty_motiv_local.sh | 2 +- utils/warranty_motiv_local_bulk.sh | 2 +- utils/warranty_motiv_prod.sh | 2 +- utils/warranty_motiv_prod_bulk.sh | 2 +- 5 files changed, 25 insertions(+), 7 deletions(-) diff --git a/utils/load_warranty_serial/load_serials.php b/utils/load_warranty_serial/load_serials.php index d5369aac..b0c3081e 100644 --- a/utils/load_warranty_serial/load_serials.php +++ b/utils/load_warranty_serial/load_serials.php @@ -4,10 +4,11 @@ require_once(__DIR__ . '/../../vendor/autoload.php'); use Symfony\Component\Dotenv\Dotenv; +// TODO: this whole thing needs to be refactored + // load csv $csv = fopen($argv[1], 'r'); -$dsn = $argv[2]; -$output_file = $argv[3]; +$output_file = $argv[2]; $output_fh = fopen($output_file, "w"); @@ -25,6 +26,24 @@ $dotenv->loadEnv(__DIR__.'/../../.env'); $user = $_ENV['DB_USER']; $pass = $_ENV['DB_PASSWORD']; +$db_info = $_ENV['DATABASE_URL']; + +// sample format of db_info: mysql://db_user:db_password@127.0.0.1:3306/resq +// dsn for PDO needs to be: mysql:host=127.0.0.1:3306;dbname=resq;charset=UTF8 + +$result = preg_split("/[\/:@]/", $db_info); +$db_type = 'mysql:host='; +$user = $result[3]; +$pass = $result[4]; +$ip_port = $result[5] . ':' . $result[6] . ';'; +$db_name = 'dbname=' . $result[7] . ';'; +$charset = 'charset=UTF8'; + +$dsn = $db_type . $ip_port . $db_name . $charset; + +//error_log($dsn); +//error_log($user); +//error_log($pass); // connect to db $db = new PDO($dsn, $user, $pass); @@ -157,4 +176,3 @@ while (($row = fgetcsv($csv)) !== false) fclose($csv); fclose($output_fh); - diff --git a/utils/warranty_motiv_local.sh b/utils/warranty_motiv_local.sh index ddfcd6f5..e99c7f64 100755 --- a/utils/warranty_motiv_local.sh +++ b/utils/warranty_motiv_local.sh @@ -6,4 +6,4 @@ load_status_file="/tmp/warranty_load_status_$proc_date.txt" echo $download_file echo $load_status_file /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php $proc_date $download_file 1 -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file "mysql:host=localhost;dbname=resq;charset=UTF8" $load_status_file +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file $load_status_file diff --git a/utils/warranty_motiv_local_bulk.sh b/utils/warranty_motiv_local_bulk.sh index 14a5e636..c4f2a551 100755 --- a/utils/warranty_motiv_local_bulk.sh +++ b/utils/warranty_motiv_local_bulk.sh @@ -37,4 +37,4 @@ touch /tmp/warranty_download_serial.csv /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-06-21 /tmp/warranty_download_serial.csv 0 /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-07-21 /tmp/warranty_download_serial.csv 0 touch /tmp/warranty_load_status.txt -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=localhost;dbname=resq;charset=UTF8" /tmp/warranty_load_status.txt +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv /tmp/warranty_load_status.txt diff --git a/utils/warranty_motiv_prod.sh b/utils/warranty_motiv_prod.sh index 798158ef..124f6e96 100755 --- a/utils/warranty_motiv_prod.sh +++ b/utils/warranty_motiv_prod.sh @@ -5,5 +5,5 @@ load_status_file="/tmp/warranty_load_status_$proc_date.txt" #echo $download_file #echo $load_status_file /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php $proc_date $download_file 1 -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" $load_status_file +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php $download_file $load_status_file diff --git a/utils/warranty_motiv_prod_bulk.sh b/utils/warranty_motiv_prod_bulk.sh index 446e68f1..c4f2a551 100755 --- a/utils/warranty_motiv_prod_bulk.sh +++ b/utils/warranty_motiv_prod_bulk.sh @@ -37,4 +37,4 @@ touch /tmp/warranty_download_serial.csv /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-06-21 /tmp/warranty_download_serial.csv 0 /usr/bin/php /var/www/resq/utils/get_warranty_serial/new_get_serials.php 06-07-21 /tmp/warranty_download_serial.csv 0 touch /tmp/warranty_load_status.txt -/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv "mysql:host=172.18.203.191:3306;dbname=resq;charset=UTF8" /tmp/warranty_load_status.txt +/usr/bin/php /var/www/resq/utils/load_warranty_serial/load_serials.php /tmp/warranty_download_serial.csv /tmp/warranty_load_status.txt From bd0b24b0344f1aa415b8407eacff386c651a8437 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 9 Jun 2021 08:46:18 +0000 Subject: [PATCH 08/31] Fix splitting of database info. #576 --- utils/load_warranty_serial/load_serials.php | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/utils/load_warranty_serial/load_serials.php b/utils/load_warranty_serial/load_serials.php index b0c3081e..812b151c 100644 --- a/utils/load_warranty_serial/load_serials.php +++ b/utils/load_warranty_serial/load_serials.php @@ -24,19 +24,18 @@ if (!file_exists($argv[1])) $dotenv = new Dotenv(); $dotenv->loadEnv(__DIR__.'/../../.env'); -$user = $_ENV['DB_USER']; -$pass = $_ENV['DB_PASSWORD']; $db_info = $_ENV['DATABASE_URL']; // sample format of db_info: mysql://db_user:db_password@127.0.0.1:3306/resq // dsn for PDO needs to be: mysql:host=127.0.0.1:3306;dbname=resq;charset=UTF8 -$result = preg_split("/[\/:@]/", $db_info); +preg_match('/^mysql:\/\/(.*):(.*)@(.*):(.*)\/(.*)/', $db_info, $result); + $db_type = 'mysql:host='; -$user = $result[3]; -$pass = $result[4]; -$ip_port = $result[5] . ':' . $result[6] . ';'; -$db_name = 'dbname=' . $result[7] . ';'; +$user = $result[1]; +$pass = $result[2]; +$ip_port = $result[3] . ':' . $result[4] . ';'; +$db_name = 'dbname=' . $result[5] . ';'; $charset = 'charset=UTF8'; $dsn = $db_type . $ip_port . $db_name . $charset; From 4351d1242ee632111c8534ac17e775215c4aeb88 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Wed, 9 Jun 2021 10:19:22 +0000 Subject: [PATCH 09/31] Fix splitting of db info. #576 --- utils/load_warranty_serial/load_serials.php | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/utils/load_warranty_serial/load_serials.php b/utils/load_warranty_serial/load_serials.php index 812b151c..c2bb5671 100644 --- a/utils/load_warranty_serial/load_serials.php +++ b/utils/load_warranty_serial/load_serials.php @@ -26,17 +26,17 @@ $dotenv->loadEnv(__DIR__.'/../../.env'); $db_info = $_ENV['DATABASE_URL']; -// sample format of db_info: mysql://db_user:db_password@127.0.0.1:3306/resq +// sample format of db_info: mysql://db_user:db_password@127.0.0.1:3306/resq?charset=utf8 // dsn for PDO needs to be: mysql:host=127.0.0.1:3306;dbname=resq;charset=UTF8 -preg_match('/^mysql:\/\/(.*):(.*)@(.*):(.*)\/(.*)/', $db_info, $result); +preg_match('/^mysql:\/\/(.*):(.*)@(.*):(.*)\/(.*)\?(.*)/', $db_info, $result); $db_type = 'mysql:host='; $user = $result[1]; $pass = $result[2]; $ip_port = $result[3] . ':' . $result[4] . ';'; $db_name = 'dbname=' . $result[5] . ';'; -$charset = 'charset=UTF8'; +$charset = $result[6]; $dsn = $db_type . $ip_port . $db_name . $charset; From 31f43aea39bd3f796c65461e09ee6ad65b9f3c30 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 10 Jun 2021 04:11:27 +0000 Subject: [PATCH 10/31] Add warranty source to Warranty and when creating warranty. #579 --- .../GenerateWarrantyFromJobOrderCommand.php | 5 +++-- src/Controller/APIController.php | 3 +++ .../CAPI/CustomerWarrantyController.php | 3 +++ src/Controller/CAPI/WarrantyController.php | 6 ++++-- src/Controller/WarrantyController.php | 3 ++- src/Entity/Warranty.php | 18 ++++++++++++++++++ src/Service/WarrantyHandler.php | 3 ++- 7 files changed, 35 insertions(+), 6 deletions(-) diff --git a/src/Command/GenerateWarrantyFromJobOrderCommand.php b/src/Command/GenerateWarrantyFromJobOrderCommand.php index 1e8e391a..381823d8 100644 --- a/src/Command/GenerateWarrantyFromJobOrderCommand.php +++ b/src/Command/GenerateWarrantyFromJobOrderCommand.php @@ -210,9 +210,10 @@ class GenerateWarrantyFromJobOrderCommand extends Command $values = '(' . $bty_model_id . ',' . $bty_size_id . ',NULL,\'' . $warranty_class . '\',\'' . $cleaned_plate_number . '\',\'' . WarrantyStatus::ACTIVE . '\',\'' . $date_create . '\',\'' . $date_purchase . '\',\'' . $date_expire . '\',NULL,' - . $sap_code . ',NULL,\'' . $first_name . '\',\'' . $last_name . '\',\'' . $mobile_number . '\',' . 0 . ',NULL' . ');'; + . $sap_code . ',NULL,\'' . $first_name . '\',\'' . $last_name . '\',\'' . $mobile_number . '\',' . 0 . ',NULL,\'' + . WarrantySource::COMMAND .'\');'; - $sql_statement = 'INSERT INTO `warranty` (bty_model_id,bty_size_id,serial,warranty_class,plate_number,status,date_create,date_purchase,date_expire,date_claim,sap_bty_id,claim_id,first_name,last_name,mobile_number,flag_activated,warranty_privacy_policy) VALUES ' . $values . "\n"; + $sql_statement = 'INSERT INTO `warranty` (bty_model_id,bty_size_id,serial,warranty_class,plate_number,status,date_create,date_purchase,date_expire,date_claim,sap_bty_id,claim_id,first_name,last_name,mobile_number,flag_activated,warranty_privacy_policy,create_source) VALUES ' . $values . "\n"; echo $sql_statement; diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 6c275ead..a1623a09 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -3151,6 +3151,9 @@ class APIController extends Controller implements LoggedController { $warr = new Warranty(); $sms_msg = $trans->trans('warranty_register_confirm'); + + // set warranty source + $warr->setCreateSource($source); } // get sap battery diff --git a/src/Controller/CAPI/CustomerWarrantyController.php b/src/Controller/CAPI/CustomerWarrantyController.php index e0c74f22..1b306cf6 100644 --- a/src/Controller/CAPI/CustomerWarrantyController.php +++ b/src/Controller/CAPI/CustomerWarrantyController.php @@ -425,6 +425,9 @@ class CustomerWarrantyController extends APIController { $warr = new Warranty(); $sms_message = $trans->trans('warranty_register_confirm'); + + // set warranty's create source + $warr->setCreateSource($source); } error_log('sap battery check'); diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index 72eb1785..f5386d55 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -275,7 +275,8 @@ class WarrantyController extends APIController ->setSAPBattery($batt) ->setDatePurchase($date_pur) ->setDateClaim(null) - ->setDateExpire($date_expire); + ->setDateExpire($date_expire) + ->setCreateSource($source); try { @@ -370,7 +371,8 @@ class WarrantyController extends APIController ->setDatePurchase($warr->getDatePurchase()) ->setDateClaim(null) ->setDateExpire($warr->getDateExpire()) - ->setClaimedFrom($warr); + ->setClaimedFrom($warr) + ->setCreateSource($source); $em->persist($new_warr); diff --git a/src/Controller/WarrantyController.php b/src/Controller/WarrantyController.php index d7ab6eb7..af75e3b2 100644 --- a/src/Controller/WarrantyController.php +++ b/src/Controller/WarrantyController.php @@ -176,7 +176,8 @@ class WarrantyController extends Controller ->setMobileNumber($req->request->get('mobile_number')) ->setDatePurchase($date_purchase) ->setClaimedFrom($req->request->get('claim_from')) - ->setStatus($req->request->get('status')); + ->setStatus($req->request->get('status')) + ->setCreateSource(WarrantySource::ADMIN_PANEL); if ($date_claim) { diff --git a/src/Entity/Warranty.php b/src/Entity/Warranty.php index a814856b..5d45e806 100644 --- a/src/Entity/Warranty.php +++ b/src/Entity/Warranty.php @@ -232,6 +232,11 @@ class Warranty */ protected $municipality_id; + /** + * @ORM\Column(type="string", length=80, options={"default": "legacy"}) + */ + protected $create_source; + public function __construct() { $this->date_create = new DateTime(); @@ -242,6 +247,7 @@ class Warranty $this->email = ''; $this->odometer = 0; $this->flag_validated = false; + $this->create_source = 'unknown'; } public function getID() @@ -658,4 +664,16 @@ class Warranty { return $this->municipality_id; } + + public function setCreateSource($source) + { + $this->create_source = $source; + return $this; + } + + public function getCreateSource() + { + return $this->create_source; + } + } diff --git a/src/Service/WarrantyHandler.php b/src/Service/WarrantyHandler.php index aadb8eac..8d84e8f6 100644 --- a/src/Service/WarrantyHandler.php +++ b/src/Service/WarrantyHandler.php @@ -93,7 +93,8 @@ class WarrantyHandler ->setLastName($last_name) ->setMobileNumber($mobile_number) ->setDatePurchase($date_purchase) - ->setWarrantyClass($warranty_class); + ->setWarrantyClass($warranty_class) + ->setCreateSource($source); $this->em->persist($warranty); $this->em->flush(); From 3937b73454f3a72a2e96b86c029eb34a209c7850 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 10 Jun 2021 07:20:02 +0000 Subject: [PATCH 11/31] Add api user name to create source for warranty and warranty_api_log. #579 --- .../CAPI/CustomerWarrantyController.php | 19 ++++++++++++- src/Controller/CAPI/WarrantyController.php | 28 +++++++++++++++++-- src/Ramcar/WarrantySource.php | 2 ++ 3 files changed, 46 insertions(+), 3 deletions(-) diff --git a/src/Controller/CAPI/CustomerWarrantyController.php b/src/Controller/CAPI/CustomerWarrantyController.php index 1b306cf6..3a7c699a 100644 --- a/src/Controller/CAPI/CustomerWarrantyController.php +++ b/src/Controller/CAPI/CustomerWarrantyController.php @@ -2,6 +2,8 @@ namespace App\Controller\CAPI; +use Catalyst\APIBundle\Entity\User as APIUser; + use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\KernelInterface; @@ -315,7 +317,11 @@ class CustomerWarrantyController extends APIController 'invoice' => $req->request->get('invoice'), ]; $action = 'create/update'; - $source = WarrantySource::CAPI; + + // get the api_user that made the call so that it gets added to the source + // source becomes CAPI_USER_ + $username = $this->getAPIUsername($em, $user_id); + $source = 'CAPI_USER_' . $username; error_log('SOURCE: ' . $source); @@ -582,4 +588,15 @@ class CustomerWarrantyController extends APIController $rt->sendSMS($clean_num, 'MOTOLITE', $message); } + protected function getAPIUsername($em, $user_id) + { + $api_user_result = $em->getRepository(APIUser::class)->findBy(['api_key' => $user_id]); + $username = ''; + foreach ($api_user_result as $api_user) + { + $username = $api_user->getName(); + } + + return $username; + } } diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index f5386d55..2dc0d837 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -2,6 +2,8 @@ namespace App\Controller\CAPI; +use Catalyst\APIBundle\Entity\User as APIUser; + use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Doctrine\ORM\Query; @@ -191,7 +193,12 @@ class WarrantyController extends APIController 'mobile_number' => $mnum, ]; $action = 'create'; - $source = WarrantySource::CAPI; + + // get the api_user that made the call so that it gets added to the source + // source becomes CAPI_USER_ + $username = $this->getAPIUsername($em, $user_id); + + $source = 'CAPI_USER_' . $username; $msg = $this->checkRequiredParameters($req, $params); error_log('msg - ' . $msg); @@ -322,7 +329,12 @@ class WarrantyController extends APIController 'id' => $id, ]; $action = 'claim'; - $source = WarrantySource::CAPI; + + // get the api_user that made the call so that it gets added to the source + // source becomes CAPI_USER_ + $username = $this->getAPIUsername($em, $user_id); + $source = 'CAPI_USER_' . $username; + $msg = $this->checkRequiredParameters($req, $params); if ($msg) @@ -777,4 +789,16 @@ class WarrantyController extends APIController return $customers; } + protected function getAPIUsername($em, $user_id) + { + $api_user_result = $em->getRepository(APIUser::class)->findBy(['api_key' => $user_id]); + $username = ''; + foreach ($api_user_result as $api_user) + { + $username = $api_user->getName(); + } + + return $username; + } + } diff --git a/src/Ramcar/WarrantySource.php b/src/Ramcar/WarrantySource.php index 3c16ee89..be9c47e1 100644 --- a/src/Ramcar/WarrantySource.php +++ b/src/Ramcar/WarrantySource.php @@ -10,6 +10,7 @@ class WarrantySource extends NameValue const BULK_UPLOAD = 'bulk_upload'; const MOBILE = 'mobile'; const COMMAND = 'command'; + const UNKNOWN = 'unknown'; const COLLECTION = [ 'capi' => 'Third Party API', @@ -18,6 +19,7 @@ class WarrantySource extends NameValue 'bulk_upload' => 'Bulk Upload', 'mobile' => 'Mobile API', 'command' => 'Command', + 'unknown' => 'Unknown', ]; } From 009d3d326706785429c503b899cc09119ac7e3d9 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 10 Jun 2021 08:07:27 +0000 Subject: [PATCH 12/31] Change retrieval of API username. #579 --- .../CAPI/CustomerWarrantyController.php | 16 +--------------- src/Controller/CAPI/WarrantyController.php | 17 +---------------- 2 files changed, 2 insertions(+), 31 deletions(-) diff --git a/src/Controller/CAPI/CustomerWarrantyController.php b/src/Controller/CAPI/CustomerWarrantyController.php index 3a7c699a..6e183cc0 100644 --- a/src/Controller/CAPI/CustomerWarrantyController.php +++ b/src/Controller/CAPI/CustomerWarrantyController.php @@ -2,8 +2,6 @@ namespace App\Controller\CAPI; -use Catalyst\APIBundle\Entity\User as APIUser; - use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Symfony\Component\HttpKernel\KernelInterface; @@ -320,7 +318,7 @@ class CustomerWarrantyController extends APIController // get the api_user that made the call so that it gets added to the source // source becomes CAPI_USER_ - $username = $this->getAPIUsername($em, $user_id); + $username = $this->getUser()->getName(); $source = 'CAPI_USER_' . $username; error_log('SOURCE: ' . $source); @@ -587,16 +585,4 @@ class CustomerWarrantyController extends APIController $rt->sendSMS($clean_num, 'MOTOLITE', $message); } - - protected function getAPIUsername($em, $user_id) - { - $api_user_result = $em->getRepository(APIUser::class)->findBy(['api_key' => $user_id]); - $username = ''; - foreach ($api_user_result as $api_user) - { - $username = $api_user->getName(); - } - - return $username; - } } diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index 2dc0d837..c0cd8aa8 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -2,8 +2,6 @@ namespace App\Controller\CAPI; -use Catalyst\APIBundle\Entity\User as APIUser; - use Symfony\Bundle\FrameworkBundle\Controller\Controller; use Symfony\Component\HttpFoundation\Request; use Doctrine\ORM\Query; @@ -196,7 +194,7 @@ class WarrantyController extends APIController // get the api_user that made the call so that it gets added to the source // source becomes CAPI_USER_ - $username = $this->getAPIUsername($em, $user_id); + $username = $this->getUser()->getName(); $source = 'CAPI_USER_' . $username; @@ -788,17 +786,4 @@ class WarrantyController extends APIController $customers = $em->getRepository(Customer::class)->findBy(['phone_mobile' => $number]); return $customers; } - - protected function getAPIUsername($em, $user_id) - { - $api_user_result = $em->getRepository(APIUser::class)->findBy(['api_key' => $user_id]); - $username = ''; - foreach ($api_user_result as $api_user) - { - $username = $api_user->getName(); - } - - return $username; - } - } From 8648f6f3f1a6b3a56b506b5473ba2d5fea4877b5 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 10 Jun 2021 10:21:20 +0000 Subject: [PATCH 13/31] Add dealer entity and PHP script to add dealers. #580 --- src/Entity/Dealer.php | 81 +++++++++++++++++++++ utils/load_dealers/load_dealers.php | 106 ++++++++++++++++++++++++++++ 2 files changed, 187 insertions(+) create mode 100644 src/Entity/Dealer.php create mode 100644 utils/load_dealers/load_dealers.php diff --git a/src/Entity/Dealer.php b/src/Entity/Dealer.php new file mode 100644 index 00000000..b60fe20c --- /dev/null +++ b/src/Entity/Dealer.php @@ -0,0 +1,81 @@ +id; + } + + public function setName($name) + { + $this->name = $name; + return $this; + } + + public function getName() + { + return $this->name; + } + + public function setAddress($address) + { + $this->address = $address; + return $this; + } + + public function getAddress() + { + return $this->address; + } + + public function setBranchCode($branch_code) + { + $this->branch_code = $branch_code; + return $this; + } + + public function getBranchCode() + { + return $this->branch_code; + } +} diff --git a/utils/load_dealers/load_dealers.php b/utils/load_dealers/load_dealers.php new file mode 100644 index 00000000..efcc2eb5 --- /dev/null +++ b/utils/load_dealers/load_dealers.php @@ -0,0 +1,106 @@ +loadEnv(__DIR__.'/../../.env'); + + $db_info = $_ENV['DATABASE_URL']; + + // sample format of db_info: mysql://db_user:db_password@127.0.0.1:3306/resq?charset=utf8 + // dsn for PDO needs to be: mysql:host=127.0.0.1:3306;dbname=resq;charset=UTF8 + + preg_match('/^mysql:\/\/(.*):(.*)@(.*):(.*)\/(.*)\?(.*)/', $db_info, $result); + + $db_type = 'mysql:host='; + $user = $result[1]; + $pass = $result[2]; + $ip_port = $result[3] . ':' . $result[4] . ';'; + $db_name = 'dbname=' . $result[5] . ';'; + $charset = $result[6]; + + $dsn = $db_type . $ip_port . $db_name . $charset; + + $db_data = array($dsn, $user, $pass); + + return $db_data; +} + +// load csv +$csv = fopen($argv[1], 'r'); +$output_file = $argv[2]; + +$output_fh = fopen($output_file, "w"); + +if (!file_exists($argv[1])) +{ + $err_message = "No csv input file found." . "\n"; + fwrite($output_fh, $err_message); + fclose($output_fh); + exit(); +} + +list($dsn, $user, $pass) = getDatabaseInfo(); + +// error_log($dsn); +// error_log($user); +// error_log($pass); + +// connect to db +$db = new PDO($dsn, $user, $pass); + +// prepared statement +$sth = $db->prepare('insert into dealer (name, address, branch_code) values (:name, :address, :branch_code)'); + +$rownum = 0; +while (($row = fgetcsv($csv)) !== false) +{ + // dealer csv file has a header + if ($rownum < 1) + { + // skip header + $rownum++; + continue; + } + + // sample of line in csv file + // columns are name, address, branch code + // BATPARTS Marcos Branch,"Km. 16 Marcos Hi-way corner Mahogany Street, Santolan, Pasig",ZN03576282 + $dealer_name = trim(strtoupper($row[0])); + $dealer_address = trim(strtoupper($row[1])); + $dealer_branch_code = trim(strtoupper($row[2])); + + // error_log('name ' . $dealer_name . ' address ' . $dealer_address . ' branch code ' . $dealer_branch_code); + error_log('Processing ' . $dealer_name); + + $res = $sth->execute([ + ':name' => $dealer_name, + ':address' => $dealer_address, + ':branch_code' => $dealer_branch_code, + ]); + + if (!$res) + { + // log error + $err = $sth->errorInfo(); + $log_message = "$dealer_name - ERROR - " . $err[2] . "\n"; + } + else + { + // log successful adding of dealer + $log_message = "$dealer_name - SUCCESS - " . "\n"; + } + fwrite($output_fh, $log_message); + + $rownum++; +} + +// close file +fclose($csv); +fclose($output_fh); +?> From 0fb09f2e6dd705b546d03633f93fdd468d88fc1f Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Fri, 11 Jun 2021 00:53:02 +0800 Subject: [PATCH 14/31] Add recommended extra battery inventory feature #582 --- src/Controller/AnalyticsController.php | 69 ++++++++++++++++++- templates/analytics/forecast_submit.html.twig | 4 ++ 2 files changed, 71 insertions(+), 2 deletions(-) diff --git a/src/Controller/AnalyticsController.php b/src/Controller/AnalyticsController.php index d18b10bb..308ef2e6 100644 --- a/src/Controller/AnalyticsController.php +++ b/src/Controller/AnalyticsController.php @@ -21,6 +21,7 @@ use DateInterval; use App\Entity\JobOrder; use App\Entity\Hub; +use App\Entity\Battery; use App\Ramcar\ShiftSchedule; @@ -125,7 +126,7 @@ class AnalyticsController extends Controller // TODO: populate the hour_shift array, depending on the shift selected $hour_shifts = $this->populateHourShift($shift); - error_log(print_r($hour_shifts, true)); + // error_log(print_r($hour_shifts, true)); // error_log(print_r($hub_list, true)); // $hub_list = [ 6, 4, 36, 7, 8, 126, 127, 18, 12, 9, 60, 10, 21, 135 ]; @@ -195,7 +196,7 @@ class AnalyticsController extends Controller // error_log(print_r($chart_all_weekdays, true)); - error_log(print_r($sched_res, true)); + // error_log(print_r($sched_res, true)); // agggregate weekday data $i = 0; @@ -367,6 +368,22 @@ class AnalyticsController extends Controller // get job order data (job orders within coverage area) $jos = $this->generateJobOrderData($conn, $hub, $distance_limit, $date_start, $date_end, $time_start, $time_end); + // get most bought battery from these JOs + $batt_id = $this->getHubBattery($conn, $jos); + $batt = $em->getRepository(Battery::class)->find($batt_id); + if ($batt == null) + $batt_data = [ + 'mfg' => 'None', + 'model' => 'None', + 'size' => 'None', + ]; + else + $batt_data = [ + 'mfg' => $batt->getManufacturer()->getName(), + 'model' => $batt->getModel()->getName(), + 'size' => $batt->getSize()->getName(), + ]; + // initialize counters $c_weekday = []; $c_day = []; @@ -433,12 +450,57 @@ class AnalyticsController extends Controller 'data_year' => $chart_year, // 'data_weekday' => $chart_weekday, 'c_weekday' => $c_weekday, // sending raw weekday data because we need to process overlaps + 'battery' => $batt_data, // TODO: refactor this pls ]; return $params; } + protected function getHubBattery($conn, $jos) + { + // collect ids + $ids = []; + foreach ($jos as $jo) + { + $ids[] = $jo['id']; + } + + // ideally we encode the ids, but right now we're assuming they'll be int + $in_text = implode(',', $ids); + + // get all the batteries ordered in these JOs + $sql = 'select battery_id, count(*) as total from invoice i,invoice_item item where i.id = item.invoice_id and i.job_order_id in (' . $in_text . ') group by battery_id'; + + $stmt = $conn->prepare($sql); + + $stmt->execute(); + $batteries = $stmt->fetchAll(); + + // error_log(print_r($batteries, true)); + + + // get the most ordered, skipping the null battery + $best_batt_id = 0; + $best_batt_count = 0; + foreach ($batteries as $batt) + { + if ($batt['battery_id'] == null) + continue; + + // if current battery is better than our best + if ($best_batt_count < $batt['total']) + { + $best_batt_id = $batt['battery_id']; + $best_batt_count = $batt['total']; + } + } + + error_log('BEST - ' . $best_batt_id . ' - ' . $best_batt_count); + + return $best_batt_id; + } + protected function generateJobOrderData($conn, $hub, $distance_limit, DateTime $date_start, DateTime $date_end, $time_start, $time_end) { $hub_coord = $hub->getCoordinates(); @@ -471,7 +533,10 @@ class AnalyticsController extends Controller $stmt->execute(); $jos = $stmt->fetchAll(); + /* error_log(count($jos)); + error_log(print_r($jos, true)); + */ return $jos; } diff --git a/templates/analytics/forecast_submit.html.twig b/templates/analytics/forecast_submit.html.twig index e9370e76..14fb5197 100644 --- a/templates/analytics/forecast_submit.html.twig +++ b/templates/analytics/forecast_submit.html.twig @@ -98,6 +98,10 @@
+
+ Recommended Extra Battery Inventory - {{ hub.battery.mfg }} - {{ hub.battery.model }} - {{ hub.battery.size }} +
+ From e3e949d42abf0e453a270b7b2dfe86098661b608 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 11 Jun 2021 05:54:33 +0000 Subject: [PATCH 15/31] Add CAPI call to get dealers. #581 --- config/api_acl.yaml | 5 +++ config/routes/capi.yaml | 6 +++ src/Controller/CAPI/DealerController.php | 52 ++++++++++++++++++++++++ 3 files changed, 63 insertions(+) create mode 100644 src/Controller/CAPI/DealerController.php diff --git a/config/api_acl.yaml b/config/api_acl.yaml index ab15187a..2e5bbdd3 100644 --- a/config/api_acl.yaml +++ b/config/api_acl.yaml @@ -62,3 +62,8 @@ access_keys: acls: - id: municipality.list label: List + - id: dealer + label: Dealer + acls: + - id: dealer.list + label: List diff --git a/config/routes/capi.yaml b/config/routes/capi.yaml index 5db14285..40e7b975 100644 --- a/config/routes/capi.yaml +++ b/config/routes/capi.yaml @@ -172,3 +172,9 @@ capi_municipality_list: path: /capi/municipality controller: App\Controller\CAPI\MunicipalityController::getAll methods: [GET] + +# dealer +capi_dealer_list: + path: /capi/dealers + controller: App\Controller\CAPI\DealerController::getAll + methods: [GET] diff --git a/src/Controller/CAPI/DealerController.php b/src/Controller/CAPI/DealerController.php new file mode 100644 index 00000000..f4f86d98 --- /dev/null +++ b/src/Controller/CAPI/DealerController.php @@ -0,0 +1,52 @@ +acl_gen = $acl_gen; + } + + public function getAll(EntityManagerInterface $em) + { + // get all dealer data order by dealer name + $this->denyAccessUnlessGranted('dealer.list', null, 'No access.'); + + $results = $em->getRepository(Dealer::class)->findBy([], ['name' => 'ASC']); + + $dealers = []; + foreach($results as $res) + { + $dealer_id = $res->getId(); + $dealer_name = $res->getName(); + $dealer_address = $res->getAddress(); + $dealer_branch_code = $res->getBranchCode(); + + $dealers[$dealer_id] = [ + 'name' => $dealer_name, + 'address' => $dealer_address, + 'branch_code' => $dealer_branch_code, + ]; + } + + $data = [ + 'dealers' => $dealers, + ]; + return new APIResponse(true, 'Dealers loaded.', $data); + } +} From 70fdfb12728c6439dc2a78e69dfbcf654a8f010c Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 11 Jun 2021 06:45:09 +0000 Subject: [PATCH 16/31] Update command with new template. #583 --- .../ImportCarClubCustomerDataCommand.php | 93 ++----------------- 1 file changed, 7 insertions(+), 86 deletions(-) diff --git a/src/Command/ImportCarClubCustomerDataCommand.php b/src/Command/ImportCarClubCustomerDataCommand.php index 49ef7679..5ae3b167 100644 --- a/src/Command/ImportCarClubCustomerDataCommand.php +++ b/src/Command/ImportCarClubCustomerDataCommand.php @@ -18,28 +18,11 @@ use App\Entity\CustomerTag; class ImportCarClubCustomerDataCommand extends Command { // field index in csv file - const F_TIMESTAMP = 0; - const F_DPA = 1; - const F_FIRST_NAME = 2; - const F_MIDDLE_NAME = 3; - const F_LAST_NAME = 4; - const F_BIRTHDATE = 5; - const F_ADDRESS = 6; - const F_CITY = 7; - const F_REGION = 8; - const F_CAR_CLUB = 9; - const F_POSITION = 10; - const F_MEMBER_NUM = 11; - const F_VEHICLE = 12; - const F_VEHICLE_EXCEL = 13; - const F_BATT_SIZE = 14; - const F_REPLACE_SKED = 15; - const F_DEALER_VISIT = 16; - const F_CONTACT_NUM = 17; - const F_BWI_LOCATION = 18; - const F_SAP_CODE = 19; - const F_SKU = 20; - const F_QTY = 21; + const F_DPA = 0; + const F_FIRST_NAME = 1; + const F_LAST_NAME = 2; + const F_CAR_CLUB = 3; + const F_CONTACT_NUM = 4; protected $em; protected $cust_tag_hash; @@ -145,54 +128,20 @@ class ImportCarClubCustomerDataCommand extends Command protected function setOutputInfo($fields, $status, $reason, $cust_id) { - $timestamp = trim($fields[self::F_TIMESTAMP]); - $mname = trim($fields[self::F_MIDDLE_NAME]); - $birthdate = trim($fields[self::F_BIRTHDATE]); - $address = trim($fields[self::F_ADDRESS]); - $city = trim($fields[self::F_CITY]); - $region = trim($fields[self::F_REGION]); $car_club = trim($fields[self::F_CAR_CLUB]); - $position = trim($fields[self::F_POSITION]); - $member_number = trim($fields[self::F_MEMBER_NUM]); - $vehicle = trim($fields[self::F_VEHICLE]); - $vehicle_excel = trim($fields[self::F_VEHICLE_EXCEL]); - $batt_size = trim($fields[self::F_BATT_SIZE]); - $replace_sked = trim($fields[self::F_REPLACE_SKED]); - $dealer_visit = trim($fields[self::F_DEALER_VISIT]); - $bwi_location = trim($fields[self::F_BWI_LOCATION]); - $sap_code = trim($fields[self::F_SAP_CODE]); - $sku = trim($fields[self::F_SKU]); - $qty = trim($fields[self::F_QTY]); $fname = trim($fields[self::F_FIRST_NAME]); $lname = trim($fields[self::F_LAST_NAME]); $dpa = trim($fields[self::F_DPA]); $contact_number = trim($fields[SELF::F_CONTACT_NUM]); return [ - $timestamp, $dpa, $fname, - $mname, $lname, - $birthdate, - $address, - $city, - $region, $car_club, - $position, - $member_number, - $vehicle, - $vehicle_excel, - $batt_size, - $replace_sked, - $dealer_visit, $contact_number, - $bwi_location, - $sap_code, - $sku, - $qty, - $status, - $reason, + $status, + $reason, $cust_id ]; } @@ -237,17 +186,6 @@ class ImportCarClubCustomerDataCommand extends Command // clean up contact number $valid_contact_numbers = $this->getValidContactNumbers($contact_number); - // NOTE: commenting this out because we want to add customers without mobile number - /* - // QUESTION: do we need this? - // QUESTION: why are we not adding those without contact numbers? Add customer, leave contact number blank was what was agreed, right? - if (count($valid_contact_numbers) <= 0) - { - // add info to output array - return $this->setOutputInfo($fields, 'NOT CREATED', 'Missing contact number', 0); - } - */ - // check customer tag $cust_tag = $this->findCustomerTag($car_club); $cust_id = ''; @@ -310,28 +248,11 @@ class ImportCarClubCustomerDataCommand extends Command // write the headers fputcsv($fh, [ - 'Timestamp', 'I have read and understood and agreed to the confidentiality of this form request', 'First Name', - 'Middle Name', 'Last Name', - 'Birth date', - 'Address', - 'City', - 'Region', 'Car Club/Organization', - 'Position in the organization', - 'Official Member Number (type NA if not applicable)', - 'Vehicles you own? Year - Make -Model - Plate/Conduction number (ex 2017 NISSAN NAVARA ABC 1234) you can indicate all your vehicles', - 'If your were given a chance to EXperience the New Motolite Excel, Choose 1 vehicle and it\'s plate/conduction number', - 'What is the Battery size of the vehicle you with to EXperience the New Motolite Excel', - 'Given a specific date, when can you schedule your replacement?', - 'Will you be able to visit our dealer that we will assign nearest to you?', 'Contact Number', - 'BWI LOCATION', - 'SAP CODE', - 'SKU', - 'QTY', 'Status', 'Reason', 'Customer ID', From a35101001b88ccfead2c3169786a2beb69780ba3 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Mon, 14 Jun 2021 09:26:35 +0000 Subject: [PATCH 17/31] Add more data to warranty details report. #584 --- src/Controller/ReportController.php | 185 ++++++++++++++++++++++------ 1 file changed, 147 insertions(+), 38 deletions(-) diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index 86247929..b4e4ce3b 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -692,24 +692,71 @@ class ReportController extends Controller // csv output $csv_handle = fopen('php://output', 'w+'); fputcsv($csv_handle, [ + 'Customer ID', + 'Customer First Name', + 'Customer Last Name', + 'Customer Is Confirmed?', + 'Customer Classification', + 'Customer Has Mobile App?', + 'Customer Title', + 'Customer Is Active?', + 'Customer Mobile Phone', + 'Customer Landline Phone', + 'Customer Office Phone', + 'Customer Fax Phone', + 'Customer Email Address', + 'Customer Notes', + 'Customer Has Third Party Privacy Policy?', + 'Customer Has Promo Privacy Policy?', + 'Customer Is CSAT', + 'Customer Mobile App Privacy Policy ID', + 'Customer Third Party Policy ID', + 'Customer Promo Privacy ID', + 'Customer DPA Consent', + 'Customer Date Created', + 'Customer SMS Research Flag', + 'Customer Email Research Flag', + 'Customer Create Source', + 'Vehicle ID', + 'Vehicle Manufacturer ID', + 'Vehicle Make', + 'Vehicle Model Year From', + 'Vehicle Model Year To', + 'Vehicle Mobile App Flag', 'Warranty ID', - 'Serial', - 'Battery Model', - 'Battery Size', + 'Warranty Battery Model ID', + 'Warranty Battery Size ID', + 'Warranty Serial', 'Warranty Class', - 'Plate Number', - 'Status', - 'Date Created', - 'Date Purchased', - 'Expiry Date', - 'Date Claimed', - 'SAP Battery ID', - 'Claim ID', - 'Last Name', - 'First Name', - 'Mobile Number', - 'Privacy Policy Number', - 'Activated?', + 'Warranty Plate Number', + 'Warranty Status', + 'Warranty Date Created', + 'Warranty Date Purchased', + 'Warranty Expiry Date', + 'Warranty Date Claimed', + 'Warranty SAP Battery ID', + 'Warranty Claim ID', + 'Warranty First Name', + 'Warranty Last Name', + 'Warranty Mobile Number', + 'Warranty Is Activated?', + 'Warranty Privacy Policy Number', + 'Warranty Email Address', + 'Warranty Vehicle ID', + 'Warranty Customer ID', + 'Warranty File Invoice', + 'Warranty File Card', + 'Warranty Vehicle Model Year', + 'Warranty Odometer', + 'Warranty Dealer Name', + 'Warranty Dealer Address', + 'Warranty Contact Number', + 'Warranty Customer Address', + 'Warranty Customer Date Purchase', + 'Warranty Is Validated?', + 'Warranty Province ID', + 'Warranty Municipality ID', + 'Warranty Create Source', ]); foreach ($data as $row) @@ -1429,12 +1476,27 @@ class ReportController extends Controller $results = []; $conn = $em->getConnection(); - $sql = 'SELECT w.id, w.serial, w.warranty_class, w.plate_number, - w.status, w.date_create, w.date_purchase, w.date_expire, + $sql = 'SELECT w.id AS w_id, w.serial, w.warranty_class, w.plate_number, + w.status, w.date_create as w_date_create, w.date_purchase, w.date_expire, w.date_claim, w.sap_bty_id, w.claim_id, w.first_name, w.last_name, w.mobile_number, w.flag_activated, - w.warranty_privacy_policy, w.bty_model_id, w.bty_size_id - FROM warranty w'; + w.warranty_privacy_policy, w.bty_model_id, w.bty_size_id, + w.email as w_email, w.vehicle_id, w.customer_id, w.file_invoice, + w.file_warr_card, w.v_model_year, w.odometer, w.dealer_name, + w.dealer_address, w.contact_num, w.cust_address, + w.date_purchase_cust, w.flag_validated, w.province_id, + w.municipality_id, w.create_source AS w_create_source, c.id AS c_id, + c.first_name AS c_fname, c.last_name AS c_lname, c.flag_confirmed, + c.customer_classification, c.flag_mobile_app, c.title, c.flag_active, + c.phone_mobile, c.phone_landline, c.phone_office, c.phone_fax, + c.email AS c_email, c.customer_notes, c.priv_third_party, c.priv_promo, + c.flag_csat, c.policy_mobile_app_id, c.policy_third_party_id, + c.policy_promo_id, c.flag_dpa_consent, c.date_create AS c_date_create, + c.flag_research_sms, c.flag_research_email, c.create_source AS c_create_source, + v.id AS v_id, v.manufacturer_id, v.make, v.model_year_from, + v.model_year_to, v.flag_mobile + FROM warranty w JOIN customer c ON w.customer_id = c.id + JOIN vehicle v ON w.vehicle_id = v.id'; $stmt = $conn->prepare($sql); $stmt->execute(); @@ -1461,24 +1523,71 @@ class ReportController extends Controller } $results[] = [ - 'id' => $row['id'], - 'serial' => $row['serial'], - 'battery_model' => $bmodel_name, - 'battery_size' => $bsize_name, - 'warranty_class' => $row['warranty_class'], - 'plate_number' => $row['plate_number'], - 'status' => $row['status'], - 'date_create' => $row['date_create'], - 'date_purchase' => $row['date_purchase'], - 'date_expire' => $row['date_expire'], - 'date_claim' => $row['date_claim'], - 'sap_bty_id' => $row['sap_bty_id'], - 'claim_id' => $row['claim_id'], - 'last_name' => $row['last_name'], - 'first_name' => $row['first_name'], - 'mobile_number' => $row['mobile_number'], - 'privacy_policy' => $row['warranty_privacy_policy'], - 'flag_activated' => (boolean) $row['flag_activated'], + 'cust_id' => $row['c_id'], + 'cust_first_name' => $row['c_fname'], + 'cust_last_name' => $row['c_lname'], + 'cust_flag_confirm' => $row['flag_confirmed'], + 'cust_classification' => $row['customer_classification'], + 'cust_flag_mobile_app' => $row['flag_mobile_app'], + 'cust_title' => $row['title'], + 'cust_flag_active' => $row['flag_active'], + 'cust_phone_mobile' => $row['phone_mobile'], + 'cust_phone_landline' => $row['phone_landline'], + 'cust_phone_office' => $row['phone_office'], + 'cust_phone_fax' => $row['phone_fax'], + 'cust_email' => $row['c_email'], + 'cust_notes' => $row['customer_notes'], + 'cust_priv_third_party' => $row['priv_third_party'], + 'cust_priv_promo' => $row['priv_promo'], + 'cust_flag_csat' => $row['flag_csat'], + 'cust_policy_mobile_app_id' => $row['policy_mobile_app_id'], + 'cust_policy_third_party_id' => $row['policy_third_party_id'], + 'cust_policy_promo_id' => $row['policy_promo_id'], + 'cust_flag_dpa_consent' => $row['flag_dpa_consent'], + 'cust_date_create' => $row['c_date_create'], + 'cust_flag_research_sms' => $row['flag_research_sms'], + 'cust_flag_research_email' => $row['flag_research_email'], + 'cust_create_source' => $row['c_create_source'], + 'v_id' => $row['v_id'], + 'v_manufacturer_id' => $row['manufacturer_id'], + 'v_make' => $row['make'], + 'v_model_year_from' => $row['model_year_from'], + 'v_model_year_to' => $row['model_year_to'], + 'v.flag_mobile' => $row['flag_mobile'], + 'warr_id' => $row['w_id'], + 'warr_battery_model' => $bmodel_name, + 'warr_battery_size' => $bsize_name, + 'warr_serial' => $row['serial'], + 'warr_class' => $row['warranty_class'], + 'warr_plate_number' => $row['plate_number'], + 'warr_status' => $row['status'], + 'warr_date_create' => $row['w_date_create'], + 'warr_date_purchase' => $row['date_purchase'], + 'warr_date_expire' => $row['date_expire'], + 'warr_date_claim' => $row['date_claim'], + 'warr_sap_bty_id' => $row['sap_bty_id'], + 'warr_claim_id' => $row['claim_id'], + 'warr_first_name' => $row['first_name'], + 'warr_last_name' => $row['last_name'], + 'warr_mobile_number' => $row['mobile_number'], + 'warr_flag_activated' => (boolean) $row['flag_activated'], + 'warr_privacy_policy' => $row['warranty_privacy_policy'], + 'warr_email' => $row['w_email'], + 'warr_vehicle_id' =>$row['vehicle_id'], + 'warr_customer_id' => $row['customer_id'], + 'warr_file_invoice' => $row['file_invoice'], + 'warr_file_warr_card' => $row['file_warr_card'], + 'warr_v_model_year' => $row['v_model_year'], + 'warr_odometer' => $row['odometer'], + 'warr_dealer_name' => $row['dealer_name'], + 'warr_dealer_address' => $row['dealer_address'], + 'warr_contact_number' => $row['contact_num'], + 'warr_customer_address' => $row['cust_address'], + 'warr_customer_date_purchase' => $row['date_purchase_cust'], + 'warr_flag_validated' => $row['flag_validated'], + 'warr_province_id' => $row['province_id'], + 'warr_municipality_id' => $row['municipality_id'], + 'warr_create_source' => $row['w_create_source'], ]; } From 7a377d2ede018b2d61e86273e254494f034fe109 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Mon, 14 Jun 2021 18:03:18 +0800 Subject: [PATCH 18/31] Add id to dealer capi call #585 --- src/Controller/CAPI/DealerController.php | 1 + 1 file changed, 1 insertion(+) diff --git a/src/Controller/CAPI/DealerController.php b/src/Controller/CAPI/DealerController.php index f4f86d98..c59e4a54 100644 --- a/src/Controller/CAPI/DealerController.php +++ b/src/Controller/CAPI/DealerController.php @@ -38,6 +38,7 @@ class DealerController extends APIController $dealer_branch_code = $res->getBranchCode(); $dealers[$dealer_id] = [ + 'id' => $dealer_id, 'name' => $dealer_name, 'address' => $dealer_address, 'branch_code' => $dealer_branch_code, From a6af9c1bb9ab498bec0b90f85240594049098dd8 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 17 Jun 2021 03:23:13 +0000 Subject: [PATCH 19/31] Add crud access for dealers. #586 --- config/acl.yaml | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/config/acl.yaml b/config/acl.yaml index 0f858fa9..b9b42afb 100644 --- a/config/acl.yaml +++ b/config/acl.yaml @@ -502,3 +502,17 @@ access_keys: label: Update - id: customer_tag.delete label: Delete + + - id: dealer + label: Dealer Access + acls: + - id: dealer.menu + label: Menu + - id: dealer.list + label: List + - id: dealer.add + label: Add + - id: dealer.update + label: Update + - id: dealer.delete + label: Delete From 4c3b895702cc7c5869d176e3f531789cc7a4760a Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 17 Jun 2021 04:01:21 +0000 Subject: [PATCH 20/31] Add date range for warranty details report. Fix query to include all warranties. #587 --- config/routes/report.yaml | 4 +- src/Controller/ReportController.php | 27 +++++++-- .../report/warranty-details/form.html.twig | 55 +++++++++++++++---- 3 files changed, 68 insertions(+), 18 deletions(-) diff --git a/config/routes/report.yaml b/config/routes/report.yaml index f9d780ef..02f12f41 100644 --- a/config/routes/report.yaml +++ b/config/routes/report.yaml @@ -73,9 +73,9 @@ rep_warranty_details_form: controller: App\Controller\ReportController::warrantyDetailsForm methods: [GET] -rep_warranty_details_export_csv: +rep_warranty_details_submit: path: /report/warranty_details_report - controller: App\Controller\ReportController::warrantyDetailsExportCSV + controller: App\Controller\ReportController::warrantyDetailsSubmit methods: [POST] rep_jo_details_form: diff --git a/src/Controller/ReportController.php b/src/Controller/ReportController.php index b4e4ce3b..f259619a 100644 --- a/src/Controller/ReportController.php +++ b/src/Controller/ReportController.php @@ -683,9 +683,9 @@ class ReportController extends Controller /** * @Menu(selected="outlet_list") */ - public function warrantyDetailsExportCSV(Request $resq, EntityManagerInterface $em) + public function warrantyDetailsSubmit(Request $req, EntityManagerInterface $em) { - $data = $this->getWarrantyDetailsData($em); + $data = $this->getWarrantyDetailsData($req, $em); $resp = new StreamedResponse(); $resp->setCallback(function() use ($data) { @@ -1468,11 +1468,24 @@ class ReportController extends Controller return $results; } - protected function getWarrantyDetailsData(EntityManagerInterface $em) + protected function getWarrantyDetailsData(Request $req, EntityManagerInterface $em) { $bm_hash = $this->loadBatteryModels($em); $bs_hash = $this->loadBatterySizes($em); + // get dates + $raw_date_start = $req->request->get('date_start'); + $raw_date_end = $req->request->get('date_end'); + + $date_start = DateTime::createFromFormat('m/d/Y', $raw_date_start); + $date_end = DateTime::createFromFormat('m/d/Y', $raw_date_end); + $date_start->setTime(0,0); + $date_end->setTime(23,59); + + // convert to string in the correct format so we can plug it in the query + $str_date_start = $date_start->format('Y-m-d H:i:s'); + $str_date_end = $date_end->format('Y-m-d H:i:s'); + $results = []; $conn = $em->getConnection(); @@ -1495,11 +1508,13 @@ class ReportController extends Controller c.flag_research_sms, c.flag_research_email, c.create_source AS c_create_source, v.id AS v_id, v.manufacturer_id, v.make, v.model_year_from, v.model_year_to, v.flag_mobile - FROM warranty w JOIN customer c ON w.customer_id = c.id - JOIN vehicle v ON w.vehicle_id = v.id'; + FROM warranty w LEFT JOIN customer c ON w.customer_id = c.id + LEFT JOIN vehicle v ON w.vehicle_id = v.id + WHERE w.date_create >= :start_date + AND w.date_create <= :end_date'; $stmt = $conn->prepare($sql); - $stmt->execute(); + $stmt->execute(['start_date' => $str_date_start, 'end_date' => $str_date_end]); $query_results = $stmt->fetchAll(); diff --git a/templates/report/warranty-details/form.html.twig b/templates/report/warranty-details/form.html.twig index c329785a..03229bbb 100644 --- a/templates/report/warranty-details/form.html.twig +++ b/templates/report/warranty-details/form.html.twig @@ -21,30 +21,65 @@
- +

- Generate Warranty Details CSV File + Select a date range

-
-
-
-
-
-
- -
+ +
+
+
+ +
+ +
+ +
+
+
+
+
+
+
+
+
{% endblock %} +{% block scripts %} + +{% endblock %} From 614183fa2d77e5b19bcbac178a6ec3132c717e3b Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 17 Jun 2021 07:27:22 +0000 Subject: [PATCH 21/31] Add CRUD UI for dealers. #586 --- config/menu.yaml | 4 + config/routes/dealer.yaml | 33 ++++ src/Controller/DealerController.php | 271 ++++++++++++++++++++++++++++ templates/dealer/form.html.twig | 154 ++++++++++++++++ templates/dealer/list.html.twig | 151 ++++++++++++++++ 5 files changed, 613 insertions(+) create mode 100644 config/routes/dealer.yaml create mode 100644 src/Controller/DealerController.php create mode 100644 templates/dealer/form.html.twig create mode 100644 templates/dealer/list.html.twig diff --git a/config/menu.yaml b/config/menu.yaml index 35709ee0..fc4751fb 100644 --- a/config/menu.yaml +++ b/config/menu.yaml @@ -110,6 +110,10 @@ main_menu: acl: hub.menu label: Hub parent: location + - id: dealer_list + acl: dealer.list + label: Dealer + parent: location - id: geofence_list acl: geofence.menu label: Geofence diff --git a/config/routes/dealer.yaml b/config/routes/dealer.yaml new file mode 100644 index 00000000..4c37e46e --- /dev/null +++ b/config/routes/dealer.yaml @@ -0,0 +1,33 @@ +dealer_list: + path: /dealers + controller: App\Controller\DealerController::index + +dealer_rows: + path: /dealers/rows + controller: App\Controller\DealerController::rows + methods: [POST] + +dealer_create: + path: /dealers/create + controller: App\Controller\DealerController::addForm + methods: [GET] + +dealer_create_submit: + path: /dealers/create + controller: App\Controller\DealerController::addSubmit + methods: [POST] + +dealer_update: + path: /dealers/{id} + controller: App\Controller\DealerController::updateForm + methods: [GET] + +dealer_update_submit: + path: /dealers/{id} + controller: App\Controller\DealerController::updateSubmit + methods: [POST] + +dealer_delete: + path: /dealers/{id} + controller: App\Controller\DealerController::destroy + methods: [DELETE] diff --git a/src/Controller/DealerController.php b/src/Controller/DealerController.php new file mode 100644 index 00000000..75c1e035 --- /dev/null +++ b/src/Controller/DealerController.php @@ -0,0 +1,271 @@ +denyAccessUnlessGranted('dealer.list', null, 'No access.'); + + return $this->render('dealer/list.html.twig'); + } + + public function rows(Request $req) + { + $this->denyAccessUnlessGranted('dealer.list', null, 'No access.'); + + // get query builder + $qb = $this->getDoctrine() + ->getRepository(Dealer::class) + ->createQueryBuilder('q'); + + // get datatable params + $datatable = $req->request->get('datatable'); + + // count total records + $tquery = $qb->select('COUNT(q)'); + $this->setQueryFilters($datatable, $tquery); + $total = $tquery->getQuery() + ->getSingleScalarResult(); + + // get current page number + $page = $datatable['pagination']['page'] ?? 1; + + $perpage = $datatable['pagination']['perpage']; + $offset = ($page - 1) * $perpage; + + // add metadata + $meta = [ + 'page' => $page, + 'perpage' => $perpage, + 'pages' => ceil($total / $perpage), + 'total' => $total, + 'sort' => 'asc', + 'field' => 'id' + ]; + + // build query + $query = $qb->select('q'); + $this->setQueryFilters($datatable, $query); + + // check if sorting is present, otherwise use default + if (isset($datatable['sort']['field']) && !empty($datatable['sort']['field'])) { + $order = $datatable['sort']['sort'] ?? 'asc'; + $query->orderBy('q.' . $datatable['sort']['field'], $order); + } else { + $query->orderBy('q.id', 'asc'); + } + + // get rows for this page + $obj_rows = $query->setFirstResult($offset) + ->setMaxResults($perpage) + ->getQuery() + ->getResult(); + + // process rows + $rows = []; + foreach ($obj_rows as $orow) { + // add row data + $row['id'] = $orow->getID(); + $row['name'] = $orow->getName(); + $row['address'] = $orow->getAddress(); + $row['branch_code'] = $orow->getBranchCode(); + + // add row metadata + $row['meta'] = [ + 'update_url' => '', + 'delete_url' => '' + ]; + + // add crud urls + if ($this->isGranted('dealer.update')) + $row['meta']['update_url'] = $this->generateUrl('dealer_update', ['id' => $row['id']]); + if ($this->isGranted('dealer.delete')) + $row['meta']['delete_url'] = $this->generateUrl('dealer_delete', ['id' => $row['id']]); + + $rows[] = $row; + } + + // response + return $this->json([ + 'meta' => $meta, + 'data' => $rows + ]); + + } + + /** + * @Menu(selected="dealer_list") + */ + public function addForm() + { + $this->denyAccessUnlessGranted('dealer.add', null, 'No access.'); + + $params = []; + $params['obj'] = new Dealer(); + $params['mode'] = 'create'; + + // response + return $this->render('dealer/form.html.twig', $params); + } + + public function addSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator) + { + $this->denyAccessUnlessGranted('dealer.add', null, 'No access.'); + + // create new object + $em = $this->getDoctrine()->getManager(); + $obj = new Dealer(); + + $this->setObject($obj, $req); + + // validate + $errors = $validator->validate($obj); + + // initialize error list + $error_array = []; + + // add errors to list + foreach ($errors as $error) { + $error_array[$error->getPropertyPath()] = $error->getMessage(); + } + + // check if any errors were found + if (!empty($error_array)) { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } + + // validated! save the entity + $em->persist($obj); + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + + /** + * @Menu(selected="dealer_list") + */ + public function updateForm($id) + { + $this->denyAccessUnlessGranted('dealer.update', null, 'No access.'); + + // get row data + $em = $this->getDoctrine()->getManager(); + $obj = $em->getRepository(Dealer::class)->find($id); + + // make sure this row exists + if (empty($obj)) + throw $this->createNotFoundException('The item does not exist'); + + $params = []; + $params['obj'] = $obj; + $params['mode'] = 'update'; + + // response + return $this->render('dealer/form.html.twig', $params); + } + + public function updateSubmit(Request $req, EncoderFactoryInterface $ef, ValidatorInterface $validator, $id) + { + $this->denyAccessUnlessGranted('dealer.update', null, 'No access.'); + + // get object data + $em = $this->getDoctrine()->getManager(); + $obj = $em->getRepository(Dealer::class)->find($id); + + // make sure this object exists + if (empty($obj)) + throw $this->createNotFoundException('The item does not exist'); + + $this->setObject($obj, $req); + + // validate + $errors = $validator->validate($obj); + + // initialize error list + $error_array = []; + + // add errors to list + foreach ($errors as $error) { + $error_array[$error->getPropertyPath()] = $error->getMessage(); + } + + // check if any errors were found + if (!empty($error_array)) { + // return validation failure response + return $this->json([ + 'success' => false, + 'errors' => $error_array + ], 422); + } + + // validated! save the entity + $em->flush(); + + // return successful response + return $this->json([ + 'success' => 'Changes have been saved!' + ]); + } + + public function destroy($id) + { + $this->denyAccessUnlessGranted('dealer.delete', null, 'No access.'); + + // get object data + $em = $this->getDoctrine()->getManager(); + $obj = $em->getRepository(Dealer::class)->find($id); + + if (empty($obj)) + throw $this->createNotFoundException('The item does not exist'); + + // delete this object + $em->remove($obj); + $em->flush(); + + // response + $response = new Response(); + $response->setStatusCode(Response::HTTP_OK); + $response->send(); + } + + protected function setObject(Dealer $obj, Request $req) + { + // set and save values + $obj->setName($req->request->get('name')) + ->setAddress($req->request->get('address', '')) + ->setBranchCode($req->request->get('branch_code', '')); + } + + protected function setQueryFilters($datatable, QueryBuilder $query) + { + if (isset($datatable['query']['data-rows-search']) && !empty($datatable['query']['data-rows-search'])) { + $query->where('q.name LIKE :filter') + ->orWhere('q.address LIKE :filter') + ->setParameter('filter', '%' . $datatable['query']['data-rows-search'] . '%'); + } + } +} diff --git a/templates/dealer/form.html.twig b/templates/dealer/form.html.twig new file mode 100644 index 00000000..d95339d8 --- /dev/null +++ b/templates/dealer/form.html.twig @@ -0,0 +1,154 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

Dealers

+
+
+
+ +
+ +
+
+
+
+
+
+ + + +

+ {% if mode == 'update' %} + Edit Hub + {{ obj.getName() }} + {% else %} + New Dealer + {% endif %} +

+
+
+
+
+
+
+
+
+
+ + + +
+
+ + + +
+
+
+
+ + + +
+
+
+
+
+
+
+
+
+ + Back +
+
+
+
+ +
+
+
+
+{% endblock %} + + +{% block scripts %} + +{% endblock %} diff --git a/templates/dealer/list.html.twig b/templates/dealer/list.html.twig new file mode 100644 index 00000000..f6428c6b --- /dev/null +++ b/templates/dealer/list.html.twig @@ -0,0 +1,151 @@ +{% extends 'base.html.twig' %} + +{% block body %} + +
+
+
+

+ Dealers +

+
+
+
+ +
+ +
+
+
+
+
+
+
+
+
+
+ + + + +
+
+
+
+ +
+
+ +
+ +
+
+
+
+
+{% endblock %} + +{% block scripts %} + +{% endblock %} From e7395217da45c3169693c4f2c7bb16b1facaaf10 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 17 Jun 2021 07:32:50 +0000 Subject: [PATCH 22/31] Fix typo. #586 --- templates/dealer/form.html.twig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/templates/dealer/form.html.twig b/templates/dealer/form.html.twig index d95339d8..9bcf906d 100644 --- a/templates/dealer/form.html.twig +++ b/templates/dealer/form.html.twig @@ -23,7 +23,7 @@

{% if mode == 'update' %} - Edit Hub + Edit Dealer {{ obj.getName() }} {% else %} New Dealer From 532df141edbe4f3d184982fad9d27ce67a3065b5 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 17 Jun 2021 09:01:44 +0000 Subject: [PATCH 23/31] Add customer source when creating a new customer. #548 --- .../CreateCustomerFromWarrantyCommand.php | 3 ++- src/Command/ImportCustomerCommand.php | 3 ++- src/Controller/APIController.php | 4 ++++ src/Controller/CAPI/CustomerController.php | 11 ++++++++++- .../CAPI/CustomerWarrantyController.php | 4 +++- src/Controller/CAPI/WarrantyController.php | 6 ++++-- src/Ramcar/CustomerSource.php | 16 ++++++++++++++++ .../CustomerHandler/ResqCustomerHandler.php | 4 ++++ 8 files changed, 45 insertions(+), 6 deletions(-) create mode 100644 src/Ramcar/CustomerSource.php diff --git a/src/Command/CreateCustomerFromWarrantyCommand.php b/src/Command/CreateCustomerFromWarrantyCommand.php index 416ee514..203fac6f 100644 --- a/src/Command/CreateCustomerFromWarrantyCommand.php +++ b/src/Command/CreateCustomerFromWarrantyCommand.php @@ -216,7 +216,8 @@ class CreateCustomerFromWarrantyCommand extends Command $new_cust = new Customer(); $new_cust->setFirstName($w_first_name) ->setLastName($w_last_name) - ->setPhoneMobile($w_mobile_num); + ->setPhoneMobile($w_mobile_num) + ->setCreateSource('CMB_CreateFromCustomerWarranty'); $this->em->persist($new_cust); diff --git a/src/Command/ImportCustomerCommand.php b/src/Command/ImportCustomerCommand.php index e2c55832..562c2df3 100644 --- a/src/Command/ImportCustomerCommand.php +++ b/src/Command/ImportCustomerCommand.php @@ -418,7 +418,8 @@ class ImportCustomerCommand extends Command $fields[self::F_OFFICE_PHONE], $fields[self::F_FAX], $fields[self::F_EMAIL], - isset($fields[self::F_NOTES]) ? $fields[self::F_NOTES] : '' + isset($fields[self::F_NOTES]) ? $fields[self::F_NOTES] : '', + 'CMB_ImportCustomerCommand' ]; $cust_row = str_replace('\\', '\\\\', implode('|', $cust_fields)) . "\n"; fputs($cust_file, $cust_row); diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index a1623a09..f6d764cd 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -29,6 +29,7 @@ use App\Ramcar\JOEventType; use App\Ramcar\AdvanceOrderSlot; use App\Ramcar\AutoAssignStatus; use App\Ramcar\WarrantySource; +use App\Ramcar\CustomerSource; use App\Service\InvoiceGeneratorInterface; use App\Service\RisingTideGateway; @@ -416,6 +417,9 @@ class APIController extends Controller implements LoggedController if ($cust == null) { $cust = new Customer(); + + // set customer source + $cust->setCreateSource(CustomerSource::MOBILE); $em->persist($cust); $this->session->setCustomer($cust); diff --git a/src/Controller/CAPI/CustomerController.php b/src/Controller/CAPI/CustomerController.php index 55aae2bd..36dbba24 100644 --- a/src/Controller/CAPI/CustomerController.php +++ b/src/Controller/CAPI/CustomerController.php @@ -15,6 +15,8 @@ use App\Entity\Customer; use App\Entity\CustomerVehicle; use App\Entity\Vehicle; +use App\Ramcar\CustomerSource; + use Catalyst\APIBundle\Access\Generator as ACLGenerator; class CustomerController extends APIController @@ -154,10 +156,17 @@ class CustomerController extends APIController else { // customer not found + // get the api_user that made the call so that it gets added to the source + // source becomes CAPI_USER_ + $user_id = $_SERVER['HTTP_X_CATA_API_KEY']; + $username = $this->getUser()->getName(); + $source = 'CAPI_USER_' . $username; + $new_cust = new Customer(); $new_cust->setFirstName($first_name) ->setLastName($last_name) - ->setPhoneMobile($mobile_number); + ->setPhoneMobile($mobile_number) + ->setCreateSource($source); $em->persist($new_cust); diff --git a/src/Controller/CAPI/CustomerWarrantyController.php b/src/Controller/CAPI/CustomerWarrantyController.php index 6e183cc0..0c1c869e 100644 --- a/src/Controller/CAPI/CustomerWarrantyController.php +++ b/src/Controller/CAPI/CustomerWarrantyController.php @@ -106,6 +106,7 @@ class CustomerWarrantyController extends APIController 'serial' => $serial, ]; $action = 'check'; + // TODO: we need to modify this later. $source = WarrantySource::CAPI; // check required parameters @@ -491,7 +492,8 @@ class CustomerWarrantyController extends APIController ->setEmail($req->request->get('email')) ->setCreateSource('web_warranty') ->setPrivacyPromo($priv_promo) - ->setPhoneMobile($req->request->get('contact_num')); + ->setPhoneMobile($req->request->get('contact_num')) + ->setCreateSource($source); $em->persist($cust); } diff --git a/src/Controller/CAPI/WarrantyController.php b/src/Controller/CAPI/WarrantyController.php index c0cd8aa8..4db8051c 100644 --- a/src/Controller/CAPI/WarrantyController.php +++ b/src/Controller/CAPI/WarrantyController.php @@ -728,10 +728,12 @@ class WarrantyController extends APIController $w_last_name = $warranty->getLastName(); $new_cust = new Customer(); - // TODO: add customer source + // add customer source + $cust_source = $warranty->getCreateSource(); $new_cust->setFirstName($w_first_name) ->setLastName($w_last_name) - ->setPhoneMobile($w_mobile_num); + ->setPhoneMobile($w_mobile_num) + ->setCreateSource($cust_source); $em->persist($new_cust); diff --git a/src/Ramcar/CustomerSource.php b/src/Ramcar/CustomerSource.php new file mode 100644 index 00000000..5acfa41d --- /dev/null +++ b/src/Ramcar/CustomerSource.php @@ -0,0 +1,16 @@ + 'Mobile API', + 'admin_panel' => 'Admin Panel', + 'legacy' => 'Legacy', + ]; +} diff --git a/src/Service/CustomerHandler/ResqCustomerHandler.php b/src/Service/CustomerHandler/ResqCustomerHandler.php index 1554a288..f8685801 100644 --- a/src/Service/CustomerHandler/ResqCustomerHandler.php +++ b/src/Service/CustomerHandler/ResqCustomerHandler.php @@ -15,6 +15,7 @@ use App\Ramcar\CustomerClassification; use App\Ramcar\FuelType; use App\Ramcar\VehicleStatusCondition; use App\Ramcar\CrudException; +use App\Ramcar\CustomerSource; use App\Entity\Customer; use App\Entity\CustomerVehicle; @@ -189,6 +190,9 @@ class ResqCustomerHandler implements CustomerHandlerInterface $this->setObject($row, $req); + // set customer source only when new customer + $row->setCreateSource(CustomerSource::ADMIN_PANEL); + // custom validation for vehicles $vehicles = json_decode($req->request->get('vehicles')); From 2b356194bb1cc423fae0bd93037ca33d18d642ad Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Thu, 17 Jun 2021 09:04:57 +0000 Subject: [PATCH 24/31] Fix typo. Remove not needed packages. #548 --- src/Command/CreateCustomerFromWarrantyCommand.php | 2 +- src/Controller/CAPI/CustomerController.php | 2 -- 2 files changed, 1 insertion(+), 3 deletions(-) diff --git a/src/Command/CreateCustomerFromWarrantyCommand.php b/src/Command/CreateCustomerFromWarrantyCommand.php index 203fac6f..5ffe3a46 100644 --- a/src/Command/CreateCustomerFromWarrantyCommand.php +++ b/src/Command/CreateCustomerFromWarrantyCommand.php @@ -217,7 +217,7 @@ class CreateCustomerFromWarrantyCommand extends Command $new_cust->setFirstName($w_first_name) ->setLastName($w_last_name) ->setPhoneMobile($w_mobile_num) - ->setCreateSource('CMB_CreateFromCustomerWarranty'); + ->setCreateSource('CMB_CreateCustomerFromWarranty'); $this->em->persist($new_cust); diff --git a/src/Controller/CAPI/CustomerController.php b/src/Controller/CAPI/CustomerController.php index 36dbba24..9148321e 100644 --- a/src/Controller/CAPI/CustomerController.php +++ b/src/Controller/CAPI/CustomerController.php @@ -15,8 +15,6 @@ use App\Entity\Customer; use App\Entity\CustomerVehicle; use App\Entity\Vehicle; -use App\Ramcar\CustomerSource; - use Catalyst\APIBundle\Access\Generator as ACLGenerator; class CustomerController extends APIController From 406df3d0834aef6e3463ea5c7f1fe206ea06ecea Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 18 Jun 2021 07:00:56 +0000 Subject: [PATCH 25/31] Add setting of customer and vehicle when warranty is created via mobile API, rider API, and admin panel. #588 --- src/Controller/APIController.php | 31 +++++++++++++++++++ .../JobOrderHandler/ResqJobOrderHandler.php | 2 +- .../RiderAPIHandler/ResqRiderAPIHandler.php | 2 +- src/Service/WarrantyHandler.php | 10 ++++-- 4 files changed, 40 insertions(+), 5 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index a1623a09..1d13ad47 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -40,6 +40,7 @@ use App\Service\InventoryManager; use App\Service\RiderAssignmentHandlerInterface; use App\Service\WarrantyAPILogger; use App\Service\PromoLogger; + use App\Entity\MobileSession; use App\Entity\Customer; @@ -3185,6 +3186,16 @@ class APIController extends Controller implements LoggedController return $res; } + $customer = $this->session->getCustomer(); + if ($customer != null) + { + $warr->setCustomer($customer); + // get customer vehicles + $vehicle = $this->findCustomerVehicle($customer, $req->request->get('plate_number')); + + if ($vehicle != null) + $warr->setVehicle($vehicle); + } // create or update warranty entry $warr->setSerial($serial) @@ -3259,6 +3270,26 @@ class APIController extends Controller implements LoggedController return $cust; } + protected function findCustomerVehicle($customer, $plate_number) + { + $clean_plate = Warranty::cleanPlateNumber($plate_number); + if ($clean_plate) + { + // find the customer vehicle and get the vehicle + $cust_vehicles = $customer->getVehicles(); + foreach ($cust_vehicles as $cv) + { + if ($cv->getPlateNumber() == $clean_plate) + { + $vehicle = $cv->getVehicle(); + return $vehicle; + } + } + } + + return null; + } + protected function findNearestHub($jo, EntityManagerInterface $em, MapTools $map_tools) { // get the nearest 10 hubs diff --git a/src/Service/JobOrderHandler/ResqJobOrderHandler.php b/src/Service/JobOrderHandler/ResqJobOrderHandler.php index 2ec57b40..c9ba36b3 100644 --- a/src/Service/JobOrderHandler/ResqJobOrderHandler.php +++ b/src/Service/JobOrderHandler/ResqJobOrderHandler.php @@ -1062,7 +1062,7 @@ class ResqJobOrderHandler implements JobOrderHandlerInterface $user_id = $user->getUsername(); $source = WarrantySource::ADMIN_PANEL; - $this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class, $user_id, $source); + $this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class, $user_id, $source, $obj->getCustomer(), $obj->getCustomerVehicle()->getVehicle()); } else error_log('Invalid plate number for warranty. Plate number = ' . $obj->getCustomerVehicle()->getPlateNumber()); diff --git a/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php b/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php index 6f1711c3..10678139 100644 --- a/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php +++ b/src/Service/RiderAPIHandler/ResqRiderAPIHandler.php @@ -602,7 +602,7 @@ class ResqRiderAPIHandler implements RiderAPIHandlerInterface // for riders, use rider session id $user_id = $this->session->getID(); $source = WarrantySource::RAPI; - $this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class, $user_id, $source); + $this->wh->createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, $batt_list, $date_purchase, $warranty_class, $user_id, $source, $jo->getCustomer(), $jo->getCustomerVehicle()->getVehicle()); } // send mqtt event (fulfilled) diff --git a/src/Service/WarrantyHandler.php b/src/Service/WarrantyHandler.php index 8d84e8f6..7ba9c6f8 100644 --- a/src/Service/WarrantyHandler.php +++ b/src/Service/WarrantyHandler.php @@ -30,7 +30,8 @@ class WarrantyHandler } public function createWarranty($serial, $plate_number, $first_name, $last_name, $mobile_number, - $batt_list, DateTime $date_purchase, $warranty_class, $user_id, $source) + $batt_list, DateTime $date_purchase, $warranty_class, $user_id, + $source, $customer, $cust_vehicle) { // new warranty $warranty = new Warranty(); @@ -94,7 +95,9 @@ class WarrantyHandler ->setMobileNumber($mobile_number) ->setDatePurchase($date_purchase) ->setWarrantyClass($warranty_class) - ->setCreateSource($source); + ->setCreateSource($source) + ->setCustomer($customer) + ->setVehicle($cust_vehicle); $this->em->persist($warranty); $this->em->flush(); @@ -362,7 +365,8 @@ class WarrantyHandler public function cleanPlateNumber($plate) { - // remove spaces and make upper case + // TODO: make this more like Warranty's static cleanPlateNumber? + // remove spaces and make upper case return strtoupper(str_replace(' ', '', $plate)); } From 4a0adef749e7c9933013cb2e44af1b5215754a05 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 18 Jun 2021 07:44:38 +0000 Subject: [PATCH 26/31] Fixed search for customer vehicle. #588 --- src/Controller/APIController.php | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 1d13ad47..15059510 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -3191,8 +3191,8 @@ class APIController extends Controller implements LoggedController { $warr->setCustomer($customer); // get customer vehicles - $vehicle = $this->findCustomerVehicle($customer, $req->request->get('plate_number')); - + + $vehicle = $this->findCustomerVehicle($em, $customer, $req->request->get('plate_number')); if ($vehicle != null) $warr->setVehicle($vehicle); } @@ -3270,20 +3270,23 @@ class APIController extends Controller implements LoggedController return $cust; } - protected function findCustomerVehicle($customer, $plate_number) + protected function findCustomerVehicle($em, $customer, $plate_number) { $clean_plate = Warranty::cleanPlateNumber($plate_number); if ($clean_plate) { // find the customer vehicle and get the vehicle - $cust_vehicles = $customer->getVehicles(); - foreach ($cust_vehicles as $cv) + $cv = $em->getRepository(CustomerVehicle::class)->findOneBy(['plate_number' => $clean_plate]); + if ($cv != null) { - if ($cv->getPlateNumber() == $clean_plate) + // confirm that customer vehicle found does belong to customer + if ($cv->getCustomer() == $customer) { $vehicle = $cv->getVehicle(); return $vehicle; } + else + return null; } } From ceb54afa10296a6a8bee83a8db45ef1295e4d95b Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 18 Jun 2021 08:15:33 +0000 Subject: [PATCH 27/31] Fixed search for customer vehicle. #588 --- src/Controller/APIController.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 15059510..4ada7063 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -3276,7 +3276,7 @@ class APIController extends Controller implements LoggedController if ($clean_plate) { // find the customer vehicle and get the vehicle - $cv = $em->getRepository(CustomerVehicle::class)->findOneBy(['plate_number' => $clean_plate]); + $cv = $em->getRepository(CustomerVehicle::class)->findOneBy(['plate_number' => $clean_plate, 'customer' => $customer]); if ($cv != null) { // confirm that customer vehicle found does belong to customer From 391237f08fb9ff2abbc9a509bb25df18ca1b0032 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Fri, 18 Jun 2021 08:27:47 +0000 Subject: [PATCH 28/31] Remove customer checking. #588 --- src/Controller/APIController.php | 10 ++-------- 1 file changed, 2 insertions(+), 8 deletions(-) diff --git a/src/Controller/APIController.php b/src/Controller/APIController.php index 4ada7063..c718ab1d 100644 --- a/src/Controller/APIController.php +++ b/src/Controller/APIController.php @@ -3279,14 +3279,8 @@ class APIController extends Controller implements LoggedController $cv = $em->getRepository(CustomerVehicle::class)->findOneBy(['plate_number' => $clean_plate, 'customer' => $customer]); if ($cv != null) { - // confirm that customer vehicle found does belong to customer - if ($cv->getCustomer() == $customer) - { - $vehicle = $cv->getVehicle(); - return $vehicle; - } - else - return null; + $vehicle = $cv->getVehicle(); + return $vehicle; } } From 46cc089f485ca6a6c78e5b743692be8fbd088558 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Fri, 18 Jun 2021 21:20:33 +0800 Subject: [PATCH 29/31] Fix rider optimization issue when jo count for hub is 0 #589 --- src/Controller/AnalyticsController.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Controller/AnalyticsController.php b/src/Controller/AnalyticsController.php index 308ef2e6..98ebd399 100644 --- a/src/Controller/AnalyticsController.php +++ b/src/Controller/AnalyticsController.php @@ -466,6 +466,12 @@ class AnalyticsController extends Controller $ids[] = $jo['id']; } + // no jos, so no battery + if (count($ids) <= 0) + { + return 0; + } + // ideally we encode the ids, but right now we're assuming they'll be int $in_text = implode(',', $ids); From 9a7622ed5c8fbac9b5160ed8b5a2e633715b47f0 Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Sun, 20 Jun 2021 01:06:28 +0800 Subject: [PATCH 30/31] Index ticket entity to speed up related ticket fetching #590 --- src/Controller/TicketController.php | 2 +- src/Entity/Ticket.php | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/src/Controller/TicketController.php b/src/Controller/TicketController.php index c79aedd2..b870576e 100644 --- a/src/Controller/TicketController.php +++ b/src/Controller/TicketController.php @@ -314,7 +314,7 @@ class TicketController extends Controller if (empty($obj)) throw $this->createNotFoundException('The item does not exist'); - $em = $this->getDoctrine()->getManager(); + // $em = $this->getDoctrine()->getManager(); $customer = $obj->getCustomer(); $job_order = $obj->getJobOrder(); diff --git a/src/Entity/Ticket.php b/src/Entity/Ticket.php index cdf44ab1..311f8f39 100644 --- a/src/Entity/Ticket.php +++ b/src/Entity/Ticket.php @@ -12,7 +12,11 @@ use DateTime; /** * @ORM\Entity - * @ORM\Table(name="ticket") + * @ORM\Table(name="ticket", indexes={ + * @ORM\Index(columns={"plate_number"}), + * @ORM\Index(columns={"first_name"}, flags={"fulltext"}), + * @ORM\Index(columns={"last_name"}, flags={"fulltext"}) + * }) */ class Ticket { From 1631cacf98688376ebbd30c0e0588f94ac5644ce Mon Sep 17 00:00:00 2001 From: Kendrick Chan Date: Sun, 20 Jun 2021 01:33:02 +0800 Subject: [PATCH 31/31] Optimize query for related tickets - split into 3 separate queries #590 --- src/Controller/TicketController.php | 24 ++++++++++++++++++++++++ src/Entity/Ticket.php | 5 +++-- 2 files changed, 27 insertions(+), 2 deletions(-) diff --git a/src/Controller/TicketController.php b/src/Controller/TicketController.php index b870576e..303b34a6 100644 --- a/src/Controller/TicketController.php +++ b/src/Controller/TicketController.php @@ -337,6 +337,28 @@ class TicketController extends Controller $params['redirect_url'] = $cust_update_url; } + // optimized get related tickets + $rel_tix = []; + // one query for each so we use indeces + if (!empty($obj->getFirstName()) && !empty($obj->getLastName())) + $rel_tix[] = $em->getRepository(Ticket::class)->findBy(['first_name' => $obj->getFirstName(), 'last_name' => $obj->getLastName()]); + if (!empty($obj->getContactNumber())) + $rel_tix[] = $em->getRepository(Ticket::class)->findBy(['contact_num' => $obj->getContactNumber()]); + if (!empty($obj->getPlateNumber())) + $rel_tix[] = $em->getRepository(Ticket::class)->findBy(['plate_number' => $obj->getPlateNumber()]); + + $consolidated_rel_tix = []; + foreach ($rel_tix as $rel_tickets) + { + foreach ($rel_tickets as $rticket) + { + $rtid = $rticket->getID(); + $consolidated_rel_tix[$rtid] = $rticket; + } + } + $params['related_tickets'] = $consolidated_rel_tix; + + /* // get related tickets $qb = $em->getRepository(Ticket::class) ->createQueryBuilder('q'); @@ -353,6 +375,8 @@ class TicketController extends Controller $params['related_tickets'] = $query->getQuery() ->getResult(); + */ + $params['obj'] = $obj; diff --git a/src/Entity/Ticket.php b/src/Entity/Ticket.php index 311f8f39..35882075 100644 --- a/src/Entity/Ticket.php +++ b/src/Entity/Ticket.php @@ -13,9 +13,10 @@ use DateTime; /** * @ORM\Entity * @ORM\Table(name="ticket", indexes={ + * @ORM\Index(columns={"contact_num"}), * @ORM\Index(columns={"plate_number"}), - * @ORM\Index(columns={"first_name"}, flags={"fulltext"}), - * @ORM\Index(columns={"last_name"}, flags={"fulltext"}) + * @ORM\Index(columns={"first_name"}), + * @ORM\Index(columns={"last_name"}) * }) */ class Ticket