<?php
class Unor_model extends CI_Model {

    // ✅ Ambil semua data UNOR
    public function get_all($search = null, $unor_induk_id = null, $unor_mandiri = null) {
        if ($search) {
            $this->db->group_start()
                ->like('nama', $search)
                ->or_like('unor_induk_nama', $search)
                ->or_like('unor_atasan_nama', $search)
            ->group_end();
        }

        if ($unor_induk_id) {
            $this->db->where('unor_induk_id', $unor_induk_id);
        }

        if ($unor_mandiri !== null) {
            $this->db->where('unor_mandiri', $unor_mandiri);
        }

        return $this->db->order_by('nama', 'ASC')->get('unor')->result();
    }

    // ✅ Perbaiki: gunakan distinct() + select(..., FALSE)
    public function get_unor_induk_list() {
        return $this->db
            ->select('unor_induk_id, unor_induk_nama', FALSE) // ← FALSE = non-backtick
            ->distinct() // ← gunakan method distinct()
            ->where('unor_induk_id IS NOT NULL')
            ->order_by('unor_induk_nama', 'ASC')
            ->get('unor')
            ->result();
    }
}