<link href="_lib/search.css" rel="stylesheet" type="text/css">
<link href="_lib/gradient.css" rel="stylesheet" type="text/css">
<a class="button" onclick="window.open('data:application/msexcel,'+document.getElementById('export').outerHTML.replace(/ /g, '%20'));">Export Data ke Excel</a>&nbsp;<a class="button" onclick="window.open('data:application/msword,'+document.getElementById('export').outerHTML.replace(/ /g, '%20'));">Export Data ke Word</a>
<?php
include 'config/koneksi.php';
include '_lib/fungsi_indotgl.php';
	

//menampilkan data
$posisi  = 0;
$empty = "";
$tgl_awal = date('Y-m-d', strtotime($_POST['tgl_awal']));
$tgl_akhir = date('Y-m-d', strtotime($_POST['tgl_akhir']));
$hasil = mysql_query("SELECT 
a.nama_gelar,
SUM(CASE WHEN DATE(c.tanggal_pendaftaran) <'$tgl_awal' THEN 1 ELSE 0 END) - SUM(CASE WHEN DATE(d.tanggal_putusan) < '$tgl_awal' THEN 1 ELSE 0 END) AS sisa_lalu,
SUM(CASE WHEN DATE(c.tanggal_pendaftaran) BETWEEN '$tgl_awal' AND '$tgl_akhir' THEN 1 ELSE 0 END) AS masuk,
SUM(CASE WHEN DATE(c.tanggal_pendaftaran) <'$tgl_awal' THEN 1 ELSE 0 END) - SUM(CASE WHEN DATE(d.tanggal_putusan) < '$tgl_awal' THEN 1 ELSE 0 END) +
SUM(CASE WHEN DATE(c.tanggal_pendaftaran) BETWEEN '$tgl_awal' AND '$tgl_akhir' THEN 1 ELSE 0 END) AS jumlah,
SUM(CASE WHEN DATE(d.tanggal_putusan) BETWEEN '$tgl_awal' AND '$tgl_akhir' THEN 1 ELSE 0 END) AS putus,
SUM(CASE WHEN DATE(c.tanggal_pendaftaran) <'$tgl_awal' THEN 1 ELSE 0 END) - SUM(CASE WHEN DATE(d.tanggal_putusan) < '$tgl_awal' THEN 1 ELSE 0 END) +
SUM(CASE WHEN DATE(c.tanggal_pendaftaran) BETWEEN '$tgl_awal' AND '$tgl_akhir' THEN 1 ELSE 0 END) - SUM(CASE WHEN DATE(d.tanggal_putusan) BETWEEN '$tgl_awal' AND '$tgl_akhir' THEN 1 ELSE 0 END) AS sisa_akhir,
(SUM(CASE WHEN DATE(d.tanggal_putusan) BETWEEN '$tgl_awal' AND '$tgl_akhir' THEN 1 ELSE 0 END) *100) / ((SUM(CASE WHEN DATE(c.tanggal_pendaftaran) <'$tgl_awal' THEN 1 ELSE 0 END) - SUM(CASE WHEN DATE(d.tanggal_putusan) < '$tgl_awal' THEN 1 ELSE 0 END)) + (SUM(CASE WHEN DATE(c.tanggal_pendaftaran) BETWEEN '$tgl_awal' AND '$tgl_akhir' THEN 1 ELSE 0 END))) AS kinerja
FROM panitera_pn a, perkara_panitera_pn b, perkara c
LEFT JOIN perkara_putusan d ON c.perkara_id = d.perkara_id 
WHERE b.panitera_id = a.id
AND b.perkara_id = c.perkara_id
AND b.aktif = 'Y'
AND b.urutan = '1'
GROUP BY a.nama_gelar
ORDER BY kinerja DESC") or die("Query failed with error: ".mysql_error());
echo "<div id='export'>";
echo "<h2>Pembagian Perkara Kepada masing-masing PP</h2><br>";
echo "<table align=center><tr>
    <th width='3%'>No.</th>
	<th width='18%'>Nama Hakim</th>
	<th width='12%'>Sisa Lalu</th>
	<th width='12%'>Perkara Diterima</th>
	<th width='12%'>Beban Perkara</th>
	<th width='12%'>Perkara Diputus</th>
	<th width='12%'>Sisa Akhir</th>
	<th width='12%'>Kinerja</th></tr>";
	
$no = $posisi+1;
$totalperkara = mysql_num_rows($hasil);
$tgla = tgl_indo($tgl_awal);
$tglb = tgl_indo($tgl_akhir);
echo "<p align=left>Dari Tanggal <b>$tgla</b> Sampai Tanggal <b>$tglb</b></p><br>";
while($r=mysql_fetch_array($hasil)){
$masuk_lalu = $r['masuk_lalu'];
$putus_lalu = $r['putus_lalu'];
$masuk = $r['masuk'];
$jumlah = $r['jumlah'];
$putus = $r['putus'];
$sisa_lalu = $r['sisa_lalu'];
$sisa = $r['sisa_akhir'];
$kinerja = $r['kinerja'];

echo "<tr>
  <td align='center'>$no</td>
  <td>$r[nama_gelar]</td>
  <td align='center'><a onclick='window.open('', 'popupwindow', 'scrollbars=yes,width=1350,height=520');return true' target='popupwindow' href='home.php?page=kinerja-detail_pembagian_perkara_hakim1'>$sisa_lalu</a></td>
  <td align='center'><a onclick='window.open('', 'popupwindow', 'scrollbars=yes,width=1350,height=520');return true' target='popupwindow' href='home.php?page=kinerja-detail_pembagian_perkara_hakim1'>$masuk</a></td>  
  <td align='center'><a onclick='window.open('', 'popupwindow', 'scrollbars=yes,width=1350,height=520');return true' target='popupwindow' href='home.php?page=kinerja-detail_pembagian_perkara_hakim1'>$jumlah</a></td>
  <td align='center'><a onclick='window.open('', 'popupwindow', 'scrollbars=yes,width=1350,height=520');return true' target='popupwindow' href='home.php?page=kinerja-detail_pembagian_perkara_hakim1'>$putus</a></td>
  <td align='center'><a onclick='window.open('', 'popupwindow', 'scrollbars=yes,width=1350,height=520');return true' target='popupwindow' href='home.php?page=kinerja-detail_pembagian_perkara_hakim1'>$sisa</a></td>
  <td align='center'><font color='green'>".number_format($kinerja,2, '.', '')." %</a></td></tr>";
  $no++;
  }
echo "</table><br>";
?>