<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'];
$tglnow	= date('Y-m-d');
$tgllap	= strtotime($tglnow);
$jmldata= 0;

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

		echo "<tr>				
			<td></td>
			<td><b>Supplier : $r1[kode_sp] -</b></td>
			<td><b>$r1[nama]</b></td>
		</tr>";
		$query = mysql_query("SELECT * FROM hutang WHERE kode_sp='$kodesp' AND !(jumlah=0) ORDER BY tanggal asc");
		
		$no=1;
		$sjumlah=0;
		while($r=mysql_fetch_array($query)){
			$tanggal=$r['tanggal'];
			$tglfak	= strtotime($tanggal);
			$slstgl	= $tgllap-$tglfak;
			$umur	= $slstgl / 60 / 60 / 24;
			$umur	= round($umur,0);
			
			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[kode_cab]</td>				
				<td align='right'>".number_format($r['jumlah'],2)."</td>
				<td align='center'>".jin_date_str($r['tanggal_jt'])."</td>
				<td align='center'>$umur</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,2)."</td>
		</tr>";
		$tjumlah=$tjumlah+$sjumlah;
	}
	echo "<tr>			
		<td></td>
		<td></td>
		<td></td>
		<td align='right'>Total </td>
		<td align='right'>".number_format($tjumlah,2)."</td>
	</tr>
</table>
<table width='100%'>
	<tr>
		<td>Jumlah data : $jmldata</td>				
	</tr>
</table>";
echo "</div>";
?>