<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'];
$tglawal= $_GET['tglawal'];
$tglakhir= $_GET['tglakhir'];

$sql2 	= "SELECT * FROM stock WHERE kode_st='$kode' ORDER BY kode_st";
$query2 = mysql_query($sql2);
$rows	= mysql_num_rows($query2);

$r2=mysql_fetch_array($query2);
$namast=$r2[nama_st];
$satuan=$r2[satuan];
$jmlstok=$r2[jml_stok];

$sql1 	= "SELECT kode_st,sum(masuk) as jmasuk,sum(keluar) as jkeluar FROM rekap_mbr WHERE tanggal>='$tglawal' AND kode_st='$kode' AND batal='' GROUP BY kode_st ";
$query1 = mysql_query($sql1);
while($r1=mysql_fetch_array($query1)){			
	$jmasuk=$r1[jmasuk];
	$jkeluar=$r1[jkeluar];
}
$stawal=$jmlstok-$jmasuk+$jkeluar;
$sisa  =$stawal;

echo "<table>
			<tr>
				<td>Persediaan</td>
				<td>:</td>
				<td><b>$kode<b></td>
				<td>-</td>
				<td><b>$namast</b></td>
				<td width='2%'></td>
				<td>Tanggal :</td>				
				<td><b>".jin_date_str($tglawal)."</b></td>
				<td>s/d</td>
				<td><b>".jin_date_str($tglakhir)."</b></td>	
			</tr>
			<tr>
				<td>Stok Awal</td>
				<td>:</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>Sisa</th>
			</tr>";
		
			$jmasuk =0;
			$jkeluar=0;
			$no=1;
			
			$sql	= "SELECT * FROM rekap_mbr WHERE tanggal BETWEEN '$tglawal' AND '$tglakhir' AND kode_st='$kode' AND batal='' ORDER BY tanggal ";
			$query	= mysql_query($sql);
			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 align='center'>$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($sisa,2)."</td>
				</tr>";			
				$jmasuk=$jmasuk+$r[masuk];
				$jkeluar=$jkeluar+$r[keluar];
				$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>";
?>