Add loading of data files. #762
This commit is contained in:
parent
f52293caa6
commit
a7c6988607
1 changed files with 88 additions and 31 deletions
|
|
@ -65,7 +65,7 @@ class GetJobOrderArchiveDataCommand extends Command
|
|||
FROM job_order
|
||||
WHERE YEAR(date_create) = :year
|
||||
ORDER BY date_create
|
||||
LIMIT 100';
|
||||
LIMIT 100000';
|
||||
|
||||
$query_stmt = $db->prepare($query_sql);
|
||||
$query_stmt->bindValue('year', $year, PDO::PARAM_STR);
|
||||
|
|
@ -92,7 +92,7 @@ class GetJobOrderArchiveDataCommand extends Command
|
|||
// special since this is not directly related to JO but to invoice
|
||||
$this->deleteDataFiles('invoice_item');
|
||||
|
||||
$related_files = [];
|
||||
$archive_files = [];
|
||||
while ($row = $results->fetchAssociative())
|
||||
{
|
||||
$jo_data['job_order'][$row['id']] = $this->createJobOrderArchiveData($row);
|
||||
|
|
@ -120,48 +120,27 @@ class GetJobOrderArchiveDataCommand extends Command
|
|||
$query_stmt = $db->prepare($query_sql);
|
||||
$query_stmt->bindValue('id', $row['id']);
|
||||
|
||||
$files[] = call_user_func($callbackJO, $row, $query_stmt, $table_name, $year);
|
||||
$files = call_user_func($callbackJO, $row, $query_stmt, $table_name, $year);
|
||||
|
||||
// TODO: need to figure out how to get the filenames
|
||||
foreach ($files as $key =>$file)
|
||||
{
|
||||
$related_files[$key] = $file;
|
||||
if ($file != null)
|
||||
$archive_files[$key] = $file;
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
error_log(print_r($related_files, true));
|
||||
|
||||
// write the array into the file
|
||||
$file = $this->createDataFileRelatedArchiveData($jo_data, $jo_tname, 'w');
|
||||
|
||||
if ($file != null)
|
||||
{
|
||||
$archive_tname = $jo_tname . '_archive_' . $year;
|
||||
|
||||
// load statement for job order
|
||||
$load_stmt = 'LOAD DATA LOCAL INFILE \'' . $file . '\' INTO TABLE ' . $archive_tname . '
|
||||
FIELDS TERMINATED BY \'|\'
|
||||
LINES TERMINATED BY \'\\r\\n\'
|
||||
(id, customer_id, cvehicle_id, rider_id, date_create,
|
||||
date_schedule, date_fulfill, @coordinates, flag_advance, service_type,
|
||||
source, date_cancel, status, delivery_instructions, delivery_address,
|
||||
create_user_id, assign_user_id, date_assign, warranty_class, process_user_id,
|
||||
hub_id, cancel_reason, ref_jo_id, tier1_notes, tier2_notes,
|
||||
mode_of_payment, or_name, landmark, promo_detail, or_num,
|
||||
trade_in_type, flag_rider_rating, flag_coolant, facilitated_hub_id, facilitated_type,
|
||||
coord_long, coord_lat, priority, meta, status_autoassign,
|
||||
first_name, last_name, plate_number, phone_mobile, no_trade_in_reason,
|
||||
will_wait, reason_not_waiting, not_waiting_notes, delivery_status, emergency_type_id,
|
||||
ownership_type_id, cust_location_id, source_of_awareness, remarks, initial_concern,
|
||||
initial_concern_notes, gender, caller_classification, inventory_count)
|
||||
SET coordinates=ST_GeomFromText(@geo_coordinates)';
|
||||
|
||||
// call load data infile
|
||||
$this->loadDataFileForArchiveData($load_stmt);
|
||||
$archive_files[$jo_tname] = $file;
|
||||
}
|
||||
|
||||
// error_log(print_r($archive_files, true));
|
||||
$this->loadArchiveFiles($archive_files, $year);
|
||||
}
|
||||
|
||||
protected function getRelatedArchiveData($row, $query_stmt, $table_name, $year)
|
||||
|
|
@ -197,7 +176,8 @@ class GetJobOrderArchiveDataCommand extends Command
|
|||
// write the array into the file
|
||||
$file = $this->createDataFileRelatedArchiveData($data, $table_name, 'a');
|
||||
|
||||
$files[$table_name] = $file;
|
||||
if ($file != null)
|
||||
$files[$table_name] = $file;
|
||||
|
||||
return $files;
|
||||
}
|
||||
|
|
@ -679,6 +659,83 @@ class GetJobOrderArchiveDataCommand extends Command
|
|||
return $data;
|
||||
}
|
||||
|
||||
protected function loadArchiveFiles($archive_files, $year)
|
||||
{
|
||||
foreach ($archive_files as $tname => $file)
|
||||
{
|
||||
$archive_tname = $tname . '_archive_' . $year;
|
||||
|
||||
if ($tname == 'job_order')
|
||||
{
|
||||
// load statement for job order
|
||||
$load_stmt = 'LOAD DATA LOCAL INFILE \'' . $file . '\' INTO TABLE ' . $archive_tname . '
|
||||
FIELDS TERMINATED BY \'|\'
|
||||
LINES TERMINATED BY \'\\r\\n\'
|
||||
(id, customer_id, cvehicle_id, rider_id, date_create,
|
||||
date_schedule, date_fulfill, @coordinates, flag_advance, service_type,
|
||||
source, date_cancel, status, delivery_instructions, delivery_address,
|
||||
create_user_id, assign_user_id, date_assign, warranty_class, process_user_id,
|
||||
hub_id, cancel_reason, ref_jo_id, tier1_notes, tier2_notes,
|
||||
mode_of_payment, or_name, landmark, promo_detail, or_num,
|
||||
trade_in_type, flag_rider_rating, flag_coolant, facilitated_hub_id, facilitated_type,
|
||||
coord_long, coord_lat, priority, meta, status_autoassign,
|
||||
first_name, last_name, plate_number, phone_mobile, no_trade_in_reason,
|
||||
will_wait, reason_not_waiting, not_waiting_notes, delivery_status, emergency_type_id,
|
||||
ownership_type_id, cust_location_id, source_of_awareness, remarks, initial_concern,
|
||||
initial_concern_notes, gender, caller_classification, inventory_count)
|
||||
SET coordinates=ST_GeomFromText(@geo_coordinates)';
|
||||
}
|
||||
if ($tname == 'jo_event')
|
||||
{
|
||||
$load_stmt = 'LOAD DATA LOCAL INFILE \'' . $file . '\' INTO TABLE ' . $archive_tname . '
|
||||
FIELDS TERMINATED BY \'|\'
|
||||
LINES TERMINATED BY \'\\r\\n\'
|
||||
(id, create_user_id, job_order_id, date_create, date_happen, type_id, rider_id)';
|
||||
}
|
||||
if ($tname == 'jo_rejection')
|
||||
{
|
||||
$load_stmt = 'LOAD DATA LOCAL INFILE \'' . $file . '\' INTO TABLE ' . $archive_tname . '
|
||||
FIELDS TERMINATED BY \'|\'
|
||||
LINES TERMINATED BY \'\\r\\n\'
|
||||
(id, user_id, hub_id, jo_id, date_create, reason, remarks, contact_person)';
|
||||
}
|
||||
if ($tname == 'invoice')
|
||||
{
|
||||
$load_stmt = 'LOAD DATA LOCAL INFILE \'' . $file . '\' INTO TABLE ' . $archive_tname . '
|
||||
FIELDS TERMINATED BY \'|\'
|
||||
LINES TERMINATED BY \'\\r\\n\'
|
||||
(id, user_id, job_order_id, date_create, date_paid, discount, trade_in, vat, vat_exclusive_price,
|
||||
total_price, status, promo_id, used_customer_tag_id)';
|
||||
}
|
||||
if ($tname == 'rider_rating')
|
||||
{
|
||||
$load_stmt = 'LOAD DATA LOCAL INFILE \'' . $file . '\' INTO TABLE ' . $archive_tname . '
|
||||
FIELDS TERMINATED BY \'|\'
|
||||
LINES TERMINATED BY \'\\r\\n\'
|
||||
(id, rider_id, customer_id, jo_id, date_create, rating, comment)';
|
||||
}
|
||||
if ($tname == 'ticket')
|
||||
{
|
||||
$load_stmt = 'LOAD DATA LOCAL INFILE \'' . $file . '\' INTO TABLE ' . $archive_tname . '
|
||||
FIELDS TERMINATED BY \'|\'
|
||||
LINES TERMINATED BY \'\\r\\n\'
|
||||
(id, user_id, customer_id, date_create, status, ticket_type, other_ticket_type, first_name, last_name,
|
||||
contact_num, details, job_order_id, plate_number, ticket_type_id, subticket_type_id,
|
||||
source_of_awareness, remarks, other_description)';
|
||||
}
|
||||
if ($tname == 'invoice_item')
|
||||
{
|
||||
$load_stmt = 'LOAD DATA LOCAL INFILE \'' . $file . '\' INTO TABLE ' . $archive_tname . '
|
||||
FIELDS TERMINATED BY \'|\'
|
||||
LINES TERMINATED BY \'\\r\\n\'
|
||||
(id, invoice_id, title, qty, price, battery_id)';
|
||||
}
|
||||
|
||||
// call load data infile
|
||||
$this->loadDataFileForArchiveData($load_stmt);
|
||||
}
|
||||
}
|
||||
|
||||
protected function loadDataFileForArchiveData($load_stmt)
|
||||
{
|
||||
$conn = $this->em->getConnection();
|
||||
|
|
|
|||
Loading…
Reference in a new issue