<script type="text/javascript">
    $(function() {
        $("#theList tr:even").addClass("stripe1");
        $("#theList tr:odd").addClass("stripe2");

        $("#theList tr").hover(
            function() {
                $(this).toggleClass("highlight");
            },
            function() {
                $(this).toggleClass("highlight");
            }
        );
    });
</script>

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

	$tgl_awal	= $_GET['tgl_awal'];
	$tgl_akhir	= $_GET['tgl_akhir'];
	$urut     	= $_GET['urut'];
	$user		= $_GET['user'];
	$nafile 	= 'rekappj_'.$user;

	mysql_query("CREATE TABLE $nafile LIKE lap_jual");
	mysql_query("DELETE FROM $nafile WHERE 1");

	$sql1= mysql_query("SELECT kode_st,nama_st,barcode,satuan,sum(jml_unit) as tunit,sum(jumlah) as tjumlah FROM faktur_pjt WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' GROUP BY kode_st");
	$row1=mysql_num_rows($sql1);
	
	if($row1>0){	
		while($r1=mysql_fetch_array($sql1)){
			$kodest	=$r1['kode_st'];
			$namast	=$r1['nama_st'];
			$barcode=$r1['barcode'];
			$satuan	=$r1['satuan'];
			$tunit	=$r1['tunit'];
			$tjumlah=$r1['tjumlah'];
			
			mysql_query("INSERT INTO $nafile (kode_st,nama_st,barcode,satuan,tgl_awal,tgl_akhir,jml_unit,jumlah,hpp,laba,margin) VALUES('$kodest','$namast','$barcode','$satuan','$tgl_awal','$tgl_akhir','$tunit','$tjumlah','0','0','0')");
		}
	}
	
echo "<div id='info'>	
	<table id='theList' width='100%'>
		<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)){
			
			echo "<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($r['jumlah'])."</td>
			</tr>";
			$tjumlah=$tjumlah+$r['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>";
echo "</div>";
?>