<script type="text/javascript">
$(document).ready(function() {
    $(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'];
$tglnow	= date('Y-m-d');

echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Nomor Faktur</th>
			<th>Tanggal Faktur</th>
			<th>Saldo Rp</th>
			<th>Jatuh Tempo</th>
			<th>Umur (hari)</th>			
		</tr>
		</table>";
		
		if (!empty($cari))
			$query1 = "SELECT * FROM piutang WHERE kode_pl LIKE '%$cari%' OR nama LIKE '%$cari%' GROUP BY kode_pl";
		else
			$queryl = "SELECT * FROM piutang GROUP BY kode_pl";
		
		$data1	= mysql_query($query1);
		
		$tjumlah=0;
		$jdata=1;
		while($r_data1=mysql_fetch_array($data1)){
			$kodepl = $r_data1[kode_pl];
			
			echo "<table>
				<tr>
					<td></td>
					<td>Pelanggan :	$r_data1[kode_pl] - $r_data1[nama]</td>					
				</tr>
				</table>
				<table>";
				
			$sql = "SELECT kode_pl,nofak,tanggal,jumlah,tanggal_jt FROM piutang WHERE kode_pl='$kodepl' ";
			$query = mysql_query($sql);
		
			$no=1;
			$sjumlah=0;
			while($r_data=mysql_fetch_array($query)){
				$sjumlah= $sjumlah+$r_data[jumlah];
				$umur	= $tglnow-$r_data[tanggal];

				echo "<tr>
					<td align='center'>$no</td>
					<td align='center'>$r_data[nofak]</td>
					<td>".jin_date_str($r_data[tanggal])."</td>
					<td align='center'>".number_format($r_data[jumlah],0)."</td>					
					<td>".jin_date_str($r_data[tanggal_jt])."</td>					
					<td align='center'>$umur</td>
					</tr>";
				$no++;
				$jdata++;				
			}
			
			echo "<tr>					
					<td></td>
					<td></td>
					<td align='right'>Jumlah</td>
					<td align='right'>".number_format($sjumlah,2)."</td>
				</tr>";
			$tjumlah=$tjumlah+$sjumlah;
		}
		echo "<tr></tr>
				<tr>					
					<td></td>
					<td></td>
					<td align='right'>Total</td>
					<td align='right'>".number_format($tjumlah,2)."</td>
				</tr>";
		
	echo "</table>";
	
	echo "<table width='100%'>
		<tr>
			<td>Jumlah data : $jdata</td>
		</tr>
	</table>";
?>