<?php 



class M_strategi extends CI_Model{	



    



    function __construct() {



        parent::__construct();



    }



    



    function kode_user(){



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



    }



    



    function data_strategi(){



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



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



    }



    function data_head_strategi(){



        $sql = "SELECT head,kode_head,count(kode_head) jml FROM tb_strategi WHERE is_deleted = 0 GROUP BY kode_head";



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



    }



    function ambil_nomor_head(){



        $sql = "SELECT max(kode_head) max_kode FROM tb_strategi";



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



    }



    function ambil_nomor_strategi($kode_head){



        $sql = "SELECT max(kode_strategi) max_kode FROM tb_strategi WHERE kode_head = '$kode_head'";



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



    }



    function simpan_strategi($data){



        $kode_user = $this->kode_user();



        $sql = "INSERT INTO `tb_strategi`  (`head`, `kode_head`,`kode_strategi`, `keterangan`, `created_at`, `created_by`) 



                VALUES                     ('$data[head]','$data[kode_head]','$data[kode_strategi]','$data[keterangan]',NOW(),'$kode_user')";



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



    }



    function data_detail_strategi($kode_head){



        $sql = "SELECT * FROM tb_strategi WHERE is_deleted = 0 AND kode_head = '$kode_head'";



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



    }



    function update_nomor_strategi($data){



        $kode_user = $this->kode_user();



        $sql = "UPDATE `tb_strategi` SET `keterangan`='$data[keterangan]',`updated_at`=NOW(),`updated_by`='$kode_user' WHERE kode_strategi = '$data[kode_strategi]'";



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



    }



    function hapus_nomor_strategi($data){



        $sql = "UPDATE `tb_strategi` SET `is_deleted`='1' WHERE kode_strategi = '$data[kode_strategi]'";



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



    }



    function hapus_head_strategi($data){



        $sql = "UPDATE `tb_strategi` SET `is_deleted`='1' WHERE kode_head = '$data[kode_head]'";



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



    }



    function ganti_nama_head($data){



        $sql = "UPDATE `tb_strategi` SET `head`='$data[head]' WHERE kode_head = '$data[kode_head]'";



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



    }



}