<?php 

class M_laporan_rekap_bidang extends CI_Model{	

    

    function __construct() {

        parent::__construct();

    }

    

    function kode_user(){

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

    }

    function data_pka_periode($data){

        $sql = "SELECT pka.kode_pka,pka.bidang,pka.bidang,b.nama nama_bidang

                FROM tb_pka pka 

                INNER JOIN tb_bidang b ON b.id_bidang = pka.bidang

                WHERE pka.periode_thn = '$data[periode_thn]' AND pka.is_deleted = 0 AND pka.acc !=2 /*AND pka.evaluasi =1*/

                GROUP BY pka.bidang

                ORDER BY pka.bidang ASC";

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

    }

    function data_pka_periode_kode_pka($data){

        $sql = "SELECT pka.kode_pka

                FROM tb_pka pka 

                WHERE pka.bidang = '$data[bidang]' AND periode_thn = '$data[periode_thn]' AND pka.is_deleted = 0 AND pka.acc !=2 /*AND pka.evaluasi =1*/

                ";

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

    }

    function ambil_penerimaan($data){

        $sql = "SELECT penerimaan FROM tb_pka_penerimaan WHERE kode_pka = '$data[kode_pka]'

                ";

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

    }

    function ambil_pengeluaran($data){

        $sql = "SELECT pengeluaran FROM tb_pka_pengeluaran WHERE kode_pka = '$data[kode_pka]'

                ";

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

    }

    function ambil_triwulan($data){

        $sql = "SELECT triwulan FROM tb_pka WHERE kode_pka = '$data[kode_pka]'

                ";

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

    }

    ///////////////////// rekap bidang 2

    function data_pka_periode_2($data){

        $sql = "SELECT pka.kode_pka,pka.kma,pka.bidang,pka.bidang,pka.nama_kegiatan,b.nama nama_bidang,c.nama nama_um

                FROM tb_pka pka 

                INNER JOIN tb_bidang b ON b.id_bidang = pka.bidang

                INNER JOIN tb_unit_misioner c ON c.id_unit_misioner = pka.unit_misioner

                WHERE pka.periode_thn = '$data[periode_thn]' AND pka.is_deleted = 0 AND pka.bidang = '$data[id_bidang]' AND pka.acc !=2 /*AND pka.evaluasi =1*/

                ORDER BY c.kode,pka.kma ASC";

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

    }

    function data_pka_periode_3($data){

        $sql = "SELECT pka.*,b.nama nama_bidang,c.nama nama_um,d.nama nama_jk

                FROM tb_pka pka 

                INNER JOIN tb_bidang b ON b.id_bidang = pka.bidang

                INNER JOIN tb_unit_misioner c ON c.id_unit_misioner = pka.unit_misioner

                INNER JOIN tb_jenis_kegiatan d ON d.id_jenis_kegiatan = pka.jenis_kegiatan

                WHERE pka.periode_thn = '$data[periode_thn]' AND pka.is_deleted = 0 AND pka.bidang = '$data[id_bidang]' AND pka.acc !=2 /*AND pka.evaluasi =1*/

                ORDER BY c.kode,pka.kma ASC";

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

    }

}