diff --git a/app/Config/Routes.php b/app/Config/Routes.php index 1130749..f9eb141 100644 --- a/app/Config/Routes.php +++ b/app/Config/Routes.php @@ -211,13 +211,13 @@ $routes->group('certificates', function($routes) { // Untuk Index Tiap Menu $routes->get('maintenance', 'Certificates::maintenanceIndex'); // OK - // $routes->get('installation', 'Certificates::installationIndex'); // OK + $routes->get('installation', 'Certificates::installationIndex'); // OK // $routes->get('training', 'Certificates::trainingIndex'); // OK // $routes->get('calibration', 'Certificates::calibrateIndex'); // OK // Untuk Get API $routes->get('api/getindexmaintenance', 'Certificates::getDataIndexMaintenance'); // OK - // $routes->get('api/getindexinstallation', 'Certificates::getDataIndexInstallation'); // OK + $routes->get('api/getindexinstallation', 'Certificates::getDataIndexInstallation'); // OK // $routes->get('api/getindextraining', 'Certificates::getDataIndexTraining'); // OK // $routes->get('api/getindexcalibrate', 'Certificates::getDataIndexCalibrate'); diff --git a/app/Controllers/Activities.php b/app/Controllers/Activities.php index 8e4f977..7586f4c 100644 --- a/app/Controllers/Activities.php +++ b/app/Controllers/Activities.php @@ -1666,6 +1666,7 @@ class Activities extends Controller { return view('invtrans_index', $data); } + // Untuk CRUD Sertifikat Maintenance public function createCertificateMaintenance ($actid, $issuedDate, $userid_owner) { $db = \Config\Database::connect(); @@ -1789,4 +1790,6 @@ class Activities extends Controller { $certificateModel->where('actid', $actid)->delete(); } + + } \ No newline at end of file diff --git a/app/Controllers/Certificates.php b/app/Controllers/Certificates.php index 03abb9b..77ff1d0 100644 --- a/app/Controllers/Certificates.php +++ b/app/Controllers/Certificates.php @@ -15,62 +15,54 @@ class Certificates extends BaseController { protected array $data; - // Untuk Sertifikat Instalasi [1] + // Untuk Sertifikat Instalasi (BAI) [1] public function installationIndex() { // Index return view('certificate_installation_index'); } public function getDataIndexInstallation() { // Untuk API Get Data - // $actid = $this->request->getVar('actid'); Siapa Tahu Buat - - $certificates = [ - [ - 'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11914', - 'certname' => 'Jokoh Calibration Certificate', - 'productname' => 'Jokoh', - 'productnumber' => 'SN-2024-001', - 'issuedate' => '2024-01-15', - 'expirydate' => '2025-01-15', - 'vendor' => 'Summit Calibration Lab', - 'isval' => null - ], - [ - 'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11915', - 'certname' => 'Electrical Safety Test', - 'productname' => 'GE Healthcare VIVID', - 'productnumber' => 'GE-VIV-Q992', - 'issuedate' => '2024-06-12', - 'expirydate' => '2026-03-01', - 'vendor' => 'Pramita Medika Service', - 'isval' => '2026-03-01' - ], - [ - 'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11915', - 'certname' => 'Electrical Safety Test', - 'productname' => 'GE Healthcare VIVID', - 'productnumber' => 'GE-VIV-Q992', - 'issuedate' => '2024-06-12', - 'expirydate' => '2026-10-01', - 'vendor' => 'Pramita Medika Service', - 'isval' => '2026-09-01' - ], - [ - 'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11915', - 'certname' => 'Electrical Safety Test', - 'productname' => 'GE Healthcare VIVID', - 'productnumber' => 'GE-VIV-Q992', - 'issuedate' => '2024-06-12', - 'expirydate' => '2026-01-01', - 'vendor' => 'Pramita Medika Service', - 'isval' => '2026-09-01' - ], - ]; + $userPosId = session()->get('userposid'); + $userId = session()->get('userid'); - // If no actid, return all certificates - if (empty($certificates)) { - return $this->response->setJSON(null); + $certificateModel = new CertificateModel(); + + // 1. Mulai Query Builder + $builder = $certificateModel->select(' + certificates.cert_id, + certificates.cert_number, + certificates.cert_name, + certificates.cert_type, + certificates.actid, + certificates.issued_date, + certificates.expired_date, + certificates.status, + certificates.user_validation_at, + certificates.spv_validation_at, + certificates.manager_validation_at, + activities.subject as activity_subject, + CONCAT(users.firstname, " ", users.lastname) as fullname + ') + ->join('activities', 'activities.actid = certificates.actid', 'left') + ->join('users', 'users.userid = certificates.user_id', 'left') + ->where('certificates.cert_type', 'BAI'); + + // 2. Filter berdasarkan Role + if (in_array($userPosId, [1, 3, 5])) { // Manager & IT: Tidak perlu filter tambahan (lihat semua) + } else if ($userPosId == 2) { // SPV: Melihat data user yang "reportto"-nya adalah ID supervisor ini + $builder->where('users.reportto', $userId); + } else if ($userPosId == 4) { // TSOIVD: Hanya melihat data milik sendiri + $builder->where('certificates.user_id', $userId); + } else {// Role lain: Tidak diberi akses + return $this->response->setJSON([]); } - return $this->response->setJSON($certificates); + // 3. Eksekusi Query + $allData = $builder->findAll(); + + if (empty($allData)) { + return $this->response->setJSON([]); // Kembalikan array kosong agar frontend tidak error + } + + return $this->response->setJSON($allData); } public function createinstallationPreview($certid = null) { // Untuk Preview Sertifikat //Melakukan search data dari database @@ -126,7 +118,8 @@ class Certificates extends BaseController { CONCAT(users.firstname, " ", users.lastname) as fullname ') ->join('activities', 'activities.actid = certificates.actid', 'left') - ->join('users', 'users.userid = certificates.user_id', 'left'); + ->join('users', 'users.userid = certificates.user_id', 'left') + ->where('certificates.cert_type', 'MC');; // 2. Filter berdasarkan Role if (in_array($userPosId, [1, 3, 5])) { // Manager & IT: Tidak perlu filter tambahan (lihat semua) @@ -268,133 +261,133 @@ class Certificates extends BaseController { // Untuk Sertifikat Training [3] - public function trainingIndex() { - return view('certificate_training_index'); - } - public function getDataIndexTraining() { - // $actid = $this->request->getVar('actid'); + // public function trainingIndex() { + // return view('certificate_training_index'); + // } + // public function getDataIndexTraining() { + // // $actid = $this->request->getVar('actid'); - // Sample data - replace with actual database query - $certificates = [ - [ - 'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11919', - 'certname' => 'Jokoh Calibration Certificate', - 'productname' => 'Jokoh', - 'productnumber' => 'SN-2024-001', - 'issuedate' => '2024-01-15', - 'expirydate' => '2025-01-15', - 'vendor' => 'Summit Calibration Lab', - 'isval' => null - ], - [ - 'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11919', - 'certname' => 'Electrical Safety Test', - 'productname' => 'GE Healthcare VIVID', - 'productnumber' => 'GE-VIV-Q992', - 'issuedate' => '2024-06-12', - 'expirydate' => '2026-10-01', - 'vendor' => 'Pramita Medika Service', - 'isval' => '2026-03-01' - ] - ]; + // // Sample data - replace with actual database query + // $certificates = [ + // [ + // 'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11919', + // 'certname' => 'Jokoh Calibration Certificate', + // 'productname' => 'Jokoh', + // 'productnumber' => 'SN-2024-001', + // 'issuedate' => '2024-01-15', + // 'expirydate' => '2025-01-15', + // 'vendor' => 'Summit Calibration Lab', + // 'isval' => null + // ], + // [ + // 'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11919', + // 'certname' => 'Electrical Safety Test', + // 'productname' => 'GE Healthcare VIVID', + // 'productnumber' => 'GE-VIV-Q992', + // 'issuedate' => '2024-06-12', + // 'expirydate' => '2026-10-01', + // 'vendor' => 'Pramita Medika Service', + // 'isval' => '2026-03-01' + // ] + // ]; - // If no actid, return all certificates - if (empty($certificates)) { - return $this->response->setJSON(null); - } + // // If no actid, return all certificates + // if (empty($certificates)) { + // return $this->response->setJSON(null); + // } - return $this->response->setJSON($certificates); - } - public function createTrainingPreview($certid = null) { // Untuk Preview Sertifikat - //Melakukan search data dari database + // return $this->response->setJSON($certificates); + // } + // public function createTrainingPreview($certid = null) { // Untuk Preview Sertifikat + // //Melakukan search data dari database - if (!$certid) { - return $this->response->setStatusCode(400)->setJSON(['error' => 'Certificate ID is required']); - } + // if (!$certid) { + // return $this->response->setStatusCode(400)->setJSON(['error' => 'Certificate ID is required']); + // } - // Get certificate data Berdasarkan certid - $certificate = [ - 'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11919', - 'certname' => 'Jokoh Calibration Certificate', - 'productname' => 'Jokoh', - 'productnumber' => 'SN-2024-001', - 'issuedate' => '2024-01-15', - 'expirydate' => '2025-01-15', - 'vendor' => 'Summit Calibration Lab', - 'isval' => null - ]; + // // Get certificate data Berdasarkan certid + // $certificate = [ + // 'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11919', + // 'certname' => 'Jokoh Calibration Certificate', + // 'productname' => 'Jokoh', + // 'productnumber' => 'SN-2024-001', + // 'issuedate' => '2024-01-15', + // 'expirydate' => '2025-01-15', + // 'vendor' => 'Summit Calibration Lab', + // 'isval' => null + // ]; - if (empty($certificate)) { // JIka Tidak Ada - return $this->response->setStatusCode(404)->setJSON(['error' => 'Maintenance certificate not found']); - } + // if (empty($certificate)) { // JIka Tidak Ada + // return $this->response->setStatusCode(404)->setJSON(['error' => 'Maintenance certificate not found']); + // } - return $this->previewPdf($certificate, 'training'); // Preview PDF - } + // return $this->previewPdf($certificate, 'training'); // Preview PDF + // } // Untuk Sertifikat Calibrate [4] - public function calibrateIndex() { - return view('certificate_calibrate_index'); - } - public function getDataIndexCalibrate() { - // $actid = $this->request->getVar('actid'); + // public function calibrateIndex() { + // return view('certificate_calibrate_index'); + // } + // public function getDataIndexCalibrate() { + // // $actid = $this->request->getVar('actid'); - // Sample data - replace with actual database query - $certificates = [ - [ - 'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11919', - 'certname' => 'Jokoh Calibration Certificate', - 'productname' => 'Jokoh', - 'productnumber' => 'SN-2024-001', - 'issuedate' => '2024-01-15', - 'expirydate' => '2025-01-15', - 'vendor' => 'Summit Calibration Lab', - 'isval' => null - ], - [ - 'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11919', - 'certname' => 'Electrical Safety Test', - 'productname' => 'GE Healthcare VIVID', - 'productnumber' => 'GE-VIV-Q992', - 'issuedate' => '2024-06-12', - 'expirydate' => '2026-10-01', - 'vendor' => 'Pramita Medika Service', - 'isval' => '2026-03-01' - ] - ]; + // // Sample data - replace with actual database query + // $certificates = [ + // [ + // 'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11919', + // 'certname' => 'Jokoh Calibration Certificate', + // 'productname' => 'Jokoh', + // 'productnumber' => 'SN-2024-001', + // 'issuedate' => '2024-01-15', + // 'expirydate' => '2025-01-15', + // 'vendor' => 'Summit Calibration Lab', + // 'isval' => null + // ], + // [ + // 'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11919', + // 'certname' => 'Electrical Safety Test', + // 'productname' => 'GE Healthcare VIVID', + // 'productnumber' => 'GE-VIV-Q992', + // 'issuedate' => '2024-06-12', + // 'expirydate' => '2026-10-01', + // 'vendor' => 'Pramita Medika Service', + // 'isval' => '2026-03-01' + // ] + // ]; - // If no actid, return all certificates - if (empty($certificates)) { - return $this->response->setJSON(null); - } + // // If no actid, return all certificates + // if (empty($certificates)) { + // return $this->response->setJSON(null); + // } - return $this->response->setJSON($certificates); - } - public function createCalibratePreview($certid = null) { // Untuk Preview Sertifikat - //Melakukan search data dari database + // return $this->response->setJSON($certificates); + // } + // public function createCalibratePreview($certid = null) { // Untuk Preview Sertifikat + // //Melakukan search data dari database - if (!$certid) { - return $this->response->setStatusCode(400)->setJSON(['error' => 'Certificate ID is required']); - } + // if (!$certid) { + // return $this->response->setStatusCode(400)->setJSON(['error' => 'Certificate ID is required']); + // } - // Get certificate data Berdasarkan certid - $certificate = [ - 'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11919', - 'certname' => 'Jokoh Calibration Certificate', - 'productname' => 'Jokoh', - 'productnumber' => 'SN-2024-001', - 'issuedate' => '2024-01-15', - 'expirydate' => '2025-01-15', - 'vendor' => 'Summit Calibration Lab', - 'isval' => null - ]; + // // Get certificate data Berdasarkan certid + // $certificate = [ + // 'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11919', + // 'certname' => 'Jokoh Calibration Certificate', + // 'productname' => 'Jokoh', + // 'productnumber' => 'SN-2024-001', + // 'issuedate' => '2024-01-15', + // 'expirydate' => '2025-01-15', + // 'vendor' => 'Summit Calibration Lab', + // 'isval' => null + // ]; - if (empty($certificate)) { // JIka Tidak Ada - return $this->response->setStatusCode(404)->setJSON(['error' => 'Maintenance certificate not found']); - } + // if (empty($certificate)) { // JIka Tidak Ada + // return $this->response->setStatusCode(404)->setJSON(['error' => 'Maintenance certificate not found']); + // } - return $this->previewPdf($certificate, 'calibrate', 'tms24i'); // Preview PDF - } + // return $this->previewPdf($certificate, 'calibrate', 'tms24i'); // Preview PDF + // } // Helper Function Preview dan Validate diff --git a/app/Views/activities_editor.php b/app/Views/activities_editor.php index 2227a64..0bff096 100644 --- a/app/Views/activities_editor.php +++ b/app/Views/activities_editor.php @@ -223,7 +223,7 @@ if(isset($data)) { Calibration Certificate - + -->
| No | -Certificate Name | -Product/Equipment | -Type | -Issue Date | -Expiry Date | -Status | -Vendor | -Action | -
|---|---|---|---|---|---|---|---|---|
| = $no++; ?> | -
- = htmlspecialchars($certname) ?>
- - ID: = $certid ?> - |
-
- = htmlspecialchars($productname) ?>
-
- SN: = htmlspecialchars($productnumber) ?> - - |
- = $typeBadge ?> | -= $issuedate ?> | -= $expirydate ?> | -= $statusBadge ?> | -= htmlspecialchars($vendor) ?> | -
-
-
-
-
- |
-
| Certificate Name | -Product/Equipment | -Activity Report | -Issue Date | -Expiry Date | -Status | -Action | +Certificate | +Act Report | +Issue Date | +Validation | +Action |
|---|
| No | -Certificate Name | -Product/Equipment | -Type | -Issue Date | -Expiry Date | -Status | -Vendor | -Action | -
|---|---|---|---|---|---|---|---|---|
| = $no++; ?> | -
- = htmlspecialchars($certname) ?>
- - ID: = $certid ?> - |
-
- = htmlspecialchars($productname) ?>
-
- SN: = htmlspecialchars($productnumber) ?> - - |
- = $typeBadge ?> | -= $issuedate ?> | -= $expirydate ?> | -= $statusBadge ?> | -= htmlspecialchars($vendor) ?> | -
-
-
-
-
-
- |
-
|
-
- No certificates found - - |
- ||||||||