Fix load file issue. #762
This commit is contained in:
parent
3773a664d1
commit
f52293caa6
1 changed files with 18 additions and 58 deletions
|
|
@ -92,6 +92,7 @@ class GetJobOrderArchiveDataCommand extends Command
|
||||||
// special since this is not directly related to JO but to invoice
|
// special since this is not directly related to JO but to invoice
|
||||||
$this->deleteDataFiles('invoice_item');
|
$this->deleteDataFiles('invoice_item');
|
||||||
|
|
||||||
|
$related_files = [];
|
||||||
while ($row = $results->fetchAssociative())
|
while ($row = $results->fetchAssociative())
|
||||||
{
|
{
|
||||||
$jo_data['job_order'][$row['id']] = $this->createJobOrderArchiveData($row);
|
$jo_data['job_order'][$row['id']] = $this->createJobOrderArchiveData($row);
|
||||||
|
|
@ -119,11 +120,20 @@ class GetJobOrderArchiveDataCommand extends Command
|
||||||
$query_stmt = $db->prepare($query_sql);
|
$query_stmt = $db->prepare($query_sql);
|
||||||
$query_stmt->bindValue('id', $row['id']);
|
$query_stmt->bindValue('id', $row['id']);
|
||||||
|
|
||||||
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;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
error_log(print_r($related_files, true));
|
||||||
|
|
||||||
// write the array into the file
|
// write the array into the file
|
||||||
$file = $this->createDataFileRelatedArchiveData($jo_data, $jo_tname, 'w');
|
$file = $this->createDataFileRelatedArchiveData($jo_data, $jo_tname, 'w');
|
||||||
|
|
||||||
|
|
@ -159,6 +169,7 @@ class GetJobOrderArchiveDataCommand extends Command
|
||||||
$results = $query_stmt->executeQuery();
|
$results = $query_stmt->executeQuery();
|
||||||
|
|
||||||
$data = [];
|
$data = [];
|
||||||
|
$files = [];
|
||||||
|
|
||||||
while ($q_row = $results->fetchAssociative())
|
while ($q_row = $results->fetchAssociative())
|
||||||
{
|
{
|
||||||
|
|
@ -167,7 +178,9 @@ class GetJobOrderArchiveDataCommand extends Command
|
||||||
if ($table_name == 'invoice')
|
if ($table_name == 'invoice')
|
||||||
{
|
{
|
||||||
// get invoice item related data
|
// get invoice item related data
|
||||||
$this->getInvoiceItemArchiveData($q_row, $year);
|
$ii_file = $this->getInvoiceItemArchiveData($q_row, $year);
|
||||||
|
|
||||||
|
$files['invoice_item'] = $ii_file;
|
||||||
}
|
}
|
||||||
|
|
||||||
$fields = [];
|
$fields = [];
|
||||||
|
|
@ -184,53 +197,9 @@ class GetJobOrderArchiveDataCommand extends Command
|
||||||
// write the array into the file
|
// write the array into the file
|
||||||
$file = $this->createDataFileRelatedArchiveData($data, $table_name, 'a');
|
$file = $this->createDataFileRelatedArchiveData($data, $table_name, 'a');
|
||||||
|
|
||||||
// TODO: this needs to move or something because we are writing duplicate rows into the db
|
$files[$table_name] = $file;
|
||||||
if ($file != null)
|
|
||||||
{
|
|
||||||
$archive_tname = $table_name . '_archive_' . $year;
|
|
||||||
|
|
||||||
if ($table_name == 'jo_event')
|
return $files;
|
||||||
{
|
|
||||||
$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 ($table_name == '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 ($table_name == '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 ($table_name == '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 ($table_name == '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)';
|
|
||||||
}
|
|
||||||
|
|
||||||
// call load data infile
|
|
||||||
$this->loadDataFileForArchiveData($load_stmt);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function getInvoiceItemArchiveData($row, $year)
|
protected function getInvoiceItemArchiveData($row, $year)
|
||||||
|
|
@ -266,16 +235,7 @@ class GetJobOrderArchiveDataCommand extends Command
|
||||||
|
|
||||||
$file = $this->createDataFileRelatedArchiveData($ii_data, 'invoice_item', 'a');
|
$file = $this->createDataFileRelatedArchiveData($ii_data, 'invoice_item', 'a');
|
||||||
|
|
||||||
if ($file != null)
|
return $file;
|
||||||
{
|
|
||||||
$archive_tname = 'invoice_item_archive' . $year;
|
|
||||||
|
|
||||||
$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
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected function deleteDataFiles($tname)
|
protected function deleteDataFiles($tname)
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue