Change jo event creation. #654
This commit is contained in:
parent
c8208df0f3
commit
941f59ab6e
1 changed files with 54 additions and 64 deletions
|
|
@ -29,8 +29,7 @@ use DateInterval;
|
||||||
class FulfillOpenJobOrderCommand extends Command
|
class FulfillOpenJobOrderCommand extends Command
|
||||||
{
|
{
|
||||||
const DEFAULT_SAP_WARRANTY = 12;
|
const DEFAULT_SAP_WARRANTY = 12;
|
||||||
const JO_BATCH_CTR = 500;
|
const JO_BATCH_CTR = 200;
|
||||||
const JO_EVENT_BATCH_CTR = 500;
|
|
||||||
|
|
||||||
protected $em;
|
protected $em;
|
||||||
protected $batt_hash;
|
protected $batt_hash;
|
||||||
|
|
@ -95,9 +94,8 @@ class FulfillOpenJobOrderCommand extends Command
|
||||||
$jo_ctr = 0;
|
$jo_ctr = 0;
|
||||||
$update_jo_ctr = 0;
|
$update_jo_ctr = 0;
|
||||||
$update_wheres = [];
|
$update_wheres = [];
|
||||||
$create_jo_event_ctr = 0;
|
|
||||||
$jo_event_values = '';
|
|
||||||
$w_data = [];
|
$w_data = [];
|
||||||
|
$jo_evt_data = [];
|
||||||
|
|
||||||
foreach ($jo_results as $jo_row)
|
foreach ($jo_results as $jo_row)
|
||||||
{
|
{
|
||||||
|
|
@ -116,7 +114,7 @@ class FulfillOpenJobOrderCommand extends Command
|
||||||
$this->fulfillJO($conn, $jo_id, $update_jo_ctr, $update_wheres, $jo_ctr, $total_jos);
|
$this->fulfillJO($conn, $jo_id, $update_jo_ctr, $update_wheres, $jo_ctr, $total_jos);
|
||||||
|
|
||||||
// create JO event
|
// create JO event
|
||||||
$this->createJOEvent($conn, $jo_id, $str_current_date, $rider_id, $create_jo_event_ctr, $jo_event_values, $jo_ctr, $total_jos);
|
$jo_evt_data[] = $this->createJOEvent($conn, $jo_id, $str_current_date, $rider_id);
|
||||||
|
|
||||||
// error_log($jo_ctr . ' Processing JO ' . $jo_id);
|
// error_log($jo_ctr . ' Processing JO ' . $jo_id);
|
||||||
|
|
||||||
|
|
@ -131,8 +129,10 @@ class FulfillOpenJobOrderCommand extends Command
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO: make data file too for JO event creation
|
// load data file for jo event
|
||||||
|
$this->createLoadDataFileForJOEvent($jo_evt_data);
|
||||||
|
|
||||||
|
// load data file for warranty
|
||||||
$this->createLoadDataFileForWarranty($w_data);
|
$this->createLoadDataFileForWarranty($w_data);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
|
|
@ -172,50 +172,28 @@ class FulfillOpenJobOrderCommand extends Command
|
||||||
$update_jo_ctr++;
|
$update_jo_ctr++;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function createJOEvent($conn, $jo_id, $str_current_date, $rider_id, &$create_jo_event_ctr, &$jo_event_value_string,
|
protected function createJOEvent($conn, $jo_id, $str_current_date, $rider_id)
|
||||||
$jo_ctr, $total_jos)
|
|
||||||
{
|
{
|
||||||
// create jo event
|
// create jo event
|
||||||
// set user to admin that has id of 1
|
// set user to admin that has id of 1
|
||||||
$user_id = 1;
|
$user_id = 1;
|
||||||
|
|
||||||
$r_id = 'NULL';
|
$r_id = '\N';
|
||||||
// need to check rider id if null since that will change the jo_event_values
|
|
||||||
// check if rider is null
|
// check if rider is null
|
||||||
if ($rider_id != NULL)
|
if ($rider_id != NULL)
|
||||||
$r_id = $rider_id;
|
$r_id = $rider_id;
|
||||||
|
|
||||||
// need to check rider id if null since that will change the jo_event_values
|
// create array for the jo event
|
||||||
$jo_event_values = '(' . $user_id . ',' . $jo_id . ',\'' . $str_current_date . '\',\'' . $str_current_date . '\',\'' . JOEventType::FULFILL . '\',' . $r_id . ')';
|
$data = [
|
||||||
|
$user_id,
|
||||||
|
$jo_id,
|
||||||
|
$str_current_date,
|
||||||
|
$str_current_date,
|
||||||
|
JOEventType::FULFILL,
|
||||||
|
$r_id,
|
||||||
|
];
|
||||||
|
|
||||||
if (strlen($jo_event_value_string) == 0)
|
return $data;
|
||||||
{
|
|
||||||
// first entry to insert, no comma before
|
|
||||||
$jo_event_value_string = $jo_event_values;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
// need to insert a comma after the existing string
|
|
||||||
$jo_event_value_string = $jo_event_value_string . ',' . $jo_event_values;
|
|
||||||
}
|
|
||||||
|
|
||||||
// insert to db when we reach max # of JOs or when we reach total number of jos
|
|
||||||
if (($create_jo_event_ctr == self::JO_EVENT_BATCH_CTR) ||
|
|
||||||
($jo_ctr == $total_jos))
|
|
||||||
{
|
|
||||||
$create_jo_event_sql = 'INSERT into `jo_event` (create_user_id, job_order_id, date_create, date_happen, type_id, rider_id) VALUES ' . $jo_event_value_string . ';' . "\n";
|
|
||||||
|
|
||||||
// error_log($create_jo_event_sql);
|
|
||||||
|
|
||||||
$create_jo_event_stmt = $conn->prepare($create_jo_event_sql);
|
|
||||||
$create_jo_event_stmt->execute();
|
|
||||||
|
|
||||||
// reset the counter and value string
|
|
||||||
$jo_event_value_string = '';
|
|
||||||
$create_jo_event_ctr = 0;
|
|
||||||
}
|
|
||||||
else
|
|
||||||
$create_jo_event_ctr++;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getBatteryInformation($conn, $jo_id)
|
protected function getBatteryInformation($conn, $jo_id)
|
||||||
|
|
@ -326,30 +304,6 @@ class FulfillOpenJobOrderCommand extends Command
|
||||||
WarrantySource::ADMIN_PANEL,
|
WarrantySource::ADMIN_PANEL,
|
||||||
];
|
];
|
||||||
|
|
||||||
/*
|
|
||||||
// populate the values string for the values to be inserted into warranty
|
|
||||||
// check for sap_code. Not all batteries have sap_code
|
|
||||||
if ($sap_code == 'NULL')
|
|
||||||
{
|
|
||||||
$value_string = '(' . $model_id . ',' . $size_id . ',' . $sap_code . ',\'' . $warranty_class . '\',\''
|
|
||||||
. $plate_number . '\',\'' . $warranty_status . '\',\'' . $str_current_date . '\',\'' . $str_date_schedule
|
|
||||||
. '\',\'' . $str_date_expire . '\',\'' . $first_name . '\',\'' . $last_name . '\',\'' . $mobile . '\',' . 1 . ',' . $vehicle_id . ',' . $cust_id . ',\'' . WarrantySource::ADMIN_PANEL . '\')';
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
$value_string = '(' . $model_id . ',' . $size_id . ',\'' . $sap_code . '\',\'' . $warranty_class . '\',\''
|
|
||||||
. $plate_number . '\',\'' . $warranty_status . '\',\'' . $str_current_date . '\',\'' . $str_date_schedule
|
|
||||||
. '\',\'' . $str_date_expire . '\',\'' . $first_name . '\',\'' . $last_name . '\',\'' . $mobile . '\',' . 1 . ',' . $vehicle_id . ',' . $cust_id . ',\'' . WarrantySource::ADMIN_PANEL . '\')';
|
|
||||||
}
|
|
||||||
|
|
||||||
$sql_statement = 'INSERT INTO `warranty` (bty_model_id,bty_size_id,sap_bty_id,warranty_class,plate_number,status,date_create,date_purchase,date_expire,first_name,last_name,mobile_number,flag_activated,vehicle_id,customer_id, create_source) VALUES ' . $value_string . ';' . "\n";
|
|
||||||
|
|
||||||
// error_log($sql_statement);
|
|
||||||
|
|
||||||
$stmt = $conn->prepare($sql_statement);
|
|
||||||
$stmt->execute();
|
|
||||||
*/
|
|
||||||
|
|
||||||
return $warranty_data;
|
return $warranty_data;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -383,6 +337,42 @@ class FulfillOpenJobOrderCommand extends Command
|
||||||
$result = $stmt->execute();
|
$result = $stmt->execute();
|
||||||
if (!$result)
|
if (!$result)
|
||||||
error_log('Failed loading data.');
|
error_log('Failed loading data.');
|
||||||
|
|
||||||
|
// TODO: delete file?
|
||||||
|
}
|
||||||
|
|
||||||
|
protected function createLoadDataFileForJOEvent($jo_evt_data)
|
||||||
|
{
|
||||||
|
// cache directory
|
||||||
|
$cache_dir = __DIR__ . '/../../var/cache';
|
||||||
|
|
||||||
|
$file = $cache_dir . '/jo_event_data.tab';
|
||||||
|
error_log('opening file for jo_event - ' . $file);
|
||||||
|
|
||||||
|
$fp = fopen($file, 'w');
|
||||||
|
if ($fp === false)
|
||||||
|
{
|
||||||
|
error_log('could not open file for load data infile - ' . $file);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
foreach ($jo_evt_data as $key => $data)
|
||||||
|
{
|
||||||
|
$line = implode('|', $data) . "\r\n";
|
||||||
|
fwrite($fp, $line);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fclose($fp);
|
||||||
|
|
||||||
|
error_log('Loading jo event data');
|
||||||
|
$conn = $this->em->getConnection();
|
||||||
|
$stmt = $conn->prepare('LOAD DATA LOCAL INFILE \'' . $file . '\' INTO TABLE jo_event FIELDS TERMINATED BY \'|\' LINES TERMINATED BY \'\\r\\n\' (create_user_id, job_order_id, date_create, date_happen, type_id, rider_id)');
|
||||||
|
$result = $stmt->execute();
|
||||||
|
if (!$result)
|
||||||
|
error_log('Failed loading data.');
|
||||||
|
|
||||||
|
// TODO: delete file?
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getCustomerInfo($conn, $id)
|
protected function getCustomerInfo($conn, $id)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue