Update CRUD Installation Certificate
This commit is contained in:
parent
aac4ad2034
commit
038e5e74db
@ -221,20 +221,19 @@ $routes->group('certificates', function($routes) {
|
||||
// $routes->get('api/getindextraining', 'Certificates::getDataIndexTraining'); // OK
|
||||
// $routes->get('api/getindexcalibrate', 'Certificates::getDataIndexCalibrate');
|
||||
|
||||
// Untuk Get Modal Data
|
||||
$routes->post('api/showmaintenance', 'Certificates::showDataMaintenance'); // OK
|
||||
$routes->post('api/showinstallation', 'Certificates::showDataInstallation'); // OK
|
||||
|
||||
// Untuk Preview Cerificate
|
||||
$routes->get('maintenance/show/(:any)', 'Certificates::createMaintenancePreview/$1'); // OK
|
||||
// $routes->get('installation/show/(:any)', 'Certificates::createInstallationPreview/$1'); // OK
|
||||
$routes->get('installation/show/(:any)', 'Certificates::createInstallationPreview/$1'); // OK
|
||||
// $routes->get('training/show/(:any)', 'Certificates::createTrainingPreview/$1'); // OK
|
||||
// $routes->get('calibration/show/(:any)/(:any)', 'Certificates::createCalibratePreview/$1/$2');
|
||||
|
||||
$routes->post('api/validatecertificate', 'Certificates::validateCertificate'); // OK
|
||||
|
||||
$routes->get('maintenance/number/$1', 'Certificates::getMaintenanceCertificate'); // OK
|
||||
|
||||
$routes->get('number/(:segment)', 'Certificates::view/$1');
|
||||
|
||||
$routes->get('number/(:segment)', 'Certificates::view/$1'); // OK
|
||||
});
|
||||
|
||||
|
||||
|
||||
@ -468,7 +468,12 @@ class Activities extends Controller {
|
||||
if ($this->request->getVar('maintenance')) { // Jika Maintenance Dicentang
|
||||
$issuedDate = $data['new_value']['closedate'] ?? null;
|
||||
$userid_owner = $data['new_value']['userid_owner'];
|
||||
$this->createCertificateMaintenance($actid, $issuedDate, $userid_owner);
|
||||
$this->createCertificate($actid, $issuedDate, $userid_owner, 'MC');
|
||||
}
|
||||
if ($this->request->getVar('installation')) { // Jika Maintenance Dicentang
|
||||
$issuedDate = $data['new_value']['closedate'] ?? null;
|
||||
$userid_owner = $data['new_value']['userid_owner'];
|
||||
$this->createCertificate($actid, $issuedDate, $userid_owner, 'IC');
|
||||
}
|
||||
|
||||
} else {
|
||||
@ -547,16 +552,31 @@ class Activities extends Controller {
|
||||
|
||||
|
||||
// UNTUK CERTIFICATES
|
||||
if ($this->request->getVar('maintenance')) { // Maintenance
|
||||
// Maintenance sertifikat create or update
|
||||
$certificateTypes = [
|
||||
'maintenance' => 'MC',
|
||||
'installation' => 'IC',
|
||||
];
|
||||
$hasAnyAction = false;
|
||||
$issuedDate = $data['new_value']['closedate'] ?? null;
|
||||
$userid_owner = $data['new_value']['userid_owner'];
|
||||
$this->updateCertificateMaintenance($actid, $issuedDate, $userid_owner);
|
||||
} else {
|
||||
// Hapus softdelete sertifikat
|
||||
$this->deleteCertificateMaintenance($actid);
|
||||
foreach ($certificateTypes as $requestName => $certCode) { //perulangan untuk mengecek semua checkbox
|
||||
if ($this->request->getVar($requestName)) {
|
||||
$hasAnyAction = true; // Jika checkbox dicentang, tandai bahwa ada aksi
|
||||
$this->updateCertificate($actid, $issuedDate, $userid_owner, $certCode);
|
||||
}
|
||||
|
||||
}
|
||||
if (!$hasAnyAction) { // Jika setelah dicek semua ternyata tidak ada satupun yang dicentang, baru jalankan delete
|
||||
$this->deleteCertificate($actid);
|
||||
}
|
||||
// if ($this->request->getVar('maintenance')) { // Maintenance
|
||||
// // Maintenance sertifikat create or update
|
||||
// $issuedDate = $data['new_value']['closedate'] ?? null;
|
||||
// $userid_owner = $data['new_value']['userid_owner'];
|
||||
// $this->updateCertificate($actid, $issuedDate, $userid_owner, 'MC');
|
||||
// } else {
|
||||
// // Hapus softdelete sertifikat
|
||||
// $this->deleteCertificate($actid);
|
||||
// }
|
||||
}
|
||||
|
||||
// act by consumables
|
||||
@ -1672,8 +1692,8 @@ class Activities extends Controller {
|
||||
return view('invtrans_index', $data);
|
||||
}
|
||||
|
||||
// Untuk CRUD Sertifikat Maintenance
|
||||
public function createCertificateMaintenance ($actid, $issuedDate, $userid_owner) {
|
||||
// Untuk CRUD Sertifikat
|
||||
public function createCertificate ($actid, $issuedDate, $userid_owner, $certificate_type) {
|
||||
|
||||
$db = \Config\Database::connect();
|
||||
$sql = "SELECT prl.productaliastext as productname, pr.productnumber as snnumber, st.sitename
|
||||
@ -1686,15 +1706,29 @@ class Activities extends Controller {
|
||||
$query = $db->query($sql);
|
||||
$result = $query->getRowArray();
|
||||
|
||||
$expiredDate = $issuedDate ? date('Y-m-d', strtotime($issuedDate . ' + 6 months')) : null;
|
||||
$insertCert = [
|
||||
'cert_name' => "MC_" . ($result['productname'] ?? 'UNKNOWN') . "_" . ($result['snnumber'] ?? '0') . "_" . $actid,
|
||||
'cert_type' => "MC",
|
||||
// 'cert_name' => "MC_" . ($result['productname'] ?? 'UNKNOWN') . "_" . ($result['snnumber'] ?? '0') . "_" . $actid,
|
||||
// 'cert_type' => "MC",
|
||||
'actid' => $actid,
|
||||
'issued_date' => $issuedDate,
|
||||
'expired_date' => $expiredDate,
|
||||
// 'expired_date' => $expiredDate,
|
||||
'user_id' => $userid_owner
|
||||
];
|
||||
|
||||
if ($certificate_type == 'MC') {
|
||||
$expiredDate = $issuedDate ? date('Y-m-d', strtotime($issuedDate . ' + 6 months')) : null;
|
||||
|
||||
// Input Array
|
||||
$insertCert['cert_name'] = "MC_" . ($result['productname'] ?? 'UNKNOWN') . "_" . ($result['snnumber'] ?? '0') . "_" . $actid;
|
||||
$insertCert['cert_type'] = "MC";
|
||||
$insertCert['expired_date'] = $expiredDate;
|
||||
}
|
||||
if ($certificate_type == 'IC') {
|
||||
// Input Array
|
||||
$insertCert['cert_name'] = "IC_" . ($result['productname'] ?? 'UNKNOWN') . "_" . ($result['snnumber'] ?? '0') . "_" . $actid;
|
||||
$insertCert['cert_type'] = "IC";
|
||||
}
|
||||
|
||||
$certificateModel = new CertificateModel();
|
||||
$certificateModel->insert($insertCert);
|
||||
|
||||
@ -1703,7 +1737,7 @@ class Activities extends Controller {
|
||||
$newCertificate = $certificateModel->find($certid);
|
||||
$certificateModel->update($certid, ['file_url' => base_url('certificates/number/'.$newCertificate['cert_number'])]);
|
||||
}
|
||||
public function updateCertificateMaintenance($actid, $issuedDate, $userid_owner) {
|
||||
public function updateCertificate($actid, $issuedDate, $userid_owner, $certificate_type) {
|
||||
$certificateModel = new CertificateModel();
|
||||
|
||||
// 1. Cek apakah data sudah ada menggunakan findAll()
|
||||
@ -1739,21 +1773,31 @@ class Activities extends Controller {
|
||||
$query = $db->query($sql, [$actid]);
|
||||
$result = $query->getRowArray();
|
||||
|
||||
// 3. Setelan Tanggal
|
||||
$validIssuedDate = $issuedDate;
|
||||
$expiredDate = $validIssuedDate ? date('Y-m-d', strtotime($validIssuedDate . ' + 6 months')) : null;
|
||||
|
||||
// Siapkan Payload
|
||||
$certPayload = [
|
||||
'cert_name' => "MC_" . ($result['productname'] ?? 'UNKNOWN') . "_" . ($result['snnumber'] ?? '0') . "_" . $actid,
|
||||
'cert_type' => "MC",
|
||||
// 'cert_name' => "MC_" . ($result['productname'] ?? 'UNKNOWN') . "_" . ($result['snnumber'] ?? '0') . "_" . $actid,
|
||||
// 'cert_type' => "MC",
|
||||
'actid' => $actid,
|
||||
'issued_date' => $validIssuedDate,
|
||||
'expired_date' => $expiredDate,
|
||||
'issued_date' => $issuedDate,
|
||||
// 'expired_date' => $expiredDate,
|
||||
'user_id' => $userid_owner,
|
||||
'deleted_at' => null
|
||||
];
|
||||
|
||||
if ($certificate_type == 'MC') {
|
||||
$expiredDate = $issuedDate ? date('Y-m-d', strtotime($issuedDate . ' + 6 months')) : null;
|
||||
|
||||
// Input Array
|
||||
$certPayload['cert_name'] = "MC_" . ($result['productname'] ?? 'UNKNOWN') . "_" . ($result['snnumber'] ?? '0') . "_" . $actid;
|
||||
$certPayload['cert_type'] = "MC";
|
||||
$certPayload['expired_date'] = $expiredDate;
|
||||
}
|
||||
if ($certificate_type == 'IC') {
|
||||
// Input Array
|
||||
$certPayload['cert_name'] = "IC_" . ($result['productname'] ?? 'UNKNOWN') . "_" . ($result['snnumber'] ?? '0') . "_" . $actid;
|
||||
$certPayload['cert_type'] = "IC";
|
||||
}
|
||||
|
||||
// 4. Logika Insert atau Update menggunakan penanda $isDataExist
|
||||
if (!$isDataExist) {
|
||||
// Jika data belum ada sama sekali (array kosong), eksekusi INSERT
|
||||
@ -1772,7 +1816,7 @@ class Activities extends Controller {
|
||||
->update();
|
||||
}
|
||||
}
|
||||
public function deleteCertificateMaintenance($actid) {
|
||||
public function deleteCertificate($actid) {
|
||||
$certificateModel = new CertificateModel();
|
||||
|
||||
// 1. Cek apakah data sudah ada menggunakan findAll()
|
||||
@ -1793,7 +1837,6 @@ class Activities extends Controller {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
$certificateModel->where('actid', $actid)->delete();
|
||||
}
|
||||
|
||||
|
||||
@ -15,11 +15,11 @@ class Certificates extends BaseController {
|
||||
|
||||
protected array $data;
|
||||
|
||||
// Untuk Sertifikat Instalasi (BAI) [1]
|
||||
// Untuk Sertifikat Instalasi (BAI) [1] - Done
|
||||
public function installationIndex() { // Index
|
||||
return view('certificate_installation_index');
|
||||
}
|
||||
public function getDataIndexMaintenance() {
|
||||
public function getDataIndexInstallation() {
|
||||
$userPosId = session()->get('userposid');
|
||||
$userId = session()->get('userid');
|
||||
|
||||
@ -64,9 +64,123 @@ class Certificates extends BaseController {
|
||||
|
||||
return $this->response->setJSON($allData);
|
||||
}
|
||||
public function showDataInstallation() { // Untuk API Get Data
|
||||
$certid = $this->request->getPost('certid');
|
||||
if (!$certid) {
|
||||
return $this->response->setStatusCode(400)->setJSON(['error' => 'Certificate ID Not Found']);
|
||||
}
|
||||
$certificateModel = new CertificateModel();
|
||||
$data = $certificateModel->select('
|
||||
certificates.cert_id,
|
||||
certificates.cert_number,
|
||||
certificates.cert_name,
|
||||
certificates.status,
|
||||
activities.actid,
|
||||
activities.subject,
|
||||
productcatalog.productname,
|
||||
sites.sitename,
|
||||
products.productnumber,
|
||||
CASE
|
||||
WHEN certificates.cert_type = "MC" THEN "Maintenance"
|
||||
WHEN certificates.cert_type = "IC" THEN "Installation"
|
||||
WHEN certificates.cert_type = "UTC" THEN "User Training"
|
||||
WHEN certificates.cert_type = "BAI" THEN "Berita Acara Instalasi"
|
||||
WHEN certificates.cert_type = "BAP" THEN "Berita Acara Penarikan"
|
||||
ELSE certificates.cert_type
|
||||
END AS certtype,
|
||||
CONCAT(us.firstname, " ", us.lastname) AS username,
|
||||
certificates.user_validation_at,
|
||||
CONCAT(spv.firstname, " ", spv.lastname) AS spvname,
|
||||
certificates.spv_validation_at,
|
||||
CONCAT(mgr.firstname, " ", mgr.lastname) AS managername,
|
||||
certificates.manager_validation_at,
|
||||
certificates.issued_date,
|
||||
certificates.expired_date
|
||||
', false)
|
||||
->join('activities', 'activities.actid = certificates.actid', 'inner')
|
||||
->join('products', 'products.productid = activities.productid', 'inner')
|
||||
->join('productcatalog', 'productcatalog.catalogid = products.catalogid', 'inner')
|
||||
->join('sites', 'sites.siteid = activities.siteid', 'left')
|
||||
->join('users as us', 'us.userid = certificates.user_id', 'left')
|
||||
->join('users as spv', 'spv.userid = certificates.spv_id', 'left')
|
||||
->join('users as mgr', 'mgr.userid = certificates.manager_id', 'left')
|
||||
->join('userposition', 'userposition.userposid = us.userposid', 'left')
|
||||
->where('certificates.cert_id', $certid)
|
||||
->first();
|
||||
|
||||
$data['issued_date'] = $data['issued_date'] ? date('d M Y', strtotime($data['issued_date'])) : null;
|
||||
$data['user_validation_at'] = $data['user_validation_at'] ? date('d M Y H:i', strtotime($data['user_validation_at'])) : null;
|
||||
$data['spv_validation_at'] = $data['spv_validation_at'] ? date('d M Y H:i', strtotime($data['spv_validation_at'])) : null;
|
||||
$data['manager_validation_at'] = $data['manager_validation_at'] ? date('d M Y H:i', strtotime($data['manager_validation_at'])) : null;
|
||||
|
||||
if (empty($data)) { // Jika Tidak Ada
|
||||
return $this->response->setStatusCode(404)->setJSON(['error' => 'Installation certificate not found']);
|
||||
}
|
||||
return $this->response->setJSON($data);
|
||||
}
|
||||
public function createInstallationPreview($certid = null) { // Untuk Preview Sertifikat
|
||||
|
||||
if (!$certid) {
|
||||
return $this->response->setStatusCode(400)->setJSON(['error' => 'Certificate ID Not Found']);
|
||||
}
|
||||
$certificateModel = new CertificateModel();
|
||||
$data = $certificateModel->select('
|
||||
certificates.cert_name,
|
||||
certificates.file_url,
|
||||
productalias.productaliastext as productname,
|
||||
sites.sitename as sitename,
|
||||
products.productnumber,
|
||||
CASE
|
||||
WHEN certificates.cert_type = "MC" THEN "Maintenance"
|
||||
WHEN certificates.cert_type = "IC" THEN "Installation"
|
||||
WHEN certificates.cert_type = "UTC" THEN "User Training"
|
||||
WHEN certificates.cert_type = "BAI" THEN "Berita Acara Instalasi"
|
||||
WHEN certificates.cert_type = "BAP" THEN "Berita Acara Penarikan"
|
||||
ELSE certificates.cert_type
|
||||
END AS cert_type,
|
||||
CONCAT(users.firstname, " ", users.lastname) AS fullname,
|
||||
userposition.texts AS user_position,
|
||||
certificates.issued_date,
|
||||
certificates.cert_number -- Penting agar callback UUID tetap jalan
|
||||
', false)
|
||||
->join('users', 'users.userid = certificates.user_id', 'left')
|
||||
->join('userposition', 'userposition.userposid = users.userposid', 'left')
|
||||
->join('activities', 'activities.actid = certificates.actid', 'left')
|
||||
->join('sites', 'sites.siteid = activities.siteid', 'left')
|
||||
->join('products', 'products.productid = activities.productid', 'left')
|
||||
->join('productcatalog', 'productcatalog.catalogid = products.catalogid', 'left')
|
||||
->join('productalias', 'productalias.productaliasid = productcatalog.productaliasid', 'left')
|
||||
->where('certificates.cert_id', $certid)
|
||||
->first();
|
||||
$certificate = [
|
||||
'certname' => $data['cert_name'],
|
||||
'sitename' => $data['sitename'],
|
||||
'certtype' => $data['cert_type'],
|
||||
'fullname' => $data['fullname'],
|
||||
'userposition' => $data['user_position'],
|
||||
'productname' => $data['productname'],
|
||||
'productnumber' => $data['productnumber'],
|
||||
'issueddate' => $data['issued_date']
|
||||
];
|
||||
|
||||
$builder = new Builder(
|
||||
writer: new PngWriter(),
|
||||
data: $data['file_url'],
|
||||
size: 120,
|
||||
margin: 0
|
||||
);
|
||||
$result = $builder->build();
|
||||
$certificate['qrcode'] = $result->getDataUri();
|
||||
|
||||
if (empty($certificate)) { // Jika Tidak Ada
|
||||
return $this->response->setStatusCode(404)->setJSON(['error' => 'Installation certificate not found']);
|
||||
}
|
||||
|
||||
return $this->previewPdf($certificate, 'installation'); // Preview PDF
|
||||
}
|
||||
|
||||
|
||||
// Untuk Sertifikat Maintenance [2]
|
||||
// Untuk Sertifikat Maintenance [2] - Done
|
||||
public function maintenanceIndex() { // Index
|
||||
return view('certificate_maintenance_index');
|
||||
}
|
||||
@ -378,7 +492,10 @@ class Certificates extends BaseController {
|
||||
|
||||
// Format dates
|
||||
$certificate['issueddate'] = date('d-M-Y', strtotime($certificate['issueddate']));
|
||||
|
||||
if(isset($certificate['expireddate'])) {
|
||||
$certificate['expireddate'] = date('d-M-Y', strtotime($certificate['expireddate']));
|
||||
}
|
||||
|
||||
// Select template and orientation based on type
|
||||
$template = '';
|
||||
|
||||
@ -250,9 +250,9 @@ if(isset($data)) {
|
||||
Berita Acara Instalasi
|
||||
</label>
|
||||
</div>
|
||||
</div> -->
|
||||
</div>
|
||||
|
||||
<!-- <div class="col-md-6 mb-2">
|
||||
<div class="col-md-6 mb-2">
|
||||
<div class="form-check">
|
||||
<input class="form-check-input" type="checkbox" name="training" value="1" id="training" <?= in_array('UTC', $cert_types) ? 'checked' : '' ?>>
|
||||
<label class="form-check-label" for="training">
|
||||
@ -637,11 +637,10 @@ if(isset($data)) {
|
||||
|
||||
<div class="row mb-3">
|
||||
<div class="col-12 col-lg-5">
|
||||
<label for="site" class="form-label border-start border-5 border-primary ps-1">Nama</label>
|
||||
<select name="siteid" id="siteid" class="form-select form-select-sm select2 site" required>
|
||||
<option value="">-- Choose one --</option>
|
||||
|
||||
</select>
|
||||
<div class="form-group">
|
||||
<label for="trainingname" class="form-label">Nama</label>
|
||||
<input type='text' class="form-control form-control-sm trainingname" placeholder="Masukkan nama" />
|
||||
</div>
|
||||
</div>
|
||||
<div class="col-12 col-lg-5">
|
||||
<div class="form-group">
|
||||
@ -803,14 +802,14 @@ $(document).ready(function() {
|
||||
if (this.value == '5') {
|
||||
$("#maintenance").prop('disabled', false);
|
||||
// $("#calibration").prop('disabled', true);
|
||||
// $("#installation").prop('disabled', true);
|
||||
$("#installation").prop('disabled', true);
|
||||
// $("#offreport").prop('disabled', true);
|
||||
// $("#training").prop('disabled', true);
|
||||
}
|
||||
else if (this.value == '3') {
|
||||
$("#maintenance").prop('disabled', true);
|
||||
// $("#calibration").prop('disabled', false);
|
||||
// $("#installation").prop('disabled', false);
|
||||
$("#installation").prop('disabled', false);
|
||||
// $("#offreport").prop('disabled', false);
|
||||
// $("#training").prop('disabled', false);
|
||||
}
|
||||
@ -818,7 +817,7 @@ $(document).ready(function() {
|
||||
// Ini akan menjadi default jika #acttypeid kosong atau bukan 5 dan 3
|
||||
$("#maintenance").prop('disabled', true);
|
||||
// $("#calibration").prop('disabled', true);
|
||||
// $("#installation").prop('disabled', true);
|
||||
$("#installation").prop('disabled', true);
|
||||
// $("#offreport").prop('disabled', true);
|
||||
// $("#training").prop('disabled', true);
|
||||
}
|
||||
|
||||
@ -125,8 +125,8 @@
|
||||
<h4>has completed through a series of <?= $certificate['certtype'] ?></h4>
|
||||
<h4>and the final result:</h4>
|
||||
<h2>PASSED</h2>
|
||||
<h4>Date of Instrument Maintenance and Inspection: <?= $certificate['issueddate'] ?></h4>
|
||||
<!-- <h4>Valid until <?= $certificate['expireddate'] ?></h4> -->
|
||||
<h4>Date of Installation and Inspection: <?= $certificate['issueddate'] ?></h4>
|
||||
|
||||
</div>
|
||||
|
||||
<table class="signature-table">
|
||||
@ -169,8 +169,7 @@
|
||||
<h4>has completed through a series of <?= $certificate['certtype'] ?></h4>
|
||||
<h4>and the final result:</h4>
|
||||
<h2>PASSED</h2>
|
||||
<h4>Date of Instrument Maintenance and Inspection: <?= $certificate['issueddate'] ?></h4>
|
||||
<!-- <h4>Valid until <?= $certificate['expireddate'] ?></h4> -->
|
||||
<h4>Date of Installation and Inspection: <?= $certificate['issueddate'] ?></h4>
|
||||
</div>
|
||||
|
||||
<table class="signature-table">
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user