forked from mahdahar/crm-summit
Update notifikasi sertifikat - view cells
This commit is contained in:
parent
ba1cfce243
commit
4496d75a4e
85
app/Cells/SidebarCertificateCell.php
Normal file
85
app/Cells/SidebarCertificateCell.php
Normal file
@ -0,0 +1,85 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Cells;
|
||||||
|
use CodeIgniter\View\Cells\Cell;
|
||||||
|
|
||||||
|
class SidebarCertificateCell extends Cell {
|
||||||
|
|
||||||
|
public $countAll = 0;
|
||||||
|
public $countUtc;
|
||||||
|
public $countMc;
|
||||||
|
public $countIc;
|
||||||
|
|
||||||
|
public function mount() {
|
||||||
|
$userPosId = session()->get('userposid');
|
||||||
|
$userId = session()->get('userid');
|
||||||
|
|
||||||
|
$db = \Config\Database::connect();
|
||||||
|
|
||||||
|
// Hanya Untuk Manager TSO
|
||||||
|
if ($userPosId == 1 && $userId == 1) {
|
||||||
|
|
||||||
|
// Eksekusi HANYA 1 QUERY untuk mengambil semua perhitungan
|
||||||
|
$result = $db->table('certificates')
|
||||||
|
->select("
|
||||||
|
SUM(CASE WHEN cert_type = 'UTC' THEN 1 ELSE 0 END) as totalUtc,
|
||||||
|
SUM(CASE WHEN cert_type = 'MC' THEN 1 ELSE 0 END) as totalMc,
|
||||||
|
SUM(CASE WHEN cert_type = 'IC' THEN 1 ELSE 0 END) as totalIc
|
||||||
|
")
|
||||||
|
->where('certificates.status', 'unvalidated')
|
||||||
|
->Where('certificates.manager_validation_at', null)
|
||||||
|
->get()
|
||||||
|
->getRow();
|
||||||
|
|
||||||
|
// Assign hasil ke property class, pastikan menjadi integer (fallback ke 0 jika tabel kosong)
|
||||||
|
$this->countUtc = (int) ($result->totalUtc ?? 0);
|
||||||
|
$this->countMc = (int) ($result->totalMc ?? 0);
|
||||||
|
$this->countIc = (int) ($result->totalIc ?? 0);
|
||||||
|
|
||||||
|
// Untuk SPV IVD
|
||||||
|
} else if ($userPosId == 2) {
|
||||||
|
|
||||||
|
// Eksekusi HANYA 1 QUERY untuk mengambil semua perhitungan
|
||||||
|
$result = $db->table('certificates')
|
||||||
|
->select("
|
||||||
|
SUM(CASE WHEN certificates.cert_type = 'UTC' THEN 1 ELSE 0 END) as totalUtc,
|
||||||
|
SUM(CASE WHEN certificates.cert_type = 'MC' THEN 1 ELSE 0 END) as totalMc,
|
||||||
|
SUM(CASE WHEN certificates.cert_type = 'IC' THEN 1 ELSE 0 END) as totalIc
|
||||||
|
")
|
||||||
|
->join('users', 'users.userid = certificates.user_id', 'left')
|
||||||
|
->where('users.reportto', $userId)
|
||||||
|
->where('certificates.status', 'unvalidated')
|
||||||
|
->Where('certificates.spv_validation_at', null)
|
||||||
|
->get()
|
||||||
|
->getRow();
|
||||||
|
|
||||||
|
// Assign hasil ke property class, pastikan menjadi integer (fallback ke 0 jika tabel kosong)
|
||||||
|
$this->countUtc = (int) ($result->totalUtc ?? 0);
|
||||||
|
$this->countMc = (int) ($result->totalMc ?? 0);
|
||||||
|
$this->countIc = (int) ($result->totalIc ?? 0);
|
||||||
|
|
||||||
|
// Untuk TSO IVD
|
||||||
|
} else if ($userPosId == 4) {
|
||||||
|
// Eksekusi HANYA 1 QUERY untuk mengambil semua perhitungan
|
||||||
|
$result = $db->table('certificates')
|
||||||
|
->select("
|
||||||
|
SUM(CASE WHEN cert_type = 'UTC' THEN 1 ELSE 0 END) as totalUtc,
|
||||||
|
SUM(CASE WHEN cert_type = 'MC' THEN 1 ELSE 0 END) as totalMc,
|
||||||
|
SUM(CASE WHEN cert_type = 'IC' THEN 1 ELSE 0 END) as totalIc
|
||||||
|
")
|
||||||
|
->where('user_id', $userId)
|
||||||
|
->where('user_validation_at', null)
|
||||||
|
->get()
|
||||||
|
->getRow();
|
||||||
|
|
||||||
|
// Assign hasil ke property class, pastikan menjadi integer (fallback ke 0 jika tabel kosong)
|
||||||
|
$this->countUtc = (int) ($result->totalUtc ?? 0);
|
||||||
|
$this->countMc = (int) ($result->totalMc ?? 0);
|
||||||
|
$this->countIc = (int) ($result->totalIc ?? 0);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Hitung total keseluruhan di level PHP, bukan di Database
|
||||||
|
$this->countAll = $this->countUtc + $this->countMc + $this->countIc;
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
50
app/Cells/sidebar_certificate_cell.php
Normal file
50
app/Cells/sidebar_certificate_cell.php
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
<?php
|
||||||
|
$certificateNotification = '';
|
||||||
|
$certificateNotificationUtc = '';
|
||||||
|
$certificateNotificationMc = '';
|
||||||
|
$certificateNotificationIc = '';
|
||||||
|
|
||||||
|
if ($countAll > 0) {
|
||||||
|
$certificateNotification = "<span><i class='fa-solid fa-circle-exclamation'></i></span>";
|
||||||
|
}
|
||||||
|
if ($countUtc > 0) {
|
||||||
|
$certificateNotificationUtc = "<span class='badge bg-warning text-dark px-2'>$countUtc</span>";
|
||||||
|
}
|
||||||
|
if ($countMc > 0) {
|
||||||
|
$certificateNotificationMc = "<span class='badge bg-warning text-dark px-2'>$countMc</span>";
|
||||||
|
}
|
||||||
|
if ($countIc > 0) {
|
||||||
|
$certificateNotificationIc = "<span class='badge bg-warning text-dark px-2'>$countIc</span>";
|
||||||
|
}
|
||||||
|
?>
|
||||||
|
|
||||||
|
<li>
|
||||||
|
<a class="has-arrow waves-effect waves-dark d-flex justify-content-between align-items-center" href='javascript:void(0)' aria-expanded="false">
|
||||||
|
<span>
|
||||||
|
<i class="fa-solid fa-certificate"></i><span class='hide-menu'>Certificates</span>
|
||||||
|
</span>
|
||||||
|
<?= $certificateNotification ?>
|
||||||
|
</a>
|
||||||
|
<ul aria-expanded="false" class="collapse">
|
||||||
|
<li>
|
||||||
|
<a href="<?=base_url();?>certificates/training" class="d-flex justify-content-between align-items-center">
|
||||||
|
Training
|
||||||
|
<?= $certificateNotificationUtc ?>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="<?=base_url();?>certificates/maintenance" class="d-flex justify-content-between align-items-center">
|
||||||
|
Maintenance
|
||||||
|
<?= $certificateNotificationMc ?>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<li>
|
||||||
|
<a href="<?=base_url();?>certificates/installation" class="d-flex justify-content-between align-items-center">
|
||||||
|
Installation
|
||||||
|
<?= $certificateNotificationIc ?>
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<!-- <li><a href="<?=base_url();?>certificates/calibration">Callibration</a></li> -->
|
||||||
|
<!-- <li><a href="<?=base_url();?>certificates/official-report">Official Report</a></li> -->
|
||||||
|
</ul>
|
||||||
|
</li>
|
||||||
@ -38,15 +38,8 @@
|
|||||||
</ul>
|
</ul>
|
||||||
</li>
|
</li>
|
||||||
|
|
||||||
<li> <a class="has-arrow waves-effect waves-dark" href='javascript:void(0)' aria-expanded="false"> <i class="fa-solid fa-certificate"></i><span class='hide-menu'>Certificates</span> </a>
|
<!-- Menu Menggunakan Teknik View Cell Yang Ada Pada app/Cells -->
|
||||||
<ul aria-expanded="false" class="collapse">
|
<?= view_cell('SidebarCertificateCell') ?>
|
||||||
<li><a href="<?=base_url();?>certificates/training">Training</a></li>
|
|
||||||
<li><a href="<?=base_url();?>certificates/maintenance">Maintenance</a></li>
|
|
||||||
<li><a href="<?=base_url();?>certificates/installation">Installation</a></li>
|
|
||||||
<!-- <li><a href="<?=base_url();?>certificates/calibration">Callibration</a></li> -->
|
|
||||||
<!-- <li><a href="<?=base_url();?>certificates/official-report">Official Report</a></li> -->
|
|
||||||
</ul>
|
|
||||||
</li>
|
|
||||||
|
|
||||||
<?php if ( !($isTSM || $isPS) ): ?>
|
<?php if ( !($isTSM || $isPS) ): ?>
|
||||||
<li> <a class="waves-effect waves-dark" href='<?=base_url();?>contacts' aria-expanded="false"> <i class="fa-solid fa-address-book"></i><span class="hide-menu">Contact</span></a> </li>
|
<li> <a class="waves-effect waves-dark" href='<?=base_url();?>contacts' aria-expanded="false"> <i class="fa-solid fa-address-book"></i><span class="hide-menu">Contact</span></a> </li>
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user