<?php 

class M_dashboard extends CI_Model{	

    

    function __construct() {

        parent::__construct();

    }

    

    function kode_user(){

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

    }

    function periode_thn(){

        $kode_user = $this->kode_user();

        $sql = "SELECT `periode_thn` FROM `tb_sesi_pka` WHERE is_deleted=0 ORDER BY id_sesi_pka DESC";

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

    }

    function data_pka($periode_thn){

        $kode_user = $this->kode_user();

        $sql = "SELECT kode_pka FROM tb_pka WHERE created_by = '$kode_user' AND periode_thn = '$periode_thn' AND acc != '2' AND is_deleted='0'";

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

    }

    function data_pka_pengeluaran($kode_pka){

        $kode_user = $this->kode_user();

        $sql = "SELECT * FROM `tb_pka_pengeluaran` WHERE kode_pka = '$kode_pka'";

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

    }

    function data_pka_penerimaan($kode_pka){

        $kode_user = $this->kode_user();

        $sql = "SELECT * FROM `tb_pka_penerimaan` WHERE kode_pka = '$kode_pka'";

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

    }

    function data_pka_tersimpan($periode_thn){

        $kode_user = $this->kode_user();

        $sql = "SELECT kode_pka FROM tb_save_pka WHERE created_by = '$kode_user'";

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

    }

    function data_pka_pengeluaran_tersimpan($kode_pka){

        $kode_user = $this->kode_user();

        $sql = "SELECT * FROM `tb_save_pka_pengeluaran` WHERE kode_pka = '$kode_pka'";

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

    }

    function data_pka_penerimaan_tersimpan($kode_pka){

        $kode_user = $this->kode_user();

        $sql = "SELECT * FROM `tb_save_pka_penerimaan` WHERE kode_pka = '$kode_pka'";

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

    }

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

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

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

    function data_pka_admin($periode_thn){

        // $kode_user = $this->kode_user();

        $sql = "SELECT kode_pka FROM tb_pka WHERE periode_thn = '$periode_thn' AND acc != '2' AND is_deleted ='0'";

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

    }

    function data_pka_pengeluaran_admin($kode_pka){

        $kode_user = $this->kode_user();

        $sql = "SELECT * FROM `tb_pka_pengeluaran` WHERE kode_pka = '$kode_pka'";

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

    }

    function data_pka_penerimaan_admin($kode_pka){

        $kode_user = $this->kode_user();

        $sql = "SELECT * FROM `tb_pka_penerimaan` WHERE kode_pka = '$kode_pka'";

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

    }
    function chart_log($date){
        $sql = "SELECT count(created_at) c FROM `tb_log` WHERE date(created_at) = '$date' GROUP BY date(created_at)";
        return $this->db->query($sql);
    }

}