<?php
class User_model extends CI_Model {

    public function get_total_users() {
        return $this->db->count_all('users');
    }

    // ✅ Perbaikan utama: hitung DISTINCT dari kolom `skpd` di tabel `users`
    public function get_total_opd() {
        $this->db->select('skpd');
        $this->db->from('users');
        $this->db->where('skpd IS NOT NULL');
        $this->db->where('skpd !=', '');
        $this->db->group_by('skpd');
        return $this->db->count_all_results();
    }

    public function get_total_jabatan() {
        $this->db->select('jabatan');
        $this->db->from('users');
        $this->db->where('jabatan IS NOT NULL');
        $this->db->where('jabatan !=', '');
        $this->db->group_by('jabatan');
        return $this->db->count_all_results();
    }

    public function get_ketua_tim() {
        $this->db->like('tugas_tambahan', 'Ketua Tim Kerja');
        return $this->db->count_all_results('users');
    }

    public function get_by_eselon($eselon) {
        if (is_array($eselon)) {
            $this->db->where_in('eselon', $eselon);
        } else {
            $this->db->where('eselon', $eselon);
        }
        return $this->db->count_all_results('users');
    }
}