Add retrieval of ids for deletion. #762

This commit is contained in:
Korina Cordero 2023-09-26 13:03:47 +08:00
parent fde9b367ec
commit e65083bc4c

View file

@ -66,7 +66,7 @@ class GetJobOrderArchiveDataCommand extends Command
FROM job_order FROM job_order
WHERE YEAR(date_create) = :year WHERE YEAR(date_create) = :year
ORDER BY date_create ORDER BY date_create
LIMIT 125000'; LIMIT 100000';
$query_stmt = $db->prepare($query_sql); $query_stmt = $db->prepare($query_sql);
$query_stmt->bindValue('year', $year, PDO::PARAM_STR); $query_stmt->bindValue('year', $year, PDO::PARAM_STR);
@ -151,6 +151,14 @@ class GetJobOrderArchiveDataCommand extends Command
// error_log(print_r($archive_files, true)); // error_log(print_r($archive_files, true));
$this->loadArchiveFiles($archive_files, $year); $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) protected function getRelatedArchiveData($row, $query_stmt, $table_name, $year)
@ -256,7 +264,7 @@ class GetJobOrderArchiveDataCommand extends Command
$cache_dir = __DIR__ . '/../../var/cache'; $cache_dir = __DIR__ . '/../../var/cache';
$file = $cache_dir . '/' . $table_name . '_archive.tab'; $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); $fp = fopen($file, $option);
if ($fp === false) 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) protected function loadDataFileForArchiveData($load_stmt)
{ {
$conn = $this->em->getConnection(); $conn = $this->em->getConnection();