<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'];
	$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_pj  WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND concat(substr(waktu,12,8)) BETWEEN '11:00:00' AND '15:00:00' AND batal='' 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'];
			
			if($tjumlah>6000000000){
				$jumlah=2000000000;	
				$jumlah1=2000000000;
				$jumlah2=2000000000;
				$jumlah3=$tjumlah-6000000000;			
			}else if($tjumlah>4000000000){
				$jumlah=2000000000;
				$jumlah1=2000000000;				
				$jumlah2=$tjumlah-4000000000;
				$jumlah3=0;
			}else if($tjumlah>2000000000){
				$jumlah=2000000000;				
				$jumlah1=$tjumlah-2000000000;
				$jumlah2=2000000000;				
				$jumlah3=0;
			}else{
				$jumlah=$tjumlah;
				$jumlah1=0;
				$jumlah2=0;
				$jumlah3=0;				
			}
			
			mysql_query("INSERT INTO $nafile (kode_st,nama_st,barcode,satuan,tgl_awal,tgl_akhir,jml_unit,jumlah,jumlah1,jumlah2,jumlah3) VALUES('$kodest','$namast','$barcode','$satuan','$tgl_awal','$tgl_akhir','$tunit','$jumlah','$jumlah1','$jumlah2','$jumlah3')");
		}
	}

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>";
				
		$sql= mysql_query("SELECT * FROM $nafile ORDER BY kode_st ");
		
		$no=1;
		$tjumlah=0;
		while($r=mysql_fetch_array($sql)){
			$jumlah=$r['jumlah']+$r['jumlah1']+$r['jumlah2']+$r['jumlah3'];
			
			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($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>";
echo "</div>";
?>