Modify warranty creation to be done by load data infile. #654
This commit is contained in:
parent
31e2088b6a
commit
c8208df0f3
2 changed files with 52 additions and 11 deletions
|
|
@ -11,6 +11,8 @@ doctrine:
|
|||
driver: 'pdo_mysql'
|
||||
server_version: '5.7'
|
||||
charset: utf8mb4
|
||||
options:
|
||||
!php/const PDO::MYSQL_ATTR_LOCAL_INFILE: true
|
||||
|
||||
# With Symfony 3.3, remove the `resolve:` prefix
|
||||
url: '%env(resolve:DATABASE_URL)%'
|
||||
|
|
|
|||
|
|
@ -93,12 +93,11 @@ class FulfillOpenJobOrderCommand extends Command
|
|||
$total_jos = count($jo_results);
|
||||
|
||||
$jo_ctr = 0;
|
||||
$running_jo_total = 0;
|
||||
$running_jo_event_total = 0;
|
||||
$update_jo_ctr = 0;
|
||||
$update_wheres = [];
|
||||
$create_jo_event_ctr = 0;
|
||||
$jo_event_values = '';
|
||||
$w_data = [];
|
||||
|
||||
foreach ($jo_results as $jo_row)
|
||||
{
|
||||
|
|
@ -128,10 +127,14 @@ class FulfillOpenJobOrderCommand extends Command
|
|||
$batt_id = $this->getBatteryInformation($conn, $jo_id);
|
||||
|
||||
if (($batt_id != null) && (isset($this->batt_hash[$batt_id])))
|
||||
$this->createWarrantyForJO($conn, $current_date, $str_date_schedule, $cust_id, $cv_id, $warranty_class, $batt_id);
|
||||
$w_data[] = $this->createWarrantyForJO($conn, $current_date, $str_date_schedule, $cust_id, $cv_id, $warranty_class, $batt_id);
|
||||
}
|
||||
}
|
||||
|
||||
// TODO: make data file too for JO event creation
|
||||
|
||||
$this->createLoadDataFileForWarranty($w_data);
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
|
@ -268,7 +271,10 @@ class FulfillOpenJobOrderCommand extends Command
|
|||
$date_expire = $this->computeDateExpire($date_schedule, $warranty_period);
|
||||
|
||||
// convert to string the expiry date
|
||||
$str_date_expire = $date_expire->format('Y-m-d H:i:s');
|
||||
$str_date_expire = $date_expire->format('Y-m-d');
|
||||
|
||||
// convert date schedule to just date
|
||||
$str_date_purchase = $date_schedule->format('Y-m-d');
|
||||
|
||||
// check if date_expire is after or equal to the current date
|
||||
// if so, set warranty status to active
|
||||
|
|
@ -298,9 +304,8 @@ class FulfillOpenJobOrderCommand extends Command
|
|||
if (isset($this->sap_batt_hash['sap_code']))
|
||||
$sap_code = $this->batt_hash[$batt_id]['sap_code'];
|
||||
else
|
||||
$sap_code = 'NULL';
|
||||
$sap_code = '\N';
|
||||
|
||||
/*
|
||||
// create array for the infile
|
||||
$warranty_data = [
|
||||
$model_id,
|
||||
|
|
@ -310,17 +315,18 @@ class FulfillOpenJobOrderCommand extends Command
|
|||
$plate_number,
|
||||
$warranty_status,
|
||||
$str_current_date,
|
||||
$str_date_schedule,
|
||||
$str_date_purchase,
|
||||
$str_date_expire,
|
||||
$first_name,
|
||||
$last_name,
|
||||
$mobile,
|
||||
1,
|
||||
$vehicle_id,
|
||||
$cust_id,
|
||||
$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')
|
||||
|
|
@ -342,8 +348,41 @@ class FulfillOpenJobOrderCommand extends Command
|
|||
|
||||
$stmt = $conn->prepare($sql_statement);
|
||||
$stmt->execute();
|
||||
*/
|
||||
|
||||
// $this->createLoadDataFileForWarranty($warranty_data);
|
||||
return $warranty_data;
|
||||
}
|
||||
|
||||
protected function createLoadDataFileForWarranty($warranty_data)
|
||||
{
|
||||
// cache directory
|
||||
$cache_dir = __DIR__ . '/../../var/cache';
|
||||
|
||||
$file = $cache_dir . '/warranty_data.tab';
|
||||
error_log('opening file for warranty - ' . $file);
|
||||
|
||||
$fp = fopen($file, 'w');
|
||||
if ($fp === false)
|
||||
{
|
||||
error_log('could not open file for load data infile - ' . $file);
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach ($warranty_data as $key => $data)
|
||||
{
|
||||
$line = implode('|', $data) . "\r\n";
|
||||
fwrite($fp, $line);
|
||||
}
|
||||
}
|
||||
|
||||
fclose($fp);
|
||||
|
||||
error_log('Loading warranty data');
|
||||
$conn = $this->em->getConnection();
|
||||
$stmt = $conn->prepare('LOAD DATA LOCAL INFILE \'' . $file . '\' INTO TABLE warranty FIELDS TERMINATED BY \'|\' LINES TERMINATED BY \'\\r\\n\' (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)');
|
||||
$result = $stmt->execute();
|
||||
if (!$result)
|
||||
error_log('Failed loading data.');
|
||||
}
|
||||
|
||||
protected function getCustomerInfo($conn, $id)
|
||||
|
|
|
|||
Loading…
Reference in a new issue