<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');
$jmldata= 0;

echo "<div id='info'>
	<table id='theList' width='100%'>
	<tr>
		<th>No.</th>
		<th>Nomor Faktur</th>
		<th>Tanggal</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 (kode_sp LIKE '%$cari%' OR nama LIKE '%$cari%') AND !(jumlah=0) 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");
		
		$no=1;
		$sjumlah=0;
		while($r=mysql_fetch_array($query)){
			$tanggal=$r['tanggal'];
			$thn	= substr($tanggal,0,4);
			$bln	= substr($tanggal,5,2);
			$tgl	= substr($tanggal,8,2);
			$bln1	= $bln;
			$hari	= $tgl;
			$thn	= (int) $thn;
			$bln	= (int) $bln;
			$tgl	= (int) $tgl;
			$thn1	= $thn-2000;

			$kab = $thn;

			while($kab>4){
				$kab=$kab-4;
			}
		
			if($kab==0) 
				$feb=29; 
			else 	
				$feb=28;
			$umur=0;
			while($tanggal<$tglnow){
				$tgl++;
				$umur++;
			
				if($bln==1){
					if($tgl==32){
						$bln=$bln+1;
						$tgl = 1;
					}
				}else if($bln==2){
					if($feb==29){
						if($tgl==30){
							$bln=$bln+1;
							$tgl=1;
						}
					}else{
						if($tgl==29){
							$bln=$bln+1;
							$tgl=1;
						}
					}
				}else if($bln==3){
					if($tgl==32){
						$bln=$bln+1;
						$tgl = 1;
					}
				}else if($bln==4){
					if($tgl==31){
						$bln=$bln+1;
						$tgl = 1;
					}
				}else if($bln==5){
					if($tgl==32){
						$bln=$bln+1;
						$tgl = 1;
					}
				}else if($bln==6){
					if($tgl==31){
						$bln=$bln+1;
						$tgl = 1;
					}
				}else if($bln==7){
					if($tgl==32){
						$bln=$bln+1;
						$tgl = 1;
					}
				}else if($bln==8){
					if($tgl==32){
						$bln=$bln+1;
						$tgl = 1;
					}
				}else if($bln==9){
					if($tgl==31){
						$bln=$bln+1;
						$tgl = 1;
					}
				}else if($bln==10){
					if($tgl==32){
						$bln=$bln+1;
						$tgl = 1;
					}
				}else if($bln==11){
					if($tgl==31){
						$bln=$bln+1;
						$tgl = 1;
					}
				}else if($bln==12){
					if($tgl==32){
						$bln=1;
						$thn=$thn+1;
						$tgl = 1;
					}
				}				
				$tanggal=$thn.'-'.sprintf("%02s",$bln).'-'.sprintf("%02s",$tgl);
			}
										
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[nofak]</td>				
				<td align='center'>".jin_date_str($r['tanggal'])."</td>
				<td align='right'>".number_format($r['jumlah'])."</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 align='right'>Jumlah</td>
			<td align='right'>".number_format($sjumlah)."</td>
		</tr>";
		$tjumlah=$tjumlah+$sjumlah;
	}
	echo "<tr>			
		<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>";

echo "</div>";
?>