Update Maintenance Done
This commit is contained in:
parent
3aef3dff96
commit
2553db6d5d
@ -209,28 +209,26 @@ $routes->get('/guidebook/delete/(:num)', 'Guidebook::delete/$1');
|
|||||||
// Certificates
|
// Certificates
|
||||||
$routes->group('certificates', function($routes) {
|
$routes->group('certificates', function($routes) {
|
||||||
|
|
||||||
// Untuk Index
|
|
||||||
$routes->get('/', 'Certificates::index');
|
|
||||||
|
|
||||||
// Untuk Index Tiap Menu
|
// Untuk Index Tiap Menu
|
||||||
$routes->get('maintenance', 'Certificates::maintenanceIndex');
|
$routes->get('maintenance', 'Certificates::maintenanceIndex'); // OK
|
||||||
|
$routes->get('installation', 'Certificates::installationIndex');
|
||||||
$routes->get('training', 'Certificates::trainingIndex');
|
$routes->get('training', 'Certificates::trainingIndex');
|
||||||
$routes->get('calibration', 'Certificates::calibrateIndex');
|
$routes->get('calibration', 'Certificates::calibrateIndex');
|
||||||
|
|
||||||
$routes->get('api/getindexmaintenance', 'Certificates::getDataIndexMaintenance');
|
|
||||||
|
$routes->get('api/getindexmaintenance', 'Certificates::getDataIndexMaintenance'); // OK
|
||||||
$routes->get('api/getindextraining', 'Certificates::getDataIndexTraining');
|
$routes->get('api/getindextraining', 'Certificates::getDataIndexTraining');
|
||||||
|
|
||||||
|
|
||||||
$routes->post('api/validate', 'Certificates::validateCertificate');
|
$routes->post('api/validateCertificate', 'Certificates::validateCertificate'); // OK
|
||||||
|
$routes->post('api/generatepdf', 'Certificates::generatePdf'); // OK
|
||||||
|
|
||||||
|
|
||||||
// Untuk View Cerificate
|
// Untuk View Cerificate
|
||||||
|
$routes->get('maintenance/show/(:any)', 'Certificates::createMaintenancePreview/$1'); // OK
|
||||||
$routes->get('training/show/(:any)', 'Certificates::createTraining/$1');
|
$routes->get('training/show/(:any)', 'Certificates::createTraining/$1');
|
||||||
$routes->get('calibration/show/(:any)/(:any)', 'Certificates::createCalibrate/$1/$2');
|
$routes->get('calibration/show/(:any)/(:any)', 'Certificates::createCalibrate/$1/$2');
|
||||||
$routes->get('maintenance/show/(:any)', 'Certificates::createMaintenance/$1');
|
|
||||||
|
|
||||||
// $routes->get('view/(:any)', 'Certificates::view/$1');
|
|
||||||
// $routes->get('get/(:any)', 'Certificates::get/$1');
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@ -10,118 +10,27 @@ class Certificates extends BaseController {
|
|||||||
|
|
||||||
protected array $data;
|
protected array $data;
|
||||||
|
|
||||||
// Halaman Utama
|
// Untuk Sertifikat Instalasi [1]
|
||||||
public function maintenanceIndex() {
|
public function installationIndex() { // Index
|
||||||
|
return view('certificate_installation_index');
|
||||||
|
}
|
||||||
|
public function getDataIndexInstallation() { // Untuk API Get Data
|
||||||
|
// $actid = $this->request->getVar('actid'); Siapa Tahu Buat
|
||||||
|
}
|
||||||
|
public function createinstallationPreview($certid = null) { // Untuk Preview Sertifikat
|
||||||
|
//Melakukan search data dari database
|
||||||
|
}
|
||||||
|
|
||||||
|
// Untuk Sertifikat Maintenance [2]
|
||||||
|
public function maintenanceIndex() { // Index
|
||||||
return view('certificate_maintenance_index');
|
return view('certificate_maintenance_index');
|
||||||
}
|
}
|
||||||
public function trainingIndex() {
|
public function getDataIndexMaintenance() { // Untuk API Get Data
|
||||||
return view('certificate_training_index');
|
// $actid = $this->request->getVar('actid'); Siapa Tahu Buat
|
||||||
}
|
|
||||||
public function calibrateIndex() {
|
|
||||||
|
|
||||||
$certificates = [
|
|
||||||
// [
|
|
||||||
// 'certid' => 'CERT001',
|
|
||||||
// 'certname' => 'TMS50i Calibration Certificate',
|
|
||||||
// 'productname' => 'tms50i',
|
|
||||||
// 'productnumber' => 'SN-2024-001',
|
|
||||||
// 'type' => 'calibration',
|
|
||||||
// 'issuedate' => '2024-01-15',
|
|
||||||
// 'expirydate' => '2025-01-15',
|
|
||||||
// 'vendor' => 'Summit Calibration Lab',
|
|
||||||
// 'description' => 'Annual calibration certificate for TMS50i equipment.'
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'certid' => 'CERT002',
|
|
||||||
// 'certname' => 'TMS24i Calibration Certificate',
|
|
||||||
// 'productname' => 'tms24i',
|
|
||||||
// 'productnumber' => 'SN-2024-002',
|
|
||||||
// 'type' => 'calibration',
|
|
||||||
// 'issuedate' => '2024-01-16',
|
|
||||||
// 'expirydate' => '2025-01-16',
|
|
||||||
// 'vendor' => 'Summit Calibration Lab',
|
|
||||||
// 'description' => 'Annual calibration certificate for tms24i equipment.'
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'certid' => 'CERT003',
|
|
||||||
// 'certname' => 'tms30i Calibration Certificate',
|
|
||||||
// 'productname' => 'tms30i',
|
|
||||||
// 'productnumber' => 'SN-2024-003',
|
|
||||||
// 'type' => 'calibration',
|
|
||||||
// 'issuedate' => '2024-01-17',
|
|
||||||
// 'expirydate' => '2025-01-17',
|
|
||||||
// 'vendor' => 'Summit Calibration Lab',
|
|
||||||
// 'description' => 'Annual calibration certificate for tms30i equipment.'
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'certid' => 'CERT004',
|
|
||||||
// 'certname' => 'BS430 Calibration Certificate',
|
|
||||||
// 'productname' => 'bs430',
|
|
||||||
// 'productnumber' => 'SN-2024-004',
|
|
||||||
// 'type' => 'calibration',
|
|
||||||
// 'issuedate' => '2024-01-18',
|
|
||||||
// 'expirydate' => '2025-01-18',
|
|
||||||
// 'vendor' => 'Summit Calibration Lab',
|
|
||||||
// 'description' => 'Annual calibration certificate for BS430 equipment.'
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'certid' => 'CERT005',
|
|
||||||
// 'certname' => 'CL900i Calibration Certificate',
|
|
||||||
// 'productname' => 'cl900i',
|
|
||||||
// 'productnumber' => 'SN-2024-005',
|
|
||||||
// 'type' => 'calibration',
|
|
||||||
// 'issuedate' => '2024-01-19',
|
|
||||||
// 'expirydate' => '2025-01-19',
|
|
||||||
// 'vendor' => 'Summit Calibration Lab',
|
|
||||||
// 'description' => 'Annual calibration certificate for CL900i equipment.'
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'certid' => 'CERT006',
|
|
||||||
// 'certname' => 'Jokoh Calibration Certificate',
|
|
||||||
// 'productname' => 'jokoh',
|
|
||||||
// 'productnumber' => 'SN-2024-006',
|
|
||||||
// 'type' => 'calibration',
|
|
||||||
// 'issuedate' => '2024-01-20',
|
|
||||||
// 'expirydate' => '2025-01-20',
|
|
||||||
// 'vendor' => 'Summit Calibration Lab',
|
|
||||||
// 'description' => 'Annual calibration certificate for Jokoh equipment.'
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'certid' => 'CERT007',
|
|
||||||
// 'certname' => 'BC760R Calibration Certificate',
|
|
||||||
// 'productname' => 'bc760r',
|
|
||||||
// 'productnumber' => 'SN-2024-007',
|
|
||||||
// 'type' => 'calibration',
|
|
||||||
// 'issuedate' => '2024-01-21',
|
|
||||||
// 'expirydate' => '2025-01-21',
|
|
||||||
// 'vendor' => 'Summit Calibration Lab',
|
|
||||||
// 'description' => 'Annual calibration certificate for BC760R equipment.'
|
|
||||||
// ],
|
|
||||||
// [
|
|
||||||
// 'certid' => 'CERT008',
|
|
||||||
// 'certname' => 'BC5140 Calibration Certificate',
|
|
||||||
// 'productname' => 'bc5140',
|
|
||||||
// 'productnumber' => 'SN-2024-008',
|
|
||||||
// 'type' => 'calibration',
|
|
||||||
// 'issuedate' => '2024-01-22',
|
|
||||||
// 'expirydate' => '2025-01-22',
|
|
||||||
// 'vendor' => 'Summit Calibration Lab',
|
|
||||||
// 'description' => 'Annual calibration certificate for BC5140 equipment.'
|
|
||||||
// ],
|
|
||||||
];
|
|
||||||
|
|
||||||
$data = ['certificates' => $certificates];
|
|
||||||
return view('certificate_calibration_index', $data);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
// Untuk API Get Data
|
|
||||||
public function getDataIndexMaintenance() {
|
|
||||||
// $actid = $this->request->getVar('actid');
|
|
||||||
|
|
||||||
$certificates = [
|
$certificates = [
|
||||||
[
|
[
|
||||||
'certid' => 'CERT001',
|
'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11914',
|
||||||
'certname' => 'Jokoh Calibration Certificate',
|
'certname' => 'Jokoh Calibration Certificate',
|
||||||
'productname' => 'Jokoh',
|
'productname' => 'Jokoh',
|
||||||
'productnumber' => 'SN-2024-001',
|
'productnumber' => 'SN-2024-001',
|
||||||
@ -131,69 +40,17 @@ class Certificates extends BaseController {
|
|||||||
'isval' => null
|
'isval' => null
|
||||||
],
|
],
|
||||||
[
|
[
|
||||||
'certid' => 'CERT002',
|
'certid' => 'f353ca91-4fc5-49f2-9b9e-304f83d11915',
|
||||||
'certname' => 'Installation Certificate - Sysmex XN',
|
|
||||||
'productname' => 'Sysmex',
|
|
||||||
'productnumber' => 'XN-1000-5521',
|
|
||||||
'issuedate' => '2024-02-10',
|
|
||||||
'expirydate' => '2026-02-10',
|
|
||||||
'vendor' => 'Global Medika Indonesia',
|
|
||||||
'isval' => '2026-03-01'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'certid' => 'CERT003',
|
|
||||||
'certname' => 'Maintenance Certificate Q3',
|
|
||||||
'productname' => 'Mindray BC-5380',
|
|
||||||
'productnumber' => 'MR-5380-BC88',
|
|
||||||
'issuedate' => '2024-03-05',
|
|
||||||
'expirydate' => '2024-09-05',
|
|
||||||
'vendor' => 'Citra Sehat Teknik',
|
|
||||||
'isval' => '2026-03-01'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'certid' => 'CERT004',
|
|
||||||
'certname' => 'User Training - Hematology Analyzer',
|
|
||||||
'productname' => 'Beckman Coulter',
|
|
||||||
'productnumber' => 'BC-DXH-900',
|
|
||||||
'issuedate' => '2024-05-20',
|
|
||||||
'expirydate' => '2027-05-20',
|
|
||||||
'vendor' => 'Bio-Rad Laboratories',
|
|
||||||
'isval' => '2026-03-01'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'certid' => 'CERT005',
|
|
||||||
'certname' => 'Electrical Safety Test',
|
'certname' => 'Electrical Safety Test',
|
||||||
'productname' => 'GE Healthcare VIVID',
|
'productname' => 'GE Healthcare VIVID',
|
||||||
'productnumber' => 'GE-VIV-Q992',
|
'productnumber' => 'GE-VIV-Q992',
|
||||||
'issuedate' => '2024-06-12',
|
'issuedate' => '2024-06-12',
|
||||||
'expirydate' => '2026-03-01',
|
'expirydate' => '2026-10-01',
|
||||||
'vendor' => 'Pramita Medika Service',
|
'vendor' => 'Pramita Medika Service',
|
||||||
'isval' => '2026-03-01'
|
'isval' => '2026-03-01'
|
||||||
],
|
|
||||||
[
|
|
||||||
'certid' => 'CERT005',
|
|
||||||
'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' => null
|
|
||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
// If actid is provided, return specific certificate
|
|
||||||
// if ($actid) {
|
|
||||||
// $result = null;
|
|
||||||
// foreach ($certificates as $cert) {
|
|
||||||
// if ($cert['certid'] === $actid) {
|
|
||||||
// $result = $cert;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return $this->response->setJSON($result);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// If no actid, return all certificates
|
// If no actid, return all certificates
|
||||||
if (empty($certificates)) {
|
if (empty($certificates)) {
|
||||||
return $this->response->setJSON(null);
|
return $this->response->setJSON(null);
|
||||||
@ -201,6 +58,36 @@ class Certificates extends BaseController {
|
|||||||
|
|
||||||
return $this->response->setJSON($certificates);
|
return $this->response->setJSON($certificates);
|
||||||
}
|
}
|
||||||
|
public function createMaintenancePreview($certid = null) { // Untuk Preview Sertifikat
|
||||||
|
//Melakukan search data dari database
|
||||||
|
|
||||||
|
if (!$certid) {
|
||||||
|
return $this->response->setStatusCode(400)->setJSON(['error' => 'Certificate ID is required']);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get certificate data Berdasarkan certid
|
||||||
|
$certificate = [
|
||||||
|
'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
|
||||||
|
];
|
||||||
|
|
||||||
|
if (empty($certificate)) { // JIka Tidak Ada
|
||||||
|
return $this->response->setStatusCode(404)->setJSON(['error' => 'Maintenance certificate not found']);
|
||||||
|
}
|
||||||
|
|
||||||
|
return $this->previewPdf($certificate, 'maintenance'); // Preview PDF
|
||||||
|
}
|
||||||
|
|
||||||
|
// Untuk Sertifikat Training [3]
|
||||||
|
public function trainingIndex() {
|
||||||
|
return view('certificate_training_index');
|
||||||
|
}
|
||||||
public function getDataIndexTraining() {
|
public function getDataIndexTraining() {
|
||||||
// $actid = $this->request->getVar('actid');
|
// $actid = $this->request->getVar('actid');
|
||||||
|
|
||||||
@ -244,18 +131,6 @@ class Certificates extends BaseController {
|
|||||||
]
|
]
|
||||||
];
|
];
|
||||||
|
|
||||||
// If actid is provided, return specific certificate
|
|
||||||
// if ($actid) {
|
|
||||||
// $result = null;
|
|
||||||
// foreach ($certificates as $cert) {
|
|
||||||
// if ($cert['certid'] === $actid) {
|
|
||||||
// $result = $cert;
|
|
||||||
// break;
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
// return $this->response->setJSON($result);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// If no actid, return all certificates
|
// If no actid, return all certificates
|
||||||
if (empty($certificates)) {
|
if (empty($certificates)) {
|
||||||
return $this->response->setJSON(null);
|
return $this->response->setJSON(null);
|
||||||
@ -264,253 +139,14 @@ class Certificates extends BaseController {
|
|||||||
return $this->response->setJSON($certificates);
|
return $this->response->setJSON($certificates);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Untuk Sertifikat Calibrate [4]
|
||||||
public function validateCertificate() {
|
public function calibrateIndex() {
|
||||||
$certid = $this->request->getPost('certid');
|
return view('certificate_calibration_index');
|
||||||
|
|
||||||
if (!$certid) {
|
|
||||||
return $this->response->setJSON([
|
|
||||||
'success' => false,
|
|
||||||
'message' => 'Certificate ID is required'
|
|
||||||
]);
|
|
||||||
}
|
|
||||||
|
|
||||||
return $this->response->setJSON([
|
|
||||||
'success' => true,
|
|
||||||
'message' => 'Certificate validated successfully'
|
|
||||||
// 'validationDate' => $validationDate
|
|
||||||
]);
|
|
||||||
|
|
||||||
// try {
|
|
||||||
// $db = \Config\Database::connect();
|
|
||||||
// $builder = $db->table('certificates');
|
|
||||||
|
|
||||||
// $certificate = $builder->where('certid', $certid)->get()->getRowArray();
|
|
||||||
|
|
||||||
// if (!$certificate) {
|
|
||||||
// return $this->response->setJSON([
|
|
||||||
// 'success' => false,
|
|
||||||
// 'message' => 'Certificate not found'
|
|
||||||
// ]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// if ($certificate['isval'] !== null) {
|
|
||||||
// return $this->response->setJSON([
|
|
||||||
// 'success' => false,
|
|
||||||
// 'message' => 'Certificate has already been validated'
|
|
||||||
// ]);
|
|
||||||
// }
|
|
||||||
|
|
||||||
// $validationDate = date('Y-m-d');
|
|
||||||
// $builder->where('certid', $certid)->update(['isval' => $validationDate]);
|
|
||||||
|
|
||||||
// return $this->response->setJSON([
|
|
||||||
// 'success' => true,
|
|
||||||
// 'message' => 'Certificate validated successfully',
|
|
||||||
// 'validationDate' => $validationDate
|
|
||||||
// ]);
|
|
||||||
|
|
||||||
// } catch (\Exception $e) {
|
|
||||||
// log_message('error', 'Certificate validation error: ' . $e->getMessage());
|
|
||||||
// return $this->response->setJSON([
|
|
||||||
// 'success' => false,
|
|
||||||
// 'message' => 'An error occurred during validation'
|
|
||||||
// ]);
|
|
||||||
// }
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// Helper Function Preview dan Validate
|
||||||
|
private function previewPdf($certificate, $type, $productType=null) { // Untuk Show/Preview PDF
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
public function createTraining($certid = null) {
|
|
||||||
if (!$certid) {
|
|
||||||
return $this->response->setStatusCode(400)->setJSON(['error' => 'Certificate ID is required']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get certificate data
|
|
||||||
$certificates = [
|
|
||||||
[
|
|
||||||
'certid' => 'CERT001',
|
|
||||||
'certname' => 'Jokoh Training Certificate',
|
|
||||||
'productname' => 'Jokoh',
|
|
||||||
'productnumber' => 'SN-2024-001',
|
|
||||||
'issuedate' => '2024-01-15',
|
|
||||||
'expirydate' => '2025-01-15',
|
|
||||||
'vendor' => 'Summit Calibration Lab'
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
$certificate = null;
|
|
||||||
foreach ($certificates as $cert) {
|
|
||||||
if ($cert['certid'] === $certid) {
|
|
||||||
$certificate = $cert;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$certificate) {
|
|
||||||
return $this->response->setStatusCode(404)->setJSON(['error' => 'Training certificate not found']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate PDF
|
|
||||||
return $this->generatePDF($certificate, 'training');
|
|
||||||
}
|
|
||||||
public function createCalibrate($certid = null, $productname = null) {
|
|
||||||
if (!$certid) {
|
|
||||||
return $this->response->setStatusCode(400)->setJSON(['error' => 'Certificate ID is required']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get certificate data
|
|
||||||
$certificates = [
|
|
||||||
[
|
|
||||||
'certid' => 'CERT001',
|
|
||||||
'certname' => 'TMS50i Calibration Certificate',
|
|
||||||
'productname' => 'tms50i',
|
|
||||||
'productnumber' => 'SN-2024-001',
|
|
||||||
'type' => 'calibration',
|
|
||||||
'issuedate' => '2024-01-15',
|
|
||||||
'expirydate' => '2025-01-15',
|
|
||||||
'vendor' => 'Summit Calibration Lab',
|
|
||||||
'description' => 'Annual calibration certificate for TMS50i equipment.'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'certid' => 'CERT002',
|
|
||||||
'certname' => 'tms24i Calibration Certificate',
|
|
||||||
'productname' => 'tms24i',
|
|
||||||
'productnumber' => 'SN-2024-002',
|
|
||||||
'type' => 'calibration',
|
|
||||||
'issuedate' => '2024-01-16',
|
|
||||||
'expirydate' => '2025-01-16',
|
|
||||||
'vendor' => 'Summit Calibration Lab',
|
|
||||||
'description' => 'Annual calibration certificate for tms24i equipment.'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'certid' => 'CERT003',
|
|
||||||
'certname' => 'tms30i Calibration Certificate',
|
|
||||||
'productname' => 'tms30i',
|
|
||||||
'productnumber' => 'SN-2024-003',
|
|
||||||
'type' => 'calibration',
|
|
||||||
'issuedate' => '2024-01-17',
|
|
||||||
'expirydate' => '2025-01-17',
|
|
||||||
'vendor' => 'Summit Calibration Lab',
|
|
||||||
'description' => 'Annual calibration certificate for tms30i equipment.'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'certid' => 'CERT004',
|
|
||||||
'certname' => 'BS430 Calibration Certificate',
|
|
||||||
'productname' => 'bs430',
|
|
||||||
'productnumber' => 'SN-2024-004',
|
|
||||||
'type' => 'calibration',
|
|
||||||
'issuedate' => '2024-01-18',
|
|
||||||
'expirydate' => '2025-01-18',
|
|
||||||
'vendor' => 'Summit Calibration Lab',
|
|
||||||
'description' => 'Annual calibration certificate for BS430 equipment.'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'certid' => 'CERT005',
|
|
||||||
'certname' => 'CL900i Calibration Certificate',
|
|
||||||
'productname' => 'cl900i',
|
|
||||||
'productnumber' => 'SN-2024-005',
|
|
||||||
'type' => 'calibration',
|
|
||||||
'issuedate' => '2024-01-19',
|
|
||||||
'expirydate' => '2025-01-19',
|
|
||||||
'vendor' => 'Summit Calibration Lab',
|
|
||||||
'description' => 'Annual calibration certificate for CL900i equipment.'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'certid' => 'CERT006',
|
|
||||||
'certname' => 'Jokoh Calibration Certificate',
|
|
||||||
'productname' => 'jokoh',
|
|
||||||
'productnumber' => 'SN-2024-006',
|
|
||||||
'type' => 'calibration',
|
|
||||||
'issuedate' => '2024-01-20',
|
|
||||||
'expirydate' => '2025-01-20',
|
|
||||||
'vendor' => 'Summit Calibration Lab',
|
|
||||||
'description' => 'Annual calibration certificate for Jokoh equipment.'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'certid' => 'CERT007',
|
|
||||||
'certname' => 'BC760R Calibration Certificate',
|
|
||||||
'productname' => 'bc760r',
|
|
||||||
'productnumber' => 'SN-2024-007',
|
|
||||||
'type' => 'calibration',
|
|
||||||
'issuedate' => '2024-01-21',
|
|
||||||
'expirydate' => '2025-01-21',
|
|
||||||
'vendor' => 'Summit Calibration Lab',
|
|
||||||
'description' => 'Annual calibration certificate for BC760R equipment.'
|
|
||||||
],
|
|
||||||
[
|
|
||||||
'certid' => 'CERT008',
|
|
||||||
'certname' => 'BC5140 Calibration Certificate',
|
|
||||||
'productname' => 'bc5140',
|
|
||||||
'productnumber' => 'SN-2024-008',
|
|
||||||
'type' => 'calibration',
|
|
||||||
'issuedate' => '2024-01-22',
|
|
||||||
'expirydate' => '2025-01-22',
|
|
||||||
'vendor' => 'Summit Calibration Lab',
|
|
||||||
'description' => 'Annual calibration certificate for BC5140 equipment.'
|
|
||||||
],
|
|
||||||
];
|
|
||||||
|
|
||||||
$certificate = null;
|
|
||||||
foreach ($certificates as $cert) {
|
|
||||||
if ($cert['certid'] === $certid) {
|
|
||||||
$certificate = $cert;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$certificate) {
|
|
||||||
return $this->response->setStatusCode(404)->setJSON(['error' => 'Calibration certificate not found']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Generate PDF
|
|
||||||
return $this->generatePDF($certificate, 'calibration', $productname);
|
|
||||||
}
|
|
||||||
public function createMaintenance($certid = null) {
|
|
||||||
if (!$certid) {
|
|
||||||
return $this->response->setStatusCode(400)->setJSON(['error' => 'Certificate ID is required']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Get certificate data
|
|
||||||
$certificates = [
|
|
||||||
[
|
|
||||||
'certid' => 'CERT001',
|
|
||||||
'certname' => 'Jokoh Calibration Certificate',
|
|
||||||
'productname' => 'Jokoh',
|
|
||||||
'productnumber' => 'SN-2024-001',
|
|
||||||
'issuedate' => '2024-01-15',
|
|
||||||
'expirydate' => '2025-01-15',
|
|
||||||
'vendor' => 'Summit Calibration Lab'
|
|
||||||
]
|
|
||||||
];
|
|
||||||
|
|
||||||
$certificate = null;
|
|
||||||
foreach ($certificates as $cert) {
|
|
||||||
if ($cert['certid'] === $certid) {
|
|
||||||
$certificate = $cert;
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!$certificate) {
|
|
||||||
return $this->response->setStatusCode(404)->setJSON(['error' => 'Maintenance certificate not found']);
|
|
||||||
}
|
|
||||||
|
|
||||||
// dd($certificate);
|
|
||||||
|
|
||||||
// Generate PDF
|
|
||||||
return $this->generatePDF($certificate, 'maintenance');
|
|
||||||
}
|
|
||||||
|
|
||||||
// Digunakan Untuk Generate PDF Show
|
|
||||||
private function generatePDF($certificate, $type, $productType=null) {
|
|
||||||
// Generate PDF
|
// Generate PDF
|
||||||
$options = new Options();
|
$options = new Options();
|
||||||
$options->set('isRemoteEnabled', true);
|
$options->set('isRemoteEnabled', true);
|
||||||
@ -542,7 +178,7 @@ class Certificates extends BaseController {
|
|||||||
// Select template and orientation based on type
|
// Select template and orientation based on type
|
||||||
$template = 'certificate_pdf';
|
$template = 'certificate_pdf';
|
||||||
$orientation = 'portrait';
|
$orientation = 'portrait';
|
||||||
|
|
||||||
switch($type) {
|
switch($type) {
|
||||||
case 'training':
|
case 'training':
|
||||||
$template = 'certificates/certificate_training';
|
$template = 'certificates/certificate_training';
|
||||||
@ -593,4 +229,200 @@ class Certificates extends BaseController {
|
|||||||
$filename = 'Certificate_' . $certificate['certid'] . '.pdf';
|
$filename = 'Certificate_' . $certificate['certid'] . '.pdf';
|
||||||
$dompdf->stream($filename, ['Attachment' => false]);
|
$dompdf->stream($filename, ['Attachment' => false]);
|
||||||
}
|
}
|
||||||
|
public function validateCertificate() { // Untuk Validasi Certificate
|
||||||
|
$certid = $this->request->getPost('certid');
|
||||||
|
$certificateType = $this->request->getPost('certificateType');
|
||||||
|
|
||||||
|
if (!$certid) {
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Certificate ID is required'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dummy data certificates
|
||||||
|
$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
|
||||||
|
];
|
||||||
|
|
||||||
|
if ($certificates['certid'] === $certid) {
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'success' => true,
|
||||||
|
'message' => 'Certificate has already been validateda'
|
||||||
|
]);
|
||||||
|
} else {
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Certificate not found'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// $validationDate = date('Y-m-d');
|
||||||
|
|
||||||
|
// return $this->response->setJSON([
|
||||||
|
// 'success' => true,
|
||||||
|
// 'message' => 'Certificate validated ' . $certificateType,
|
||||||
|
// 'validationDate' => $validationDate
|
||||||
|
// ]);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// Helper Generate dan Save PDF
|
||||||
|
public function generatePdf() {
|
||||||
|
$certid = $this->request->getPost('certid');
|
||||||
|
$certificateType = $this->request->getPost('certificateType');
|
||||||
|
|
||||||
|
if (!$certid) {
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Certificate ID is required'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Dummy data certificates
|
||||||
|
$certificate = [
|
||||||
|
'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
|
||||||
|
];
|
||||||
|
|
||||||
|
if (empty($certificate)) {
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Certificate not found'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
$filePath = $this->savePdf($certificate, $certificateType, null);
|
||||||
|
|
||||||
|
if (!$filePath) {
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Failed to generate PDF'
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
|
||||||
|
$relativePath = str_replace(FCPATH, '', $filePath);
|
||||||
|
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'success' => true,
|
||||||
|
'message' => 'PDF generated and saved successfully',
|
||||||
|
'filePath' => $relativePath
|
||||||
|
]);
|
||||||
|
|
||||||
|
} catch (\Exception $e) {
|
||||||
|
return $this->response->setJSON([
|
||||||
|
'success' => false,
|
||||||
|
'message' => 'Failed to generate PDF: ' . $e->getMessage()
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
private function savePdf($certificate, $type, $productType=null) {
|
||||||
|
// Generate PDF
|
||||||
|
$options = new Options();
|
||||||
|
$options->set('isRemoteEnabled', true);
|
||||||
|
$options->set('isHtml5ParserEnabled', true);
|
||||||
|
|
||||||
|
$dompdf = new Dompdf($options);
|
||||||
|
|
||||||
|
// Format dates
|
||||||
|
$issuedate = date('F d, Y', strtotime($certificate['issuedate']));
|
||||||
|
$expirydate = date('F d, Y', strtotime($certificate['expirydate']));
|
||||||
|
|
||||||
|
// Get status
|
||||||
|
$today = date('Y-m-d');
|
||||||
|
$expiryCheck = date('Y-m-d', strtotime($certificate['expirydate']));
|
||||||
|
$daysUntilExpiry = (strtotime($expiryCheck) - strtotime($today)) / (60 * 60 * 24);
|
||||||
|
|
||||||
|
if ($daysUntilExpiry < 0) {
|
||||||
|
$status = 'Expired';
|
||||||
|
$statusColor = '#dc3545';
|
||||||
|
} elseif ($daysUntilExpiry <= 30) {
|
||||||
|
$status = 'Expiring Soon';
|
||||||
|
$statusColor = '#ffc107';
|
||||||
|
} else {
|
||||||
|
$status = 'Active';
|
||||||
|
$statusColor = '#28a745';
|
||||||
|
}
|
||||||
|
|
||||||
|
// Select template and orientation based on type
|
||||||
|
$template = 'certificate_pdf';
|
||||||
|
$orientation = 'portrait';
|
||||||
|
|
||||||
|
switch($type) {
|
||||||
|
case 'training':
|
||||||
|
$template = 'certificates/certificate_training';
|
||||||
|
$orientation = 'landscape';
|
||||||
|
break;
|
||||||
|
case 'calibration':
|
||||||
|
if ($productType == 'tms50i') {
|
||||||
|
$template = 'certificates/callibrations_template/certificate_tms50i_calibration';
|
||||||
|
} else if ($productType == 'tms24i') {
|
||||||
|
$template = 'certificates/callibrations_template/certificate_tms24i_calibration';
|
||||||
|
} else if ($productType == 'tms30i') {
|
||||||
|
$template = 'certificates/callibrations_template/certificate_tms30i_calibration';
|
||||||
|
} else if ($productType == 'bs430') {
|
||||||
|
$template = 'certificates/callibrations_template/certificate_bs430_calibration';
|
||||||
|
} else if ($productType == 'cl900i') {
|
||||||
|
$template = 'certificates/callibrations_template/certificate_cl900i_calibration';
|
||||||
|
} else if ($productType == 'jokoh') {
|
||||||
|
$template = 'certificates/callibrations_template/certificate_jokoh_calibration';
|
||||||
|
} else if ($productType == 'bc760r') {
|
||||||
|
$template = 'certificates/callibrations_template/certificate_bc760r_calibration';
|
||||||
|
} else if ($productType == 'bc5140') {
|
||||||
|
$template = 'certificates/callibrations_template/certificate_bc5140_calibration';
|
||||||
|
} else {
|
||||||
|
return $this->response->setStatusCode(404)->setJSON(['error' => 'Not Found']);
|
||||||
|
}
|
||||||
|
$orientation = 'portrait';
|
||||||
|
break;
|
||||||
|
case 'maintenance':
|
||||||
|
$template = 'certificates/certificate_maintenance';
|
||||||
|
$orientation = 'landscape';
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
$html = view($template, [
|
||||||
|
'certificate' => $certificate,
|
||||||
|
'issuedate' => $issuedate,
|
||||||
|
'expirydate' => $expirydate,
|
||||||
|
'status' => $status,
|
||||||
|
'statusColor' => $statusColor
|
||||||
|
]);
|
||||||
|
|
||||||
|
$dompdf->loadHtml($html);
|
||||||
|
$dompdf->setPaper('A4', $orientation);
|
||||||
|
$dompdf->render();
|
||||||
|
|
||||||
|
// Generate filename with timestamp
|
||||||
|
$timestamp = date('YmdHis');
|
||||||
|
$filename = 'Certificate_' . $certificate['certid'] . '_' . $timestamp . '.pdf';
|
||||||
|
|
||||||
|
// Ensure upload directory exists
|
||||||
|
$uploadDir = FCPATH . 'upload' . DIRECTORY_SEPARATOR . 'documents';
|
||||||
|
if (!is_dir($uploadDir)) {
|
||||||
|
mkdir($uploadDir, 0755, true);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Save PDF to file
|
||||||
|
$filePath = $uploadDir . DIRECTORY_SEPARATOR . $filename;
|
||||||
|
file_put_contents($filePath, $dompdf->output());
|
||||||
|
|
||||||
|
// Return file path
|
||||||
|
return $filePath;
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
@ -215,7 +215,7 @@ if(isset($data)) {
|
|||||||
<div class="form-check">
|
<div class="form-check">
|
||||||
<input class="form-check-input" type="checkbox" name="calibration" id="calibration" value="1">
|
<input class="form-check-input" type="checkbox" name="calibration" id="calibration" value="1">
|
||||||
<label class="form-check-label" for="calibration">
|
<label class="form-check-label" for="calibration">
|
||||||
Calibration
|
Calibration Certificate
|
||||||
</label>
|
</label>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|||||||
@ -114,10 +114,17 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12 mb-3">
|
<div class="col-md-6 mb-3">
|
||||||
<label class="form-label fw-bold">Vendor</label>
|
<label class="form-label fw-bold">Vendor</label>
|
||||||
<p id="modalVendor" class="form-control-plaintext">-</p>
|
<p id="modalVendor" class="form-control-plaintext">-</p>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="col-md-6 mb-3">
|
||||||
|
<label class="form-label fw-bold">Activity Report</label>
|
||||||
|
<p id="modalExpiryDate" class="form-control-plaintext">
|
||||||
|
<a href="javascript:void(0)" class="activity-report-link text-decoration-none" data-certid="${certid}" style="color:#d43215b0;">Act ID - Nama AR - Nama User <i class="fa-solid fa-up-right-from-square"></i></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="alert alert-warning">
|
<div class="alert alert-warning">
|
||||||
<i class="fa-solid fa-info-circle"></i>
|
<i class="fa-solid fa-info-circle"></i>
|
||||||
@ -220,8 +227,8 @@ $(function () {
|
|||||||
expirydate,
|
expirydate,
|
||||||
statusBadge,
|
statusBadge,
|
||||||
isval == null
|
isval == null
|
||||||
? `<button type="button" class="btn btn-warning text-dark btn-validate" data-certid="${certid}" data-certname="${certname}" data-productname="${productname}" data-productnumber="${productnumber}" data-issuedate="${issuedate}" data-expirydate="${expirydate}" data-vendor="${vendor}"><i class="fa-solid fa-check-double"></i></button>`
|
? `<div class="text-center"><button type="button" class="btn btn-warning text-dark btn-validate" data-certid="${certid}" data-certname="${certname}" data-productname="${productname}" data-productnumber="${productnumber}" data-issuedate="${issuedate}" data-expirydate="${expirydate}" data-vendor="${vendor}"><i class="fa-solid fa-check-double"></i></button></div>`
|
||||||
: `<button type="button" class="btn btn-success btn-view" data-certid="${certid}"><i class="fa-regular fa-file-pdf"></i></button>`
|
: `<div class="text-center"><button type="button" class="btn btn-success btn-view" data-certid="${certid}"><i class="fa-regular fa-file-pdf"></i></button></div>`
|
||||||
];
|
];
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@ -253,6 +260,20 @@ $(function () {
|
|||||||
table.search(this.value).draw();
|
table.search(this.value).draw();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// Type filter using DataTables column filter
|
||||||
|
$('#typeFilter').on('change', function () {
|
||||||
|
let type = $(this).val();
|
||||||
|
|
||||||
|
// Filter by type column (index 1 - Certificate Name contains type info)
|
||||||
|
if (type === '') {
|
||||||
|
table.column(1).search('').draw();
|
||||||
|
} else {
|
||||||
|
// Capitalize first letter for search
|
||||||
|
let typeText = type.charAt(0).toUpperCase() + type.slice(1);
|
||||||
|
table.column(1).search(typeText).draw();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
// Status filter
|
// Status filter
|
||||||
$('#statusFilter').on('change', function () {
|
$('#statusFilter').on('change', function () {
|
||||||
let map = {
|
let map = {
|
||||||
@ -316,14 +337,33 @@ $(function () {
|
|||||||
if (!confirm('Are you sure?')) return;
|
if (!confirm('Are you sure?')) return;
|
||||||
|
|
||||||
$.post(
|
$.post(
|
||||||
'<?= base_url('certificates/api/validate') ?>',
|
'<?= base_url('certificates/api/validateCertificate') ?>',
|
||||||
{ certid },
|
{ certid, certificateType},
|
||||||
function (response) {
|
function (response) {
|
||||||
|
|
||||||
if (response.success) {
|
if (response.success) {
|
||||||
$('#validateModal').modal('hide');
|
$('#validateModal').modal('hide');
|
||||||
alert('Certificate maintenance validated successfully');
|
alert(response.message);
|
||||||
location.reload();
|
|
||||||
|
// Generate and save PDF after successful validation
|
||||||
|
$.post(
|
||||||
|
'<?= base_url('certificates/api/generatepdf') ?>',
|
||||||
|
{ certid, certificateType },
|
||||||
|
function (pdfResponse) {
|
||||||
|
if (pdfResponse.success) {
|
||||||
|
alert('PDF generated and saved successfully!');
|
||||||
|
location.reload();
|
||||||
|
} else {
|
||||||
|
alert('Validation successful but PDF generation failed: ' + (pdfResponse.message || 'Unknown error'));
|
||||||
|
location.reload();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
'json'
|
||||||
|
).fail(function () {
|
||||||
|
alert('Validation successful but failed to generate PDF');
|
||||||
|
location.reload();
|
||||||
|
});
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
alert(response.message || 'Validation failed');
|
alert(response.message || 'Validation failed');
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user