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

	$tgl_awal = $_GET['tgl_awal'];
	$tgl_akhir= $_GET['tgl_akhir'];
	$user 	  = $_GET['user'];
	$total=0;
	$no=0;

	$content = "<b><li>REKAP PENJUALAN USER $user</li>
		<li>TANGGAL : ".jin_date_str($tgl_awal)." S/D ".jin_date_str($tgl_akhir)."</li></b>
		<br>
	
		<table width='390' border='1' style='border-collapse:collapse'>
		<tr>
			<th>No.</th>
			<th>Kode Barang</th>
			<th>Nama Barang</th>
			<th>Satuan</th>
			<th>Jumlah Unit</th>			
			<th>Total Harga</th>
		</tr>";
		
		$query	= "SELECT kode_st,nama_st,satuan,sum(jml_unit) as totunit,sum(jumlah) as totjumlah FROM faktur_pj 
			WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND user='$user'	AND batal='' GROUP BY kode_st	";
		$data	= mysql_query($query);
		
		while($r_data=mysql_fetch_array($data)){		
			$content .= "<tr>	
				<td align='center'>$no</td>
				<td align='center'>$r_data[kode_st]</td>
				<td>$r_data[nama_st]</td>
				<td align='center'>$r_data[satuan]</td>
				<td align='right'>$r_data[totunit]</td>			
				<td align='right'>$r_data[totjumlah]</td>				
			</tr>";
			$total=$total+$r_data[totjumlah];
			$no++;
		}
		
		$content .= "<tr>
			<td></td>
			<td></td>
			<td></td>			
			<td></td>
			<td align='right'>Total</td>
			<td align='right'>$total</td>
		</tr>";
		
		$content .= "</table>";
			
		header("Content-type: application/x-msdownload");
		header("Content-Disposition: attachment; filename=rekap_pjl.xls");
		header("Pragma: no-cache");
		header("Expires: 0");
		echo $content;
?>
