<?php 
    $data=array();
    $exc=array(9,11,13,15,17,19,21,23);
    $col=23;
?>
<div style="padding:5px;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>Tahun '.$tahun;
                    ?>
                </td>
            </tr>
            <tr>
                <th rowspan="4">No</th>
                <th rowspan="4">Bulan</th>
                <th colspan="3" rowspan="2">Jumlah Perkara</th>
                <th colspan="4" rowspan="2">Jumlah Perkara Mediasi</th>
                <!-- <th rowspan="4">% Jumlah Perkara Mediasi Terhadap Jumlah Perkara Diterima</th> -->
                <th colspan="12">Jumlah Hasil Mediasi dan % Hasil Mediasi Terhadap Jumlah Perkara Mediasi</th>
                <th rowspan="3" colspan="2">Mediasi Berjalan</th>
            </tr>
            <tr>
                <th colspan="6">Berhasil</th>
                <th rowspan="2" colspan="2" width="15">Total 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 rowspan="2">Sisa Bulan Lalu</th> 
                <th rowspan="2">Bulan Berjalan</th> 
                <th rowspan="2">Total</th>
                <th rowspan="2">Sisa Bulan Lalu</th> 
                <th rowspan="2">Bulan Berjalan</th> 
                <th rowspan="2">Total</th>
                <th rowspan="2">%</th>
                <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 <=7 ; $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($rekap!=''){
                    if($rekap->num_rows>0){
                        $i=0;
                        for ($i=1; $i <= $rekap->num_rows(); $i++) { 
                            echo '<tr>';
                            echo '<td style="text-align:center">'.$i.'</td>';
                            echo "<td style ='text-align:left'>".array_values($rekap->row_array($i-1))[0]."</td>";
                            for ($j=1; $j <= $col-2; $j++) {
                                echo '<td style="text-align:center">'.$this->templatehelper->isnull(array_values($rekap->row_array($i-1))[$j]).'</td>';
                                $k=array_values($rekap->row_array($i-1))[$j];
                                if(in_array($j, $exc)){
                                    $k=0;
                                }
                                if($j==1 || $j==4){
                                    if($i==1){
                                        $data[$j+2]+=$k;
                                    }
                                }elseif($j==20){
                                    $data[$j+2]=$k;
                                }else{
                                    $data[$j+2]+=$k;
                                }
                            }         
                            echo '</tr>';         
                        }
                        $data[5]=$data[4]+$data[3];
                        $data[8]=$data[7]+$data[6];
                        if($data[5]>0){
                            if($data[8]>0){
                                $data[9]=round($data[8]/$data[5]*100).'%';  
                            }
                        }
                        if($data[8]>0){
                            for ($i=10; $i<$col ; $i++) { 
                                if($data[$i]>0){
                                    $data[$i+1]=round($data[$i]/$data[8]*100).'%';  
                                }
                                $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="8"><br>Mengetahui<br>Ketua <?php echo ucwords(strtolower($nama_pn));?></td>
                <td colspan="7"></td>
                <td colspan="8"><?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="8"><?php echo '<u>'.$nama_ketua.'</u><br>NIP.'.$nip_ketua;?></td>
                <td colspan="7"></td>
                <td colspan="8"><?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"
            });
        });
    });
</script>