diff --git a/src/Command/GetJobOrderArchiveDataCommand.php b/src/Command/GetJobOrderArchiveDataCommand.php index 2aa81c42..061bddc2 100644 --- a/src/Command/GetJobOrderArchiveDataCommand.php +++ b/src/Command/GetJobOrderArchiveDataCommand.php @@ -92,6 +92,7 @@ class GetJobOrderArchiveDataCommand extends Command // special since this is not directly related to JO but to invoice $this->deleteDataFiles('invoice_item'); + $related_files = []; while ($row = $results->fetchAssociative()) { $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->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 $file = $this->createDataFileRelatedArchiveData($jo_data, $jo_tname, 'w'); @@ -159,6 +169,7 @@ class GetJobOrderArchiveDataCommand extends Command $results = $query_stmt->executeQuery(); $data = []; + $files = []; while ($q_row = $results->fetchAssociative()) { @@ -167,7 +178,9 @@ class GetJobOrderArchiveDataCommand extends Command if ($table_name == 'invoice') { // get invoice item related data - $this->getInvoiceItemArchiveData($q_row, $year); + $ii_file = $this->getInvoiceItemArchiveData($q_row, $year); + + $files['invoice_item'] = $ii_file; } $fields = []; @@ -184,53 +197,9 @@ class GetJobOrderArchiveDataCommand extends Command // write the array into the file $file = $this->createDataFileRelatedArchiveData($data, $table_name, 'a'); - // TODO: this needs to move or something because we are writing duplicate rows into the db - if ($file != null) - { - $archive_tname = $table_name . '_archive_' . $year; + $files[$table_name] = $file; - if ($table_name == '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 ($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); - } + return $files; } protected function getInvoiceItemArchiveData($row, $year) @@ -266,16 +235,7 @@ class GetJobOrderArchiveDataCommand extends Command $file = $this->createDataFileRelatedArchiveData($ii_data, 'invoice_item', 'a'); - if ($file != null) - { - $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 - } + return $file; } protected function deleteDataFiles($tname)