<script type="text/javascript">
	window.print();
</script>
<?php
	include '../../inc/inc.koneksi.php';
	include '../../inc/fungsi_tanggal.php';
		
	$cari	= $_GET['cari'];
	$tgljt1	= $_GET['tgljt1'];
	$tgljt2	= $_GET['tgljt2'];
	$tglnow = date('Y-m-d');
	$tgllap	= strtotime($tglnow);
	$jmldata= 0;
	
	if($cari=='')
		$kel='KESELURUHAN';
	else
		$kel=$cari;
		
	$sql2 = mysql_query("SELECT * FROM company");
	$r2	  = mysql_fetch_assoc($sql2);
	$kop1 = $r2['nama1'];
	$kop2 = $r2['nama2'];
	$kop3 = $r2['alamat'];
	
	echo "<table width='100%' style='font:12px arial'>
		<tr>
			<td>$kop1</td>
		</tr>
		<tr>
			<td>$kop2</td>
		</tr>
		<tr>
			<td>$kop3</td>
		</tr>
	</table>
		
	<table width='100%'>
		<tr>
			<td align='center' style='font:14px arial'><b>DAFTAR HUTANG DAGANG</b></td>
		</tr>
		<tr>
			<td align='center' style='font:14px arial'><b>JATUH TEMPO ".jin_date_str($tgljt1)." S/D ".jin_date_str($tgljt2)."</b></td>
		</tr>
		<tr>
			<td align='center' style='font:14px arial'><b>PER TANGGAL ".jin_date_str($tglnow)."</b></td>
		</tr>
		<tr>
			<td align='center' style='font:14px arial'><b>Supplier : $kel</b></td>
		</tr>
	</table>
	<br>
	
<table width='100%' border='1' style='border-collapse:collapse;font:12px arial'>
	<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 tanggal_jt BETWEEN '$tgljt1' AND '$tgljt2' AND !jumlah=0 AND (kode_sp LIKE '%$cari%' OR nama LIKE '%$cari%') GROUP BY kode_sp";
	else
		$query1	= "SELECT kode_sp,nama FROM hutang WHERE tanggal_jt BETWEEN '$tgljt1' AND '$tgljt2' AND !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 tanggal_jt BETWEEN '$tgljt1' AND '$tgljt2' ");
		
		$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[gudang]</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></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%' style='font:12px arial'>
	<tr>
		<td>Jumlah data : $jmldata</td>
	</tr>
</table>";
?>