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

class m_skum extends CI_Model {
	
	function getlisttransaksi($perkara_id,$tahapan_id){
		try {
			if(!is_numeric($perkara_id)){
				return '';
			}
			$sql = "SELECT * FROM perkara_biaya WHERE perkara_id='".$perkara_id."' AND jenis_transaksi = 1 AND tahapan_id=".$tahapan_id." ORDER BY tanggal_transaksi DESC;";
			return $this->db->query($sql);
		} catch (Exception $e) {
			return '';
		}
	}

	function getdataskum($perkara_id,$perkara_biaya_id){
		try {
			if(!is_numeric($perkara_id)){
				return '';
			}
			$sql="SELECT 
						a.perkara_id,
						a.nomor_perkara,
						b.tanggal_transaksi, 
						b.jumlah,
						CONCAT(b.uraian, IF(b.tahapan_id=10,' Tingkat Pertama', '')) AS uraian,	
						IF(b.pihak_id IS NULL ,p1.nama,	p.nama) AS nama,
						CASE
							WHEN b.tahapan_id=10 THEN 
								CASE
									WHEN a.alur_perkara_id=2 THEN IF(b.pihak_ke=2,'Termohon','Pemohon')
									WHEN a.alur_perkara_id=16 THEN IF(b.pihak_ke=2,'Termohon','Pemohon')
									WHEN a.alur_perkara_id=1 AND a.jenis_perkara_id=140 THEN IF(b.pihak_ke=2,'Termohon Keberatan','Pemohon Keberatan')
									WHEN a.alur_perkara_id=1 AND a.jenis_perkara_id=139 THEN IF(b.pihak_ke=2,'Termohon Keberatan','Pemohon Keberatan')
									WHEN a.alur_perkara_id=15 AND a.jenis_perkara_id=346 THEN IF(b.pihak_ke=2,'Termohon','Pemohon')
									ELSE IF(b.pihak_ke=2,'Tergugat','Penggugat')
								END
							WHEN b.tahapan_id=20 THEN IF(b.pihak_ke=2,'Terbanding','Pembanding')
							WHEN b.tahapan_id=30 THEN IF(b.pihak_ke=2,'Termohon Kasasi','Pemohon Kasasi')
							WHEN b.tahapan_id=40 THEN IF(b.pihak_ke=2,'Termohon PK','Pemohon PK')
						END AS sebagai
					FROM perkara AS a
					LEFT JOIN (SELECT 
						@pihak_id:=`pihak_id`,
						x.*
					FROM perkara_biaya AS x WHERE id='".$perkara_biaya_id."') AS b ON a.`perkara_id`=b.`perkara_id`
					LEFT JOIN (SELECT id AS pihakid, nama FROM pihak WHERE id = @pihak_id) AS p ON b.`pihak_id`=p.pihakid
					LEFT JOIN (SELECT * FROM perkara_pihak1 WHERE perkara_id='".$perkara_id."' AND urutan=1) AS p1 ON a.`perkara_id`=p1.`perkara_id`
					WHERE a.perkara_id='".$perkara_id."'";
			return $this->db->query($sql);
			} catch (Exception $e) {
				return '';
		}
	}

	function getsatker(){
		try {
			$sql = "SELECT `value` AS nama_satker FROM sys_config WHERE id=62;";
			return $this->db->query($sql);
		} catch (Exception $e) {
			return '';
		}
	}
	
	function getalamatsatker(){
		try {
			$sql = "SELECT `value` AS alamat_satker FROM sys_config WHERE id=63;";
			return $this->db->query($sql);
		} catch (Exception $e) {
			return '';
		}
	}

	function getkasir(){
		try {
			$sql = "SELECT b.`fullname` AS nama_kasir, '' AS nip_kasir 
					FROM sys_user_group AS a
					JOIN sys_users b ON a.`userid`=b.`userid`
					WHERE a.`groupid`=702;";
			return $this->db->query($sql);
		} catch (Exception $e) {
			return '';
		}
	}
	function getpanitera(){
		try {
			$sql = "SELECT `value` AS nama_panitera FROM sys_config WHERE id=68;";
			return $this->db->query($sql);
		} catch (Exception $e) {
			return '';
		}
	}

}									
?>