<?php 

class M_laporan_excel extends CI_Model{	

    

    function __construct() {

        parent::__construct();

    }

    

    function kode_user(){

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

    }

    function data_detail_pka($data){

        $sql = "SELECT p.*,um.nama nm_um,jk.nama nm_jk,b.nama nm_b,pk.nama nm_pk,s.kode_strategi,u.username,u.email,s.keterangan s_ket,s.head FROM tb_pka p

        		LEFT JOIN tb_unit_misioner um ON um.id_unit_misioner = p.unit_misioner

        		LEFT JOIN tb_jenis_kegiatan jk ON jk.id_jenis_kegiatan = p.jenis_kegiatan

        		LEFT JOIN tb_bidang b ON b.id_bidang = p.bidang

        		LEFT JOIN tb_prioritas_kegiatan pk ON pk.id_prioritas_kegiatan = p.prioritas_kegiatan

        		LEFT JOIN tb_strategi s ON s.id_strategi = p.nomor_strategi

        		LEFT JOIN tb_user u ON u.kode_user = p.created_by

        		WHERE p.no_pka='$data[no_pka]'

                ORDER BY id_pka ASC";

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

    }

    function select_data_pka_penerimaan($data){

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

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

    }

    function select_data_pka_pengeluaran($data){

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

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

    }





    ////////////////////////user///////////////////////////

    function data_pka_dashboard_user($periode){

        $kode_user = $this->kode_user();

        $sql = "SELECT p.*,um.nama nm_um,jk.nama nm_jk,b.nama nm_b,pk.nama nm_pk,s.kode_strategi,u.username,u.email,s.keterangan s_ket,s.head FROM tb_pka p

                LEFT JOIN tb_unit_misioner um ON um.id_unit_misioner = p.unit_misioner

                LEFT JOIN tb_jenis_kegiatan jk ON jk.id_jenis_kegiatan = p.jenis_kegiatan

                LEFT JOIN tb_bidang b ON b.id_bidang = p.bidang

                LEFT JOIN tb_prioritas_kegiatan pk ON pk.id_prioritas_kegiatan = p.prioritas_kegiatan

                LEFT JOIN tb_strategi s ON s.id_strategi = p.nomor_strategi

                LEFT JOIN tb_user u ON u.kode_user = p.created_by

                WHERE p.acc = 1 and p.is_deleted = 0 AND p.periode_thn = '$periode' AND p.created_by = '$kode_user'";

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

    }

    function select_data_pka_penerimaan_dashboard_user($data){

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

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

    }

    function select_data_pka_pengeluaran_dashboard_user($data){

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

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

    }

    ///////////////////////////////////////////////////////////////



    //////////////////////////admin////////////

    function data_pka_dashboard_admin($periode){

        $sql = "SELECT p.*,um.nama nm_um,jk.nama nm_jk,b.nama nm_b,pk.nama nm_pk,s.kode_strategi,u.username,u.email,s.keterangan s_ket,s.head FROM tb_pka p

                LEFT JOIN tb_unit_misioner um ON um.id_unit_misioner = p.unit_misioner

                LEFT JOIN tb_jenis_kegiatan jk ON jk.id_jenis_kegiatan = p.jenis_kegiatan

                LEFT JOIN tb_bidang b ON b.id_bidang = p.bidang

                LEFT JOIN tb_prioritas_kegiatan pk ON pk.id_prioritas_kegiatan = p.prioritas_kegiatan

                LEFT JOIN tb_strategi s ON s.id_strategi = p.nomor_strategi

                LEFT JOIN tb_user u ON u.kode_user = p.created_by

                WHERE p.acc = 1 and p.is_deleted = 0 AND p.periode_thn = '$periode'";

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

    }

    function select_data_pka_penerimaan_dashboard_admin($data){

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

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

    }

    function select_data_pka_pengeluaran_dashboard_admin($data){

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

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

    }

}