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

	$tglawal	= $_GET['tgl_awal'];
	$tglakhir	= $_GET['tgl_akhir'];
	$kodeplg    = $_GET['kodeplg'];
	$namaplg    = $_GET['namaplg'];
	$urut     	= $_GET['urut'];
	$user		= $_GET['user'];
	$nafile 	= 'rekappj_'.$user;

	$sql2	= mysql_query("SELECT * FROM company");
	$r2		= mysql_fetch_assoc($sql2);
	$kop1 	= $r2['nama1'];
	$kop2 	= $r2['nama2'];
	$kop3 	= $r2['alamat'];

	$content = "<b><li>$kop1</li></b>
		<li>$kop2</li>
		<li>$kop3</li>
		<hr>
		<b><li>REKAPITULASI PENJUALAN BARANG DAGANGAN</li>
		<li>TANGGAL : ".jin_date_str($tglawal)." S/D ".jin_date_str($tglakhir)."</li></b>
		<br>
	<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($urut=='kode')
			$sql= mysql_query("SELECT * FROM $nafile ORDER BY kode_st ");
		else
			$sql= mysql_query("SELECT * FROM $nafile ORDER BY jumlah desc ");
		
		$no=1;
		$tjumlah=0;
		while($r=mysql_fetch_array($sql)){
			$jumlah=$r['jumlah']+$r['jumlah1']+$r['jumlah2']+$r['jumlah3'];
			
			$content .= "<tr>
				<td align='center'>$no</td>
				<td align='center'>$r[kode_st]</td>
				<td>$r[nama_st]</td>
				<td>$r[barcode]</td>
				<td>$r[satuan]</td>
				<td align='right'>$r[jml_unit]</td>			
				<td align='right'>".number_format($jumlah)."</td>
			</tr>";
			$tjumlah=$tjumlah+$jumlah;
			$no++;
		}
		$content .= "<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>";
	
	header("Content-type: application/x-msdownload");
	header("Content-Disposition: attachment; filename=rekappjl_$tglakhir.xls");
	header("Pragma: no-cache");
	header("Expires: 0");
	echo $content;
?>