From b102ba657c1b4c44b9b05925d399f977f5eaebcd Mon Sep 17 00:00:00 2001 From: mahdahar <89adham@gmail.com> Date: Thu, 5 Mar 2026 09:59:02 +0700 Subject: [PATCH] Add ISPDF flag endpoint and dashboard indicator - Add POST /api/requests/{accessnumber}/pdf endpoint (no auth required) - Add setPdfFlag() method to update CM_REQUESTS.ISPDF to 1 - Log PDF_FLAG events to AUDIT_EVENTS table - Include ISPDF field in dashboard API response - Add PDF icon indicator in dashboard table (after Val column) - Icon shows green when ISPDF=1, gray when null/0 - Pass accessnumber to PDF spooler for tracking Files modified: - app/Config/Routes.php: Add external PDF endpoint route - app/Controllers/RequestsController.php: Add setPdfFlag method, include ISPDF in query - app/Controllers/ReportController.php: Pass accessnumber to spooler - app/Libraries/PdfHelper.php: Pass accessnumber to spooler - app/Views/shared/content_requests.php: Add PDF column with icon --- app/Config/Routes.php | 3 +++ app/Controllers/ReportController.php | 10 +++++++--- app/Controllers/RequestsController.php | 25 +++++++++++++++++++++---- app/Libraries/PdfHelper.php | 15 +++++++++++---- app/Views/shared/content_requests.php | 16 +++++++++------- 5 files changed, 51 insertions(+), 18 deletions(-) diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 616728e..963faa7 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -108,5 +108,8 @@ $routes->group('report', ['filter' => 'role:0,1,2,4'], function ($routes) { $routes->get('report/status/(:any)', 'ReportController::checkPdfStatus/$1'); +// External PDF generator endpoint - no auth required +$routes->post('api/requests/(:any)/pdf', 'RequestsController::setPdfFlag/$1'); + // Keep backward compatibility - updated filter $routes->get('print/(:num)', 'ReportController::generate/$1', ['filter' => 'role:0,1,2,3,4']); diff --git a/app/Controllers/ReportController.php b/app/Controllers/ReportController.php index 74c0435..afeea21 100644 --- a/app/Controllers/ReportController.php +++ b/app/Controllers/ReportController.php @@ -118,8 +118,8 @@ class ReportController extends BaseController $filename = $accessnumber . ($eng == 1 ? '_eng' : '') . '.pdf'; $collectionDate = $data['collectionDate'] ?? ''; - try { - $jobId = $this->postToSpooler($html, $filename, $collectionDate); +try { + $jobId = $this->postToSpooler($html, $filename, $collectionDate, $accessnumber); $sqlCheck = "SELECT COUNT(*) as cnt FROM GDC_CMOD.dbo.AUDIT_REQUESTS WHERE ACCESSNUMBER = ? AND STEPTYPE IN ('GEN_PDF', 'REGEN_PDF')"; @@ -171,7 +171,7 @@ class ReportController extends BaseController return $this->response->setJSON($response); } - private function postToSpooler($html, $filename, $collectionDate = '') + private function postToSpooler($html, $filename, $collectionDate = '', $accessnumber = '') { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://glenlis:3000/api/pdf/generate'); @@ -186,6 +186,10 @@ class ReportController extends BaseController $payload['collectionDate'] = $collectionDate; } + if ($accessnumber) { + $payload['accessnumber'] = $accessnumber; + } + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ diff --git a/app/Controllers/RequestsController.php b/app/Controllers/RequestsController.php index 31f2ec3..2585218 100644 --- a/app/Controllers/RequestsController.php +++ b/app/Controllers/RequestsController.php @@ -16,13 +16,13 @@ class RequestsController extends BaseController // Only allow Lab role (role 2) if ($userroleid == 2) { - $sql = "SELECT d.*, r.REPORT_LANG from GDC_CMOD.dbo.V_DASHBOARD_DEV d + $sql = "SELECT d.*, r.REPORT_LANG, r.ISPDF from GDC_CMOD.dbo.V_DASHBOARD_DEV d LEFT JOIN GDC_CMOD.dbo.CM_REQUESTS r ON r.ACCESSNUMBER=d.SP_ACCESSNUMBER where d.COLLECTIONDATE between '$date1 00:00' and '$date2 23:59' and d.ODR_DDATE between '$date1 00:00' and '$date2 23:59' and (d.TESTS IS NOT NULL AND d.TESTS like '%[A-Za-z]%')"; } else { - $sql = "SELECT d.*, r.REPORT_LANG from GDC_CMOD.dbo.V_DASHBOARD_DEV d + $sql = "SELECT d.*, r.REPORT_LANG, r.ISPDF from GDC_CMOD.dbo.V_DASHBOARD_DEV d LEFT JOIN GDC_CMOD.dbo.CM_REQUESTS r ON r.ACCESSNUMBER=d.SP_ACCESSNUMBER where d.COLLECTIONDATE between '$date1 00:00' and '$date2 23:59' and d.ODR_DDATE between '$date1 00:00' and '$date2 23:59'"; @@ -176,9 +176,10 @@ class RequestsController extends BaseController curl_setopt($ch, CURLOPT_URL, 'http://glenlis:3000/api/pdf/generate'); curl_setopt($ch, CURLOPT_POST, 1); - $payload = [ +$payload = [ 'html' => $html, - 'filename' => $filename + 'filename' => $filename, + 'accessnumber' => $accessnumber ]; if (!empty($data['collectionDate'])) { @@ -216,4 +217,20 @@ class RequestsController extends BaseController 'message' => 'English PDF queued for generation' ]; } + + public function setPdfFlag(string $accessnumber): \CodeIgniter\HTTP\ResponseInterface + { + $db = \Config\Database::connect(); + + $sql = "UPDATE GDC_CMOD.dbo.CM_REQUESTS SET ISPDF = 1 WHERE ACCESSNUMBER = ?"; + $db->query($sql, [$accessnumber]); + + $logAudit = "INSERT INTO GDC_CMOD.dbo.AUDIT_EVENTS (ACCESSNUMBER, EVENT_TYPE, USERID, EVENT_AT) VALUES (?, 'PDF_FLAG', 'SYSTEM', GETDATE())"; + $db->query($logAudit, [$accessnumber]); + + return $this->response->setJSON([ + 'status' => 'success', + 'accessnumber' => $accessnumber + ]); + } } diff --git a/app/Libraries/PdfHelper.php b/app/Libraries/PdfHelper.php index 44ee894..4a1eb0a 100644 --- a/app/Libraries/PdfHelper.php +++ b/app/Libraries/PdfHelper.php @@ -21,18 +21,25 @@ class PdfHelper $html = view('report/template', $data); $filename = $accessnumber . ($eng == 1 ? '_eng' : '') . '.pdf'; - return $this->postHtmlToSpooler($html, $filename); + return $this->postHtmlToSpooler($html, $filename, $accessnumber); } - public function postHtmlToSpooler(string $html, string $filename): string + public function postHtmlToSpooler(string $html, string $filename, string $accessnumber = ''): string { $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, 'http://glenlis:3000/api/pdf/generate'); curl_setopt($ch, CURLOPT_POST, 1); - curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode([ + + $payload = [ 'html' => $html, 'filename' => $filename - ])); + ]; + + if ($accessnumber) { + $payload['accessnumber'] = $accessnumber; + } + + curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($payload)); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HTTPHEADER, [ 'Content-Type: application/json' diff --git a/app/Views/shared/content_requests.php b/app/Views/shared/content_requests.php index a9184e6..dab02e4 100644 --- a/app/Views/shared/content_requests.php +++ b/app/Views/shared/content_requests.php @@ -185,6 +185,7 @@
2:
+