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

class Report_pidmil_upaya_hukum extends CI_Model{
	
	function get_info_pn(){
		try {
			$this->db->select('*');
			$this->db->where('id >=', 61); 
			return $this->db->get('sys_config');
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}
	function getJenisPerkara($idalurperkara){
		if(empty($idalurperkara)) return '';
		try {
			$this->db->where('id',$idalurperkara);
			return $this->db->get('alur_perkara')->row()->nama;
		} catch (Exception $e) {
			log_message('error', $e);
		}
	}

	function get_tahun($idalurperkara){
		try {
			return $this->db->query('SELECT YEAR(min(tanggal_pendaftaran)) AS years FROM perkara WHERE alur_perkara_id IN ('.$idalurperkara.');');
		} catch (Exception $e) {
			
		}
	}

	function get_rekap($idalurperkara,$periode_awal,$periode_akhir){
		try {
			if($idalurperkara==120){
				return $this->db->query("SELECT
										'Banding' 		AS uraian
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))  AS sisa_lalu_m1
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))  AS sisa_lalu_m2
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))  AS sisa_lalu_m3
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))  AS sisa_lalu_jml
											
										,SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))  AS masuk_m1
										,SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))  AS masuk_m2
										,SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))  AS masuk_m3
										,SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))  
										+SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))  
										+SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))  AS masuk_jml
											
										,SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=1,1,0))  AS putus_01
										,SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  AS putus_02	
										,SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS putus_03
										,SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=1,1,0))  
										+SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  	
										+SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS putus_jml
										
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))+
										 SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))-
										 SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=1,1,0)) AS sisa_akhir_01
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))+
										 SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))-
										 SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  AS sisa_akhir_02
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))+
										 SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))-
										 SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS sisa_akhir_03
										
										,(SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))+
										 SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))-
										 SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=1,1,0)))+
										 (SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))+
										 SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))-
										 SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=2,1,0)))+
										 (SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))+
										 SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))-
										 SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=3,1,0)))  AS sisa_akhir_jml
										
									FROM perkara_banding AS pb
									LEFT JOIN perkara_matra AS pm ON pb.perkara_id=pm.perkara_id
									WHERE pb.alur_perkara_id=".$idalurperkara."
									UNION
									SELECT
										'Kasasi' 		AS uraian
										,SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$periode_awal."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))  AS sisa_lalu_m1
										,SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$periode_awal."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))  AS sisa_lalu_m2
										,SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$periode_awal."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))  AS sisa_lalu_m3
										,SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$periode_awal."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$periode_awal."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$periode_awal."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))  AS sisa_lalu_jml
											
										,SUM(IF((LEFT(permohonan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))  AS masuk_m1
										,SUM(IF((LEFT(permohonan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))  AS masuk_m2
										,SUM(IF((LEFT(permohonan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))  AS masuk_m3
										,SUM(IF((LEFT(permohonan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))  
										+SUM(IF((LEFT(permohonan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))  
										+SUM(IF((LEFT(permohonan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))  AS masuk_jml
											
										,SUM(IF((LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND putusan_kasasi IS NOT NULL AND pm.matra=1,1,0))  AS putus_01
										,SUM(IF((LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND putusan_kasasi IS NOT NULL AND pm.matra=2,1,0))  AS putus_02	
										,SUM(IF((LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND putusan_kasasi IS NOT NULL AND pm.matra=3,1,0))  AS putus_03
										,SUM(IF((LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND putusan_kasasi IS NOT NULL AND pm.matra=1,1,0))  
										+SUM(IF((LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND putusan_kasasi IS NOT NULL AND pm.matra=2,1,0))  	
										+SUM(IF((LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND putusan_kasasi IS NOT NULL AND pm.matra=3,1,0))  AS putus_jml
										
										,SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$periode_awal."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))+
										 SUM(IF((LEFT(permohonan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))-
										 SUM(IF((LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND putusan_kasasi IS NOT NULL AND pm.matra=1,1,0)) AS sisa_akhir_01
										,SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$periode_awal."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))+
										 SUM(IF((LEFT(permohonan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))-
										 SUM(IF((LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND putusan_kasasi IS NOT NULL AND pm.matra=2,1,0))  AS sisa_akhir_02
										,SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$periode_awal."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))+
										 SUM(IF((LEFT(permohonan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))-
										 SUM(IF((LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND putusan_kasasi IS NOT NULL AND pm.matra=3,1,0))  AS sisa_akhir_03
										
										,(SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$periode_awal."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))+
										 SUM(IF((LEFT(permohonan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))-
										 SUM(IF((LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND putusan_kasasi IS NOT NULL AND pm.matra=1,1,0)))+
										 (SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$periode_awal."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))+
										 SUM(IF((LEFT(permohonan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))-
										 SUM(IF((LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND putusan_kasasi IS NOT NULL AND pm.matra=2,1,0)))+
										 (SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$periode_awal."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))+
										 SUM(IF((LEFT(permohonan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))-
										 SUM(IF((LEFT(putusan_kasasi,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_kasasi,7)<=CONCAT('".$periode_akhir."')) AND putusan_kasasi IS NOT NULL AND pm.matra=3,1,0)))  AS sisa_akhir_jml
										
										
									FROM perkara_kasasi AS pb
									LEFT JOIN perkara_matra AS pm ON pb.perkara_id=pm.perkara_id
									WHERE pb.alur_perkara_id=".$idalurperkara."
									UNION
									SELECT
										'Peninjauan Kembali' 		AS uraian
										,SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$periode_awal."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))  AS sisa_lalu_m1
										,SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$periode_awal."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))  AS sisa_lalu_m2
										,SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$periode_awal."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))  AS sisa_lalu_m3
										,SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$periode_awal."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$periode_awal."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$periode_awal."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))  AS sisa_lalu_jml
											
										,SUM(IF((LEFT(permohonan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_pk,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))  AS masuk_m1
										,SUM(IF((LEFT(permohonan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_pk,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))  AS masuk_m2
										,SUM(IF((LEFT(permohonan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_pk,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))  AS masuk_m3
										,SUM(IF((LEFT(permohonan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_pk,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))  
										+SUM(IF((LEFT(permohonan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_pk,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))  
										+SUM(IF((LEFT(permohonan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_pk,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))  AS masuk_jml
											
										,SUM(IF((LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_pk,7)<=CONCAT('".$periode_akhir."')) AND putusan_pk IS NOT NULL AND pm.matra=1,1,0))  AS putus_01
										,SUM(IF((LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_pk,7)<=CONCAT('".$periode_akhir."')) AND putusan_pk IS NOT NULL AND pm.matra=2,1,0))  AS putus_02	
										,SUM(IF((LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_pk,7)<=CONCAT('".$periode_akhir."')) AND putusan_pk IS NOT NULL AND pm.matra=3,1,0))  AS putus_03
										,SUM(IF((LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_pk,7)<=CONCAT('".$periode_akhir."')) AND putusan_pk IS NOT NULL AND pm.matra=1,1,0))  
										+SUM(IF((LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_pk,7)<=CONCAT('".$periode_akhir."')) AND putusan_pk IS NOT NULL AND pm.matra=2,1,0))  	
										+SUM(IF((LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_pk,7)<=CONCAT('".$periode_akhir."')) AND putusan_pk IS NOT NULL AND pm.matra=3,1,0))  AS putus_jml
										
										,SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$periode_awal."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))+
										 SUM(IF((LEFT(permohonan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_pk,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))-
										 SUM(IF((LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_pk,7)<=CONCAT('".$periode_akhir."')) AND putusan_pk IS NOT NULL AND pm.matra=1,1,0)) AS sisa_akhir_01
										,SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$periode_awal."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))+
										 SUM(IF((LEFT(permohonan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_pk,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))-
										 SUM(IF((LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_pk,7)<=CONCAT('".$periode_akhir."')) AND putusan_pk IS NOT NULL AND pm.matra=2,1,0))  AS sisa_akhir_02
										,SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$periode_awal."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))+
										 SUM(IF((LEFT(permohonan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_pk,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))-
										 SUM(IF((LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_pk,7)<=CONCAT('".$periode_akhir."')) AND putusan_pk IS NOT NULL AND pm.matra=3,1,0))  AS sisa_akhir_03
										
										,(SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$periode_awal."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))+
										 SUM(IF((LEFT(permohonan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_pk,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))-
										 SUM(IF((LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_pk,7)<=CONCAT('".$periode_akhir."')) AND putusan_pk IS NOT NULL AND pm.matra=1,1,0)))+
										 (SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$periode_awal."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))+
										 SUM(IF((LEFT(permohonan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_pk,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))-
										 SUM(IF((LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_pk,7)<=CONCAT('".$periode_akhir."')) AND putusan_pk IS NOT NULL AND pm.matra=2,1,0)))+
										 (SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$periode_awal."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))+
										 SUM(IF((LEFT(permohonan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_pk,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))-
										 SUM(IF((LEFT(putusan_pk,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_pk,7)<=CONCAT('".$periode_akhir."')) AND putusan_pk IS NOT NULL AND pm.matra=3,1,0)))  AS sisa_akhir_jml




									FROM perkara_pk AS pb
									LEFT JOIN perkara_matra AS pm ON pb.perkara_id=pm.perkara_id
									WHERE pb.alur_perkara_id=".$idalurperkara."
									UNION
									SELECT
										'Grasi' 		AS uraian
										,SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$periode_awal."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))  AS sisa_lalu_m1
										,SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$periode_awal."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))  AS sisa_lalu_m2
										,SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$periode_awal."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))  AS sisa_lalu_m3
										,SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$periode_awal."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$periode_awal."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$periode_awal."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))  AS sisa_lalu_jml
											
										,SUM(IF((LEFT(permohonan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_grasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))  AS masuk_m1
										,SUM(IF((LEFT(permohonan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_grasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))  AS masuk_m2
										,SUM(IF((LEFT(permohonan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_grasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))  AS masuk_m3
										,SUM(IF((LEFT(permohonan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_grasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))  
										+SUM(IF((LEFT(permohonan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_grasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))  
										+SUM(IF((LEFT(permohonan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_grasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))  AS masuk_jml
											
										,SUM(IF((LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(tanggal_putusan_grasi,7)<=CONCAT('".$periode_akhir."')) AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=1,1,0))  AS putus_01
										,SUM(IF((LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(tanggal_putusan_grasi,7)<=CONCAT('".$periode_akhir."')) AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=2,1,0))  AS putus_02	
										,SUM(IF((LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(tanggal_putusan_grasi,7)<=CONCAT('".$periode_akhir."')) AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=3,1,0))  AS putus_03
										,SUM(IF((LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(tanggal_putusan_grasi,7)<=CONCAT('".$periode_akhir."')) AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=1,1,0))  
										+SUM(IF((LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(tanggal_putusan_grasi,7)<=CONCAT('".$periode_akhir."')) AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=2,1,0))  	
										+SUM(IF((LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(tanggal_putusan_grasi,7)<=CONCAT('".$periode_akhir."')) AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=3,1,0))  AS putus_jml
										
										,SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$periode_awal."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))+
										 SUM(IF((LEFT(permohonan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_grasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))-
										 SUM(IF((LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(tanggal_putusan_grasi,7)<=CONCAT('".$periode_akhir."')) AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=1,1,0)) AS sisa_akhir_01
										,SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$periode_awal."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))+
										 SUM(IF((LEFT(permohonan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_grasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))-
										 SUM(IF((LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(tanggal_putusan_grasi,7)<=CONCAT('".$periode_akhir."')) AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=2,1,0))  AS sisa_akhir_02
										,SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$periode_awal."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))+
										 SUM(IF((LEFT(permohonan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_grasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))-
										 SUM(IF((LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(tanggal_putusan_grasi,7)<=CONCAT('".$periode_akhir."')) AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=3,1,0))  AS sisa_akhir_03
										
										,(SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$periode_awal."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))+
										 SUM(IF((LEFT(permohonan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_grasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))-
										 SUM(IF((LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(tanggal_putusan_grasi,7)<=CONCAT('".$periode_akhir."')) AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=1,1,0)))+
										 (SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$periode_awal."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))+
										 SUM(IF((LEFT(permohonan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_grasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))-
										 SUM(IF((LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(tanggal_putusan_grasi,7)<=CONCAT('".$periode_akhir."')) AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=2,1,0)))+
										 (SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$periode_awal."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))+
										 SUM(IF((LEFT(permohonan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_grasi,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))-
										 SUM(IF((LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$periode_awal."') and LEFT(tanggal_putusan_grasi,7)<=CONCAT('".$periode_akhir."')) AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=3,1,0)))  AS sisa_akhir_jml
										
									FROM perkara_grasi AS pb
									LEFT JOIN perkara_matra AS pm ON pb.perkara_id=pm.perkara_id
									WHERE pb.alur_perkara_id=".$idalurperkara."");
			}elseif($idalurperkara==121){
				return $this->db->query("SELECT
										'Banding' 		AS uraian
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))  AS sisa_lalu_m1
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))  AS sisa_lalu_m2
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))  AS sisa_lalu_m3
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))  AS sisa_lalu_jml
											
										,SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))  AS masuk_m1
										,SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))  AS masuk_m2
										,SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))  AS masuk_m3
										,SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))  
										+SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))  
										+SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))  AS masuk_jml
											
										,SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=1,1,0))  AS putus_01
										,SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  AS putus_02	
										,SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS putus_03
										,SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=1,1,0))  
										+SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  	
										+SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS putus_jml
										
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))+
										 SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))-
										 SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=1,1,0)) AS sisa_akhir_01
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))+
										 SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))-
										 SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  AS sisa_akhir_02
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))+
										 SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))-
										 SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS sisa_akhir_03
										
										,(SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=1,1,0))+
										 SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=1,1,0))-
										 SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=1,1,0)))+
										 (SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=2,1,0))+
										 SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=2,1,0))-
										 SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=2,1,0)))+
										 (SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$periode_awal."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."')) AND pm.matra=3,1,0))+
										 SUM(IF((LEFT(permohonan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(permohonan_banding,7)<=CONCAT('".$periode_akhir."')) AND pm.matra=3,1,0))-
										 SUM(IF((LEFT(putusan_banding,7)>=CONCAT('".$periode_awal."') and LEFT(putusan_banding,7)<=CONCAT('".$periode_akhir."')) AND putusan_banding IS NOT NULL AND pm.matra=3,1,0)))  AS sisa_akhir_jml
										
									FROM perkara_banding AS pb
									LEFT JOIN perkara_matra AS pm ON pb.perkara_id=pm.perkara_id
									WHERE pb.alur_perkara_id=".$idalurperkara."");				
			}					
		} catch (Exception $e) {
			
		}
	}

	function get_rekap1($idalurperkara,$tahun){
		try {
			if($idalurperkara==120){
				return $this->db->query("SELECT
										'Banding' 		AS uraian
										,SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))  AS sisa_lalu_m1
										,SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))  AS sisa_lalu_m2
										,SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))  AS sisa_lalu_m3
										,SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))  AS sisa_lalu_jml
											
										,SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))  AS masuk_m1
										,SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))  AS masuk_m2
										,SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))  AS masuk_m3
										,SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))  AS masuk_jml
											
										,SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=1,1,0))  AS putus_01
										,SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  AS putus_02	
										,SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS putus_03
										,SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  	
										+SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS putus_jml
										
										,SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=1,1,0))  AS sisa_akhir_01
										,SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  AS sisa_akhir_02
										,SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS sisa_akhir_03
										
										,(SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=1,1,0)))
										+(SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=2,1,0)))
										+(SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=3,1,0)))  AS sisa_akhir_jml
										
									FROM perkara_banding AS pb
									LEFT JOIN perkara_matra AS pm ON pb.perkara_id=pm.perkara_id
									WHERE pb.alur_perkara_id=".$idalurperkara."
									UNION
									SELECT
										'Kasasi' 		AS uraian
										,SUM(IF(LEFT(permohonan_kasasi,4)<CONCAT('".$tahun."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))  AS sisa_lalu_m1
										,SUM(IF(LEFT(permohonan_kasasi,4)<CONCAT('".$tahun."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))  AS sisa_lalu_m2
										,SUM(IF(LEFT(permohonan_kasasi,4)<CONCAT('".$tahun."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))  AS sisa_lalu_m3
										,SUM(IF(LEFT(permohonan_kasasi,4)<CONCAT('".$tahun."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_kasasi,4)<CONCAT('".$tahun."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_kasasi,4)<CONCAT('".$tahun."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))  AS sisa_lalu_jml
											
										,SUM(IF(LEFT(permohonan_kasasi,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))  AS masuk_m1
										,SUM(IF(LEFT(permohonan_kasasi,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))  AS masuk_m2
										,SUM(IF(LEFT(permohonan_kasasi,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))  AS masuk_m3
										,SUM(IF(LEFT(permohonan_kasasi,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_kasasi,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_kasasi,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))  AS masuk_jml
											
										,SUM(IF(LEFT(putusan_kasasi,4)=CONCAT('".$tahun."') AND putusan_kasasi IS NOT NULL AND pm.matra=1,1,0))  AS putus_01
										,SUM(IF(LEFT(putusan_kasasi,4)=CONCAT('".$tahun."') AND putusan_kasasi IS NOT NULL AND pm.matra=2,1,0))  AS putus_02	
										,SUM(IF(LEFT(putusan_kasasi,4)=CONCAT('".$tahun."') AND putusan_kasasi IS NOT NULL AND pm.matra=3,1,0))  AS putus_03
										,SUM(IF(LEFT(putusan_kasasi,4)=CONCAT('".$tahun."') AND putusan_kasasi IS NOT NULL AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(putusan_kasasi,4)=CONCAT('".$tahun."') AND putusan_kasasi IS NOT NULL AND pm.matra=2,1,0))  	
										+SUM(IF(LEFT(putusan_kasasi,4)=CONCAT('".$tahun."') AND putusan_kasasi IS NOT NULL AND pm.matra=3,1,0))  AS putus_jml
										
										,SUM(IF(LEFT(permohonan_kasasi,4)<CONCAT('".$tahun."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_kasasi,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(putusan_kasasi,4)=CONCAT('".$tahun."') AND putusan_kasasi IS NOT NULL AND pm.matra=1,1,0))  AS sisa_akhir_01
										,SUM(IF(LEFT(permohonan_kasasi,4)<CONCAT('".$tahun."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_kasasi,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(putusan_kasasi,4)=CONCAT('".$tahun."') AND putusan_kasasi IS NOT NULL AND pm.matra=2,1,0))  AS sisa_akhir_02
										,SUM(IF(LEFT(permohonan_kasasi,4)<CONCAT('".$tahun."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_kasasi,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(putusan_kasasi,4)=CONCAT('".$tahun."') AND putusan_kasasi IS NOT NULL AND pm.matra=3,1,0))  AS sisa_akhir_03
										
										,(SUM(IF(LEFT(permohonan_kasasi,4)<CONCAT('".$tahun."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_kasasi,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(putusan_kasasi,4)=CONCAT('".$tahun."') AND putusan_kasasi IS NOT NULL AND pm.matra=1,1,0)))
										+(SUM(IF(LEFT(permohonan_kasasi,4)<CONCAT('".$tahun."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_kasasi,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(putusan_kasasi,4)=CONCAT('".$tahun."') AND putusan_kasasi IS NOT NULL AND pm.matra=2,1,0)))
										+(SUM(IF(LEFT(permohonan_kasasi,4)<CONCAT('".$tahun."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_kasasi,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(putusan_kasasi,4)=CONCAT('".$tahun."') AND putusan_kasasi IS NOT NULL AND pm.matra=3,1,0)))  AS sisa_akhir_jml
										
									FROM perkara_kasasi AS pb
									LEFT JOIN perkara_matra AS pm ON pb.perkara_id=pm.perkara_id
									WHERE pb.alur_perkara_id=".$idalurperkara."
									UNION
									SELECT
										'Peninjauan Kembali' 		AS uraian
										,SUM(IF(LEFT(permohonan_pk,4)<CONCAT('".$tahun."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))  AS sisa_lalu_m1
										,SUM(IF(LEFT(permohonan_pk,4)<CONCAT('".$tahun."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))  AS sisa_lalu_m2
										,SUM(IF(LEFT(permohonan_pk,4)<CONCAT('".$tahun."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))  AS sisa_lalu_m3
										,SUM(IF(LEFT(permohonan_pk,4)<CONCAT('".$tahun."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_pk,4)<CONCAT('".$tahun."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_pk,4)<CONCAT('".$tahun."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))  AS sisa_lalu_jml
											
										,SUM(IF(LEFT(permohonan_pk,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))  AS masuk_m1
										,SUM(IF(LEFT(permohonan_pk,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))  AS masuk_m2
										,SUM(IF(LEFT(permohonan_pk,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))  AS masuk_m3
										,SUM(IF(LEFT(permohonan_pk,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_pk,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_pk,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))  AS masuk_jml
											
										,SUM(IF(LEFT(putusan_pk,4)=CONCAT('".$tahun."') AND putusan_pk IS NOT NULL AND pm.matra=1,1,0))  AS putus_01
										,SUM(IF(LEFT(putusan_pk,4)=CONCAT('".$tahun."') AND putusan_pk IS NOT NULL AND pm.matra=2,1,0))  AS putus_02	
										,SUM(IF(LEFT(putusan_pk,4)=CONCAT('".$tahun."') AND putusan_pk IS NOT NULL AND pm.matra=3,1,0))  AS putus_03
										,SUM(IF(LEFT(putusan_pk,4)=CONCAT('".$tahun."') AND putusan_pk IS NOT NULL AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(putusan_pk,4)=CONCAT('".$tahun."') AND putusan_pk IS NOT NULL AND pm.matra=2,1,0))  	
										+SUM(IF(LEFT(putusan_pk,4)=CONCAT('".$tahun."') AND putusan_pk IS NOT NULL AND pm.matra=3,1,0))  AS putus_jml
										
										,SUM(IF(LEFT(permohonan_pk,4)<CONCAT('".$tahun."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_pk,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(putusan_pk,4)=CONCAT('".$tahun."') AND putusan_pk IS NOT NULL AND pm.matra=1,1,0))  AS sisa_akhir_01
										,SUM(IF(LEFT(permohonan_pk,4)<CONCAT('".$tahun."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_pk,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(putusan_pk,4)=CONCAT('".$tahun."') AND putusan_pk IS NOT NULL AND pm.matra=2,1,0))  AS sisa_akhir_02
										,SUM(IF(LEFT(permohonan_pk,4)<CONCAT('".$tahun."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_pk,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(putusan_pk,4)=CONCAT('".$tahun."') AND putusan_pk IS NOT NULL AND pm.matra=3,1,0))  AS sisa_akhir_03
										
										,(SUM(IF(LEFT(permohonan_pk,4)<CONCAT('".$tahun."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_pk,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(putusan_pk,4)=CONCAT('".$tahun."') AND putusan_pk IS NOT NULL AND pm.matra=1,1,0)))
										+(SUM(IF(LEFT(permohonan_pk,4)<CONCAT('".$tahun."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_pk,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(putusan_pk,4)=CONCAT('".$tahun."') AND putusan_pk IS NOT NULL AND pm.matra=2,1,0)))
										+(SUM(IF(LEFT(permohonan_pk,4)<CONCAT('".$tahun."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_pk,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(putusan_pk,4)=CONCAT('".$tahun."') AND putusan_pk IS NOT NULL AND pm.matra=3,1,0)))  AS sisa_akhir_jml
										
									FROM perkara_pk AS pb
									LEFT JOIN perkara_matra AS pm ON pb.perkara_id=pm.perkara_id
									WHERE pb.alur_perkara_id=".$idalurperkara."
									UNION
									SELECT
										'Grasi' 		AS uraian
										,SUM(IF(LEFT(permohonan_grasi,4)<CONCAT('".$tahun."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))  AS sisa_lalu_m1
										,SUM(IF(LEFT(permohonan_grasi,4)<CONCAT('".$tahun."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))  AS sisa_lalu_m2
										,SUM(IF(LEFT(permohonan_grasi,4)<CONCAT('".$tahun."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))  AS sisa_lalu_m3
										,SUM(IF(LEFT(permohonan_grasi,4)<CONCAT('".$tahun."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_grasi,4)<CONCAT('".$tahun."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_grasi,4)<CONCAT('".$tahun."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))  AS sisa_lalu_jml
											
										,SUM(IF(LEFT(permohonan_grasi,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))  AS masuk_m1
										,SUM(IF(LEFT(permohonan_grasi,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))  AS masuk_m2
										,SUM(IF(LEFT(permohonan_grasi,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))  AS masuk_m3
										,SUM(IF(LEFT(permohonan_grasi,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_grasi,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_grasi,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))  AS masuk_jml
											
										,SUM(IF(LEFT(tanggal_putusan_grasi,4)=CONCAT('".$tahun."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=1,1,0))  AS putus_01
										,SUM(IF(LEFT(tanggal_putusan_grasi,4)=CONCAT('".$tahun."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=2,1,0))  AS putus_02	
										,SUM(IF(LEFT(tanggal_putusan_grasi,4)=CONCAT('".$tahun."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=3,1,0))  AS putus_03
										,SUM(IF(LEFT(tanggal_putusan_grasi,4)=CONCAT('".$tahun."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(tanggal_putusan_grasi,4)=CONCAT('".$tahun."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=2,1,0))  	
										+SUM(IF(LEFT(tanggal_putusan_grasi,4)=CONCAT('".$tahun."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=3,1,0))  AS putus_jml
										
										,SUM(IF(LEFT(permohonan_grasi,4)<CONCAT('".$tahun."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_grasi,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(tanggal_putusan_grasi,4)=CONCAT('".$tahun."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=1,1,0))  AS sisa_akhir_01
										,SUM(IF(LEFT(permohonan_grasi,4)<CONCAT('".$tahun."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_grasi,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(tanggal_putusan_grasi,4)=CONCAT('".$tahun."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=2,1,0))  AS sisa_akhir_02
										,SUM(IF(LEFT(permohonan_grasi,4)<CONCAT('".$tahun."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_grasi,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(tanggal_putusan_grasi,4)=CONCAT('".$tahun."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=3,1,0))  AS sisa_akhir_03
										
										,(SUM(IF(LEFT(permohonan_grasi,4)<CONCAT('".$tahun."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_grasi,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(tanggal_putusan_grasi,4)=CONCAT('".$tahun."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=1,1,0)))
										+(SUM(IF(LEFT(permohonan_grasi,4)<CONCAT('".$tahun."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_grasi,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(tanggal_putusan_grasi,4)=CONCAT('".$tahun."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=2,1,0)))
										+(SUM(IF(LEFT(permohonan_grasi,4)<CONCAT('".$tahun."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_grasi,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(tanggal_putusan_grasi,4)=CONCAT('".$tahun."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=3,1,0)))  AS sisa_akhir_jml
										
									FROM perkara_grasi AS pb
									LEFT JOIN perkara_matra AS pm ON pb.perkara_id=pm.perkara_id
									WHERE pb.alur_perkara_id=".$idalurperkara."");
			}elseif($idalurperkara==121){
				return $this->db->query("SELECT
										'Banding' 		AS uraian
										,SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))  AS sisa_lalu_m1
										,SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))  AS sisa_lalu_m2
										,SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))  AS sisa_lalu_m3
										,SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))  AS sisa_lalu_jml
											
										,SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))  AS masuk_m1
										,SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))  AS masuk_m2
										,SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))  AS masuk_m3
										,SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))  AS masuk_jml
											
										,SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=1,1,0))  AS putus_01
										,SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  AS putus_02	
										,SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS putus_03
										,SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  	
										+SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS putus_jml
										
										,SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=1,1,0))  AS sisa_akhir_01
										,SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  AS sisa_akhir_02
										,SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS sisa_akhir_03
										
										,(SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=1,1,0)))
										+(SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=2,1,0)))
										+(SUM(IF(LEFT(permohonan_banding,4)<CONCAT('".$tahun."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,4)>=CONCAT('".$tahun."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_banding,4)=CONCAT('".$tahun."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(putusan_banding,4)=CONCAT('".$tahun."') AND putusan_banding IS NOT NULL AND pm.matra=3,1,0)))  AS sisa_akhir_jml
										
									FROM perkara_banding AS pb
									LEFT JOIN perkara_matra AS pm ON pb.perkara_id=pm.perkara_id
									WHERE pb.alur_perkara_id=".$idalurperkara."");				
			}					
		} catch (Exception $e) {
			
		}
	}

	function get_stat_perkara($period,$idalurperkara){
		try {
			return $this->db->query("
				SELECT alur_perkara_id,alur_perkara_nama,
				SUM(
					CASE 
						WHEN (tanggal_putusan IS NULL OR LEFT(tanggal_putusan,7)>='".$period."') AND LEFT(tanggal_pendaftaran,7) < '".$period."' THEN 1
						ELSE 0
						END
					) AS sisa,
				SUM(
					CASE 
						WHEN (tanggal_putusan IS NOT NULL AND LEFT(tanggal_putusan,7)<'".$period."') AND LEFT(tanggal_pendaftaran,7) < '".$period."' AND 
								(tanggal_minutasi IS NULL OR LEFT(tanggal_minutasi,7)>='".$period."') THEN 1
						ELSE 0
						END
					) AS putus_blm_minut,
				SUM(
					CASE 
						WHEN (keputusan_mediasi IS NOT NULL AND LEFT(keputusan_mediasi,7)<'".$period."') AND LEFT(tanggal_pendaftaran,7) < '".$period."' AND 
								(tanggal_minutasi IS NULL OR LEFT(tanggal_minutasi,7)>='".$period."') AND hasil_mediasi='Y' THEN 1
						ELSE 0
						END
					) AS med_blm_minut,
				SUM(
					CASE 
						WHEN LEFT(tanggal_pendaftaran,7) = '".$period."' THEN 1
						ELSE 0
						END
					) AS masuk,
				SUM(
					CASE 
						WHEN (penetapan_majelis_hakim IS NULL OR LEFT(penetapan_majelis_hakim,7)>'".$period."') AND LEFT(tanggal_pendaftaran,7) <= '".$period."' THEN 1
						ELSE 0
						END
					) AS blm_majelis,
				SUM(
					CASE 
						WHEN (tanggal_putusan IS NOT NULL AND LEFT(tanggal_putusan,7)='".$period."') AND LEFT(tanggal_pendaftaran,7) <= '".$period."' THEN 1
						ELSE 0
						END
					) AS putus,
				SUM(
					CASE 
						WHEN (tanggal_minutasi IS NOT NULL AND LEFT(tanggal_minutasi,7)='".$period."') AND LEFT(tanggal_pendaftaran,7) <= '".$period."' THEN 1
						ELSE 0
						END
					) AS minut,
				SUM(
					CASE 
						WHEN (tanggal_putusan IS NOT NULL AND LEFT(tanggal_putusan,7)<='".$period."') AND LEFT(tanggal_pendaftaran,7) <= '".$period."' AND 
								(tanggal_minutasi IS NULL OR LEFT(tanggal_minutasi,7)>'".$period."') THEN 1
						WHEN (LEFT(mediasi_berhasil,7)<='".$period."') AND LEFT(tanggal_pendaftaran,7) <= '".$period."' AND 
								(tanggal_minutasi IS NULL OR LEFT(tanggal_minutasi,7)>='".$period."') THEN 1
						ELSE 0
						END
					) AS blm_minut,
				SUM(
					CASE 
						WHEN (tanggal_cabut IS NOT NULL AND LEFT(tanggal_cabut,7)='".$period."') AND LEFT(tanggal_pendaftaran,7) <= '".$period."' THEN 1
						ELSE 0
						END
					) AS cabut,
				SUM(
					CASE 
						WHEN (tanggal_gugur IS NOT NULL AND LEFT(tanggal_gugur,7)='".$period."') AND LEFT(tanggal_pendaftaran,7) <= '".$period."' THEN 1
						ELSE 0
						END
					) AS gugur,
				SUM(
					CASE 
						WHEN LEFT(tanggal_pendaftaran,7) <= '".$period."' AND hasil_mediasi='Y' AND status_mediator='H' AND LEFT(mediasi_berhasil,7) = '".$period."'  THEN 1
						ELSE 0
						END
					) AS mediator_hakim_berhasil,
					SUM(
					CASE 
						WHEN LEFT(tanggal_pendaftaran,7) <= '".$period."' AND hasil_mediasi='N' AND status_mediator='H' AND LEFT(mediasi_berhasil,7) = '".$period."'  THEN 1
						ELSE 0
						END
					) AS mediator_hakim_gagal
				FROM v_perkara
				WHERE alur_perkara_id IN (".$idalurperkara.")
				AND LEFT(tanggal_pendaftaran,7) <='".$period."';
				");
		} catch (Exception $e) {
			
		}
	}

	function get_stat_perkara_bln($period,$idalurperkara){
		try {
			return $this->db->query("
				SELECT jenis_perkara_id,jenis_perkara_nama,
				SUM(
					CASE 
						WHEN (tanggal_putusan IS NULL OR LEFT(tanggal_putusan,7)>='".$period."') AND LEFT(tanggal_pendaftaran,7) < '".$period."' THEN 1
						ELSE 0
						END
					) AS sisa,
				SUM(
					CASE 
						WHEN (tanggal_putusan IS NOT NULL AND LEFT(tanggal_putusan,7)<'".$period."') AND LEFT(tanggal_pendaftaran,7) < '".$period."' AND 
								(tanggal_minutasi IS NULL OR LEFT(tanggal_minutasi,7)>='".$period."') THEN 1
						ELSE 0
						END
					) AS putus_blm_minut,
				SUM(
					CASE 
						WHEN (keputusan_mediasi IS NOT NULL AND LEFT(keputusan_mediasi,7)<'".$period."') AND LEFT(tanggal_pendaftaran,7) < '".$period."' AND 
								(tanggal_minutasi IS NULL OR LEFT(tanggal_minutasi,7)>='".$period."') AND hasil_mediasi='Y' THEN 1
						ELSE 0
						END
					) AS med_blm_minut,
				SUM(
					CASE 
						WHEN LEFT(tanggal_pendaftaran,7) = '".$period."' THEN 1
						ELSE 0
						END
					) AS masuk,
				SUM(
					CASE 
						WHEN (penetapan_majelis_hakim IS NULL OR LEFT(penetapan_majelis_hakim,7)>'".$period."') AND LEFT(tanggal_pendaftaran,7) <= '".$period."' THEN 1
						ELSE 0
						END
					) AS blm_majelis,
				SUM(
					CASE 
						WHEN (tanggal_putusan IS NOT NULL AND LEFT(tanggal_putusan,7)='".$period."') AND LEFT(tanggal_pendaftaran,7) <= '".$period."' THEN 1
						ELSE 0
						END
					) AS putus,
				SUM(
					CASE 
						WHEN (tanggal_minutasi IS NOT NULL AND LEFT(tanggal_minutasi,7)='".$period."') AND LEFT(tanggal_pendaftaran,7) <= '".$period."' THEN 1
						ELSE 0
						END
					) AS minut,
				SUM(
					CASE 
						WHEN (tanggal_putusan IS NOT NULL AND LEFT(tanggal_putusan,7)<='".$period."') AND LEFT(tanggal_pendaftaran,7) <= '".$period."' AND 
								(tanggal_minutasi IS NULL OR LEFT(tanggal_minutasi,7)>'".$period."') THEN 1
						WHEN (LEFT(mediasi_berhasil,7)<='".$period."') AND LEFT(tanggal_pendaftaran,7) <= '".$period."' AND 
								(tanggal_minutasi IS NULL OR LEFT(tanggal_minutasi,7)>='".$period."') THEN 1
						ELSE 0
						END
					) AS blm_minut,
				SUM(
					CASE 
						WHEN (tanggal_cabut IS NOT NULL AND LEFT(tanggal_cabut,7)='".$period."') AND LEFT(tanggal_pendaftaran,7) <= '".$period."' THEN 1
						ELSE 0
						END
					) AS cabut,
				SUM(
					CASE 
						WHEN (tanggal_gugur IS NOT NULL AND LEFT(tanggal_gugur,7)='".$period."') AND LEFT(tanggal_pendaftaran,7) <= '".$period."' THEN 1
						ELSE 0
						END
					) AS gugur,
				SUM(
					CASE 
						WHEN LEFT(tanggal_pendaftaran,7) <= '".$period."' AND hasil_mediasi='Y' AND LEFT(mediasi_berhasil,7) = '".$period."'  THEN 1
						ELSE 0
						END
					) AS mediasi_berhasil,
					SUM(
					CASE 
						WHEN LEFT(tanggal_pendaftaran,7) <= '".$period."' AND hasil_mediasi='N' AND LEFT(mediasi_berhasil,7) = '".$period."'  THEN 1
						ELSE 0
						END
					) AS mediasi_gagal
				FROM v_perkara
				WHERE alur_perkara_id IN (".$idalurperkara.")
				AND LEFT(tanggal_pendaftaran,7) <='".$period."'
				GROUP BY jenis_perkara_id;");
		} catch (Exception $e) {
			
		}
	}
	function get_lap_perkara($period,$idalurperkara){
		try {
			if($idalurperkara==120){
				return $this->db->query("SELECT
										'Banding' 		AS uraian
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))  AS sisa_lalu_m1
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))  AS sisa_lalu_m2
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))  AS sisa_lalu_m3
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))  AS sisa_lalu_jml
											
										,SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=1,1,0))  AS masuk_m1
										,SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=2,1,0))  AS masuk_m2
										,SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=3,1,0))  AS masuk_m3
										,SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=3,1,0))  AS masuk_jml
											
										,SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=1,1,0))  AS putus_01
										,SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  AS putus_02	
										,SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS putus_03
										,SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  	
										+SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS putus_jml
										
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=1,1,0))  AS sisa_akhir_01
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  AS sisa_akhir_02
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS sisa_akhir_03
										
										,(SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=1,1,0)))
										+(SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=2,1,0)))
										+(SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=3,1,0)))  AS sisa_akhir_jml
										
									FROM perkara_banding AS pb
									LEFT JOIN perkara_matra AS pm ON pb.perkara_id=pm.perkara_id
									WHERE pb.alur_perkara_id=".$idalurperkara."
									UNION
									SELECT
										'Kasasi' 		AS uraian
										,SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$period."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))  AS sisa_lalu_m1
										,SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$period."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))  AS sisa_lalu_m2
										,SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$period."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))  AS sisa_lalu_m3
										,SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$period."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$period."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$period."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))  AS sisa_lalu_jml
											
										,SUM(IF(LEFT(permohonan_kasasi,7)=CONCAT('".$period."') AND pm.matra=1,1,0))  AS masuk_m1
										,SUM(IF(LEFT(permohonan_kasasi,7)=CONCAT('".$period."') AND pm.matra=2,1,0))  AS masuk_m2
										,SUM(IF(LEFT(permohonan_kasasi,7)=CONCAT('".$period."') AND pm.matra=3,1,0))  AS masuk_m3
										,SUM(IF(LEFT(permohonan_kasasi,7)=CONCAT('".$period."') AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_kasasi,7)=CONCAT('".$period."') AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_kasasi,7)=CONCAT('".$period."') AND pm.matra=3,1,0))  AS masuk_jml
											
										,SUM(IF(LEFT(putusan_kasasi,7)=CONCAT('".$period."') AND putusan_kasasi IS NOT NULL AND pm.matra=1,1,0))  AS putus_01
										,SUM(IF(LEFT(putusan_kasasi,7)=CONCAT('".$period."') AND putusan_kasasi IS NOT NULL AND pm.matra=2,1,0))  AS putus_02	
										,SUM(IF(LEFT(putusan_kasasi,7)=CONCAT('".$period."') AND putusan_kasasi IS NOT NULL AND pm.matra=3,1,0))  AS putus_03
										,SUM(IF(LEFT(putusan_kasasi,7)=CONCAT('".$period."') AND putusan_kasasi IS NOT NULL AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(putusan_kasasi,7)=CONCAT('".$period."') AND putusan_kasasi IS NOT NULL AND pm.matra=2,1,0))  	
										+SUM(IF(LEFT(putusan_kasasi,7)=CONCAT('".$period."') AND putusan_kasasi IS NOT NULL AND pm.matra=3,1,0))  AS putus_jml
										
										,SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$period."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_kasasi,7)=CONCAT('".$period."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(putusan_kasasi,7)=CONCAT('".$period."') AND putusan_kasasi IS NOT NULL AND pm.matra=1,1,0))  AS sisa_akhir_01
										,SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$period."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_kasasi,7)=CONCAT('".$period."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(putusan_kasasi,7)=CONCAT('".$period."') AND putusan_kasasi IS NOT NULL AND pm.matra=2,1,0))  AS sisa_akhir_02
										,SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$period."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_kasasi,7)=CONCAT('".$period."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(putusan_kasasi,7)=CONCAT('".$period."') AND putusan_kasasi IS NOT NULL AND pm.matra=3,1,0))  AS sisa_akhir_03
										
										,(SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$period."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_kasasi,7)=CONCAT('".$period."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(putusan_kasasi,7)=CONCAT('".$period."') AND putusan_kasasi IS NOT NULL AND pm.matra=1,1,0)))
										+(SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$period."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_kasasi,7)=CONCAT('".$period."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(putusan_kasasi,7)=CONCAT('".$period."') AND putusan_kasasi IS NOT NULL AND pm.matra=2,1,0)))
										+(SUM(IF(LEFT(permohonan_kasasi,7)<CONCAT('".$period."') AND (putusan_kasasi IS NULL OR LEFT(putusan_kasasi,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_kasasi,7)=CONCAT('".$period."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(putusan_kasasi,7)=CONCAT('".$period."') AND putusan_kasasi IS NOT NULL AND pm.matra=3,1,0)))  AS sisa_akhir_jml
										
									FROM perkara_kasasi AS pb
									LEFT JOIN perkara_matra AS pm ON pb.perkara_id=pm.perkara_id
									WHERE pb.alur_perkara_id=".$idalurperkara."
									UNION
									SELECT
										'Peninjauan Kembali' 		AS uraian
										,SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$period."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))  AS sisa_lalu_m1
										,SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$period."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))  AS sisa_lalu_m2
										,SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$period."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))  AS sisa_lalu_m3
										,SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$period."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$period."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$period."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))  AS sisa_lalu_jml
											
										,SUM(IF(LEFT(permohonan_pk,7)=CONCAT('".$period."') AND pm.matra=1,1,0))  AS masuk_m1
										,SUM(IF(LEFT(permohonan_pk,7)=CONCAT('".$period."') AND pm.matra=2,1,0))  AS masuk_m2
										,SUM(IF(LEFT(permohonan_pk,7)=CONCAT('".$period."') AND pm.matra=3,1,0))  AS masuk_m3
										,SUM(IF(LEFT(permohonan_pk,7)=CONCAT('".$period."') AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_pk,7)=CONCAT('".$period."') AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_pk,7)=CONCAT('".$period."') AND pm.matra=3,1,0))  AS masuk_jml
											
										,SUM(IF(LEFT(putusan_pk,7)=CONCAT('".$period."') AND putusan_pk IS NOT NULL AND pm.matra=1,1,0))  AS putus_01
										,SUM(IF(LEFT(putusan_pk,7)=CONCAT('".$period."') AND putusan_pk IS NOT NULL AND pm.matra=2,1,0))  AS putus_02	
										,SUM(IF(LEFT(putusan_pk,7)=CONCAT('".$period."') AND putusan_pk IS NOT NULL AND pm.matra=3,1,0))  AS putus_03
										,SUM(IF(LEFT(putusan_pk,7)=CONCAT('".$period."') AND putusan_pk IS NOT NULL AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(putusan_pk,7)=CONCAT('".$period."') AND putusan_pk IS NOT NULL AND pm.matra=2,1,0))  	
										+SUM(IF(LEFT(putusan_pk,7)=CONCAT('".$period."') AND putusan_pk IS NOT NULL AND pm.matra=3,1,0))  AS putus_jml
										
										,SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$period."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_pk,7)=CONCAT('".$period."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(putusan_pk,7)=CONCAT('".$period."') AND putusan_pk IS NOT NULL AND pm.matra=1,1,0))  AS sisa_akhir_01
										,SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$period."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_pk,7)=CONCAT('".$period."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(putusan_pk,7)=CONCAT('".$period."') AND putusan_pk IS NOT NULL AND pm.matra=2,1,0))  AS sisa_akhir_02
										,SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$period."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_pk,7)=CONCAT('".$period."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(putusan_pk,7)=CONCAT('".$period."') AND putusan_pk IS NOT NULL AND pm.matra=3,1,0))  AS sisa_akhir_03
										
										,(SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$period."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_pk,7)=CONCAT('".$period."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(putusan_pk,7)=CONCAT('".$period."') AND putusan_pk IS NOT NULL AND pm.matra=1,1,0)))
										+(SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$period."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_pk,7)=CONCAT('".$period."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(putusan_pk,7)=CONCAT('".$period."') AND putusan_pk IS NOT NULL AND pm.matra=2,1,0)))
										+(SUM(IF(LEFT(permohonan_pk,7)<CONCAT('".$period."') AND (putusan_pk IS NULL OR LEFT(putusan_pk,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_pk,7)=CONCAT('".$period."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(putusan_pk,7)=CONCAT('".$period."') AND putusan_pk IS NOT NULL AND pm.matra=3,1,0)))  AS sisa_akhir_jml
										
									FROM perkara_pk AS pb
									LEFT JOIN perkara_matra AS pm ON pb.perkara_id=pm.perkara_id
									WHERE pb.alur_perkara_id=".$idalurperkara."
									UNION
									SELECT
										'Grasi' 		AS uraian
										,SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$period."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))  AS sisa_lalu_m1
										,SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$period."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))  AS sisa_lalu_m2
										,SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$period."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))  AS sisa_lalu_m3
										,SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$period."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$period."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$period."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))  AS sisa_lalu_jml
											
										,SUM(IF(LEFT(permohonan_grasi,7)=CONCAT('".$period."') AND pm.matra=1,1,0))  AS masuk_m1
										,SUM(IF(LEFT(permohonan_grasi,7)=CONCAT('".$period."') AND pm.matra=2,1,0))  AS masuk_m2
										,SUM(IF(LEFT(permohonan_grasi,7)=CONCAT('".$period."') AND pm.matra=3,1,0))  AS masuk_m3
										,SUM(IF(LEFT(permohonan_grasi,7)=CONCAT('".$period."') AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_grasi,7)=CONCAT('".$period."') AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_grasi,7)=CONCAT('".$period."') AND pm.matra=3,1,0))  AS masuk_jml
											
										,SUM(IF(LEFT(tanggal_putusan_grasi,7)=CONCAT('".$period."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=1,1,0))  AS putus_01
										,SUM(IF(LEFT(tanggal_putusan_grasi,7)=CONCAT('".$period."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=2,1,0))  AS putus_02	
										,SUM(IF(LEFT(tanggal_putusan_grasi,7)=CONCAT('".$period."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=3,1,0))  AS putus_03
										,SUM(IF(LEFT(tanggal_putusan_grasi,7)=CONCAT('".$period."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(tanggal_putusan_grasi,7)=CONCAT('".$period."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=2,1,0))  	
										+SUM(IF(LEFT(tanggal_putusan_grasi,7)=CONCAT('".$period."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=3,1,0))  AS putus_jml
										
										,SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$period."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_grasi,7)=CONCAT('".$period."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(tanggal_putusan_grasi,7)=CONCAT('".$period."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=1,1,0))  AS sisa_akhir_01
										,SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$period."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_grasi,7)=CONCAT('".$period."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(tanggal_putusan_grasi,7)=CONCAT('".$period."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=2,1,0))  AS sisa_akhir_02
										,SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$period."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_grasi,7)=CONCAT('".$period."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(tanggal_putusan_grasi,7)=CONCAT('".$period."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=3,1,0))  AS sisa_akhir_03
										
										,(SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$period."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_grasi,7)=CONCAT('".$period."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(tanggal_putusan_grasi,7)=CONCAT('".$period."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=1,1,0)))
										+(SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$period."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_grasi,7)=CONCAT('".$period."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(tanggal_putusan_grasi,7)=CONCAT('".$period."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=2,1,0)))
										+(SUM(IF(LEFT(permohonan_grasi,7)<CONCAT('".$period."') AND (tanggal_putusan_grasi IS NULL OR LEFT(tanggal_putusan_grasi,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_grasi,7)=CONCAT('".$period."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(tanggal_putusan_grasi,7)=CONCAT('".$period."') AND tanggal_putusan_grasi IS NOT NULL AND pm.matra=3,1,0)))  AS sisa_akhir_jml
										
									FROM perkara_grasi AS pb
									LEFT JOIN perkara_matra AS pm ON pb.perkara_id=pm.perkara_id
									WHERE pb.alur_perkara_id=".$idalurperkara."");
			}elseif($idalurperkara==121){
				return $this->db->query("SELECT
										'Banding' 		AS uraian
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))  AS sisa_lalu_m1
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))  AS sisa_lalu_m2
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))  AS sisa_lalu_m3
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))  AS sisa_lalu_jml
											
										,SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=1,1,0))  AS masuk_m1
										,SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=2,1,0))  AS masuk_m2
										,SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=3,1,0))  AS masuk_m3
										,SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=2,1,0))  
										+SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=3,1,0))  AS masuk_jml
											
										,SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=1,1,0))  AS putus_01
										,SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  AS putus_02	
										,SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS putus_03
										,SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=1,1,0))  
										+SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  	
										+SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS putus_jml
										
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=1,1,0))  AS sisa_akhir_01
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=2,1,0))  AS sisa_akhir_02
										,SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=3,1,0))  AS sisa_akhir_03
										
										,(SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=1,1,0))
										+SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=1,1,0))
										+SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=1,1,0)))
										+(SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=2,1,0))
										+SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=2,1,0))
										+SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=2,1,0)))
										+(SUM(IF(LEFT(permohonan_banding,7)<CONCAT('".$period."') AND (putusan_banding IS NULL OR LEFT(putusan_banding,7)>=CONCAT('".$period."')) AND pm.matra=3,1,0))
										+SUM(IF(LEFT(permohonan_banding,7)=CONCAT('".$period."') AND pm.matra=3,1,0))
										+SUM(IF(LEFT(putusan_banding,7)=CONCAT('".$period."') AND putusan_banding IS NOT NULL AND pm.matra=3,1,0)))  AS sisa_akhir_jml
										
									FROM perkara_banding AS pb
									LEFT JOIN perkara_matra AS pm ON pb.perkara_id=pm.perkara_id
									WHERE pb.alur_perkara_id=".$idalurperkara."");				
			}	
		} catch (Exception $e) {
			
		}
	}
}