<script type="text/javascript">	
	window.print();
</script>
<?php
	include '../../inc/inc.koneksi.php';	
	include '../../inc/fungsi_tanggal.php';

	$tgl_awal	= $_GET['tgl_awal'];
	$tgl_akhir	= $_GET['tgl_akhir'];
	$gudang		= $_GET['gudang'];
	
	if($gudang=='Gudang') $cabang='GUDANG PUSAT';
	else{
	    $sql2= mysql_query("SELECT * FROM cabang WHERE kode_cab='$gudang'");
	    $r2	 = mysql_fetch_assoc($sql2);
	    $cabang=$r2['nama_cab'];
	}

	$sql2= mysql_query("SELECT * FROM company");
	$r2	 = mysql_fetch_assoc($sql2);
	$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:9px arial;line-height:80%'>$kop2</td>
		</tr>
		<tr>
			<td style='font:9px arial;line-height:80%'>$kop3</td>
		</tr>
	</table>

	<table width='100%'>
		<tr>
			<td style='font:12px arial;line-height:80%' align='center'><b>DAFTAR STOK OPNAME</td>
		</tr>
		<tr>
			<td style='font:12px arial;line-height:80%' align='center'><b>TANGGAL : ".jin_date_str($tgl_awal)." S/D ".jin_date_str($tgl_akhir)."</b></td>
		</tr>
		<tr>
			<td style='font:12px arial;line-height:80%' align='center'><b>GUDANG : $cabang</b></td>
		</tr>
	</table>		
	
	<table width='100%' style='font:9px arial'>
		<tr>
			<th style='border-top:double 1px;border-bottom:double 1px'>No.</th>
			<th style='border-top:double 1px;border-bottom:double 1px'>Kode</th>
			<th style='border-top:double 1px;border-bottom:double 1px'>Nama Barang</th>
			<th style='border-top:double 1px;border-bottom:double 1px'>Satuan</th>
			<th style='border-top:double 1px;border-bottom:double 1px'>Harga Pokok</th>
			<th style='border-top:double 1px;border-bottom:double 1px'>Jml. Stok</th>			
			<th style='border-top:double 1px;border-bottom:double 1px'>Jml. Opname</th>
			<th style='border-top:double 1px;border-bottom:double 1px'>Selisih</th>
			<th style='border-top:double 1px;border-bottom:double 1px'>Nilai Selisih</th>
			<th style='border-top:double 1px;border-bottom:double 1px'>Posting</th>
		</tr>";
		$query1 = mysql_query("SELECT * FROM st_opname WHERE tanggal BETWEEN '$tgl_awal' AND '$tgl_akhir' AND gudang='$gudang' GROUP BY kode_op");
		
		$no=1;
		$tnilai=0;
		$jml=0;
		
		while($data1=mysql_fetch_array($query1)){
			$kodeop = $data1['kode_op'];
			echo "<tr>
				<td></td>
				<td></td>
				<td><b>$data1[kode_op] - ".jin_date_str($data1['tanggal'])."</b></td>
				<td><b>Gudang : $data1[gudang]</b></td>
			</tr>";
			$query = mysql_query("SELECT * FROM st_opname WHERE kode_op='$kodeop' ORDER BY kode_st");
			$snilai = 0;
			$no=1;
			
			while($data=mysql_fetch_array($query)){
				echo "<tr>
					<td align='center' align='center' style='line-height:80%'>$no</td>
					<td align='center' style='line-height:80%'>$data[kode_st]</td>
					<td style='line-height:80%'>$data[nama_st]</td>
					<td style='line-height:80%'>$data[satuan]</td>
					<td align='right' style='line-height:80%'>".number_format($data['hg_beli'],0)."</td>
					<td align='right' style='line-height:80%'>".number_format($data['jml_stok'],2)."</td>
					<td align='right' style='line-height:80%'>".number_format($data['jml_opn'],2)."</td>
					<td align='right' style='line-height:80%'>".number_format($data['jml_sls'],2)."</td>
					<td align='right' style='line-height:80%'>".number_format($data['nilai_sls'],0)."</td>
					<td align='center' style='line-height:80%'>$data[posting]</td>
				</tr>";
				$no++;
				$jml++;
				$snilai=$snilai+$data['nilai_sls'];
			}
			
			echo "<tr>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td></td>
				<td align='right'>Jumlah</td>
				<td align='right'>".number_format($snilai,0)."</td>
			</tr>";	
			$tnilai=$tnilai+$snilai;
		}
		echo "<tr></tr>
		<tr>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td></td>
			<td align='right'>Total</td>
			<td align='right'>".number_format($tnilai,0)."</td>
		</tr>
	</table>
	<table width='100%'>
		<tr>
			<td>Jumlah data : $jml</td>
		</tr>
	</table>";
?>