<script type="text/javascript">	
	window.print();
</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;
    $query2 = mysql_query("SELECT * FROM stock WHERE kode_st='$kode' AND kode_cab='01'");
    $r2	=mysql_fetch_assoc($query2);
    $namast=$r2['nama_st'];
    $satuan=$r2['satuan'];
    $jmlstok=$r2['jml_stokb'];
}
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' AND kode_cab='$gudang'");
    $r2	=mysql_fetch_assoc($query2);
    $namast=$r2['nama_st'];
    $satuan=$r2['satuan'];
    $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;

	$query2 = mysql_query("SELECT * FROM company");
	$r2=mysql_fetch_assoc($query2);
	$kop1 = $r2['nama1'];
	$kop2 = $r2['nama2'];
	$kop3 = $r2['alamat'];
	
	echo "<table width='100%'>
		<tr>
			<td style='font:11px arial;line-height:80%'><b>$kop1</b></td>
		</tr>
		<tr>
			<td style='font:10px arial;line-height:80%'>$kop2</td>
		</tr>
		<tr>
			<td style='font:10px arial;line-height:80%'>$kop3</td>
		</tr>
	</table>

	<table width='100%'>
		<tr>
			<td style='font:13px arial;line-height:75%' align='center'><b>KARTU PERSEDIAAN BARANG</td>	
		</tr>
		<tr>
		    <td style='font:13px arial;line-height:75%' align='center'><b>GUDANG : $cabang</td>
		</tr>
		<tr>
			<td style='font:13px arial;line-height:75%' align='center'><b>Periode  ".jin_date_str($tglawal)." S/D ".jin_date_str($tglakhir)."</td>
		</tr>
	</table>
	<br>
	<table width='100%' style='font:12px arial'>
		<tr>
			<td>Persediaan : <b>$kode - $namast</b></td>
			<td>Stok Awal : <b>".number_format($stawal,2)." $satuan</b></td>				
		</tr>
	</table>
	
	<table width='100%' border='1' style='border-collapse:collapse;font:12px arial'>
		<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>";
?>
<script type="text/javascript">	
	history.back();
</script>