<?php     
    $data=array();
    $exc=array(7,9,11,13,15,17);
    $col=17;
?>
<div style="padding:5px;min-width:100%">
    <div style="padding:20px;"></div>
    <button class="btn btnExcel" style="width:150px;text-align:center;">Export Excel</button></div>
    <table class="cetakExcel view_laporan" border="0" cellpadding="2" cellspacing="0">
    <thead>
    	<tr>
    		<td align="center" colspan="<?php echo $col;?>" style="border:1px solid #fff">
                <?php 
                  echo $perkara_nama.'<br>'.$nama_pn.'<br>Bulan '.fetch_montd($bulan).' '.$tahun;
                ?>
            </td>
    	</tr>
        <tr>
            <th rowspan="4" width="10">No</th>
            <th rowspan="4"><?php echo $nama_kolom;?></th>
            <th rowspan="4" width="20"> Sisa Mediasi Bulan Lalu</th>
            <th rowspan="4" width="20">Perkara Mediasi</th>
            <th rowspan="4" width="20">Jumlah Perkara yang Dimediasi<br>(3+4)</th>
            <th colspan="10">Jumlah Hasil Mediasi dan % Hasil Mediasi Terhadap Jumlah Perkara Mediasi</th>
            <th colspan="2" rowspan="3">Mediasi Berjalan</th>
        </tr>
        <tr>
            <th colspan="6" >Berhasil</th>
            <th rowspan="2" colspan="2" width="15">Tidak Berhasil</th>
            <th rowspan="2" colspan="2" width="15">Tidak Dapat Dilaksanakan</th>
        </tr>
        <tr>
            <th colspan="2">Akta Perdamaian / Putusan</th>  
            <th colspan="2">Berhasil Sebagian</th>
            <th colspan="2">Pencabutan</th>
        </tr>
        <tr>
            <?php 
            for ($i=1; $i <=6 ; $i++) { 
                echo '<th width="50">Jumlah</th>';
                echo '<th width="25">%</th>';
            }
            ?>
        </tr>
        <tr>
            <?php 
                for ($a=1; $a<=$col;$a++){
                    echo "<th style='width:20px;'>".$a."</th>";
                }
            ?>
        </tr>
    </thead>
    <tbody>
    	<?php
    	if($laporan!=''){
    		if($laporan->num_rows>0){
    			$i=0;
    			for ($i=1; $i <= $laporan->num_rows(); $i++) { 
      				echo '<tr>';
      				echo '<td style="text-align:center">'.$i.'</td>';
                    if(array_values($laporan->row_array($i-1))[1]>0 && $lap_mediasi==4){
                        echo "<td style ='text-align:left'><a href='view_laporan_mediasi/detil_mediator_bln/".base64_encode($this->encrypt->encode(array_values($laporan->row_array($i-1))[12]))."/".base64_encode($this->encrypt->encode($tahun))."/".base64_encode($this->encrypt->encode($idalurperkara))."/".base64_encode($this->encrypt->encode($bulanmed))."/".base64_encode($this->encrypt->encode(array_values($laporan->row_array($i-1))[0]))."'>".array_values($laporan->row_array($i-1))[0]."</a></td>";    
                    }else{
                        echo "<td style ='text-align:left'>".array_values($laporan->row_array($i-1))[0]."</td>";
                    }
      				// echo '<td style="text-align:left;word-break:break-word">'.trim(array_values($laporan->row_array($i-1))[0]).'</td>';	
      				for ($j=1; $j <= $col-2; $j++) {
      					echo '<td style="text-align:center">'.$this->templatehelper->isnull(array_values($laporan->row_array($i-1))[$j]).'</td>';
      					$k=array_values($laporan->row_array($i-1))[$j];
                        if(in_array($j, $exc)){
                            $k=0;
                        }
                        $data[$j+2]+=$k;
      				}  				
      				echo '</tr>';  				
      			}
      			if($data[5]>0){
      				for ($i=6; $i<17 ; $i++) { 
      					if($data[$i]>0){
      						$data[$i+1]=round($data[$i]/$data[5]*100).'%';	
      					}else{
      						$data[$i+1]='-';	
      					}
      					$i++;
      				}
      			}
      			echo "<td colspan='2' style ='text-align:center ;font-weight:bold'>Total</td>";
                for ($j=3; $j <=$col; $j++) {
                    echo "<td style ='text-align:center ;font-weight:bold'>".$this->templatehelper->isnull($data[$j])."</td>";
                }
    		}
    	}
    	?>
    </tbody>
    <tfoot>
    	<tr height="20">
        	<td colspan="<?php echo $col;?>"></td>
      	</tr>
    	<tr height="20">
    		<td colspan="5"><br>Mengetahui<br>Ketua <?php echo ucwords(strtolower($nama_pn));?></td>
    		<td colspan="5"></td>
    		<td colspan="5"><?php echo str_replace('Pengadilan Negeri ', '', str_replace('Pengadilan Agama ', '', str_replace("Mahkamah Syar'iyah ", '', ucwords(strtolower($nama_pn))))).', '.$this->templatehelper->convertKeTglIndo(date("Y/m/d"));?><br><br>Panitera</td>
    	</tr>
    	<tr height="60">
    		<td colspan="<?php echo $col;?>"> </td>
    	</tr>
    	<tr height="20">
    		<td colspan="5"><?php echo '<u>'.$nama_ketua.'</u><br>NIP.'.$nip_ketua;?></td>
    		<td colspan="5"></td>
    		<td colspan="5"><?php echo '<u>'.$nama_pan.'</u><br>NIP.'.$nip_pan;?></td>
    	</tr>
    </tfoot>
</table>
</div>
<script src="resources/js/jquery.table2excel.js"></script>
<script>
    $(function() {
    	$(".btnExcel").click(function(){
    		$(".cetakExcel").table2excel({
    			exclude: ".noExl",
    			name: "Excel Document Name",
    			filename: "Cetak Excel"
    		});
    	});
    });

    $('#docExcel').click(function(event){
    var tahun = '<?php echo $tahun;?>'
    var bulan = '<?php echo $bulan;?>'
    var jenis_register = '<?php echo $register;?>'
    var xls = 2;
    var w = window.open('', 'view_laporan');
    $.post('<?php echo base_url()?>cetak_register_mediasi/cetak_register', {
      bulan:bulan,
      tahun:tahun,
      jenis_register:jenis_register,
      xls:xls
    }, function(response){
      var json = jQuery.parseJSON(response);
      events = '';
      if(json.st==1){
        w.location.href ='<?php echo base_url()?>register_mediasi';
      }else{
        message_show(json.msg)
      }
    });
  });
</script>