<script type="text/javascript">
    $(function() {
        $("#theList tr:even").addClass("stripe1");
        $("#theList tr:odd").addClass("stripe2");

        $("#theList tr").hover(
            function() {
                $(this).toggleClass("highlight");
            },
            function() {
                $(this).toggleClass("highlight");
            }
        );
    });
</script>

<?php
include '../../inc/inc.koneksi.php';
include '../../inc/fungsi_tanggal.php';

$cari 	= $_GET['cari'];
$tgljt1	= $_GET['tgljt1'];
$tgljt2	= $_GET['tgljt2'];

$jmldata= 0;

echo "<table id='theList' width='100%'>
	<tr>
		<th>No.</th>
		<th>Nomor Faktur</th>
		<th>Tanggal</th>
		<th>No.Polisi</th>
		<th>Saldo Rp</th>
		<th>Jatuh Tempo</th>
		<th>Umur (hari)</th>
	</tr>";
		
	if(!empty($cari))
		$query1	= "SELECT kode_pl,nama FROM piutang WHERE tanggal_jt BETWEEN '$tgljt1' AND '$tgljt2' AND !jumlah=0 AND (kode_pl LIKE '%$cari%' OR nama LIKE '%$cari%') GROUP BY kode_pl";
	else
		$query1	= "SELECT kode_pl,nama FROM piutang WHERE tanggal_jt BETWEEN '$tgljt1' AND '$tgljt2'  AND !jumlah=0 GROUP BY kode_pl";
	
	$data1 = mysql_query($query1);
	while($r1=mysql_fetch_array($data1)){
		$kodepl=$r1[kode_pl];

		echo "<tr>				
			<td></td>
			<td><b>Pelanggan : $r1[kode_pl]</b></td>
			<td><b>$r1[nama]</b></td>
		</tr>";
		$query = mysql_query("SELECT * FROM piutang WHERE kode_pl='$kodepl' AND tanggal_jt BETWEEN '$tgljt1' AND '$tgljt2' ");
		
		$no=1;
		$sjumlah=0;
		while($r=mysql_fetch_array($query)){
			
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[nofak]</td>
				<td align='center'>".jin_date_str($r[tanggal])."</td>
				<td align='center'>$r[nopol]</td>
				<td align='right'>".number_format($r[jumlah])."</td>
				<td align='center'>".jin_date_str($r[tanggal_jt])."</td>
			</tr>";
			$sjumlah=$sjumlah+$r[jumlah];
			$no++;
			$jmldata++;
		}
		echo "<tr>								
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Jumlah</td>
			<td align='right'>".number_format($sjumlah)."</td>
		</tr>";
		$tjumlah=$tjumlah+$sjumlah;
	}
	echo "<tr>			
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>Total </td>
		<td align='right'>".number_format($tjumlah)."</td>
	</tr>
</table>
<table width='100%'>
	<tr>
		<td>Jumlah data : $jmldata</td>				
	</tr>
</table>";
?>