<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';
include '../../inc/fungsi_tanggal.php';

$kode	= $_GET['kode'];
$gudang	= $_GET['gudang'];
$tglawal= $_GET['tglawal'];
$tglakhir=$_GET['tglakhir'];
	
if($gudang=='Gudang') $cabang=$gudang;
else{
    $query2 = mysql_query("SELECT * FROM cabang WHERE kode_cab='$gudang'");
    $r2	=mysql_fetch_assoc($query2);
    $cabang=$r2['nama_cab'];
}

$query2 = mysql_query("SELECT * FROM stock WHERE kode_st='$kode'");
$r2	=mysql_fetch_assoc($query2);
$namast=$r2['nama_st'];
$satuan=$r2['satuan'];

if($gudang=='Gudang')
	$jmlstok=$r2['jml_stokb'];
else
	$jmlstok=$r2['jml_stok'];
	
$query1 = mysql_query("SELECT kode_st,sum(masuk) as jmasuk,sum(keluar) as jkeluar FROM rekap_mbr WHERE tanggal>='$tglawal' AND kode_st='$kode' AND gudang='$gudang' AND batal='' GROUP BY kode_st ");
$r1=mysql_fetch_assoc($query1);
$jmasuk=$r1['jmasuk'];
$jkeluar=$r1['jkeluar'];
$stawal=$jmlstok-$jmasuk+$jkeluar;
$sisa  =$stawal;

$jml   =0;

echo "<table>
		<tr>
			<td>Persediaan</td>
			<td>: <b>$kode - <b>$namast</b></td>
			<td width='2%'></td>
			<td>Tanggal</td>
			<td>: <b>".jin_date_str($tglawal)." s/d ".jin_date_str($tglakhir)."</b></td>
		</tr>
		<tr>
			<td>Gudang</td>
			<td>: <b>$cabang</b></td>
			<td width='2%'></td>
			<td>Stok Awal</td>
			<td>: <b>".number_format($stawal,2)." $satuan</b></td>				
		</tr>
	</table>";
	
echo "<table id='theList' width='100%'>
		<tr>
			<th>No.</th>
			<th>Tanggal</th>
			<th>Nomor Bukti</th>
			<th>Kode Trans</th>
			<th>Keterangan</th>
			<th>Masuk</th>
			<th>Keluar</th>
			<th>Harga</th>
			<th>Sisa</th>
		</tr>";
		
		$jmasuk =0;
		$jkeluar=0;		
		
		$query= mysql_query("SELECT * FROM rekap_mbr WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND kode_st='$kode' AND gudang='$gudang' AND batal='' ORDER BY tanggal ");
		$no=1;
		while($r=mysql_fetch_array($query)){
			$sisa=$sisa+$r['masuk']-$r['keluar'];
			
			echo "<tr>
				<td>$no</td>
				<td>".jin_date_str($r['tanggal'])."</td>
				<td>$r[no_bukti]</td>
				<td>$r[kode_tr]</td>
				<td>$r[keterangan]</td>
				<td align='right'>".number_format($r['masuk'],2)."</td>
				<td align='right'>".number_format($r['keluar'],2)."</td>
				<td align='right'>".number_format($r['harga'],2)."</td>
				<td align='right'>".number_format($sisa,2)."</td>
			</tr>";			
			$jmasuk=$jmasuk+$r['masuk'];
			$jkeluar=$jkeluar+$r['keluar'];
			$jml++;
			$no++;
		}	
		echo "<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Jumlah </td>
			<td align='right'>".number_format($jmasuk,2)."</td>
			<td align='right'>".number_format($jkeluar,2)."</td>
		</tr>
	</table>";
?>