From b2b39b72e1448f2e028f1b7c7a6abdd0f160e934 Mon Sep 17 00:00:00 2001 From: Korina Cordero Date: Tue, 26 Sep 2023 13:03:47 +0800 Subject: [PATCH] Add retrieval of ids for deletion. #762 --- src/Command/GetJobOrderArchiveDataCommand.php | 45 ++++++++++++++++++- 1 file changed, 43 insertions(+), 2 deletions(-) diff --git a/src/Command/GetJobOrderArchiveDataCommand.php b/src/Command/GetJobOrderArchiveDataCommand.php index 7303b79a..d6ba4582 100644 --- a/src/Command/GetJobOrderArchiveDataCommand.php +++ b/src/Command/GetJobOrderArchiveDataCommand.php @@ -66,7 +66,7 @@ class GetJobOrderArchiveDataCommand extends Command FROM job_order WHERE YEAR(date_create) = :year ORDER BY date_create - LIMIT 125000'; + LIMIT 100000'; $query_stmt = $db->prepare($query_sql); $query_stmt->bindValue('year', $year, PDO::PARAM_STR); @@ -151,6 +151,14 @@ class GetJobOrderArchiveDataCommand extends Command // error_log(print_r($archive_files, true)); $this->loadArchiveFiles($archive_files, $year); + + // need to get the list of invoice ids for deletion for invoice items + $invoice_id_list = $this->getInvoiceIds($jo_id_list); + + error_log(print_r($invoice_id_list, true)); + + // at this point, all the job order and related data have been archived into the database + $this->deleteData($jo_id_list, $invoice_id_list); } protected function getRelatedArchiveData($row, $query_stmt, $table_name, $year) @@ -256,7 +264,7 @@ class GetJobOrderArchiveDataCommand extends Command $cache_dir = __DIR__ . '/../../var/cache'; $file = $cache_dir . '/' . $table_name . '_archive.tab'; - error_log('opening file for archive - ' . $file); + // error_log('opening file for archive - ' . $file); $fp = fopen($file, $option); if ($fp === false) @@ -753,6 +761,39 @@ class GetJobOrderArchiveDataCommand extends Command } } + protected function deleteData($jo_id_list, $invoice_id_list) + { + $db = $this->em->getConnection(); + + // delete the invoice items first + } + + protected function getInvoiceIds($jo_id_list) + { + $invoice_id_list = []; + + $db = $this->em->getConnection(); + + $query_sql = 'SELECT id FROM invoice WHERE job_order_id = :id'; + + $query_stmt = $db->prepare($query_sql); + + foreach ($jo_id_list as $jo_id) + { + // need to get the invoice ids for the invoice items to delete + $query_stmt->bindValue('id', $jo_id); + + $results = $query_stmt->executeQuery(); + + while ($row = $results->fetchAssociative()) + { + $invoice_id_list[] = $row['id']; + } + } + + return $invoice_id_list; + } + protected function loadDataFileForArchiveData($load_stmt) { $conn = $this->em->getConnection();