<?php 
class M_unit_misioner extends CI_Model{	
    function __construct() {
        parent::__construct();
    }
    function kode_user(){
        return $this->session->userdata("kode_user");
    }
    function data_unit_misioner(){
        $sql = "SELECT * FROM tb_unit_misioner WHERE is_deleted = 0 ";
        return $this->db->query($sql);
    }
    function simpan_unit_misioner($data){
        $kode_user = $this->kode_user();
        $sql = "INSERT INTO `tb_unit_misioner`  (`nama`, `kode`, `keterangan`, `created_at`, `created_by`) 
                VALUES                          ('$data[nama_unit_misioner]','$data[kode_unit_misioner]','$data[keterangan]',NOW(),'$kode_user')";
        return $this->db->query($sql);
    }
    function ambil_unit_misioner($data){
        $sql = "SELECT * FROM tb_unit_misioner WHERE id_unit_misioner = '$data[id_unit_misioner]'";
        return $this->db->query($sql);
    }
    function update_unit_misioner($data){
        $kode_user = $this->kode_user();
        $sql = "UPDATE `tb_unit_misioner` SET `nama`='$data[nama_unit_misioner]',`kode`='$data[kode_unit_misioner]',`keterangan`='$data[keterangan]',`updated_at`=NOW(),`updated_by`='$kode_user' WHERE id_unit_misioner = '$data[id_unit_misioner]'";
        return $this->db->query($sql);
    }
    function hapus_unit_misioner($data){
        $sql = "UPDATE `tb_unit_misioner` SET `is_deleted`='1' WHERE id_unit_misioner = '$data[id_unit_misioner]'";
        return $this->db->query($sql);
    }
}