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

class M_template_tun_resume extends CI_Model {

	function getPihak1($IdPerkara){
		try{
			return $this->db->query('SELECT
				pihak.id AS IDPihak,
				perkara_pihak1.jenis_pihak_id AS IDJenisPihak,
				pihak.nama AS namaPihak,
				negara.nama AS negaraPihak,
				pihak.alamat AS alamatPihak,
				pihak.pekerjaan AS pekerjaanPihak 
				FROM  perkara_pihak1 
				LEFT JOIN pihak ON pihak.id=perkara_pihak1.pihak_id
				LEFT JOIN negara ON negara.id=pihak.warga_negara_id
				WHERE perkara_pihak1.perkara_id='.$IdPerkara.'');
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}

	function getPihak2($IdPerkara){
		try{
			return $this->db->query('SELECT
					pihak.id AS IDPihak,
					perkara_pihak2.jenis_pihak_id AS IDJenisPihak,
					pihak.nama AS namaPihak,
					pihak.warga_negara AS negaraPihak,
					pihak.alamat AS alamatPihak,
					pihak.pekerjaan AS pekerjaanPihak 
					FROM  perkara_pihak2 
					LEFT JOIN pihak ON pihak.id=perkara_pihak2.pihak_id
					WHERE perkara_pihak2.perkara_id='.$IdPerkara.'');
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}

	function getDataPengacara($idperkara,$pihakke){
		try{
    		if(!is_numeric($idperkara)) { return ''; }
    		$sql = "SELECT pihak_id, urutan, b.nama, b.alamat, pekerjaan, a.id 
				FROM perkara_pengacara a, pihak b
				WHERE a.pihak_id=b.id AND perkara_id=".$idperkara." AND pihak_ke=".$pihakke."
				ORDER BY urutan ASC";
			$query=$this->db->query($sql);
			return $query;
		} catch(Exception $e) { return false; }
	}


	function getPengacara($idPerkara,$idPihak){
		try{
			$this->db->select('perkara_pengacara.pihak_ke AS pihakKe
								pihak.nama AS namaPihak,
								pihak.alamat AS alamatPihak,
								pihak.warga_negara AS negeraPihak');
			$this->db->where('perkara_pengacara.perkara_id', $idPerkara); 
			$this->db->where('perkara_pengacara.pihak_id', $idPihak); 
			$this->db->from('perkara_pengacara');
			$this->db->order_by('urutan', 'asc'); 
			return $this->db->join('pihak', 'pihak.id=perkara_pengacara.pihak_id','left');
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}


	function dataPerkara($IdPerkara){
		try{
			return $this->db->query('SELECT nomor_perkara FROM perkara WHERE perkara_id='.$IdPerkara.'')->row()->nomor_perkara;
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}




}	
