<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'];
	$kodesp  	= $_GET['kodesp'];
	$namasp	    = $_GET['namasp'];
	$kodegr  	= $_GET['kodegr'];
	$namagr	    = $_GET['namagr'];
	$kodecab  	= $_GET['kodecab'];
	$urut     	= $_GET['urut'];
	$user		= $_GET['user'];
	$kodedt 	= $_GET['kodedt'];
	$namadt 	= $_GET['namadt'];
	$nafile 	= 'rekappj_'.$user;
    
    $sql2	= mysql_query("SELECT * FROM cabang WHERE kode_cab='$kodecab'");
	$r2		= mysql_fetch_assoc($sql2);
	$namacab= $r2['nama_cab'];
	
	$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:11px arial'><b>
		<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>REKAPITULASI PENJUALAN KESELURUHAN</b></td>
		</tr>
		<tr>
			<td align='center' style='font:14px arial'><b>TANGGAL : ".jin_date_str($tgl_awal)." S/D ".jin_date_str($tgl_akhir)."</b></td>
		</tr>";
		if(!$kodecab==''){
		    echo "<tr>
			    <td align='center' style='font:14px arial'><b>CABANG : $namacab</b></td>
		    </tr>";
		}
		if(!$kodesp==''){
			echo "<tr>
				<td align='center' style='font:14px arial'><b>SUPPLIER : $namasp</b></td>
			</tr>";
		}
		if(!$kodegr==''){
			echo "<tr>
				<td align='center' style='font:14px arial'><b>KELOMPOK : $namagr</b></td>
			</tr>";
		}
		if(!empty($kodedt)){
			echo "<tr>
				<td align='center' style='font:15px arial'><b>DOKTER : $namadt ($kodedt)</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>Satuan</th>
			<th>Jumlah Unit</th>
			<th>Harga Satuan</th>
			<th>Total Harga</th>
		</tr>";
				
		if($urut=='kode')
			$sql= mysql_query("SELECT * FROM $nafile WHERE !(jml_unit=0) ORDER BY kode_st ");
		if($urut=='qty')
			$sql= mysql_query("SELECT * FROM $nafile WHERE !(jml_unit=0) ORDER BY jml_unit desc ");
		else
			$sql= mysql_query("SELECT * FROM $nafile WHERE !(jml_unit=0) ORDER BY jumlah desc ");
		
		$no=1;
		$tjumlah=0;
		while($r=mysql_fetch_array($sql)){
			$jumlah	=$r['jumlah'];
			$junit	=$r['jml_unit'];
			
			if(!$junit==0) $harga=$jumlah/$junit;
			else $harga=$jumlah;
			
			echo "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[kode_st]</td>
				<td>$r[nama_st]</td>
				<td>$r[satuan]</td>
				<td align='right'>$r[jml_unit]</td>
				<td align='right'>".number_format($harga)."</td>
				<td align='right'>".number_format($jumlah)."</td>
			</tr>";
			$tjumlah=$tjumlah+$jumlah;
			$no++;
		}
		echo "<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Total</td>
			<td align='right'>".number_format($tjumlah)."</td>
		</tr>
	</table>";
?>