<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Delegasi extends CI_Model{

	function parseOrderby($col){
		if($col==1){
			return "id_pn_asal"; 
		}else if($col==2){
			return "nomor_perkara"; 
		}else if($col==3){
			return "tgl_resi"; 
		}else if($col==4){
			return "nomor_surat"; 
		}else if($col==5){
			return "id_jenis_delegasi"; 
		}else{
			return "tgl_surat"; 
		}
	}

	function isNomorPerkara($txt){
		$re1='(\\d+)';	# Integer Number 1
		$re2='(\\/)';	# Any Single Character 1
		$re3='.*?';	# Non-greedy match on filler
		$re4='(\\/)';	# Any Single Character 2
		$re5='((?:(?:[1]{1}\\d{1}\\d{1}\\d{1})|(?:[2]{1}\\d{3})))(?![\\d])';	# Year 1
		$re6='(\\/)';	# Any Single Character 3
		$re7='(PN)';	# Variable Name 1
		if ($c=preg_match_all ("/".$re1.$re2.$re3.$re4.$re5.$re6.$re7."/is", $txt, $matches)){
		      $int1=$matches[1][0];
		      $c1=$matches[2][0];
		      $c2=$matches[3][0];
		      $year1=$matches[4][0];
		      $c3=$matches[5][0];
		      $var1=$matches[6][0];
		      return 1;
		}else{
			return 0;
		}
	}

	function identitasPN(){
		try {
			$query = $this->db->query("
				SELECT * FROM    
				(SELECT VALUE AS NamaPN FROM sys_config WHERE id=62) AS a,
				(SELECT VALUE AS IDPN FROM sys_config WHERE id=81) AS b,
				(SELECT VALUE AS kode_satker FROM sys_config WHERE id=82) AS c");
			return $query;
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}

	function get_list_pt($idpt=0,$jenis_pengadilan=NULL){
		try {
			if ($jenis_pengadilan!=NULL){
				$where=" where jenis_pengadilan=$jenis_pengadilan";
			}else{
				$where=" ";
			}
			if($idpt!=0){
				$and= " AND id=$idpt";
			}else{
				$and= "";
			}
			$query = $this->db->query(
					 "SELECT * FROM pengadilan_tinggi ".$where." ".$and." ORDER BY nama ASC");
			return $query;
		} catch (Exception $e) {
			
		}
	}


	function get_id_pt($idpn){
		try {
			if(!empty($idpn)){
				$this->db->where('id',$idpn);
			}
			$query = $this->db->query( "SELECT a.id,a.nama,b.pt_id
										FROM pengadilan_tinggi AS a
										JOIN 
										(SELECT id,pt_id FROM pengadilan_negeri) AS b
										ON b.pt_id=a.id WHERE b.id=".$idpn." ORDER BY nama ASC"
										);
			return $query;
		} catch (Exception $e) {
			
		}
	}

	

	function getKodeSatker($id){
		try {
			$query = $this->db->query(
					 "SELECT kode FROM pengadilan_negeri where id = $id");
			return $query;
		} catch (Exception $e) {
			log_message('error', $e);
		}

	}

	function get_list_pn(){
		try {
			$query = $this->db->query("SELECT * FROM pengadilan_negeri ORDER BY nama ASC");
			return $query;
		} catch (Exception $e) {
		}
	}


	function getPerkaraListDelegasi($idalur=NULL,$col=NULL,$type='DESC',$begin=0,$key=''){
		$orderby = $this->parseOrderby($col);
		$andstatus='';
		if ($idalur==1) {
			$dbname="delegasi_masuk";
			$dbproses="delegasi_proses_masuk";
		}elseif($idalur==2){
			$dbname="delegasi_keluar";
			$dbproses="delegasi_proses_keluar";
		}elseif($idalur=='k_blm_k'){
			$dbname="delegasi_keluar";
			$dbproses="delegasi_proses_keluar";
			if(!empty($key)){$andstatus=' and a.status_kirim=0 ';}else{$andstatus=' where a.status_kirim=0 ';}
		}elseif($idalur=='k_sdh_k'){
			$dbname="delegasi_keluar";
			$dbproses="delegasi_proses_keluar";
			if(!empty($key)){$andstatus=' and a.status_kirim=1 ';}else{$andstatus=' where a.status_kirim=1 ';}
		}elseif($idalur=='k_sdh_l'){
			$dbname="delegasi_keluar";
			$dbproses="delegasi_proses_keluar";
			if(!empty($key)){$andstatus=' and a.status_kirim=2 ';}else{$andstatus=' where a.status_kirim=2 ';}
		}elseif($idalur=='k_blm_l'){
			$dbname="delegasi_keluar";
			$dbproses="delegasi_proses_keluar";
			if(!empty($key)){$andstatus=' and a.status_kirim<2 ';}else{$andstatus=' where a.status_kirim<2 ';}
		}elseif($idalur=='m_blm_l'){
			$dbname="delegasi_masuk";
			$dbproses="delegasi_proses_masuk";
			if(!empty($key)){$andstatus=' and a.status_kirim<1 ';}else{$andstatus=' where a.status_kirim<1 ';}
		}elseif($idalur=='m_sdh_l'){
			$dbname="delegasi_masuk";
			$dbproses="delegasi_proses_masuk";
			if(!empty($key)){$andstatus=' and a.status_kirim=1 ';}else{$andstatus=' where a.status_kirim=1 ';}
		}else{
			$dbname="delegasi_masuk";
			$dbproses="delegasi_proses_masuk";
		}
			if(!empty($key)){
				$where_like = ' WHERE a.nomor_perkara LIKE "%'.$key.'%" OR a.kode_satker_asal LIKE "%'.$key.'%" OR a.pn_asal_text LIKE "%'.$key.'%" OR a.pn_tujuan_text LIKE "%'.$key.'%" OR a.tgl_pengiriman LIKE "%'.$key.'%" OR a.tgl_surat LIKE "%'.$key.'%" OR a.nomor_surat LIKE "%'.$key.'%" OR a.jenis_delegasi_text LIKE "%'.$key.'%" OR b.status_delegasi LIKE "%'.$key.'%" OR b.jurusita_nama LIKE "%'.$key.'%"';
			} else {
				$where_like='';
			}
			try {
				$sql="SELECT SQL_CALC_FOUND_ROWS 
										a.*,
										b.perkara_id,
										b.id_status_delegasi,
										b.delegasi_id,
										b.jurusita_nama,
										b.status_delegasi,
										b.tgl_relaas,
										c.nama as pn_tujuan_text, DATEDIFF(case 
																		when (b.tgl_relaas is null)
																		THEN (curdate())
																		ELSE (b.tgl_relaas)
																		END,a.tgl_surat) as lama 
											FROM ".$dbname." AS a
											LEFT JOIN (select id,nama from pengadilan_negeri) as c
											on a.id_pn_tujuan=c.id
											LEFT JOIN
											(SELECT perkara_id,id_pn_asal,id_status_delegasi,delegasi_id,jurusita_nama,status_delegasi,tgl_relaas FROM ".$dbproses.") AS b
											ON b.delegasi_id=a.id and b.perkara_id=a.perkara_id and b.id_pn_asal=a.id_pn_asal"." ".
											$where_like." ".$andstatus." ORDER BY a.".$orderby." ASC LIMIT ".$begin.",50";
				$query = $this->db->query($sql);
				
				return $query;
			} catch (Exception $e) {
				log_message('error', $e);
			}
	}

	function getPerkaraList($idalurperkara='',$col=2,$type='DESC',$begin=0,$key=''){
		$orderby = $this->parseOrderby($col);
		$where = '';
		
		if($idalurperkara==1 OR $idalurperkara==7){
			$idalurperkara = '1,7';
		}
		if($idalurperkara>0){
			$where = "AND alur_perkara_id IN (".$idalurperkara.")";
		}else{
			$where = "";
		}

		if(!empty($key)){
			$where_like = ' WHERE (nomor_perkara LIKE "%'.$key.'%" OR tanggal_pendaftaran LIKE "%'.$key.'%" OR jenis_perkara_nama LIKE "%'.$key.'%" OR para_pihak LIKE "%'.$key.'%" OR tahapan_terakhir_text LIKE "%'.$key.'%" OR proses_terakhir_text LIKE "%'.$key.'%") ';
		}else{
			$where_like =" ";
			if($idalurperkara>0){
				$where = " WHERE alur_perkara_id IN (".$idalurperkara.")";
			}
		}
		try {
			$query = $this->db->query("SELECT SQL_CALC_FOUND_ROWS perkara_id, perkara_id,alur_perkara_id,jenis_perkara_nama,nomor_perkara
				,tanggal_pendaftaran,para_pihak, tahapan_terakhir_text, proses_terakhir_text ,
				IF(proses_terakhir_id<220,DATEDIFF(CURDATE(),tanggal_pendaftaran), DATEDIFF(tanggal_putusan,tanggal_pendaftaran) ) AS durasi
				FROM v_perkara  ".$where_like." ".$where." ORDER BY ".$orderby." ".$type." ,nomor_indeks DESC LIMIT ".$begin.",50");
			return $query;
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}

	function get_detil_delegasi($idalur,$delegasi_id=NULL,$idpnasal=NULL,$idpntujuan=NULL){

		if ($idalur=='1'){
			$dbName="delegasi_masuk";
			$sumber='asal';
		}else{
			$dbName="delegasi_keluar";
			$sumber='tujuan';
		}
		try {
			if ($idpnasal!=NULL OR $idpntujuan !==NULL) {
				$query = $this->db->query("SELECT a.*,b.nama as pn_tujuan_text
										   from ".$dbName." as a
										   left join
										   (select id,nama from pengadilan_negeri) as b
										   on a.id_pn_".$sumber."=b.id
										    WHERE a.id=".$delegasi_id.' AND a.id_pn_asal='.$idpnasal);
			}else{
				$query = $this->db->query('SELECT * 
										   from '.$dbName);
			}												   			
			return $query;
		} catch (Exception $e) {
			log_message('error', $e);
		}

	}
	function get_detil_proses($idalur,$delegasi_id,$idpnasal,$idpntujuan){
		try {
			if ($idalur==1) {
				$dbName="masuk";
			}else {
				$dbName="keluar";
			}
			if ($idpnasal!=NULL OR $idpntujuan !==NULL) {
				$query = $this->db->query('SELECT * 
										   from delegasi_proses_'.$dbName.' '.
										   ' WHERE delegasi_id='.$delegasi_id.' AND id_pn_asal='.$idpnasal.' AND id_pn_tujuan='.$idpntujuan);
			}
			
			return $query;
		} catch (Exception $e) {
			log_message('error', $e);
		}

	}

	function get_pelaksanaan($idalur,$delegasi_id,$idpnasal,$idpntujuan){
		try {
			if ($idalur==1) {
				$dbName="masuk";
			}else {
				$dbName="keluar";
			}
			if ($idpnasal!=NULL OR $idpntujuan !==NULL) {
				$query = $this->db->query('SELECT   delegasi_id,
													tgl_surat_diterima,
													perkara_id,
													tgl_penunjukan_jurusita,
													jurusita_id,
													jurusita_nama,
													id_pn_asal,
													pn_asal_text,
													kode_satker_asal,
													id_pn_tujuan,
													pn_tujuan_text,
													kode_satker_tujuan,
													tgl_relaas,
													nomor_relaas,
													tgl_pengiriman_relaas,
													nomor_surat_pengantar_relaas,
													id_status_delegasi,
													status_delegasi,
													tgl_resi,
													nomor_resi,
													biaya,
													catatan,
													diinput_oleh,
													diinput_tanggal,
													diperbaharui_oleh,
													diperbaharui_tanggal 
										   from delegasi_proses_'.$dbName.' '.
										   ' WHERE delegasi_id='.$delegasi_id.' AND id_pn_asal='.$idpnasal.' AND id_pn_tujuan='.$idpntujuan);
			}
			
			return $query;
		} catch (Exception $e) {
			log_message('error', $e);
		}

	}

	function getDataPN($id){
		try {
			$query = $this->db->query(
					 "SELECT * FROM pengadilan_negeri where id ="."'".$id."' ORDER BY nama ASC");
			return $query;
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}

	function getJenisDelegasi($id=NULL){
		try {
			if ($id!=null) {
				$query = $this->db->query(
					 "SELECT id,jenis_delegasi FROM jenis_delegasi where id = $id");
			}else{
				$query = $this->db->query(
					 "SELECT id,jenis_delegasi FROM jenis_delegasi");
			}
				return $query;
		} catch (Exception $e) {
			log_message('error', $e);
		}

	}

	function getDelegasiProses($id=NULL,$jenis){
		try {
			$query = $this->db->query(
			   'SELECT a.*,b.id AS IDMasuk
			   FROM delegasi_proses AS a
			   LEFT JOIN
			   (SELECT * FROM delegasi_'.$jenis.') AS b ON b.id=a.delegasi_id
	 			WHERE a.delegasi_id='.$id);
		  return $query;
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}

	function getDataJurusita(){
		try {
			$query = $this->db->query('SELECT * FROM  jurusita WHERE aktif="Y";');
			return $query;
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}

	function fecth_data_num($key){
		$query = $this->db->query("SELECT FOUND_ROWS() as cnt;");
		if($query->num_rows>0){
			foreach ($query->result() as $row) {
				return $row->cnt;
			}
    		return $query->num_rows;
    	}else{
    		return 0;
    	}
	}

	function fetchData($nomor_perkara,$keyword=NULL){
		if(empty($nomor_perkara)) {
			if(empty($keyword)){
				$perintah=' WHERE p.nomor_perkara='.'"'.$nomor_perkara.'"';
			} else{
				$perintah=' WHERE p.nomor_perkara LIKE '.'"'.$keyword.'"';
			}
		}else{
			$perintah=' WHERE p.nomor_perkara='.'"'.$nomor_perkara.'"';
		}

		try{
			return $this->db->query('SELECT * FROM perkara AS p
										LEFT JOIN perkara_penetapan AS pp ON p.perkara_id=pp.perkara_id
										'.$perintah);
	    }catch (Exception $e) {
	    	log_message('error', $e);
	    }
	}

	function getDataPerkara($enc,$jenis){
		if(empty($enc)) return '';

		try{
				return $this->db->query('SELECT * FROM perkara WHERE perkara_id IN (
									 SELECT a.perkara_id
									 FROM delegasi_'.$jenis.' AS a
									 LEFT JOIN
									 (SELECT perkara_id,jenis_perkara_nama FROM perkara) AS b ON a.perkara_id=b.perkara_id
									  WHERE id='.'"'.$enc.'"'.');');
	    }catch (Exception $e) {
	    	log_message('error', $e);
	    }
	}

	function update_document_keluar($encProses,$datainsert) {
			if(empty($encProses)){
					return '';
			}
			try {
					$this->db->where('id',$encProses);
					$this->db->update('delegasi_keluar',$datainsert);
					return TRUE;
				} 
					catch (Exception $e) {
					return FALSE;
			}
	}

	function update_delegasi_proses($edit=NULL,$delegasi_id,$idpnasal,$idpntujuan,$datainsert){
	
			if(empty($delegasi_id)){
				return;
			}
			try {
					if ($edit==TRUE) {
						$this->db->where('delegasi_id',$delegasi_id);
						$this->db->where('id_pn_asal',$idpnasal);
						$this->db->where('id_pn_tujuan',$idpntujuan);
						$this->db->update('delegasi_proses_masuk',$datainsert);
					}else{
						$this->db->insert('delegasi_proses_masuk',$datainsert);
					}
					return TRUE;
				} 
					catch (Exception $e) {
					return FALSE;
			}
	}
	function get_nama_dok_keluar($encProses) {
				try {
					$query = $this->db->query(
							 "SELECT * FROM  delegasi_file_keluar WHERE id=$encProses");
					return $query;
				} catch (Exception $e) {
					log_message('error', $e);
				}

	}


	function get_doc_proses($delegasi_id){
		try {
			return $this->db->query('SELECT * FROM delegasi_proses WHERE id = '.$delegasi_id);
		} catch (Exception $e) {
			
		}
	}

	function get_last_id(){
		try {
			$query = $this->db->query('SELECT IF(id IS NULL,1, MAX(id)+1) AS id FROM delegasi_keluar;');
			if($query->num_rows>0){
				return $query->row()->id;
			}else{
				return 0;
			}
		} catch (Exception $e) {
			
		}
	}

	function edit_permohonan($datainsert,$lastid,$id_pn_asal,$id_pn_tujuan) {
		try {
			$this->db->where('id',$lastid);
			$this->db->where('id_pn_asal',$id_pn_asal);
			$this->db->where('id_pn_tujuan',$id_pn_tujuan);
			$this->db->update('delegasi_keluar',$datainsert);
			return TRUE;
		} catch (Exception $e) {
			return FALSE;
		}
	}

	function update_status_kirim($data_status,$lastid,$id_pn_asal,$id_pn_tujuan) {
		try {
			$this->db->where('id',$lastid);
			$this->db->where('id_pn_asal',$id_pn_asal);
			$this->db->where('id_pn_tujuan',$id_pn_tujuan);
			$this->db->update('delegasi_keluar',$data_status);
			return TRUE;
		} catch (Exception $e) {
			return FALSE;
		}
	}
	function add_permohonan($datainsert){
		try {
			$this->db->insert('delegasi_keluar',$datainsert);
			return TRUE;
		} catch (Exception $e) {
			return FALSE;
		}
	}

	// function get_data_pihak($idperkara,$jenispihak){
	// 	try {
	// 		if(!is_numeric($idperkara)){
	// 			return '';
	// 		}
	// 		return $this->db->query('SELECT b.id,b.pihak_id,  a.*,c.nama AS kewarganegaraan, d.nama as agama
	// 										FROM pihak AS a
	// 										LEFT JOIN
	// 										(SELECT * FROM perkara_pihak'.$jenispihak.') AS b
	// 										ON a.id=b.pihak_id
	// 										LEFT JOIN
	// 										(SELECT id,nama FROM negara) AS c
	// 										ON a.warga_negara_id=c.id
	// 										LEFT JOIN
	// 										(SELECT id,nama FROM agama) AS d
	// 										ON a.agama_id=d.id
	// 										WHERE b.perkara_id='.$idperkara.' ORDER BY b.id ASC');
	// 		} catch (Exception $e) {
	// 			return '';
	// 		}
	// }

	function get_data_pihak($idperkara,$jenispihak){
		try {
			if(!is_numeric($idperkara)){
				return '';
			}
			return $this->db->query("SELECT b.urutan, b.pihak_id as id_pihak,c.pengacara_id as id_kuasa,
									d.nama, (year(now()) - year(d.tanggal_lahir)) as umur, e.nama as agama, 
									d.pekerjaan, f.nama as pendidikan, d.alamat, c.nama as nama_kuasa, c.alamat as alamat_kuasa, c.aktif_mulai as tgl_kuasa
									FROM perkara a 
									join perkara_pihak$jenispihak b on a.perkara_id = b.perkara_id
									left join 
										(select 
										case
											when (ca.jumlah = 1) then cb.nama 
											else concat(cb.nama, ' dan kawan-kawan')
											end as nama,
											cb.pengacara_id, cb.alamat, cb.aktif, cb.perkara_id, cb.pihak_id,cb.aktif_mulai
										from 
										(select COUNT(1) AS jumlah, id from perkara_pengacara caa 
										group by caa.pihak_id) ca
										LEFT join perkara_pengacara cb on ca.id = cb.id) as c 
									on a.perkara_id = c.perkara_id and b.pihak_id = c.pihak_id
									LEFT join pihak d on b.pihak_id = d.id
									LEFT join agama e on d.agama_id = e.id
									left join tingkat_pendidikan f on d.pendidikan_id = f.id
									where a.perkara_id = $idperkara order by b.urutan");
			} catch (Exception $e) {
				return '';
		}
	}



	function fetchParaPihak($idparapihak){
		try {
			$query=$this->db->query('SELECT * FROM pihak WHERE id IN ('.$idparapihak.')');
			return $query;
		} catch (Exception $e) {
			return FALSE;
		}
	}

	function del_data($encDelegasi){
		try {
			$this->db->query("DELETE FROM delegasi_keluar WHERE id =".$encDelegasi);
			$title = "Delete Data Delegasi Keluar <br />dengan id [delegasi_id=".$encDelegasi."] Oleh = ".$this->session->userdata('username');
			//$this->add_audittrail("DELETE",$title,'DELETE DATA','perkara_actio_pauliana');
			return TRUE;
		} catch (Exception $e) {
			return FALSE;
		}
	}

	function getDataPA(){
		try{
			$sql = "SELECT * FROM 
					(SELECT value AS NamaPN FROM sys_config WHERE id = 62) AS T1,
					(SELECT value AS KetuaPNNama FROM sys_config WHERE id = 64) AS T2,
					(SELECT value AS AlamatPN FROM sys_config WHERE id = 63) AS T3,
					(SELECT value AS WakilKetuaPNNama FROM sys_config WHERE id = 66) AS T4,
					(SELECT value AS PansekPNNama FROM sys_config WHERE id = 68) AS T5,
					(SELECT value AS PansekNip FROM sys_config WHERE id = 69) AS T9,
					(SELECT value AS WaPanNama FROM sys_config WHERE id = 70) AS T6, 
					(SELECT value AS ZonaWaktu FROM sys_config WHERE id = 75) AS T7,
					(SELECT value AS KodePN FROM sys_config WHERE id = 61) AS T8
					";
			$query=$this->db->query($sql);
			return $query;	
		}catch(Exception $e) { return false; }
	}


	function get_index_perkara(){
		try{
			$sql = "SELECT * FROM 
					(SELECT value AS index_perkara FROM sys_config WHERE id = 92) AS T8
					";
			$query=$this->db->query($sql);
			$ret = $query->row();
			return $ret->index_perkara;
		}catch(Exception $e) { return false; }
	}

	function get_file_delegasi($alur=2,$delegasi_id=NULL,$whit_id='yes'){
		if ($alur==1){
			$db="_masuk";
			$status_file=2;
		}else{
			$db="_keluar";
			$status_file=1;
		}

		try{
			if ($whit_id=='yes'){
				$sql = "SELECT * FROM delegasi_file".$db." where delegasi_id=".$delegasi_id.' AND status_file='.$status_file;
			}else{
				$sql = "SELECT delegasi_id,
							   id_pn_asal,
							   id_pn_tujuan,
							   perkara_id,
							   file,
							   status_file,
							   diinput_oleh,
							   diinput_tanggal,
							   diperbaharui_oleh,
							   diperbaharui_tanggal   FROM delegasi_file".$db." where delegasi_id=".$delegasi_id.' AND status_file='.$status_file;
			}
			$query=$this->db->query($sql);
			return $query;
		}catch(Exception $e) { return false; }

	}

	function get_file_keluar($alur=2,$delegasi_id=NULL,$whit_id='yes'){
		if ($alur==1){
			$db="_masuk";
		}else{
			$db="_keluar";
		}

		try{
			if ($whit_id=='yes'){
				$sql = "SELECT * FROM delegasi_file".$db." where delegasi_id=".$delegasi_id.' AND status_file=1';
			}else{
				$sql = "SELECT delegasi_id,
							   id_pn_asal,
							   id_pn_tujuan,
							   perkara_id,
							   file,
							   status_file,
							   diinput_oleh,
							   diinput_tanggal,
							   diperbaharui_oleh,
							   diperbaharui_tanggal   FROM delegasi_file".$db." where delegasi_id=".$delegasi_id.' AND status_file=1';
			}
			$query=$this->db->query($sql);
			return $query;
		}catch(Exception $e) { return false; }

	}



	function get_file_lampiran($idalur=2,$delegasi_id=NULL){
		if ($idalur==1){
			$db="_masuk";
			$status_file=1;
		}else{
			$db="_keluar";
			$status_file=2;
		}

		try{
			/*if ($whit_id=='yes'){
				$sql = "SELECT * FROM delegasi_file".$db." where delegasi_id=".$delegasi_id."  AND status_file=".$status_file;
			}else{*/
				$sql = "SELECT delegasi_id,
							   id_pn_asal,
							   id_pn_tujuan,
							   perkara_id,
							   file,
							   status_file,
							   diinput_oleh,
							   diinput_tanggal,
							   diperbaharui_oleh,
							   diperbaharui_tanggal   FROM delegasi_file".$db." where delegasi_id=".$delegasi_id." AND status_file=".$status_file;
			// }
			$query=$this->db->query($sql);
			return $query;
		}catch(Exception $e) { return false; }

	}

	function get_file_pelaksanaan($alur=1,$delegasi_id=NULL,$whit_id='yes'){
		try{
			if ($whit_id=='yes'){
				$sql = "SELECT * FROM delegasi_file_masuk where delegasi_id=".$delegasi_id.' AND status_file=2';
			}else{
				$sql = "SELECT delegasi_id,
							   id_pn_asal,
							   id_pn_tujuan,
							   perkara_id,
							   file,
							   status_file,
							   diinput_oleh,
							   diinput_tanggal,
							   diperbaharui_oleh,
							   diperbaharui_tanggal   FROM delegasi_file_masuk where delegasi_id=".$delegasi_id.' AND status_file=2';
			}
			$query=$this->db->query($sql);
			return $query;
		}catch(Exception $e) { return false; }

	}
function fetchpenetapan($enc_perkara,$keyword=NULL){
		if(empty($enc_perkara)) {
			if(empty($keyword)){
				$perintah=' WHERE perkara_id='.'"'.$enc_perkara.'"';
			} else{
				$perintah=' WHERE perkara_id LIKE '.'"'.$keyword.'"';
			}
		}else{
			$perintah=' WHERE perkara_id='.'"'.$enc_perkara.'"';
		}

		try{
			return $this->db->query('SELECT * FROM perkara_penetapan '.$perintah);
	    }catch (Exception $e) {
	    	log_message('error', $e);
	    }
	}
	function get_list_perkara($idperkara){
		try {
			$query = $this->db->query("SELECT * FROM perkara WHERE perkara_id=$idperkara ORDER BY perkara_id ASC");
			return $query;
		} catch (Exception $e) {
		}
	}
}

?>