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

<?php
	include '../../inc/inc.koneksi.php';
	include '../../inc/fungsi_tanggal.php';
			
	$kode 	    = $_GET['kode'];
	$tanggal	= $_GET['tgl'];
	
	$query2 	= mysql_query("SELECT * FROM company");
	$r2			= mysql_fetch_assoc($query2);
	$kop1 	    = $r2['nama1'];
	$kop2 	    = $r2['nama2'];
	$kop3 	    = $r2['alamat'];
	
	$sql1		= "SELECT * FROM faktur_pb WHERE kode_pb='$kode' GROUP BY kode_pb";
	$query1 	= mysql_query($sql1);
	$r			= mysql_fetch_assoc($query1);
	$nomorfk	= $r['nomor_fk'];
	$namasup	= $r['nama_sup'];
	$tgljt		= $r['tanggal_jt'];
	$user		= $r['user'];
	
	echo "<table width='100%'>
		<tr>
			<td style='font:12px arial;line-height:80%'><b>$kop1</b></td>
		</tr>
		<tr>
			<td style='font:9px arial;line-height:80%'>$kop2</td>
		</tr>
		<tr>
			<td style='font:9px arial;line-height:80%'>$kop3</td>
		</tr>
		<tr>
			<td style='font:9px arial;border-top:double 0.5px;line-height:80%'></td>
		</tr>
	</table>";
	
	echo "<table width='100%'>
		<tr>
			<td align='center' style='font:13px arial'><b>FAKTUR PEMBELIAN</b></td>
		<tr>
		<tr>
			<td style='font:9px arial;border-top:double 0.5px;line-height:80%'></td>
		</tr>
	</table>";
	
	echo "<table width='100%'>
		<tr>
			<td style='font:9px arial;line-height:80%'>Kode Trans.</td>
			<td style='font:9px arial;line-height:80%'>: $kode</td>
			<td style='font:9px arial;line-height:80%'>Tanggal</td>
			<td style='font:9px arial;line-height:80%'>: ".jin_date_str($tanggal)."</td>
		</tr>
		<tr>
			<td style='font:9px arial;line-height:80%'>No.Faktur</td>
			<td style='font:9px arial;line-height:80%'>: $nomorfk</td>
			<td style='font:9px arial;line-height:80%'>Jt.Tempo</td>
			<td style='font:9px arial;line-height:80%'>: ".jin_date_str($tgljt)."</td>
		</tr>
		<tr>
			<td style='font:9px arial;line-height:80%'>Supplier</td>
			<td style='font:9px arial;line-height:80%'>: $namasup</td>
			<td></td>
			<td></td>
		</tr>
	</table>";
		
	$query= mysql_query("SELECT * FROM faktur_pb WHERE kode_pb='$kode' ORDER BY no_urut");
		
	$tjumlah=0;
	$tbayar=0;
	$tkurang=0;
	$tpotongan=0;
		
	while($r=mysql_fetch_array($query)){
		$tjumlah=$tjumlah+$r['jumlah'];
		$tbayar=$tbayar+$r['bayar'];
		$tkurang=$tkurang+$r['kurang'];
		$tpotongan=$tpotongan+$r['potongan'];
			
		echo "<table width='100%'>
			<tr>					
				<td width='100%' style='font:9px arial;line-height:80%'>$r[nama_st]</td>
			</tr>
		</table>
		<table width='100%'>
			<tr>
				<td style='font:9px arial;line-height:80%'>".number_format($r['jml_unit'],2)." $r[satuan]</td>
				<td style='font:9px arial;line-height:80%'> x </td>
				<td align='right' style='font:9px arial;line-height:80%'>".number_format($r['hg_beli'],2)."</td>
				<td style='font:9px arial;line-height:80%'> = </td>
				<td align='right' style='font:9px arial;line-height:80%'>".number_format($r['jumlah'],2)."</td>
			</tr>
		</table>";
	}
	$netto=$tjumlah-$tpotongan;
	
	echo "<table width='100%'>
		<tr>
			<td style='font:9px arial;border-top:double 0.5px;line-height:80%'></td>
		</tr>
		<table width='100%'>
		<tr>
			<td style='font:9px arial;line-height:80%'></td>
			<td style='font:9px arial;line-height:80%'></td>
			<td style='font:9px arial;line-height:80%'>Jumlah</td>
			<td style='font:9px arial;line-height:80%'> = </td>
			<td align='right' style='font:9px arial;line-height:80%'>".number_format($tjumlah,0)."</td>
		</tr>";
		
		if(!(tpotongan==0)){
			echo "<tr>
				<td style='font:9px arial;line-height:80%'></td>
				<td style='font:9px arial;line-height:80%'></td>
				<td style='font:9px arial;line-height:80%'>Potongan</td>
				<td style='font:9px arial;line-height:80%'> = </td>
				<td align='right' style='font:9px arial;line-height:80%'>".number_format($tpotongan,0)."</td>
			</tr>
			<tr>
				<td style='font:9px arial;line-height:80%'></td>
				<td style='font:9px arial;line-height:80%'></td>
				<td style='font:9px arial;line-height:80%'>Netto</td>
				<td style='font:9px arial;line-height:80%'> = </td>
				<td align='right' style='font:9px arial;line-height:80%'>".number_format($netto,0)."</td>
			</tr>";
		}
		
		echo "<tr>
			<td style='font:9px arial;line-height:80%'></td>
			<td style='font:9px arial;line-height:80%'></td>
			<td style='font:9px arial;line-height:80%'>Dibayar</td>
			<td style='font:9px arial;line-height:80%'> = </td>
			<td align='right' style='font:9px arial;line-height:80%'>".number_format($tbayar,0)."</td>
		</tr>
		<tr>
			<td style='font:9px arial;line-height:80%'></td>
			<td style='font:9px arial;line-height:80%'></td>
			<td style='font:9px arial;border-bottom:double 1px;line-height:80%'>Kekurangan</td>
			<td style='font:9px arial;border-bottom:double 1px;line-height:80%'>=</td>
			<td style='font:9px arial;border-bottom:double 1px;line-height:80%' align='right'>".number_format($kurang,2)."</td>
		</tr>			
	</table>";
?>
<script type="text/javascript">	
	history.back();
</script>