This commit expands report generation capabilities to Customer Service (CS) role
and refactors the report system for better maintainability and PDF support.
Changes Summary:
Access Control:
- Extended report access from Lab, Admin, Superuser to include CS role (filter: 0,1,2,4)
- Removed separate CS-only print routes, consolidated into unified report routes
- Routes now support /report/:num, /report/:num/eng, /report/:num/print, /report/:num/print/eng
Controller Refactoring (ReportController):
- Refactored generate() and print() methods to share common renderReport() logic
- Removed separate preview() method - preview now handled via preview parameter
- Added ispdf parameter support for PDF generation mode
- Print functionality now logs audit events to AUDIT_REQUESTS table
Database Queries (ReportHelper):
- Improved SQL queries with explicit aliases for better readability and maintainability
- Fixed date formatting issue: changed date_format() to date() with strtotime()
- Added getValData() method to retrieve validation user information (VAL1USER, VAL2USER)
- Added null coalescing operators (?? '') for safer array access
View Updates (report/template.php):
- Conditional CSS loading: uses pdf.css when ispdf=1, otherwise style.css
- Removed "PREVIEW ONLY - DO NOT PRINT" watermark
- Conditional header/footer images - only display when generating PDF
- Added validation user display: "Val1 By : {user} | Val2 By : {user}"
- Replaced signature placeholder with "This result is valid without signature" statement
- Improved footer layout spacing
Styling Adjustments (public/assets/report/style.css):
- Adjusted margins for better print layout: dinfo (2cm), dresult (17.5cm), footer (2cm)
- Increased footer width from 17cm to 18cm
- Added responsive image classes: .img and .img-footer with max-width: 100%
- Set footer image max-height to 2.5cm
Security:
- Maintained role-based access control with proper authentication checks
- All database queries use parameterized statements (no interpolation)
- Print actions still logged to AUDIT_REQUESTS for audit trail
62 lines
1.8 KiB
PHP
62 lines
1.8 KiB
PHP
<?php
|
|
namespace App\Controllers;
|
|
|
|
use App\Controllers\BaseController;
|
|
|
|
class ReportController extends BaseController
|
|
{
|
|
protected $db;
|
|
protected $reportHelper;
|
|
|
|
public function __construct()
|
|
{
|
|
$this->db = \Config\Database::connect();
|
|
$this->reportHelper = new \App\Libraries\ReportHelper($this->db);
|
|
helper(['url', 'text']);
|
|
}
|
|
|
|
public function generate($accessnumber, $eng = 0, $ispdf = 0)
|
|
{
|
|
if ($ispdf == 0) {
|
|
$ispdf = $this->request->getVar('ispdf') ?? 0;
|
|
}
|
|
|
|
return $this->renderReport($accessnumber, $eng, $ispdf, false);
|
|
}
|
|
|
|
public function print($accessnumber, $eng = 0, $ispdf = 0)
|
|
{
|
|
if ($ispdf == 0) {
|
|
$ispdf = $this->request->getVar('ispdf') ?? 0;
|
|
}
|
|
|
|
return $this->renderReport($accessnumber, $eng, $ispdf, true);
|
|
}
|
|
|
|
private function renderReport($accessnumber, $eng, $ispdf, $shouldLog)
|
|
{
|
|
$userroleid = session()->get('userroleid');
|
|
if (!in_array($userroleid, [0, 1, 2, 4])) {
|
|
return $this->response->setStatusCode(403)->setJSON(['message' => 'Unauthorized']);
|
|
}
|
|
|
|
$data = $this->reportHelper->getReportData($accessnumber, $eng);
|
|
$data['eng'] = $eng;
|
|
$data['accessnumber'] = $accessnumber;
|
|
$data['ispdf'] = $ispdf;
|
|
|
|
if ($shouldLog == true) {
|
|
$this->logPrintAudit($accessnumber, $data['status']);
|
|
}
|
|
|
|
return view('report/template', $data);
|
|
}
|
|
|
|
private function logPrintAudit($accessnumber, $status)
|
|
{
|
|
$sql = "INSERT INTO GDC_CMOD.dbo.AUDIT_REQUESTS(ACCESSNUMBER, STEPDATE, STEPTYPE, STEPSTATUS)
|
|
VALUES(?, GETDATE(), 'PRINT', ?)";
|
|
$this->db->query($sql, [$accessnumber, $status]);
|
|
}
|
|
}
|