<?php 
class M_laporan_rekap_ev_tri extends CI_Model{	
    function __construct() {
        parent::__construct();
    }
    function kode_user(){
        return $this->session->userdata("kode_user");
    }
    function unit_misioner(){
        return $this->session->userdata("unit_misioner");
    }


    function laporan_rekap_evaluasi_pertriwulan_pdf($periode_thn,$triwulan,$unit_misioner){

        if($triwulan == "all"){
            $tr = "";
        }else{
            $tr = " AND evt.triwulan_evaluasi = '$triwulan' ";
        }
        if($unit_misioner == "all"){
            $um = "";
        }else{
            $um = " AND p.unit_misioner = '$unit_misioner' ";
        }

        $sql = "SELECT evt.*, p.kma,jk.nama nm_jk, um.nama nm_um , bd.nama nm_bd,p.nama_kegiatan,p.tujuan_kegiatan,p.ev_tri,p.indikator_kualitatif,sum(pn.penerimaan) spn,sum(pg.pengeluaran) spg,p.triwulan
                FROM tb_ev_tri evt
                LEFT JOIN tb_pka p ON p.kma  = evt.kma
                LEFT JOIN tb_pka_penerimaan pn ON pn.kode_pka  = p.kode_pka
                LEFT JOIN tb_pka_pengeluaran pg ON pg.kode_pka  = p.kode_pka
                LEFT JOIN tb_user u ON u.kode_user = p.created_by
                LEFT JOIN tb_jenis_kegiatan jk ON jk.id_jenis_kegiatan = p.jenis_kegiatan
                LEFT JOIN tb_bidang bd ON bd.id_bidang = p.bidang
                LEFT JOIN tb_unit_misioner um ON um.id_unit_misioner = p.unit_misioner
                WHERE p.periode_thn ='".str_replace("-","/",$periode_thn)."' $tr $um";
        return $this->db->query($sql);
    }
    function laporan_rekap_evaluasi_pertriwulan_pdf_user($periode_thn,$triwulan){

        if($triwulan == "all"){
            $tr = "";
        }else{
            $tr = " AND evt.triwulan_evaluasi = '$triwulan' ";
        }
        $unit_misioner = $this->unit_misioner();
        $um = " AND p.unit_misioner = '$unit_misioner' ";
 

        $sql = "SELECT evt.*, p.kma,jk.nama nm_jk, um.nama nm_um , bd.nama nm_bd,p.nama_kegiatan,p.tujuan_kegiatan,p.ev_tri,p.indikator_kualitatif,sum(pn.penerimaan) spn,sum(pg.pengeluaran) spg,p.triwulan
                FROM tb_ev_tri evt
                LEFT JOIN tb_pka p ON p.kma  = evt.kma
                LEFT JOIN tb_pka_penerimaan pn ON pn.kode_pka  = p.kode_pka
                LEFT JOIN tb_pka_pengeluaran pg ON pg.kode_pka  = p.kode_pka
                LEFT JOIN tb_user u ON u.kode_user = p.created_by
                LEFT JOIN tb_jenis_kegiatan jk ON jk.id_jenis_kegiatan = p.jenis_kegiatan
                LEFT JOIN tb_bidang bd ON bd.id_bidang = p.bidang
                LEFT JOIN tb_unit_misioner um ON um.id_unit_misioner = p.unit_misioner
                WHERE p.periode_thn ='".str_replace("-","/",$periode_thn)."' $tr $um";
        return $this->db->query($sql);
    }
}