<script type="text/javascript">
	window.print();
</script>

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

	$tgl_awal 	= $_GET['tgl_awal'];
	$tgl_akhir	= $_GET['tgl_akhir'];
	$kodesup  	= $_GET['kodesup'];
	$namasup  	= $_GET['namasup'];
	
	$query2= mysql_query("SELECT * FROM company");
	$r2		=mysql_fetch_assoc($query2);
	$kop1 = $r2['nama1'];
	$kop2 = $r2['nama2'];
	$kop3 = $r2['alamat'];
	
	echo "<table width='100%'>
		<tr>
			<td style='font:11px arial;line-height:80%'><b>$kop1</b></td>
		</tr>
		<tr>
			<td style='font:10px arial;line-height:80%'>$kop2</td>
		</tr>
		<tr>
			<td style='font:10px arial;line-height:80%'>$kop3</td>
		</tr>
	</table>

	<table width='100%'>
		<tr>
			<td style='font:13px arial;line-height:75%' align='center'><b>REKAPITULASI PEMBELIAN BARANG DAGANGAN</td>
		</tr>
		<tr>
			<td style='font:13px arial;line-height:75%' align='center'><b>TANGGAL : ".jin_date_str($tglawal)." S/D ".jin_date_str($tglakhir)."</b></td>
		</tr>";
		if(!empty($kodesp)){
			echo "<tr>
				<td style='font:13px arial;line-height:75%' align='center'><b>SUPPLIER : $namasp ($kodesp)</b></td>
			</tr>";
		}
	echo "</table>
	<br>
	
<table width='100%' border='1' style='border-collapse:collapse;font:11px arial'>
	<tr>
		<th>No.</th>
		<th>Kode Barang</th>
		<th>Nama Barang</th>
		<th>Barcode</th>
		<th>Satuan</th>
		<th>Jumlah Unit</th>		
		<th>Total Harga</th>
	</tr>";
	If(!($kodesp==''))
		$query= "SELECT kode_st,nama_st,barcode,satuan,sum(jml_unit) as totunit,sum(jumlah) as totjumlah FROM faktur_pb WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' AND kode_sup='$kodesp' GROUP BY kode_st";
	else
		$query= "SELECT kode_st,nama_st,barcode,satuan,sum(jml_unit) as totunit,sum(jumlah) as totjumlah FROM faktur_pb WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND batal='' GROUP BY kode_st";
	$data= mysql_query($query);
	$no=1;
	$total=0;
	
	while($r=mysql_fetch_array($data)){
		echo "<tr>
			<td align='center'>$no</td>
			<td align='center'>$r[kode_st]</td>
			<td>$r[nama_st]</td>
			<td>$r[barcode]</td>
			<td align='center'>$r[satuan]</td>
			<td align='right'>$r[totunit]</td>
			<td align='right'>".number_format($r['totjumlah'])."</td>
		</tr>";
		$total=$total+$r['totjumlah'];
		$no++;
	}
	
	echo "<tr>
		<td></td>
		<td></td>
		<td></td>	
		<td></td>
		<td></td>
		<td align='right'>Total</td>
		<td align='right'>".number_format($total)."</td>
	</tr>
</table>";

?>
<script type="text/javascript">
	history.back();
</script>