<?php 



class M_bidang extends CI_Model{	



    



    function __construct() {



        parent::__construct();



    }



    



    function kode_user(){



        return $this->session->userdata("kode_user");



    }



    



    function data_bidang(){



        $sql = "SELECT * FROM tb_bidang WHERE is_deleted = 0 ";



        return $this->db->query($sql);



    }



    function simpan_bidang($data){



        $kode_user = $this->kode_user();



        $sql = "INSERT INTO `tb_bidang`  (`nama`, `kode`, `keterangan`, `created_at`, `created_by`) 



                VALUES                          ('$data[nama]','$data[kode]','$data[keterangan]',NOW(),'$kode_user')";



        return $this->db->query($sql);



    }



    function ambil_bidang($data){



        $sql = "SELECT * FROM tb_bidang WHERE id_bidang = '$data[id_bidang]'";



        return $this->db->query($sql);



    }



    function update_bidang($data){



        $kode_user = $this->kode_user();



        $sql = "UPDATE `tb_bidang` SET `nama`='$data[nama]',`kode`='$data[kode]',`keterangan`='$data[keterangan]',`updated_at`=NOW(),`updated_by`='$kode_user' WHERE id_bidang = '$data[id_bidang]'";



        return $this->db->query($sql);



    }



    function hapus_bidang($data){



        $sql = "UPDATE `tb_bidang` SET `is_deleted`='1' WHERE id_bidang = '$data[id_bidang]'";



        return $this->db->query($sql);



    }



}