diff --git a/app/Cells/SidebarCertificateCell.php b/app/Cells/SidebarCertificateCell.php new file mode 100644 index 0000000..65916da --- /dev/null +++ b/app/Cells/SidebarCertificateCell.php @@ -0,0 +1,85 @@ +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; + + } +} \ No newline at end of file diff --git a/app/Cells/sidebar_certificate_cell.php b/app/Cells/sidebar_certificate_cell.php new file mode 100644 index 0000000..e4fa49f --- /dev/null +++ b/app/Cells/sidebar_certificate_cell.php @@ -0,0 +1,50 @@ + 0) { + $certificateNotification = ""; +} +if ($countUtc > 0) { + $certificateNotificationUtc = "$countUtc"; +} +if ($countMc > 0) { + $certificateNotificationMc = "$countMc"; +} +if ($countIc > 0) { + $certificateNotificationIc = "$countIc"; +} +?> + +
  • + + +
  • diff --git a/app/Views/layouts/_sidebar.php b/app/Views/layouts/_sidebar.php index 3b9230b..db9be7f 100644 --- a/app/Views/layouts/_sidebar.php +++ b/app/Views/layouts/_sidebar.php @@ -38,15 +38,8 @@ -
  • - -
  • + +