<script type="text/javascript">	
	window.print();
</script>
<?php
	include '../../inc/inc.koneksi.php';	
	include '../../inc/fungsi_tanggal.php';

	$kodepl	= $_GET['kodepl'];
	$namapl	= $_GET['namapl'];
	$cari	= $_GET['cari'];
	$tanggal= date('Y-m-d');

	$sql2	= mysql_query("SELECT * FROM company");
	$r2		= mysql_fetch_assoc($sql2);
	$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:11px arial;line-height:80%'>$kop2</td>
		</tr>
		<tr>
			<td style='font:11px arial;line-height:80%'>$kop3</td>
		</tr>
	</table>

	<table width='100%' >
		<tr>
			<td align='center' style='font:15px arial'><b>HISTORY PELANGGAN $namapl ($kodepl)</td>
		</tr>
		<tr>
			<td align='center' style='font:15px arial'><b>PER TANGGAL : ".jin_date_str($tanggal)."</b></td>
		</tr>";
		if(!empty($cari)){
			echo "<tr>
				<td align='center' style='font:15px arial'><b>PENCARIAN : $cari</b></td>
			</tr>";
		}
	echo "</table>
	<br>
	
	<table width='100%' border='1' style='border-collapse:collapse;font:11px arial'>
		<tr>
			<th>No.</th>
			<th>Tanggal</th>
			<th>Nomor Nota</th>
			<th>Kode Brg.</th>
			<th>Nama Barang</th>
			<th>Jml. Unit</th>
			<th>Satuan</th>
			<th>Harga Jual</th>
			<th>Jumlah Harga</th>
			<th>HPP</th>
		</tr>";
		if(!empty($cari))
			$sql= "SELECT * FROM faktur_pj WHERE kode_pl='$kodepl' AND (nama_st LIKE '%$cari%' OR kode_st LIKE '%$cari%') ORDER BY tanggal";
		else
			$sql= "SELECT * FROM faktur_pj WHERE kode_pl='$kodepl' ORDER BY tanggal";
		$query = mysql_query($sql);
		
		$no=1;
		$tjumlah=0;
		$thpp=0;
		while($r=mysql_fetch_array($query)){
			$hgjual=$r['jumlah']/$r['jml_unit'];
			echo "<tr>
				<td align='center'>$no</td>
				<td>".jin_date_str($r['tanggal'])."</td>
				<td>$r[kode_pj]</td>
				<td>$r[kode_st]</td>
				<td>$r[nama_st]</td>
				<td align='right'>$r[jml_unit]</td>
				<td>$r[satuan]</td>
				<td align='right'>".number_format($hgjual)."</td>
				<td align='right'>".number_format($r['jumlah'])."</td>
				<td align='right'>".number_format($r['hpp'])."</td>
			</tr>";
			$no++;
			$tjumlah=$tjumlah+$r['jumlah'];
			$thpp=$thpp+$r['hpp'];
		}
		echo "<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Jumlah </td>
			<td align='right'>".number_format($tjumlah)."</td>
			<td align='right'>".number_format($thpp)."</td>
		</tr>
	</table>";
?>