<script type="text/javascript">	
	window.print();
</script>
<?php
	include '../../inc/inc.koneksi.php';	
	include '../../inc/fungsi_tanggal.php';
	
	$cari		= $_GET['cari'];
	$gdasl   	= $_GET['gdasl'];
	$tgl_awal 	= $_GET['tgl_awal'];
	$tgl_akhir	= $_GET['tgl_akhir'];
	
	if(!empty($gdasl)){
	    $query2 = mysql_query("SELECT * FROM cabang WHERE kode_cab='$gdasl'");
	    $r2=mysql_fetch_assoc($query2);    
	    $cabang=$r2['nama_cab'];
	}
	
	$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:11px arial;line-height:80%'>$kop2</td>
		</tr>
		<tr>
			<td style='font:11px arial;line-height:80%'>$kop3</td>
		</tr>
	</table>

	<table width='100%'>
		<tr>
			<td style='font:13px arial;line-height:75%' align='center'><b>REKAPITULASI MUTASI BARANG</td>
		</tr>
		<tr>
			<td style='font:13px arial;line-height:75%' align='center'><b>TANGGAL  ".jin_date_str($tgl_awal)." S/D ".jin_date_str($tgl_akhir)."</td>
		</tr>";
		if(!empty($gdasl)){
		    echo "<tr>
			    <td style='font:13px arial;line-height:75%' align='center'><b>GUDANG ASAL : $cabang</td>
		    </tr>";
		}
	echo "</table>
	<br>
	
<table width='100%' border='1' style='border-collapse:collapse; font:12px arial'>
	<tr>
		<th>No.</th>
		<th>Kode</th>
		<th>Nama Barang</th>
		<th>Jml.Unit</th>
		<th>Satuan</th>
		<th>Keterangan</th>
	</tr>";
	
	if(!empty($cari)){
	    if(!empty($gdasl))
		    $sql1= mysql_query("SELECT kode_rm,tanggal,gd_asal,petugas,batal FROM retur_mbr WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND gd_asal='$gdasl' AND (nama_st LIKE '%$cari%' OR kode_st LIKE '%$cari%') AND posting='P' GROUP BY kode_rm");
        else
            $sql1= mysql_query("SELECT kode_rm,tanggal,gd_asal,petugas,batal FROM retur_mbr WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND (nama_st LIKE '%$cari%' OR kode_st LIKE '%$cari%') AND posting='P' GROUP BY kode_rm");
	}
	else{
		if(!empty($gdasl))
			$sql1= mysql_query("SELECT kode_rm,tanggal,gd_asal,petugas,batal FROM retur_mbr WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND gd_asal='$gdasl' AND posting='P' GROUP BY kode_rm");
		else
			$sql1= mysql_query("SELECT kode_rm,tanggal,gd_asal,petugas,batal FROM retur_mbr WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND posting='P' GROUP BY kode_rm");
	}
    
	while($r1=mysql_fetch_array($sql1)){
		$koderm	= $r1['kode_rm'];
		$batal	= $r1['batal'];
		
		echo "<tr>
			<td></td>
			<td><b>No.Bukti :</b></td>
			<td><b>$r1[kode_rm] - ".jin_date_str($r1['tanggal'])."</b></td>
			<td><b>Gd. Asal : $r1[gd_asal]</b></td>
            <td><b>Petugas : $r1[petugas] </b></td>
			<td><b>-- $r1[batal]</b></td>
		</tr>";
		
		if($batal==''){
			if(!empty($cari))
				$sql = mysql_query("SELECT * FROM retur_mbr WHERE kode_rm='$koderm' AND (nama_st LIKE '%$cari%' OR kode_st LIKE '%$cari%') ORDER BY no_urut");
			else
				$sql = mysql_query("SELECT * FROM retur_mbr WHERE kode_rm='$koderm' ORDER BY no_urut");
			$no=1;
			$sjumlah=0;
			while($r=mysql_fetch_array($sql)){			
				echo "<tr>
				    <td align='center'>$no</td>
				    <td>$r[kode_st]</td>
				    <td>$r[nama_st]</td>
				    <td align='center'>".number_format($r['jml_unit'],0)."</td>
				    <td>$r[satuan]</td>
				    <td>$r[keterangan]</td>
				</tr>";
				$no++;
			}
			echo "<tr></tr>";
		}
	}
echo "</table>

</div>";
?>